- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Adding 0.0, on the other hand, is a convenient way to convert an int to a double.
Admin
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.
Admin
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)
Admin
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?
Admin
Admin
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.)
Admin
But that works great when the order of operations is unexpected, like on the TI-85 (and probably newer TI calculators)
Hint: Conversion has a higher precedence to negation.
Admin
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.
Admin
What a skank.
Admin
There's a short circuit all right, but not where the professor thinks it is.
Admin
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.
Admin
I'm guessing your probably right. I had more than a few professors screw with me for sleeping.
Admin
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.
Admin
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...
Admin
<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?".
Admin
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).
Admin
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.
Admin
[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.
Admin
As for what % should / shouldn't do, here's what % (or mod &c.) actually does:
Taken from Wikipedia, so these figures are as real as a unicorn sliding down a rainbow.Admin
Once there was a cat who could be both alive and not alive, at the same time.
Admin
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.
Admin
Yes, I'm sure queeling the registers was exactly what he had in mind.
Admin
Leeds University?? Random Greek Lady??
Admin
Admin
yes, in Java_Script_
Admin
I just died a little inside.
Admin
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
Admin
In view of certain earlier comments, it may be worth noting that there's a WANTED: DEAD and ALIVE poster for Schrodinger's cat...
Admin
I've tried that but it doesn't work:
Perhaps I should have used "main() + 0;" ?
Admin
I can't believe you just used 2 paragraphs with 85 words in it, to actually defend the professor... Mindboggling.
Admin
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.
Admin
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.
Admin
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...
Admin
Which, in every situation I've used them, mean 10, not 0.
Admin
Admin
Those who can do
Those who can't.........TEACH
Admin
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."
Admin
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.
Admin
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!
Admin
Java has a modulus operator.
It's %
Admin
Obviously that was an IT issue and not his area either.
Admin
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
Admin
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.
Admin
Moron.
Remind me never to work near anything you have written.
Admin
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.
Admin
The above comment was in reply to:
Admin
Did he also pronounce ´features´ as ´fietsjes´ (little bikes in Dutch)?
Admin
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.
Admin
With an attitude like you're never going to find Marvin on the Heart of Gold.
Admin
obligatory xkcd reference:
http://xkcd.com/221/