63

Our programming teacher always wanted us to do this (in C#):

somedatatype somevarname;
somevarname = somevalue;

You were NEVER allowed to:

somedatatype somevarname = somevalue;

"Can't I just do it in one line?"
"No."
"Why?"
"<insert dumb statement here that gives no reason whatsoever>"

Comments
  • 12
    Just bring one senior developer from microsoft and tell him to teach your dumb teacher
  • 18
    Heck, use var to drive him nuts :D
  • 3
    @Kimmax That'd probably bother myself the most
  • 0
    I like var product = getProduct(id)
  • 4
    Maybe he comes from a background of C and doesn't want to change habits.
    It is ever so slightly more beneficial to do it his way if you declare a few variables and give them the same value. .. unless of course the compilers haven't improved in the past few years.
  • 3
    Isn't initialization always recommended than assignment?
  • 8
    Had a teacher that did the same thing,when I asked why, what I got was "well would you <open ended philosophical question that meant less and less the more you thought about it>" to which I'd respond "... If it's more efficient"
  • 0
    @PRein Only if they've never worked with some sort of C99, because that allows the short initialization syntax.
  • 7
    If you need an argument why not to write the code in this way:
    It violates the DRY principle (don't repeat yourself).
Add Comment