• Mr.'; Drop Database -- (unregistered)

    Adding 0.0, on the other hand, is a convenient way to convert an int to a double.

  • Bruce W Cassidy (unregistered)

    Hmmm... I'm wondering if this is a left-over from the fact that if you want a random number between 1 and 10 (rather than 0 to 9) you'd want to add one. Then all you need is someone who doesn't actualy understand why the original code works and just uses it blindly as a pattern. That's fairly common from my experience.

  • Rhywden (unregistered) in reply to Bruce W Cassidy

    Well, sometimes you can even find random() bugs in games like Everquest2.

    Way back, someone posted a conspiracy theory on how the random numbers in EQ2 were skewed. So, to end that argument I created a short in-game makro, did a rand1-10 several thousand times, parsed the logs and did a statistic for every single digit.

    Turned out that the numbers were indeed evenly distributed, except for one small snag: 1 and 10 only appeared half as often as the other numbers.

    That's what you get when you're using Math.round(Math.random()*9+1) instead of Math.floor(Math.random()*10+1)

  • Simon (unregistered) in reply to IT Girl
    IT Girl:
    That's right, those who can do, those who can't teach, and those who can do neither, criticize.

    And since they can neither do, nor teach, they get their criticism utterly wrong.

    How different would this site be, if half the responses didn't demonstrate even greater inability than the original WTF?

  • Quirkafleeg (unregistered) in reply to Me
    Me:
    dtobias:
    Some of those pronunciations are in fact how English pronounced those things before the Great Vowel Shift of around 1500.
    Fortunately, only a few of my professors had been teaching for that long...
    Was one of them called Chronotis?
  • CrushU (unregistered) in reply to Ahto

    Modulo arithmetic is not division and then the remainder. It's easier to think of it as mapping the entire number line into a narrower band of numbers. Mod 5, for example, all numbers must be mapped to 0-4. -1 % 5 = 4.

    Modulo does not work like division, so A * (A div B) + (A mod B) == A will only be true for positive numbers (and 0). Similar, yes, but not exact. -21 % 4 = 3. Add 4 repeatedly until you get a positive number: -21, -17, -13, -9, -5, -1, 3. 21 % 4 = 1. Subtract 4 repeatedly until you get a number 0-3: (similar to above only positive)

    (As an aside, it turns out that if we had a way to see how many additions/subtractions we did to come up with the modulo value, A * (A (mystery) B) + (A mod B) == A would work for all numbers. I'd just had a class on logic and proof where the professor had to define modulo arirthmetic for the non-CS majors.)

  • (cs) in reply to Herby
    Herby:
    On a related note, don't use '-40' as input to a Celsius to Fahrenheit converter.

    But that works great when the order of operations is unexpected, like on the TI-85 (and probably newer TI calculators)

    -40 °C>°F
                    -104
    
    -40 °F>°C
           -4.44444444444
    

    Hint: Conversion has a higher precedence to negation.

  • Stued (unregistered)

    I had a teacher just last semester for C# who told me that when I ask questions I'm challenging her authority.

    I dropped the class. In fact, the school has a perfectly good web design program so I got out of programming there altogether.

  • LoveKnuckle (unregistered) in reply to Stued
    Stued:
    I had a teacher just last semester for C# who told me that when I ask questions I'm challenging her authority.

    I dropped the class. In fact, the school has a perfectly good web design program so I got out of programming there altogether.

    What a skank.

  • Callin (unregistered)

    There's a short circuit all right, but not where the professor thinks it is.

  • anon (unregistered) in reply to Stued
    Stued:
    I had a teacher just last semester for C# who told me that when I ask questions I'm challenging her authority.

    I dropped the class. In fact, the school has a perfectly good web design program so I got out of programming there altogether.

    If you've got the brains to handle programming, you should be able to handle a teacher with an attitude problem. You've certainly got too much brains to waste in web design.

  • Drew (unregistered) in reply to Case

    I'm guessing your probably right. I had more than a few professors screw with me for sleeping.

  • (cs) in reply to Anon
    Anon:
    davedavenotdavemaybedave:
    Either way, it's obvious that logically you cannot be both something and its negation. Whatever X and not-X are, something cannot, by definition, be both at the same time.

    Never studied quantum mechanics did you?

    Until you asked me that, I both had and hadn't. Now, I just haven't. You made me lose my quantum mechanics studies, you bastard.

  • Kempeth (unregistered)

    Ahh this takes me back...

    Our Java Prof's code was ok but he had other quirks. Picture a group of students from all walks of life in a mandatory java introductory class. You've got students like me who started programming on their own like 10 years before attending that school or at least as part of their apprenticeship. "Down" to folks where the closest they've come to programming was shouting at the computer "IF you crash again THEN I'll throw you out of the window!".

    Now in front of that class place a professor who explains Java 101 with at least twice as much jargon and buzzword-babble than your average Voyager episode. That would be enough to throw even the top students into confusion, IF they were still listening after understanding the concept of the day in the first 10 minutes. But they aren't. They are intently staring into their laptops - playing Battlefield 1942 against each other and other students elsewhere in the building.

    So not only has the professor lost most of the class in his progressively more confusing elaborations but he now puts one on top of it by launching into a significantly more complex side issue announcing: "This is for the experts among you..."

    Ahhh. Those were fun days...

    Amazingly, with some lunchtime explanations from us and an admittedly good book most students actually passed that class and even the final exam. I think he finally got around to catering to the right audience during the summer learning weeks before the exams...

  • Weeds (unregistered) in reply to Mr. S.
    Mr. S.:
    SR:
    Anonymouse:
    It doesn't explain the "short-circuit" comment, but it could be that the prof was doing something out of habit. The +0 thing is occasionally used to cast something to an int. I also dimly recall doing something similar to tell the compiler to STFU about a warning.

    If it was a duck-typed language you might get away with that. In Java, an int is an int is an int.

    Except when it's an Integer

    <sings>Little boxes, little boxes, Autoboxes</sings>.

    I hear that in next Java update, Clippy the paperclip will popup and tell you "I autoboxed your int to Integer there, would you like to write a suicide note?".

  • Henning Makholm (unregistered) in reply to CrushU
    CrushU:
    Modulo arithmetic is not division and then the remainder. It's easier to think of it as mapping the entire number line into a narrower band of numbers. Mod 5, for example, all numbers must be mapped to 0-4. -1 % 5 = 4.
    However, % is not a modulus operator. It is the remainder operator. See the Java Language Specification, third edition, section 15.17.3.

    Java does not have a modulus operator (which sucks, but many other popular programming languages suck likewise. So, for that matter, does most machine instruction sets).

  • Daniel Rose (unregistered)

    In my introductory Java class in the university, the professor got a bit mixed up with the immutability of Strings. He said that because they are immutable, you cannot change a String after it has been created, so the folowing code would not work:

    String foo = "foo"; foo = foo + "bar";

    The next lesson, after some students had pointed out that it did work as expected, he conceded that he was wrong and explained what immutability actually meant.

  • The Master (unregistered) in reply to wtf

    [quote user="wtf"][quote user="davedavenotdavemaybedave] Those who teach are those who cannot do. Substitute it in and you get:

    Those who can neither do, nor not do, criticise.

    That is of course equivalent to 'Those who can both do and not do', which is a more comprehensible way to phrase it.[/quote]

    I can both do and not do. I can (for example) both walk and not walk, as the occasion demands. Not at the same time, mind you...[/quote]

    Once there was a cat who could be both alive and not alive, at the same time.

  • Shinobu (unregistered) in reply to RogerInHawaii
    RogerInHawaii:
    Lego:
    do, or not do, there is no try.
    Oh my god I hate it when someone makes that insipid statement.

    After I am done performing the task it is either done or not done. But while I'm working on the task I am trying to accomplish it. I'll give it my all, to the best of my ability. But until it is finally accomplished or I fail, the best I can say is that I am trying. "Try" does not in any way imply that I am putting in less than maximum effort.

    Hear hear. Furthermore, people who quote that don't get the concept of transactions, or error handling for that matter, and are under the delusion that we're all living in a space opera fairy tale.
    Steven Carter:
    The example was almost correct if it was a C program.
    It's declared ‘int n’ not ‘char n’ so you wouldn't have added '0' in C either. C knows that an int is an int just as much as Java does. Besides, what if you need 20-sided dice - return 0-D?

    As for what % should / shouldn't do, here's what % (or mod &c.) actually does:

      % of       Result takes       Like in
    languages       sign of
       44%         Dividend         Java & VB
       28%          Divisor         Lua & Excel
       16%          Either          Fortran & Scheme
        8%  Implementation defined  C & C++
    Taken from Wikipedia, so these figures are as real as a unicorn sliding down a rainbow.
  • The Master (unregistered) in reply to The Master
    wtf:
    davedavenotdavemaybedave:
    Those who teach are those who cannot do. Substitute it in and you get:

    Those who can neither do, nor not do, criticise.

    That is of course equivalent to 'Those who can both do and not do', which is a more comprehensible way to phrase it.

    I can both do and not do. I can (for example) both walk and not walk, as the occasion demands. Not at the same time, mind you...

    Once there was a cat who could be both alive and not alive, at the same time.

  • (cs) in reply to RIT_Warrior
    RIT_Warrior:
    Case:
    To be honest, I think the professor was actually screwing with him for sleeping in class every day. Anyone who was awake heard his explanation that the +0 was just a placeholder for the offset you want in your random number. Then that dumbass wakes up mid-class and asks a retarded question so the prof gave him a retarded joke answer.

    Then when it came to the lab, the professor mocked him even further. I know if I was in that class, I'd have been laughing so hard.

    I had a professor who would do things like that. If someone was asleep and woke up in the middle of class, he would finish his sentence and say something to the effect of "and that's the answer to the super-secret exam question", or something to that effect.

    If someone slept till the end of class, he'd tell everyone to very quietly go out to the hallway, then he would turn off the lights and close the door(he taught night classes). He said he liked to imagine the student waking up at midnight and wondering how the hell they got into a dark classroom with no one around at such an hour.

    Then the student rises and tries to leave. Whilst doing so he falls over some item of furniture, injures himself and is found dead on the morning (of the next working day). The Professor gets charged with criminal endangerment or some such nonsense as faces civil action from the student's family.

    I call BS. Tenured Profs are experts in CYOA.

  • layiat (unregistered) in reply to Herby
    Herby:
    Some Old Guy:
    I had a Chinese professor in college for a course in assembly language. He was ok except when he wanted us to queer the registers.

    MUST remember to turn off L to R converter... (or so the professor should have known)

    Yes, I'm sure queeling the registers was exactly what he had in mind.

  • Sebastien (unregistered) in reply to ari
    ari:
    madjo:
    When I got taught Java, for the first 10 weeks we didn't have any practical lessons. Exams were done on paper without the use of a computer. Yes, that meant writing source code on paper, though most questions were multiple choice type questions. And the programs you were asked to write weren't very long, and pretty easy.

    And the teacher pronounced the names of certain functions weirdly. Sleep for instance was pronounced as "Slape" (as that's how you pronounce sleep in Dutch), and a thread became threed (though I'm not sure why he did that, probably because in some cases ea is pronounced as ee in English (like eat), and he stuck to it)

    It may sounds as an exaggeration, but I assure you it's not.

    Hear hear. Been there, done that. Even in university there are still professors who simply can't pronounce English words correctly. That's not that bad, except when they teach Statistics and Research Methods...

    Leeds University?? Random Greek Lady??

  • Bosshog (unregistered) in reply to Troy
    Troy:
    This is why experience = 10x(degree)
    Woooot! Got both! FTW! Goes up to 11.
  • Venio (unregistered) in reply to Anonymouse
    Anonymouse:
    The +0 thing is occasionally used to cast something to an int.

    yes, in Java_Script_

  • n00dles (unregistered) in reply to Some Guy
    Some Guy:
    [...]

    No. Just, no. Performing modulus division on a negative number always results in a negative number.

    Let's go back to "frist" grade for a moment here, and do some "remainder division".

    21 / 5 = 4R1. Simple. Dividing 5 goes into 21 4 times, leaving 1 leftover unit. Reversing this, we get 5 * 4 + 1 = 21.

    Now, let's add the not-quite-so-frist grade concept of negative numbers into the fray.

    -21 / 5 = X. We already know that we'll get -4, but what remains? The remainder is -1. Dividing a negative number by a positive one cannot result in a positive remainder. Why? Reverse the equation. 5 * -4 + X = -21. X becomes -1. So -21 / 5 = -4R-1. QED.

    I just died a little inside.

  • MSCW (unregistered) in reply to Some Guy
    Some Guy:

    21 / 5 = 4R1. Simple. Dividing 5 goes into 21 4 times, leaving 1 leftover unit. Reversing this, we get 5 * 4 + 1 = 21.

    Now, let's add the not-quite-so-frist grade concept of negative numbers into the fray.

    -21 / 5 = X. We already know that we'll get -4, but what remains? The remainder is -1. Dividing a negative number by a positive one cannot result in a positive remainder. Why? Reverse the equation. 5 * -4 + X = -21. X becomes -1. So -21 / 5 = -4R-1. QED.

    Obviously you making a false assumption (just making -4 out of 4). You should grow further than frist grade. Even google laughts on you: http://www.google.com/#q=-21+%25+5

  • Cubist (unregistered)

    In view of certain earlier comments, it may be worth noting that there's a WANTED: DEAD and ALIVE poster for Schrodinger's cat...

  • D- student (unregistered) in reply to ipeet
    ipeet:
    Reminds me of the Data Structures & Algorithms prof I had who put the following on the board:

    public static void main() { doStuff(); }

    public static void doStuff() { /* insert main() here */ }

    Why was this done? "As a general principle, I like to keep the main function short and simple"

    I've tried that but it doesn't work:

    public static void main() {
        doStuff();
    }
    
    public static void doStuff() {
        /* insert main() here */
        main();
    }
    

    Perhaps I should have used "main() + 0;" ?

  • Izhido (unregistered) in reply to Case
    Case:
    To be honest, I think the professor was actually screwing with him for sleeping in class every day. Anyone who was awake heard his explanation that the +0 was just a placeholder for the offset you want in your random number. Then that dumbass wakes up mid-class and asks a retarded question so the prof gave him a retarded joke answer.

    Then when it came to the lab, the professor mocked him even further. I know if I was in that class, I'd have been laughing so hard.

    I can't believe you just used 2 paragraphs with 85 words in it, to actually defend the professor... Mindboggling.

  • Chelloveck (unregistered) in reply to Wyatt
    Wyatt:
    Suprised no one has mentioned it should have been rand.nextInt(10) instead of rand.nextInt() % 10, as the latter has a slight bias towards lower numbers.

    That was actually my first thought. Don't bother arguing about the behavior of modulus with negative numbers... Using the modulus operator at all just means you're doing it wrong from the get-go.

    This is probably just nit-picking, though, because the bias inherent in the PNRG algorithm probably swamps the fraction of a percent bias you get when doing 2**32 mod 10. Still, bad form.

  • random Plus Zero (unregistered) in reply to davedavenotdavemaybedave
    davedavenotdavemaybedave:
    Lego:
    davedavenotdavemaybedave:
    frits:
    davedavenotdavemaybedave:
    IT Girl:
    Pete:
    Are WTF's drying up is all code in the world becoming better.

    I think we all know there are teachers in colleges and universities that don't have a clue. Those who can't do teach after all.

    That's right, those who can do, those who can't teach, and those who can do neither, criticize.

    Are you saying critics have superpowers? Because those who 'do neither' would be people who can both 'do' and 'not do' at the same time.

    Just asking, y'know.

    Let's try restating IT Girl's post:

    Those who can neither do, nor teach, criticize.

    What's the problem, exactly?

    Those who teach are those who cannot do. Substitute it in and you get:

    Those who can neither do, nor not do, criticise.

    That is of course equivalent to 'Those who can both do and not do', which is a more comprehensible way to phrase it.

    Nope, still don't have it right. Let's look at IT Girl's post again. Expanding the contractions we get:

    "...those who can do, those who can not do teach..."

    You added the "nor".

    Just remember; do, or not do, there is no try.:-)

    --Lego

    I'm really not sure what point you're making. Frits quite correctly added the 'nor' when rearranging the sentence. Either way, it's obvious that logically you cannot be both something and its negation. Whatever X and not-X are, something cannot, by definition, be both at the same time.

    Perhaps the double- and triple-negatives are the confusing part?

    Sure someone can both do something and not do something at the same time... I call it Schrodinger's Task.

    When you are managing a person, they are in a state of doing a task for you and not doing a task for you. Only when you check in on them does their state solidify into working or slacking off.

  • foo (unregistered) in reply to Larry
    Larry:
    #!/usr/bin/perl
    if ('03' eq '3') { print "True\n" } else { print "False\n" }
    if ('03' + 0 eq '3') { print "True\n" } else { print "False\n" }
    
    Produces: False True

    Perl motto: there's more than one way to do it (and most of them make your eyes bleed and your soul go running to embrace Satan).

    Not really so bad when you understand that Perl types via context.

    The first case compares a string to a string. The strings are not equal, so it returns false.

    In the second case, you are comparing the string representation of a number with a string representation of a number (because you used the numeric '+' operator to add a string and a number, which puts you in a numeric context but then you are comparing that result with with a string which puts you back in a string context).

    Now, if this statement had produced true, you might be in Satan's territory:

    if ('03' + 0 eq '03') { print "True\n" } else { print "False\n" }

    but happily, it doesn't.

    In a weakly-typed language like Perl, it's all about understanding the context...

  • Spoe (unregistered) in reply to Mister Zimbu

    Which, in every situation I've used them, mean 10, not 0.

  • Quirkafleeg (unregistered) in reply to Henning Makholm
    Henning Makholm:
    Java does not have a modulus operator (which sucks, but many other popular programming languages suck likewise. So, for that matter, do most machine instruction sets).
    BBC BASIC:
    >PRINT -1234 MOD 5
    -4
    >
  • Mr Brik (unregistered)

    Those who can do

    Those who can't.........TEACH

  • Jay (unregistered) in reply to davedavenotdavemaybedave
    davedavenotdavemaybedave:
    IT Girl:
    Pete:
    Are WTF's drying up is all code in the world becoming better.

    I think we all know there are teachers in colleges and universities that don't have a clue. Those who can't do teach after all.

    That's right, those who can do, those who can't teach, and those who can do neither, criticize.

    Are you saying critics have superpowers? Because those who 'do neither' would be people who can both 'do' and 'not do' at the same time.

    Just asking, y'know.

    I'm not sure if you're being serious or not, but on the off chance that you really find this statement absurd, is it necessary to point out that by "neither" the writer clearly meant "can neither do nor teach" ? You could, I suppose, say that "teaching" is a form of "doing", but: (a) This is a joke. If we have to explain that the chicken obviously crossed the road to get to the other side but this fails to explain why he wanted to get to the other side, you're just hopeless. (b) If you want to take the statement seriously, in context, "do" clearly refers to doing the original task, not to teaching it.

    In any case, I think the appropriate steps are, "Those who can, do. Those who can't, teach. Those who can't teach, legislate."

  • Anonymous (unregistered) in reply to Anonymous

    I've had professors before that have stated things like that to the class when they didn't know the subject material (i.e. the class was a last minute addition to their teaching schedule). I greatly prefer professors that could admit to their shortcomings and learn from them along with the students, than try to bull$hit everyone.

    captcha: dolor - what I get when I sit through a two hour meeting that could be over in 15 minutes.

  • Jason Ewton (unregistered) in reply to Spoe

    Yes. Surely a professor wouldn't be so ignorant. The "+ (int)" is there to simply convert a zero-based result to an 'n' based result.

    Let's hope he understood that, anyway!

  • Jason Ewton (unregistered) in reply to Quirkafleeg

    Java has a modulus operator.

    It's %

  • Dan (unregistered) in reply to HopelessIntern

    Obviously that was an IT issue and not his area either.

  • THE_DUKE (unregistered) in reply to GEE

    ERmmmmm.... no not really. It depends on how modulus has been implemented in the language. Some use Modular arithmetic while some (like ANSI C I think) use remainders. In all cases however, you can get negative solutions if you have the 'correct' input

  • chunder thunder (unregistered) in reply to ipeet
    ipeet:
    To digress a bit, IMHO, the 'keep main as simple as possible' rule is misguided. I've encountered no convincing rationale for treating main() any differently from any other function in an application, and the same reasoning one uses when deciding to create a subroutine in any other function applies to main.

    IMO, in all but the simplest programs, main() should be restricted to tasks related to running the program. Dealing with arguments, initialization, etc. If it's a simple linear program, then chaining together steps is generally ok. It's for a reason you mention---reusability. By its nature, main() virtually must be the place you pull arguments out of argv and return values to the OS. If you start mixing that with nontrivial "application" logic, you're going to have extra work to do disentangling it later when you want to call your utility program as a subroutine from within a larger application.

    So, e.g., I think a main that is just "main(argc,argv){return doStuff(argv[0],argv[1]);}" (augmented to be actual code, I think it's clear what I mean) is fine. It means you can write doStuff to take straightforward arguments.

  • Dan (unregistered) in reply to Mr.'; Drop Database --
    Mr.'; Drop Database --:
    Adding 0.0, on the other hand, is a convenient way to convert an int to a double.

    Moron.

    Remind me never to work near anything you have written.

  • puzzled (unregistered) in reply to Steven Carter

    You must be confused. If you want an ASCII digit then you would add '0' to the numerical value regardless of whether you're using Java or C, although nobody said the example had anything to do with ASCII digits. And both C and Java "know" that the result of rand() or rand.nextInt() is an integer and return it as such.

  • puzzled (unregistered) in reply to puzzled

    The above comment was in reply to:

    The example was *almost* correct if it was a C program.

    In C, after you generate the random number, you have to add '0' to it, which basically adds the ascii code for 0. Having any numerical value (between 0 and 9) added to the ascii code for '0' will give you the ascii digits 0 through 9.

    Java just knows it's an integer and returns it as such.

  • a (unregistered) in reply to madjo

    Did he also pronounce ´features´ as ´fietsjes´ (little bikes in Dutch)?

  • (cs) in reply to Jayman
    Jayman:
    Gotta love those college profs, educating the next generation of WTF'ers. I remember that at least one of my Comp Sci profs took great pride in the fact that he had no industry experience; he felt that being a life-long academic kept him "undiluted" by industry practices...

    Sounds like one prof I had. Did he also believe in the platonic ideal of the waterfall model, where customers never change their ideas about the requirements? I'd had one summer working on a real product when I took that class, and I already knew it was bogus.

  • (cs) in reply to davedavenotdavemaybedave
    davedavenotdavemaybedave:

    Whatever X and not-X are, something cannot, by definition, be both at the same time.

    With an attitude like you're never going to find Marvin on the Heart of Gold.

  • (cs)

    obligatory xkcd reference:

    http://xkcd.com/221/

Leave a comment on “Surpassing the Master”

Log In or post as a guest

Replying to comment #:

« Return to Article