• fph (unregistered) in reply to Anonymous Coward
    Anonymous Coward:
    The real WTF is that this batch file fails to calculate pi = 4*arctan(1)
    Not a WTF. 4*arctan(1) expands to 4(1-1/3+1/5-...), which is painfully slow to converge if compared to the "usual" 239 formula.
  • Anon (unregistered) in reply to brouski

    Damn you! I almost LOL'd which would have given away that fact that I am not actually working!

  • Anon (unregistered) in reply to brouski
    brouski:
    My god, I type like I've got two raccoons by the tail and I'm swinging them onto the keyboard
    And someday I may even learn to quote properly!
  • (cs) in reply to Zost
    Zost:
    SINE! COSINE! COSINE! SINE! Three-point-one-four-one-five-nine!

    GO PI!

    When I was in middle school, some kid in our class wrote this limerick:

    A mathematician named Sy Was always tortured by pi. He ran out the door Yelling, "Three point one four!" And hung himself by his own tie.

    What does this have to do with batch files? Nothing.

  • (cs) in reply to Trevel
    Trevel:
    Way back when taking a computer course, we were all supposed to write a tutorial on some random part of computing. I was assigned batch files for some reason.

    Naturally, I wrote it as a batch file. (Excepting a small program I threw together to make up for the lack of any input-commands in DOS at the time.) Compared to the 'program' I'd written to pull things in and out of archive to save space on our 10M hard drive at home, it was pretty simple.

    echo Press F6 prior to pressing ENTER to complete your entry type CON > puke.txt

    :)

  • GOTO Hell (unregistered) in reply to hatterson
    hatterson:
    Scott:
    The real WTF is everyone praising this code that uses a ton of GOTO commands...

    Uhhhh....this is a batch file. use of GOTO is perfectly fine.

    It might be necessary to use GOTO, but it is not fine. Even assemblers have jump to subroutine to save the return location.

  • GeometeryFun (unregistered) in reply to JamesQMurphy
    JamesQMurphy:
    Zost:
    SINE! COSINE! COSINE! SINE! Three-point-one-four-one-five-nine!

    GO PI!

    When I was in middle school, some kid in our class wrote this limerick:

    A mathematician named Sy Was always tortured by pi. He ran out the door Yelling, "Three point one four!" And hung himself by his own tie.

    What does this have to do with batch files? Nothing.

    Now I can mention Cheif Sohcahtoa or that an occupied bathroom in an airplane is a 'high-pot-in-use'.

  • (cs) in reply to freespace
    freespace:
    The infinite series expansion of arctan is not a power series, and there is nothing wrong with expanding a power series with x=1 either, provided it converges for x=1.
    It is a power series, but you're right that there's nothing wrong with expanding it with x=1. However, the tacit point was that it's a stupid thing to do because the convergence is horribly slow. Now you could say this is about stupid coding tricks, so using x=1 would be appropriate.
  • Dan (unregistered) in reply to GOTO Hell
    GOTO Hell:
    hatterson:
    Scott:
    The real WTF is everyone praising this code that uses a ton of GOTO commands...

    Uhhhh....this is a batch file. use of GOTO is perfectly fine.

    It might be necessary to use GOTO, but it is not fine. Even assemblers have jump to subroutine to save the return location.

    Which is short for "stash the next PC in the designated register and GOTO"

  • Jeremy (unregistered)

    I've had to do quite a bit of batch programming at my current job. I've considered putting it on my resume.

    On a bet, I wrote a simple version control system using nothing but batch files and utilities that shipped with XP. It had branching and a rough way of doing labels. If you paused it in the middle and looked at the environment variables, there were about 80 extra just for the bat file.

  • (cs)

    All the "why?" comments apply just as well to the math part of the post as they do to the batch part of the post.

    The answer: /because I can./

  • Daniel (unregistered) in reply to Otto
    Otto:
    ... I can't explain why, but that code makes me want to punch something very, very hard.
    Like a Koala bear? Then maybe it is time for a new job.
  • (cs)

    Koalas aren't bears, except when asking "how much can a koala bear?"

  • Anonymous coward (unregistered)

    so, the wtf is that someone knows how to program in batch?

  • (cs) in reply to JamesQMurphy
    JamesQMurphy:
    Zost:
    SINE! COSINE! COSINE! SINE! Three-point-one-four-one-five-nine!

    GO PI!

    When I was in middle school, some kid in our class wrote this limerick:

    A mathematician named Sy Was always tortured by pi. He ran out the door Yelling, "Three point one four!" And hung himself by his own tie.

    What does this have to do with batch files? Nothing.

    A mathematician named Klein Thought the mobius strip was divine He said "If you glue the edges of two you get a neat bottle like mine."

    What does this have to do with anything? Nothing. Happy Friday all...

  • Picard (unregistered) in reply to JamesQMurphy
    JamesQMurphy:
    Zost:
    SINE! COSINE! COSINE! SINE! Three-point-one-four-one-five-nine!

    GO PI!

    When I was in middle school, some kid in our class wrote this limerick:

    A mathematician named Sy Was always tortured by pi. He ran out the door Yelling, "Three point one four!" And hung himself by his own tie.

    What does this have to do with batch files? Nothing.

    What do win batch files have to do with coding? Nothing.

  • Clicky McClicker (unregistered) in reply to swordfishBob
    swordfishBob:
    Koalas aren't bears, except when asking "how much can a koala bear?"
    Perhaps a real hard punch to the face?
  • (cs)

    I've just found a genuine use for this wonderful thing ... as a benchmark.

    I copied it (into Notepad, naturally. I thought of using DOS edit, but that's waaaay too feature-bloated) and ran it on my very sickly XP Home machine whilst downloading a Fedora DVD ISO. It took half the time you quote. Good grief, man, what are you running on? DOS emulation inside a Commodore 64?

    At some point in HHGttG, Ford Prefect defends Zaphod with the following line:

    "There's a thin line between genius and insanity."

    I think we've just found the thin line.

    Captcha: Miniscule. Is that related to a word in the English language, perhaps?

  • (cs) in reply to jimlangrunner
    jimlangrunner:
    Rev. Creflo Baller:
    Hats off to the coder, brilliant work!
    I think that should be
    Hats off to the coder, brillant work!
    to fit in with the general them.

    If you are sticking to the "them" then you are insulting Don by calling his work "brillant."

  • Frost (unregistered) in reply to pink_fairy
    pink_fairy:
    I've just found a genuine use for this wonderful thing ... as a benchmark.

    I copied it (into Notepad, naturally. I thought of using DOS edit, but that's waaaay too feature-bloated)

    Poseur. I opened a dos prompt, typed echo > pi.bat and pasted the text, which i'd copied from the post, hit ^Z.

  • (cs) in reply to Frost
    Frost:
    pink_fairy:
    I've just found a genuine use for this wonderful thing ... as a benchmark.

    I copied it (into Notepad, naturally. I thought of using DOS edit, but that's waaaay too feature-bloated)

    Poseur. I opened a dos prompt, typed echo > pi.bat and pasted the text, which i'd copied from the post, hit ^Z.

    Poseur? Moi?

    With an authentic "poseur" keyboard, one would have to hit ^W. That's because an authentic "poseur" would use only the finest, Executive, keyboard: hand-crafted from extruded Columbian polyvinyl.

    Sadly, the drivers for these things are shit. The keyboard layout is "qwertuiop," but us poseurs gotta know our "azerty" before we are True Masters of Da Batty Filez.

    (Don't even get me started on Mexican IBM keyboards.)

  • Stephen (unregistered) in reply to pitchingchris
    pitchingchris:
    You can't go by the fact that you only call 1 line that its any better. I can wrap up something into a console app, and the code behind it is much more intensive, and you'd never know the difference.
    But by creating that console app, you will have created new software to maintain. In judging the complexity of a solution, you want to take into account how standardized the software is. In this case, both NET USE and VBScript are shipped with every modern copy of the world's monopoly operating system. Grandparent was arguing that the 1-line NET USE was superior to the 2-line VBScript, and in general I'd probably agree with him (though it's a trivial example).
  • (cs) in reply to Picard
    Picard:
    JamesQMurphy:
    Zost:
    SINE! COSINE! COSINE! SINE! Three-point-one-four-one-five-nine!

    GO PI!

    When I was in middle school, some kid in our class wrote this limerick:

    A mathematician named Sy Was always tortured by pi. He ran out the door Yelling, "Three point one four!" And hung himself by his own tie.

    What does this have to do with batch files? Nothing.

    What do win batch files have to do with coding? Nothing.

    A reasonable definition of "coding" -- which, btw, elides concepts such as "agile" (I am not a monkey, but I will act as one if you pay me enough), "enterprisey", "'nuff said" -- is Turing Complete. With or without the infinite roll of paper and the pencil/marker.

    I submit that this -- in the best possible sense of the adjective -- absurd .BAT file is an excellent proponent of the theory that the DOS command language is Turing Complete.

    It's still borderline insane, though.

  • John Bollocks (unregistered) in reply to Smash King

    Could you use SETLOCAL and ENDLOCAL to create environmental variables that could be used by calling batches? I assume that the only kind of function for the Windows Batch language is to call another batch file (using EXIT to pass a return code, and %1, %2, etc to access the arguments).

  • anon (unregistered) in reply to pitchingchris
    pitchingchris:
    J.R. Blood:
    I LOVE batch files, and this one just rocks.

    I still prefer using batch for simple things, like... oh mapping drive letters to network shares. You can do it in one line and it's simple.

    NET USE T: "\SERVER1\Team Design"

    Ever do it in a VBScript file? (NOTE: Copy-n-paste from someone else's VBS file, including the typo in the server name.)

    Set wshNetwork = CreateObject("WScript.Network") wshNetwork.MapNetworkDrive "t:", "\sever1\team design"

    Job security by complexity. There's a WTF for ya.

    I don't agree with your assessment because of what it represents. net use is calling some code to do the work, underneath the scenes, there are many more lines of code that execute.

    And what do you think the WScript.Network object with it's MapNetworkDrive method are?

  • (cs)

    And to think I just wrote small programs that performed arithmetic on their parameters and returned the result, which could then be found in the ERRORLEVEL variable.

  • (cs) in reply to GeometeryFun
    GeometeryFun:
    JamesQMurphy:
    Zost:
    SINE! COSINE! COSINE! SINE! Three-point-one-four-one-five-nine!

    GO PI!

    When I was in middle school, some kid in our class wrote this limerick:

    A mathematician named Sy Was always tortured by pi. He ran out the door Yelling, "Three point one four!" And hung himself by his own tie.

    What does this have to do with batch files? Nothing.

    Now I can mention Cheif Sohcahtoa or that an occupied bathroom in an airplane is a 'high-pot-in-use'.

    My favourite is solving logarithmic equations by "dropping a log."

  • (cs) in reply to freespace
    freespace:
    The infinite series expansion of arctan is not a power series

    Funny that you would say that because the algorithm used in the batch file looks exactly like the canonical arctan power series to me.

    freespace:
    and there is nothing wrong with expanding a power series with x=1 either, provided it converges for x=1.

    Only if by "nothing wrong" you mean that logarithmic (vs. linear) convergence is acceptable. I once wrote an assembler program that calculated the first 4000 digits of Pi (on a 486) using the same power series. Took a few minutes to complete, operating directly on the decimal representation. Figuring out how long this program would have taken using x=1 is left as an exercise for the reader.

  • Jakes (unregistered) in reply to GOTO Hell
    GOTO Hell:
    hatterson:
    Scott:
    The real WTF is everyone praising this code that uses a ton of GOTO commands...

    Uhhhh....this is a batch file. use of GOTO is perfectly fine.

    It might be necessary to use GOTO, but it is not fine. Even assemblers have jump to subroutine to save the return location.

    Pftt, subroutines in Win32 batch files. Try this

    @echo off call :subroutine echo World goto :eof

    :subroutine echo Hello goto :eof

  • Jakes (unregistered) in reply to Jakes
    Jakes:
    Pftt, subroutines in Win32 batch files. Try this

    @echo off call :subroutine echo World goto :eof

    :subroutine echo Hello goto :eof

    Gawd, I should learn to look at the OP instead of the comments. But my point is GOTO :eof acts as "return from subroutine", instead of your usual jumps.

    Anyhows, I get my coat..

  • VegeBrain (unregistered)

    I can't figure out if this is brilliant or insane. I've long considered Windows batch files torture and now I have yet another reason not to change my view.

    PS: What's you're next project? Sleeping in an Iron Maiden? Pushing pins underneath your fingernails? Vacationing in a Stalin era Gulag? Enquiring minds want to know!

  • Joey (unregistered) in reply to VegeBrain
    VegeBrain:
    I can't figure out if this is brilliant or insane. I've long considered Windows batch files torture and now I have yet another reason not to change my view.

    PS: What's you're next project? Sleeping in an Iron Maiden? Pushing pins underneath your fingernails? Vacationing in a Stalin era Gulag? Enquiring minds want to know!

    Hey, at least batch programming makes you think a bit and is relaxing. And much less painful than Java or Perl :P

  • Paxinum (unregistered)

    Hmm... 20 seconds... I believe I can produce the same number of decimals in the same time, with no help of digital means.

  • (cs) in reply to Joey
    Joey:
    Hey, at least batch programming makes you think a bit and is relaxing. And much less painful than Java or Perl :P
    Perhaps, but only because writing a complex program in batch scripts is sufficiently hard that everyone with even a shred of sanity tends to give up early and switch to something better suited (where one can last long enough to get to the deeper pains).
  • Spongebob (unregistered)

    TRWTF is he should have used BPP

  • Spongebob (unregistered)

    Gah..BBP I mean...stupid typos

  • Bare (unregistered) in reply to swordfishBob
    swordfishBob:
    Koalas aren't bears, except when asking "how much can a koala bear?"

    Koalas are not bears per se, but they are commonly referred to as "Koala Bears"

  • Ignavus Anonymus (unregistered) in reply to ajlb
    ajlb:
    calculated primes using a parser for LATIN
    probably perligata
  • fdizzle (unregistered) in reply to JamesQMurphy
    JamesQMurphy:
    Zost:
    SINE! COSINE! COSINE! SINE! Three-point-one-four-one-five-nine!

    GO PI!

    When I was in middle school, some kid in our class wrote this limerick:

    A mathematician named Sy Was always tortured by pi. He ran out the door Yelling, "Three point one four!" And hung himself by his own tie.

    What does this have to do with batch files? Nothing.

    LOL I you made me choke on my coffee >< what does that have to do with my Captcha (Saluto)? Everything. >>

  • The hooded claw (unregistered)

    I love it.. its frightening.. but i love it.

  • AdT (unregistered) in reply to swordfishBob
    swordfishBob:
    Koalas aren't bears, except when asking "how much can a koala bear?"

    Every botanist knows that they aren't berries, and they don't have much to do with straw either.

    (Mmmm, I'd love to have some delicious redconoidalpseudocarp pie right now.)

  • (cs) in reply to pink_fairy
    pink_fairy:
    the theory that the DOS command language is Turing Complete.
    It has if and goto. That's sufficient to make it Turing complete, since it's sufficient to simulate a Turing machine.
  • (cs) in reply to Alin
    Alin:
    Rev. Creflo Baller:
    Hats off to the coder, brilliant work!

    More like "brillant" work!

    No, idiot. This is not "brillant", precisely because it DOES work.

    Don't use in-jokes that you don't understand, kid.

  • (cs)

    Wow, that was all kinds of awesomeness. Well done, Don! I do hope the hole that writing that batch file ripped you healed by now ;)

  • (cs) in reply to m0ffx
    m0ffx:
    pink_fairy:
    the theory that the DOS command language is Turing Complete.
    It has if and goto. That's sufficient to make it Turing complete, since it's sufficient to simulate a Turing machine.
    Well spotted.

    I wish I'd thought of that.

    Particularly relevant when replying to the previous post, as I am led to believe was my point...

  • David (unregistered) in reply to Batchyx
    Batchyx:
    Man, Win32 Batch files is for pussies. Real Men use MS-DOS/win98 batches, which comes without blocks nor even ''integer support''

    MS-DOS is for babies. Real men use PC-DOS v1.0.

  • Dan (unregistered)

    WHAT

    THE

    FUCK

  • Real-modo (unregistered)

    Wow! The most beautiful sculpture ever made from manure.

    It does prove, though, that you can't polish a turd.

  • (cs) in reply to Real-modo
    Real-modo:
    It does prove, though, that you can't polish a turd.
    Actually, you can.
  • Wyrd (unregistered) in reply to DaveK
    DaveK:
    The OP:
    so... now I can do... err....what?

    Well, now I can finally answer that question.

    Well, that give us the 'what', but you failed to answer the bigger question: WHY, in the name of all that's holy, why?

    (Also, "How long, oh Lord?" might be relevant here.)

    The lack of a good "WHY" is a feature not a bug in this case. That's what makes it a good WTF. See Intercal http://en.wikipedia.org/wiki/INTERCAL .

Leave a comment on “Stupid Coding Tricks: A Batch of Pi”

Log In or post as a guest

Replying to comment #:

« Return to Article