views:

1135

answers:

13

I am new to work but the company I work in hires a lot of non-comp-science people who are smart enough to get the work done (complex) but lack the style and practices that should help other people read their code.

For example they adopt C++ but still use C-like 3 page functions which drives new folks nuts when they try to read that. Also we feel very risky changing it as it's never easy to be sure we are not breaking something.

Now, I am involved in the project with these guys and I can't change the entire code base myself or design so that code looks good, what can I do in this situation?

PS> we actually have 3 page functions & because we do not have a concept of design, all we can do is assume what they might have thought as there is no way to know why is it designed the way it is.

I am not complaining.I am asking for suggestion,already reading some books to solve the issues Pragmatic Programmer; Design portion from B.Stroustrup; Programming and principles by B.Stroustrup;

+32  A: 

The best and most important thing you can do is lead by example. Do things the right way and try to improve things slowly. You aren't going to fix anything overnight.

Make sure every piece of code that you are responsible for is better after you are done with it. Over time, the system will tangibly be better because of your efforts.

After you build a strong reputation with your co-workers, try go start some code reviews or lunch-training sessions to get everyone up to speed on better ways to do things.

In a nutshell: it will be difficult and frustrating, but it's possible. Good luck.

Robert Greiner
Not *every* piece of code. If these old-timers have any sense of ownership at all, they'll resent the new kid making gratuitous changes. You'll be creating a conflict that will cause your style to be treated with contempt, whatever its merits. *Do* lead by example with any new code though.
Mark Ransom
@Mark that's actually a really good point (although, I must admit, I hate that it's true)... Check edits.
Robert Greiner
What is the most annoying thing you can experience? That somebody comes and rewrites your code /because they think they are better/ and then causing some bug to be introduced which senior guy then needs to fix...
Anders K.
@Anders you are 100% correct assuming that the new kid doesn't know better and that the original code is of good quality. I don't think the OP is just another cocky kid, I think he really sees some poor code that he feels he can make better. The situations are different but not necessarily mutually exclusive.
Robert Greiner
Andres,I am not asking to change their existing code neither I can change it for better, these guys are all PRO with 15+ years experience. but the code is not structured and we have to read it (makes it impossible) in our day-to-day life. I am trying to do something which will allure them to adopt process/standards/convention as they still are writing new code in the same way, of course you can't go and correct all code your self as you have your own work to do. or your manager kicks you out ;-). it kills all motivation of doing things systematically
Gollum
+9  A: 

If you're a junior dev, then the only thing you can really do is write code as elegantly and readable as possible.

If your style is indeed better, other people might notice and say "hey we should adopt this formula"

Actions speak louder than complaints, which is something I noticed.

Jack Marchetti
Unfortunately that rarely happens. If a senior dev writes functions that are 3 pages long, they're too far gone. Can't fight them though; have to get along. Best bet is to try to outshine them as much as possible in your own code.
A: 

This is how it is, get used to it or quit and find a place where it isn't like that. You will be marginalized if you criticize their efforts and they may feel threatened if you do indeed write your own, better code or improve theirs. At the end of the day they deliver code and management sees a black box that works and that's all that matters. Plus, you'll be just another kid from college who thinks he knows something about development at a business and laughed at and ostracized when not around. Honestly, a lot of the times these systems are built like this because of shaky requirements, lots of functionality bolted on with time and managements lack of respect for a stable software development process.

Not all companies are like this. I'd start looking for a new job to be honest.

Nathan Z
Leaving a steady position (especially directly out of school) is not often a good decision - regardless of the existing codebase. Adaptation and the eagerness to inject change will get you much further in life.
ezpz
I'm saying start searching for new opportunities. I've worked in environments like that and it isn't qualitative at all. Adapting to poor coding standards and design is not helpful. My advice to this kid is stick around if need be but don't expect anyone to respect his opinion if he's fresh out of school. And calling other developers out with his current status is dangerous and not beneficial. He either has to put up with it and face the reality he won't learn much from these types or he can start searching for a new place to work where people share his values.
Nathan Z
nathan, totally agree with you.
Gollum
+7  A: 

Being enthusiastic to code the right way is a good trait to possess and in the software industry we will always encounter other developers who write code that is not quite in line with our "perfect way" of coding. This should never be interpreted as rubbish code, or inept coders, because we all start out like that in some shape or form.

Always respect your peers around you as you want them to respect you. It's certainly not easy to do in an environment that highly regards ego, but attempting to approach a topic like this is never easy.

It's how you communicate

Try different approach angles, remember you are there to learn as much as to render a service.

So commenting on the "poor" code style in an "in-your-face" kind of approach might not be the result you were looking for. So then back up a bit and try approaching the topic with "I was considering the style of code used and have a few suggestions..." and see the difference that gives.

Where I work now, the one thing I've learnt is that it's fine to comment on something that's might not be good quality but then I had better have a better solution to present.

In other words, be prepared to back up your words with useful solutions and not because you feel so.

Mike J
thanks Mike, I definitely do not fight but I am worried about my growth. If I don't see how a good Code looks like, how I am going to write that way.
Gollum
Reading other people's code is a good way to find out what is good and what is bad. Remember it takes a number of years for a tree to grow, we are no different. Read and learn. That's a good starting point, and as a developer, don't be afraid to ask questions. :)
Mike J
+1  A: 

I fervently hope, this is the best opportunity to grow by facing the challenge.As Robert said,try to lead by example.If possible let them adopt your pattern.

+13  A: 

Your best bet is to NOT to handle it at all. Here are potential problems if you try:

  1. You will be criticized for doing something you were not told to (makes performance reviews go real bad.)
  2. You will have less time to do your own work.
  3. You will not advance your career by cleaning working code- if it is not broke then do not touch it.
  4. Never make enemies with people who control your career- unintentionally implying they are obsolete morons does not help your cause (especially in a bad economy).

Focus on making your own code great. Battling poorly written code is part of the ill of being a Software Engineer. You are in the wrong profession if you will not stand for it.

A little off point but important- You may need to switch jobs or teams if possible once the economy picks up. Mixing with a truckload of bad coders who do not bother to update their knowledge and practices dulls your own programming skills and weakens your marketability.

Phil
+7  A: 

The present is embodied in Hexagram 47 - K'un (Oppression): Despite exhaustion, there may yet be progress and success. For the firm and correct, the really great man, there will be good fortune. He will fall into no error. If he make speeches, his words cannot be made good.

The future is embodied in Hexagram 6 - Sung (Conflict): Though there is sincerity in one's contention, he will yet meet with opposition and obstruction. If he cherish an apprehensive caution, there will be good fortune. If he prosecute the contention to the bitter end, there will be evil. It will be advantageous to see the great man. It will not be advantageous to cross the great stream.

I Ching
Odd, but I like it. Please continue to post.
brone
This makes no sense.
Phil
Deep. Vague, but deep.
mizipzor
+2  A: 

This is the most basic reason why establishing coding standards and code review processes are a good idea.

I will not write three page functions no matter what coding standards and processes are established, but some people will. They will create 20 local variables at the beginning, without initializing any of them. You'll have pointers and integers with unspecified values. You won't know the exact meaning and scope of each variable. Etc etc.

Try to convince your manager and, later, your team, with solid arguments. Maybe you could start with a shared reading of Effective C++ or C++ Coding Standards. Try to stress the point that, when working this way and creating better code, everybody wins. If they see this as a win-win situation, they will be more open to the change.

Daniel Daranas
+1 for suggesting C++ Coding Standards. I can't praise that book enough for working with a team on a C++ system as a way to get everyone on the same page without arguing over petty things like formatting style.
A: 

You are not alone. I too faced recently, luckily we have support from Senior Management for Code Reviews. 1. Even a single line change for Bug fix should be reviewed online.

  1. Comments on code can be classified as CodingStandard/Suggestion/Clarification/Major/Minor etc

  2. While giving comments to senior you can start with Clarification/CodingStandard rather than Major

subbul
+2  A: 

I can empathize.

I'm below two senior programmers who have very unique styles that I find frustrating. We have code that consists of one main function that's 1000 lines long. (That is not a typo.) Our coding standards discourage globals, so we make every program one App object. Now our globals are member variables! When we need an iteration interface for C++ classes, why should we use the begin, end, and operator++ conventions, when First, AtLast, and Next can be used instead. We've wrapped up third party libraries in custom interfaces for no good reason. (We've wrapped log4cxx and lost functionality for no reason I can tell, and one of our date classes consists of a shared pointer to a boost::date object with a fraction of the functionality.)

Here's how I've kept my sanity. I've focused on the new languages and tools. This is our company's first project involving Python, and I've spent my time writing utilities and programs there. While the senior programmers code in what they're familiar with, I've got near free rein of all the Python code. I couldn't stand the C++ APIs we use, so I duplicated most of the same functionality in Python in a much more friendly way, and the other developers prefer it too.

Likewise, we have little familiarity with log4cxx and less with boost-build, both of which I've taken time to study in depth and know good enough that people come to me with questions. I've written a handful of resources on our wiki giving usage tips for log4cxx and numpy and other tools.

AFoglia
There is a good reason for preferring begin, end, and operator++ at least, and that would be static polymorphism. Some boost functions expect a container to implement methods named begin and end (boost::range, e.g.), and using operator++ makes those iterators standard-compliant which is also necessary for polymorphism with generic algorithms. I didn't like the style either when I first used C++, but when I found out that just providing a standard-compliant random-access iterator in my data structure allowed me to sort elements, search for elements, etc. automatically, I changed my mind.
The other things sound horrible though. Good luck with your efforts!
stinky472, I agree 100%. I was being sarcastic. :-)
AFoglia
A: 

You could address the issue of "we are afraid to touch it for fear of breaking it" by writing extensive unit tests. Once you get the unit tests in place, you will be freed to refactor at will. If your unit tests still pass after the refactoring, you can be confident you haven't broken anything.

JoelFan
It's been my experience that it is really difficult to write tests for things with such complicated internal models. What I've tended to do, instead, is to try to write testable (preferably pure) functions for the particular pieces I could easily tease out of these balls of mud, test the new functions, then modify the original code to use them. Repeating this process ultimately gets you much more comprehensible code.
Aidan Cully
@Aidan +10 that is a nice idea!
Karussell
+4  A: 

I was in the exact same shoes before. I got hired as a C++ programmer to 'lead the team' on how to use C++ by an enthusiastic manager. That was about a decade ago. Some of the newer engineers loved me, the seniors despised me. Our system was basically a pseudo-C++ system. It was like C with classes, but it appeared that people didn't even understand the usefulness of things like constructors since they hardly appeared.

You complain about functions that are 3 pages long; we had functions that were 8000 lines long full of long jumps, function pointer casts, etc. One of the seniors even formatted the code with 2-space indentations so that super deep nested blocks can be written without using much horizontal space since the seniors seemed to be allergic to writing functions and procedural programming in general. Someone even inlined a 2000 line function thinking it would make things faster. You might be dealing with some bad code, but I was dealing with the most horrid copy-and-paste code imaginable.

Unfortunately I was very young and cocky. I didn't get along with the seniors, I fought against them in territorial battles over code. They responded by creating coding standards which no sane C++ programmer could follow (ex: it's okay to use operator new, but don't use exception handling, don't use constructors or destructors, etc). As a result I wrote the most bizarre and stupid standards-workaround C++ code just to kind of rebel against those standards since I refused to write C-style code given the reason I was hired (I didn't hate C so much, but writing C code was not part of the job description: I was hired essentially as a C++ consultant), even though the standards made C-style coding the only practical way to do things. I only kept my job because I put in so much overtime to make sure that my code works very well in spite of these ridiculous coding standards.

It wasn't until years later when others started to see things my way that we lifted the silly standards and started writing more natural, easy-to-read C++ code complete with STL and boost goodies, RAII, exception-handling, etc. That isolated the seniors who refused to write code in a more sane fashion and they were finally forced to adapt.

In retrospect, I could have done things much better. The seniors were intent not to allow me to be put in a teaching position, but I think I would have gotten my point across much faster with my head down. The biggest regret I have is trying to work around the impossible coding standards rebelliously rather than getting them rectified through clear and rational discussions. As a result, I have really stupid and obfuscated C++ code in the system which people attribute to me even though that's not how I normally write C++ code. The regular developers I work with understand this, but the seniors still point to it as an example of why C++ is bad.

In short, I recommend that you focus on making more friends rather than enemies. Your friends will support you, and if your way is better and you can clearly demonstrate it, you can isolate the few who will never agree.

thanks @stinky472, I am no expert, I am learning. And if I am the one who's teaching, my future looks scary to me(where do I learn?)!
Gollum
@Gollum I really think C++ Coding Standards will brighten your day. It might be hard to get your co-workers to read it, but if they don't, it'll still strengthen your own arguments in favor of certain practices - the ones that really matter. You also don't need to be authoritative. We're all students when it comes to programming, just share what you've learned.
A: 

Just place a copy of "Clean Code" (Martin), "Refactoring: Improving the Design of Existing Code" (Fowler) or "Effective C++" somewhere in the office where people may start browsing the books. From now on, word will spread. Seriously, its never too late to learn! ;)

atamanroman
we have all the books but the problem is these people don't have interest. And I have rarely seen a guy looking for a book or blog or any information.
Gollum
maybe you should suggest burning books again ;) time for a new job? Seems that there is not much what you could learn from them, too.
atamanroman