You are not logged in.

#1 2009-10-08 18:26:27

PJ
Member
From: Sweden
Registered: 2005-10-11
Posts: 602

Missing coding convention

I am currently working in a project where there seems to be no coding convention. The interesting thing is that the company that I am working for do actually have coding convention but no one seems to follow it. What makes it even harder is that I think there seems to be one unique style for each file so the most common style doesn't seem to be an option.

The things that I have seen so far is indentation that use only tabs, 4 spaces, 3 spaces, 2 spaces, a mix of tabs and spaces or a combination of all in the same file.

The variable names are as bad as the indentation, here are a couple of examples:

this_is_a_variable;
ThisIsAvariable_signal;
thisIsAVariable;
ThisIsAVaribleStructType;
this_is_a_variable_boolean;
temp;
module_thisIsAVariable;

And these are just a couple of examples, there are more...

I think the code is really a mess when it comes to readability.

Should I use my own coding style or should I mix every style to be as close as possible to the project's style?
How do you guys do when there is no coding convention and no unique code style in a software project?

Offline

#2 2009-10-08 18:56:41

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Missing coding convention

If its inherited code, you are pretty much fcuked. Its a nightmare just trying to understand the logic behind certain parts. and if its littered with the examples that you gave, it can get pretty frustrating.

I just normally use the coding conventions available to the project. And if you use an IDE that's smart enough, you can always change the variable names according to the conventions. Although, you will need to make sure that nothing breaks in the process because I am paranoid and I don't completely trust the "rename" function of the IDEs. So always double check.

Also IDEs allow code format according to a template which you have to define once. That could help with the spacing related issues.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2009-10-08 21:01:52

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: Missing coding convention

GNU indent for the indentation problems.  I don't know of generic tools to fix variable names, but some IDEs will do it.  I don't think you mentioned what language this is?

Offline

#4 2009-10-08 21:31:14

PJ
Member
From: Sweden
Registered: 2005-10-11
Posts: 602

Re: Missing coding convention

Trent wrote:

I don't think you mentioned what language this is?

No, I didn't, it is coded in C.

Well, the problem is not that I am supporting old code, I am actually developing new code together with 20 other programmers. Some of those have been working for this project for over a year, I have been worked for a week. That makes it harder to actually suggest code refactoring which I really think is needed.

I might look into GNU indent and IDEs. Not sure if I am going to do it now since that will actually require subversion commits and it is a real pain to do small commits, a strange repository layout with a lot of misuse of subversion "features", I don't want to think how much work it would be for large changes.

Offline

#5 2009-10-09 03:53:49

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Missing coding convention

I feel ya. Its always hard to impose code conventions on people who have already been working on the project, even if you are right. There is just this inherent seniority complex.

and even if you do refactor old code, what's to say that the others won't screw it up again when they write new code.

Eclipse is a great IDE which allows a lot of code re-factoring. I use it all the time for Java. Its also available for C, although I am not sure how good the re-factoring is in the C version of the IDE.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#6 2009-10-09 07:15:02

Zeist
Arch Linux f@h Team Member
Registered: 2008-07-04
Posts: 532

Re: Missing coding convention

At work the product we mostly work on has a lot of inconsistencies when it comes to coding conventions when it comes to the parts of the system that are really old. Luckily we're hopefully going to re-write big parts of it soon which should take care of a big part of that.

I think that you should probably try to have a discussion about using coding conventions in future code. I find that it is easier to got people to follow coding conventions from now and forward than getting someone to spend the time going back and fixing their old code. For already existing code it is usually easiest to just fix things as you go along if you don't have seniority.

Last edited by Zeist (2009-10-09 07:15:47)


I haven't lost my mind; I have a tape back-up somewhere.
Twitter

Offline

Board footer

Powered by FluxBB