1

I am in a new team. I am shocked by their coding guidelines.

Example:

 strName
 iCount
 structRectangle
 listCustomers
 retVal (for the return value... that is really biting me... how someone can do this)

They demand to write the datatype before the variable with the argument that this way the developer knows everytime what datatype the variable is without scrolling up to the declaration.

Well that is true, but my argument would be then a method should not be longer than 30 lines (else put code in another method) which fits into a common 24" screen...

But I am not totally convinced because there are things like Action<T>, Dynamic, Func<T> in .NET. which force me too to go the same way and do "actionCustomers" for a delegate holding a method gettings a list of customers.

What advice can you give me as an alternative to e.g. "actionCustomers" which should render the argument of the team useless?

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
Elisabeth
  • 20,496
  • 52
  • 200
  • 321
  • Probably so that ... they can recognize later which datatype the var is associated with :) – Rahul Jun 29 '14 at 19:58
  • 4
    You could ask them to step into the year 2014 where IDEs show the type of the variable on hover. If you want a list of disadvantages of this phenomenon, you can simply look at [the wikipedia page about it](http://en.wikipedia.org/wiki/Hungarian_notation). – Jeroen Vannevel Jun 29 '14 at 19:59
  • 1
    Or probably your team members have short term memory loss problem ... LOL – Rahul Jun 29 '14 at 20:00
  • This is called Hungarian Notation. – SLaks Jun 29 '14 at 20:01
  • 1
    Note that having consistent style in a code base, even if it something horrible, is valuable thing. So if everything is done that way in existing code, I wouldn't start the battle of changing it. For new, separate projects, or for "new" languages, then it might be worth it to fight for guideline change, but probably an uphill battle you may lose. – hyde Jun 29 '14 at 20:04
  • 1
    Well it might be legacy code inherited by the team. If your team has the time, change EVERYTHING (very unlikely). Otherwise, it is better to keep following the existing guidelines and avoid the mess of two coding standards in the same code-base. – metacubed Jun 29 '14 at 20:06
  • _without scrolling up to the declaration_ . Ha. Up or down hundreds or thousands of lines.. A symptom of other problems most likely. Take it easy.. – TaW Jun 29 '14 at 20:08
  • @SLaks Ah the good old days :P . But the only reason we used Hungarian notation was that vi/emacs had no intellisense or tool-tips to give us this information. – metacubed Jun 29 '14 at 20:12
  • Well we start a new project and nobody sticked actually to those coding guidelines... they even used different languages in the variables names... you can`t imagine... – Elisabeth Jun 29 '14 at 20:17
  • possible duplicate of [Why shouldn't I use "Hungarian Notation"?](http://stackoverflow.com/questions/111933/why-shouldnt-i-use-hungarian-notation) – nawfal Jul 03 '14 at 12:06

3 Answers3

4

I would suggest that you adopt the coding style of the team you are coding with. They have adopted their style to deal with their own systemic problems. Unless you are in a position to judge their code (which it seems you are not) or you can appeal to a higher authority on code style (seems unlikely from your post) then, if you want to keep your job and demonstrate that you're a team player, you need to conform to the rules you've been given.

Why is datatype in variables bad coding style?

It's not. A relatively ancient form of it called Systems Hungarian Notation that actually encoded the type has received a lot of criticism for a lot of reasons, including redundancy, inconsistency, and poor readability. But that's not what you're dealing with. I sometimes find it helpful to include datatypes in my object names when I haven't fully decided on which container I'm going to use (list, no, set, no, dict... and usually in that order.)

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
1

This coding style is very useful when you are not using an IDE.

I often open old code files with Notepad++ (just to read it and convert to newer code, no need to open huge project to read one single file) and without this coding style, every time I see a variable, I have to search for its name inside the document just to find out its type. And that hurt my time schedule A LOT.

Long story short: you may not like the old school methods but they existed because people needed them. You will never know if one day you wish for it.

Minh Thiện
  • 160
  • 1
  • 8
1

Encoding the type of a function into the name (so-called Hungarian notation) is brain damaged—the compiler knows the types anyway and can check those, and it only confuses the programmer.

Linus Thorvalds, Linux Kernel Coding Styles

I really love that quote.

adjan
  • 13,371
  • 2
  • 31
  • 48