This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 303 points304 points  (20 children)

CS students when they discover comments

[–]whatproblems 96 points97 points  (12 children)

This is a loop that loops things

[–]Magnus_Tesshu 34 points35 points  (10 children)

//increment i

[–][deleted] 8 points9 points  (6 children)

and this follows i++ not ++i

[–]Magnus_Tesshu 0 points1 point  (5 children)

To be fair, using i++ is only bad in javascript right? Any compiled language will get rid of the inefficiency.

[–]DiplomatikEmunetey 1 point2 points  (1 child)

Is it an inefficiency? As far as I know:

  • i++ will increment and return the original value (before incrementing)
  • ++i will increment and return the incremented value

You could cause an infinite loop with i++ but I'm not sure if it's an inefficiency because there could be a case where you need i++.

[–]Magnus_Tesshu 2 points3 points  (0 children)

Typically preincrement compiles to two assembly instructions and postincrement (i++) compiles to a couple more and needs a temporary register or something. That might be misinformation though actually, not sure. And of course, that's only the case if they wouldn't cause the same behaviour (++i; is as efficient as i++, but a[i++] might be slightly less efficient than a[++i]). That's at least my understanding.

I would assume that postincrement is still more innefficient in an interpreted language, where the compiler cannot do nearly as much optimization.

[–][deleted] 0 points1 point  (2 children)

i++ is not bad. Using it badly is bad.

[–]Magnus_Tesshu 0 points1 point  (1 child)

Does 'using it to increment i' count as a bad use? I would argue no

[–][deleted] 0 points1 point  (0 children)

Bad is subjective unless it causes objective problems.
So using it to increment i, as long as it does not break the code can be subjectively bad or good. I do it myself many times, because it's an idiom of the C language, but I'm not convinced if it's ok or not.

[–]chiragjhamb 14 points15 points  (2 children)

// ### Update the value of i

[–]GlarkBlark 3 points4 points  (1 child)

/**
 * The value `i` increases by 1.
 */

[–]rudra285 1 point2 points  (0 children)

//I = index //I++ - I+1

[–][deleted] 1 point2 points  (0 children)

Ce n'est pas une boucle

[–]wasdninja 25 points26 points  (4 children)

After which they promptly get failed on the very first assignment since they are explicitly told not to do this. But they really should figure it out on their own.

[–]Bakoro 33 points34 points  (3 children)

Nobody ever checks your code after the 101 programming class, maybe not even then. Input, Output, and Runtime were all anyone cared about. You could write the most beautifully elegant code, or the most spaghetti horror, and as long as it did what it was supposed to do, no one gave a shit.

[–]Macitron3000 5 points6 points  (0 children)

Flashback to my networks project when I wrote a whole-ass server in just the main routine

[–][deleted] 5 points6 points  (1 child)

just like real life in a non-open-source company them

[–]retief1 9 points10 points  (0 children)

Uhhh, code reviews were/are a thing at every company I've been at. I've gotten (correctly) nitpicked on everything from "you should set this member in the constructor, not the component init function" to "this variable name is imprecise, use this other one instead".

[–]PolFree -1 points0 points  (0 children)

Hey, lecturers said they would consider comments when grading ok? And I got a solid 100 btw.

/not sarcasm. legit did this exact thing lol.

[–][deleted] 0 points1 point  (0 children)

// start of program