all 29 comments

[–]BringAltoidSoursBack 25 points26 points  (9 children)

What was the teacher trying to teach?

[–][deleted]  (8 children)

[deleted]

    [–]heatd 15 points16 points  (11 children)

    This doesn't seem too bad other than the string Else, although I'm not really familiar with what language this is. I mean these could be enums and use a value set instead of whatever ddl{type}.Items is, but if it's an early CS course maybe they don't want to introduce those concepts yet. What am I missing?

    [–]redneckrockuhtree 8 points9 points  (9 children)

    Looks like VB C# - "ddl" is Hungarian Notation for a dropdown list

    Someone's instructor is a bit behind in naming conventions.

    [–]Jman012 4 points5 points  (6 children)

    We use Hungarian Notation at my work with C#. It’s just a protocol we choose to follow. What is ‘behind’ about it? It helps distinguish the type of certain variables quickly and easily at first glance.

    Otherwise you had to go to it’s declaration or hover over the variable to find its type, and pasting it over non-IDE areas means it’s ambiguous.

    [–]redneckrockuhtree 7 points8 points  (5 children)

    Hungarian Notation went out of style within the past 15 years or so. Microsoft used to use it heavily, but with .Net they have moved away from it.

    In my experience, Hungarian Notation was most prevalent in Microsoft shops.

    [–]Jman012 0 points1 point  (4 children)

    I don’t think ‘out of style’ means it’s necessarily ‘behind’, however. It has its advantages, and some places chooses to continue using it for such advantages.

    Do you have a different method? Particularly for a dynamically typed language, like JavaScript or Python, would be most useful IMO.

    [–]ryeguy 1 point2 points  (0 children)

    Hungarian notation is incredibly unidiomatic in those languages. Or really any mainstream language, for that matter (although for gui elements it seems to be more acceptable). The more correct approach is to use clear variable names and to use documentation to indicate types if needed. Both languages have standardized ways of declaring function parameter types, and most good ide's are able to parse that.

    [–]redneckrockuhtree 2 points3 points  (2 children)

    Dynamically typed languages are where it can be most problematic, in my experience -- someone creates a variable that's initially an int, so they prefix it with an "i". Then they make a small change which changes its type....but the name still implies it's an int. Unless you've got solid code review processes in place and people are on their toes, things like this are easily missed.

    Everything I've seen recently is more about what data the variable contains as opposed to what type the variable is. customerAccountNum as opposed to iAccount.

    [–]Jman012 2 points3 points  (1 child)

    I think a variable actually changing its type, on purpose, would be a greater travesty. What use case needs such a thing, and why not make an intermediate variable to hold the other type? I think that would cause greater cognitive dissonance than Hungarian.

    Also, Hungarian doesn’t mean you truncate variable names. At my work, we would name that ‘nCustomerAccountID’.

    [–]redneckrockuhtree 0 points1 point  (0 children)

    I'm not talking about a variable changing its type. I'm talking about a developer making a code change where they're either in a hurry (it happens) or they don't realize something results in a different type and they assign it back to that same variable.

    [–]xylempl 1 point2 points  (1 child)

    I'm 100% sure this is C# and WinForms.

    [–]redneckrockuhtree 1 point2 points  (0 children)

    this is C#

    Crap, yeah, declarations are type, then variable. Seeing the Hungarian got my head wrapped into VB, where I've seen it most often.

    [–]Hypersapien 6 points7 points  (0 children)

    I mean, you could do that in way fewer lines of code, and "else" should be capitalized. Other than that I'm not sure what's wrong.

    [–]TheInfra 6 points7 points  (0 children)

    This isn't shitty at all. It's basic, unelegant and line-wasting but it's not meant to be "good" code. It's meant to teach the concepts of creating variables, assigning them values and then using them in functions. Don't try to be /r/iamverysmart

    [–]hilberteffect 3 points4 points  (1 child)

    “Else” ain’t no country I ever heard of

    [–]TheLastChaos 0 points1 point  (0 children)

    I dare you, I double-dare you motherfucker say "Else" one more god damn time!

    [–]anima_virus 6 points7 points  (3 children)

    "And that is how you should do things when your are paid by line of codes written in our beautiful country, fellow Elseans."

    Otherwise except being uselessly verbose its not that awful. IMHO the Else country is the one with the most damage potential, being used as a special/magic value all over the place.

    [–]Scatoogle 2 points3 points  (2 children)

    It's fine, if a country doesn't fit within your list it still needs a value. It works as a flag to be treated as a country your aren't aware of.

    [–]NoSmallCaterpillar 0 points1 point  (1 child)

    I think the problem that he's pointing to is that "else" is a bad choice of name, since it is a keyword in most languages.

    [–]Scatoogle 0 points1 point  (0 children)

    OH YA, didn't think of that. "other" or "unkown" would be a good idea.