Code Formatting Nazi

  • Thread starter Deleted member 12930
  • Start date
D

Deleted member 12930

Guest
Is anyone here a nazi like myself when it comes to formatting your code?

I've changed my personal preference over the years, but I always stay consist on a project.

For the most part this hasn't been a problem, because I primarily work independently on projects. But recently I've had too large of a workload to handle on my own, so I've been having to get help from a coworker. Good lord his formatting is horrible. Basically he mixes it all up. Between using tabs to indent, then spaces, camel case variables to dash or underscore separated variable names, spaces between operators and no spaces, etc etc etc. If there's a "way" to write code, he'll do it different every.damn.time.

Driving me insane!!!
 
Basically he mixes it all up. Between using tabs to indent, then spaces, camel case variables to dash or underscore separated variable names, spaces between operators and no spaces, etc etc etc.

In the programming classes I've been in this is definitely the sure fire way to drop your GPA.

This and using bubble sort.
 
In the programming classes I've been in this is definitely the sure fire way to drop your GPA.

This and using bubble sort.

The hard part for me is that while it's infuriating to deal with, it feels pretty inconsequential in the long run. It feels very... ruthless to harp on him about it.
 
Well, you could at least *hint* at him sticking with one type of formatting; since it looks like you don't care which it is, just need consistency.

Though, I'll take random formatting over how this one guy I work with names his variables. For example, he'll name datasets like so

dsa
dsi
dsv

As you can imagine, I have no clue what those refer to when I look at his code. Oh and no comments anywhere...
 
Well, you could at least *hint* at him sticking with one type of formatting; since it looks like you don't care which it is, just need consistency.

Yeah, I need to be more assertive. I have a hard time with my coworker. Sometimes he's spot on with his work. Other times it's just an absolute mess. From his thought process behind work to the actual implementation. So a lot of the time I feel like I have to pick my battles.

Though, I'll take random formatting over how this one guy I work with names his variables. For example, he'll name datasets like so

dsa
dsi
dsv

As you can imagine, I have no clue what those refer to when I look at his code. Oh and no comments anywhere...

Now THAT I would not stand for. The other day he used a code snippet he found online that had variable names like that. I told him to rewrite it, and add comments. He didn't like it, and did a shitty job of adding those details. Most likely because he had no idea what it was doing. :rolleyes:
 
Yeah, I need to be more assertive. I have a hard time with my coworker. Sometimes he's spot on with his work. Other times it's just an absolute mess. From his thought process behind work to the actual implementation. So a lot of the time I feel like I have to pick my battles.



Now THAT I would not stand for. The other day he used a code snippet he found online that had variable names like that. I told him to rewrite it, and add comments. He didn't like it, and did a shitty job of adding those details. Most likely because he had no idea what it was doing. :rolleyes:

I have a tendency to have semi-cryptic variable names, but nothing that bad.

the worst I do is "x" or "y" but that's just for some arbitrary variable that's getting used in 3 or 4 lines in a method.

Otherwise it's like "ddown" which is what I used in a Javascript piece that i was working on to hold a reference to a given drop down menu.
 
Is anyone here a nazi like myself when it comes to formatting your code?

I've changed my personal preference over the years, but I always stay consist on a project.

For the most part this hasn't been a problem, because I primarily work independently on projects. But recently I've had too large of a workload to handle on my own, so I've been having to get help from a coworker. Good lord his formatting is horrible. Basically he mixes it all up. Between using tabs to indent, then spaces, camel case variables to dash or underscore separated variable names, spaces between operators and no spaces, etc etc etc. If there's a "way" to write code, he'll do it different every.damn.time.

Driving me insane!!!

I will say one good thing about working in Visual Studio, the auto formatting and intellisense (go to def and the comment tooltips) keep things looking consistent and prevent me from hunting though various source files to figure out what dtTable1 is supposed mean most of the time.

I always cringe when I have to open up an old WinForms style application and a few certain previous employee's names on the doc description at the top.
So many random indentations, abuse of global variables, and what normally causes me to mutter curses under my breath is the abuse of that old program's language support for arrays of controls.
Seeing Textbox1 as a control, not a big deal. Try not be so lazy next time. Seeing Textbox1[0] - Textbox1[35] as the only inputs on the Form? That's just deliberate obfuscation.
 
I am surprised a company wouldn't have strict standards I know most of the heavy hitters do like intel,ibm,amd,etc. I know the internship I did had specific formatting for code/comments as to make it more maintainable.
 
Companies focused on programming/development specifically most likely do.

But not everyone works for those companies. :) for instance, I am on a small team of 5. Two project managers, two developers, and our manager, who used to be a developer. Our industry isn't tech related at all - we make wine. So no standards.
 
A developer's job is to make effective and understandable code.

Code can be terse, but not to the extent that it decreases clarity of intent.

One that really annoys me is when people don't clearly differentiate between private member variables and the methods/properties exposing those variables.
 
Export auto format options for VS or Eclipse. Share with co-workers. Problem solved.

In the programming classes I've been in this is definitely the sure fire way to drop your GPA.

This and using bubble sort.

lol, you must have really anal professors to care about that instead of your code correctness, performance, and design. This happens all the time in the real world when working with legacy code, you just deal with it and correct the stuff where you can (and if you have the time).
 
lol, you must have really anal professors to care about that instead of your code correctness, performance, and design.
Yep. Sounds like they're doing you a disservice.
 
Having that consistency within a language does seem like a godsend. In my work I deal with multiple teams and technologies so solutions I create will look a lot more dirty than it really is. Each team writes in a different language, and sometimes a different style within that language. SQL, JS, HTML, CSS, C# & VB... When you write something that touches multiple areas, this is bound to happen.
 
Ctrl + E, D

Also, a tool like Resharper could help install some discipline, but that's a code Nazi in it's own right until its configured correctly.

Well, you could at least *hint* at him sticking with one type of formatting; since it looks like you don't care which it is, just need consistency.

Though, I'll take random formatting over how this one guy I work with names his variables. For example, he'll name datasets like so

dsa
dsi
dsv

As you can imagine, I have no clue what those refer to when I look at his code. Oh and no comments anywhere...

It's hard to write good code with datasets at the best of times. Datasets are a leftover from winforms, before generics or linq. Doesn't support iEnumerable (directly), table adaptors are clunky, "SELECT SCOPE_IDENTITY()" disappears randomly if you make changes to other query's... MS has given up on these but they're still around.:mad:

My biggest hate is massive classes/ methods that are littered with dependencies and even a simple change can break it.
 
Last edited:
In the programming classes I've been in this is definitely the sure fire way to drop your GPA.

This and using bubble sort.

Um.........what?

lol, you must have really anal professors to care about that instead of your code correctness, performance, and design. This happens all the time in the real world when working with legacy code, you just deal with it and correct the stuff where you can (and if you have the time).

Yep. Sounds like they're doing you a disservice.

chinesepiratefood and Xeth... I hope I never have to see any of your code if you have an attitude like that about formatting requirements in a class, cause that probably means you have the same attitude about it in code you write in the real world.

Classes I took had formatting requirements but also focused on correctness, performance, and design. It is a whole lot easier to have correctness, performance, and design if the code is formatted well so it is easily readable. This also helps with maintenance.

If you really like wasting time working on barely readable code, more power to ya.

mikeblas... are you being sarcastic?
 

This explains a lot of why code I look at that other people have written makes me want to gouge out my eyes with a rusty spoon.

Oh.. lets not document anything and use randome character combinations for variables.

Lets put stuff in our code that works but we have no idea why it works... oh, it broke.. well, in that case I will have to shotgun snippets of code together some more until it seems to work... that will be another 30 hours of payable time to fix something that should take at most 1-2 hours.

Or how about we write code that works, but is completely unreadable. This is especially fun with big projects where we are calling randomely names functions and classes in multiple different files with absolutely no documentation whatsoever.

Oh.. and lets not forget formatting... we especially like puttng everything on one line, randomely indenting with no regard to having anything standardized.

Having formatting guidelines in class helps eliminate/reduce a lot of this thinking.

I am out of time, so for now
/rant.
 
This explains a lot of why code I look at that other people have written makes me want to gouge out my eyes with a rusty spoon.
Are you a drama major?

I didn't say that these things weren't important. I'm just pointing out that engineers starting out and learning to code have a lot more to worry about when being graded than formatting. It's possible to provide feedback and instruction without grade changes, and for cases like this it's more appropriate. If writing poorly formatted code is "the surefire way to drop your GPA", the implication that provided non-working code isn't the way to get a lower grade--and with that pattern, the professor is doing a disservice to their students.

Lets put stuff in our code that works but we have no idea why it works... oh, it broke.. well, in that case I will have to shotgun snippets of code together some more until it seems to work... that will be another 30 hours of payable time to fix something that should take at most 1-2 hours.
Shotgunning code snippets is a far cry from formatting and variable naming. Maybe in your rage you're conflating two issues.
 
Are you a drama major?

I didn't say that these things weren't important. I'm just pointing out that engineers starting out and learning to code have a lot more to worry about when being graded than formatting. It's possible to provide feedback and instruction without grade changes, and for cases like this it's more appropriate. If writing poorly formatted code is "the surefire way to drop your GPA", the implication that provided non-working code isn't the way to get a lower grade--and with that pattern, the professor is doing a disservice to their students.

Shotgunning code snippets is a far cry from formatting and variable naming. Maybe in your rage you're conflating two issues.

If getting more points deducted for poor formatting than points deducted for non-working/poor code is what is happening, then yes, that is not the right way to do it. But having points deducted for poor formatting is completely acceptable.

Horrible formatting warrants a decent amount of point deducted in either case. It makes it a lot harder for the teacher to look through the code to see what and how the student is going about solving the problem.

In any programming class the formatting requirements should be stated at the beginning. Usually it is something simple like 3 space indenting, no extra white space at the end of the lines, a certain number of lines between methods/functions, etc.

If a student can't follow rules like that in a classroom environment, then they have no business getting a job where those sort of things are usually required.

Usually poor formatting and poor coding go hand in hand. I see a lot more code where both apply than either poor formatting or poor coding by themselves.
 
When I was in college 14 years ago, you had two options: format the instructors way, or the books way. If you didn't do the instructors way but you did do the books, you had some ground to stand on when arguing your case because all of your learning is done from the book.

Nowadays, with fresh and younger teachers in the mix, they may be more open to formatting. Everyone has their own style and they realize it. But its important to try and standardize it when working in a team environment where everyone is touching the same code.

The only thing that bugs me is when people get a 30 in screen and use that as an excuse to not wrap their lines lol.
 
there seems to be some hyperbole used here of how formatting affects the readability of code.
 
there seems to be some hyperbole used here of how formatting affects the readability of code.

Having consistent formatting does affect the readability of code. Working on a project with several programmers each having their own preference for formatting makes future debugging a nightmare. If you are doing something just for yourself it's really not that important, but when I look at stuff I wrote "for fun" years ago it's sometimes a lot of work to figure out what's going on.

And variable naming is another..

We have some guidelines where I work. It does not take more time while programming, sure you spend a bit more time considering what a variable is called, but it will pay back when somebody else touches it later. We occasionally have consultants come over and they applaud that they have rarely seen projects of such magnitude (millions of rows of code) that are so easy to read and comprehend.
 
Formatting only matters on when "white space" matters... like python...
inalmostanycasewhitespacemattersandreadabilityisanimportantconcern.
Having consistent formatting does affect the readability of code.
It does. What's debated is the magnitude of the affect. Poor formatting does make code harder to read, but it doesn't breed genocide or race supremacy. It also doesn't make people insane or cause GPAs to plummet.
 
Last edited:
.It does. What's debated is the magnitude of the affect. Poor formatting does make code harder to read, but it doesn't breed genocide or race supremacy. It also doesn't make people insane or cause GPAs to plummet.


It costs time (and thus, money) in the business environment where many other programmers will be working with the same code.
I agree that we need to focus on functionality first, but given appropriate functionality there's no reason not to spend a few minutes formatting your code to a standard so that the other devs don't have to waste time figuring our your conventions.
 
People are worrying about this too much. It's still possible to write neat, well formatted code that is unreadable. e,g:-
Return !isTrue != False;

As long as large statements are broken down into manageable chunks (especially true with the trend to fluent API's), the editor can take care of the rest.

As Jay-Z once said "I've got 99 problems, but indenting with spaces or tabs isn't one".
 
If you are a good programmer you should take pride in your code and format it well and create good descriptive variable names.

I don't blame you for being annoyed.
 
Having to go back and understand undocumented, not well formatted code in a few projects has made me a formatting nazi. A friend dealt with the same problem, but the original programmer used Spanish for all variable names.

In school only our first few coding classes graded on style, I still use very similar style guidelines to what my first professor defined. If you are using a full IDE or even vim/emacs(vim > emacs), then there is no excuse to have at least consistent indent/tabbing in a file. I work in C 99% of the time, so code I write in other languages tends to look similar formatting wise.
 
When I was in CS, my profs didn't care what style we used. But, did require that we be consistent. That said, most you'd get marked off was a few points if you weren't. Unless of course your style made the code difficult to decipher. Like a classmate of mine that used random names for variables, that had nothing to do with what the variable contained.
 
My only argument I have against a developer who refuses to adhere to style guides is that (s)he may be lazy.

If someone didn't take the time to write their code properly, can you trust that they took the time to test it properly? Can you trust that they adhered to the design process and put some thought into why they chose the solution they did?
 
I've got the opposite problem. A bunch code for the application i'm working on is way OVERLY verbose. It's gone so far on trying to make it easy to read, that it has actually become more confusing.

Here's a sample. It's Ruby on Rails. The empty lines are actually there in the code.

Code:
 def self.imex_create_tech_def_from_hash( institution_IN, hash_IN )

    # return reference
    value_OUT = nil

    # declare variables
    tech_def_instance = nil
    current_technical_definition = ''
    current_data_system = ''
    current_time_context = ''
    no_tech_def = false

    # is there an institution?
    if ( institution_IN.blank?() == false )

      # is there a hash?
      if ( hash_IN.blank?() == false )

        # create a technical definition instance.
        tech_def_instance = TechnicalDefinition.new()
        no_tech_def = false

        # see if we populate it.  Populate if any of technical
        #    definition, data system, or time context are not
        #    empty.  Subsequent validation will catch if required
        #    values are missing.
        #if !col[:technical_definition].blank? or !col[:data_system].blank? or !col[:time_context].blank?
        # Retrieve values related to technical definition
        #    (technical definition, data system, and time
        #    context).
        # Q: Should we just grab values at this point, or also do
        #    lookups?
        current_technical_definition = hash_IN[ Term::IMEX_SYMBOL_TECHNICAL_DEFINITION ]

        # data/erb system
        current_data_system = hash_IN[ Term::IMEX_SYMBOL_DATA_SYSTEM ]

        # time context
        current_time_context = hash_IN[ Term::IMEX_SYMBOL_TIME_CONTEXT ]

        # Check to see if we have at least one of these values.
        if ( ( current_technical_definition.blank?() == false ) or ( current_data_system.blank?() == false ) or ( current_time_context.blank?() == false ) )

          # we have one of the values that indicates a technical
          #   definition is present.  Populate  the new instance.
          tech_def_instance.value = current_technical_definition

          # ERP System
          #@technical_definition.erp_system = @institution.erp_systems.find_by_name(col[:data_system]) if col[:data_system]
          if ( current_data_system.blank?() == false )

            # not blank.  Retrieve value through institution.
            tech_def_instance.erp_system = institution_IN.erp_systems.find_by_name( current_data_system )

          end

          # time context
          #@technical_definition.time_context = TimeContext.find_by_name(col[:time_context]) if col[:time_context]
          if ( current_time_context.blank?() == false )

            tech_def_instance.time_context = TimeContext.find_by_name( current_time_context )

          end

          # we have a tech def.
          no_tech_def = false

        else

          # none of the fields related to a technical definition
          #    have a value, so no tech def.
          no_tech_def = true

        end

        # do we have a valid tech def?
        if ( no_tech_def == true )

          # no tech def.  Return nil.
          value_OUT = nil

        else

          # we have a tech def. return it.
          value_OUT = tech_def_instance

        end

      end #-- end check to make sure hash passed in. --#

    end #-- end check to see if institution passed in. --#

    return value_OUT

  end #-- end static method self.imex_create_term_from_value_hash() --#

100 lines that could be compressed to less than 20. Things like if(some_Var == true) drive me crazy.

Sometimes being a nazi is not a good thing.

P.S.
BTW all the above code is supposed to do is built a new Object from the hash_IN parameter. Literally takes 2 lines.
 
^^^ I think those are just silly comments on your if statements.

anybody can see what the "if" is testing. There is no point in labeling it.
The comment needs context for what should happen if the condition is true versus when it is false.

Also. I'd say that your code is a pain to follow because of its high cyclomatic complexity. separate things out, SRP.
 
Yeah that's a bit ridiculous, but surely better than the alternative of complicated confusing code with no comments.

if (variable == true) bothers me too, in most cases I think it is unnecessary.. I believe there is a style in C that is something like this...


if (val == var)

With the idea that if you make a mistake like this...

if (val = var)

that it will fail to compile, rather than do an assignment and evaluate the expression anyway. However, other languages like c# for example would fail to compile as it would not (usually) be a boolean. Also, I'd just suggest not making silly mistakes like that than bother reordering all your IF statement tests. hehe.. .
 
Back
Top