Ask HN: I am forced to write awful code What do I do?
To have an idea about the code I am going to tell you that we have a PHP class called dbConfig which stores database credentials. This class is then extended by a DB class which has query functions and other functions that deal with data retrieval from the db. This class (DB) is then extended by a class called front-end which has some functions that generate forms and escape inputs. this class (front-end) is then extended by a Cart class that deals with user logic and creates a sort of a fully functioning shopping cart (amazing i know!).
All this badly implemented inheritance is topped up by the fact that global variables are used throughout the site/app. It is an awful procedural codebase (at one point it even uses magic quotes). Everything single job becomes a bodge job. If I have to change something it then creates an error in a totally different part of the website.
I have suggested that we move towards a MVC framework or something that will help with this horrible dependencies and will probably decouple most of the things, so that code maintenance would be easier. Sadly, it seems that the company is more interested in spewing up websites and cashing in the money (from some rather big international clients) than in creating better quality software.
Now that you know my situation.. here comes the question: What should I do? How can I speed up the transition to a development process that is up to the industry standards? (did I tell you that we still deploy apps with FTP and have htaccess authentication for the web administration area??) I am sure that there are some developers among you that have been in my situation at one point in their career... so what did you do? How can I say this to my boss? I don't want to be responsible for crappy websites that pollute the internet, I don't want to keep on bodging code.... but at the same time, I don't really want to change my workplace (it's well paid, close to home, etc. etc.)
Thank you all, and... I'm sorry for the rubbish I upload every day!
17 comments
[ 47.5 ms ] story [ 912 ms ] threadLong story short, I quit and went freelance, best decision I ever made :)
My advice to you would be that (unfortunately) it will never be considered cost effective in management's eyes to rebuild the existing sites in a decent CMS / Framework. But you should at least be able to get them to use modern dev standards on any new builds, or complete rebuild of existing sites.
A few tips:
1) Build demos and/or sneak in good code when you can. There will always be a subset of people that can appreciate good code once they see it working, increase your chances of finding those people and converting them to the cause.
2) Do not overwhelm them (them being veteran developers and management). You will scare them if you talk about starting from scatch or major overhauls. This is a battle of incremental changes, technically and culturally.
3) Don't burn yourself out. Its a daunting and draining task implementing the kinds of changes you're talking about in an organzation that doesn't want or appreciate it. If you can't find the right support, its ok to give up. If you do give up keep in mind that YOU didn't fail, you're just not in the right position or in the right organization to make it happen.
I found another developer with the same feelings about our (lack of) code quality as me and we put our desks opposite each other. This allowed us to exchange ideas and implement them in a positive environment. This worked well, and we quickly improved our deployment and testing practices.
But refactoring the code was harder. Developers that had been there 10 years knew that starting to pull at X would break Y, so they were afraid of change. Of course they had experience to avoid most problems, and this knowledge was what made them valuable to the company. At any other company they would have been sub-par developers.
Our improvement progress slowed down. We got tired of having to work really hard to get to the most basic industry standard, which were still far from stuff we could be really proud of.
In the end we both quit, and it was the right decision.
If you feel you have the support from other developers to make a change to your situation, then stay and do it with energy. But otherwise just move on, there is no point in wasting your time when there are so many better places.
When LoseThos was made, C+ was made.
Linux is a kernel, GNU/Linux is a compiler.
You are a monkey with no vision. Why on earth have 7-bit ASCII everywhere and why was the library signed characters!
The more names spaces the better. How many name spaces do you have? I have 2000 and it's only 100,000 lines of code. Pretty moduler, huh!
If you can align your interests (write better code) with their interests (make more money), you may have a chance to rewrite the code. :)
Prove them that refactoring the code can help you create more sites faster. With more sites in less time, they will make more money.
Learn? Of course. There's a huge difference in asking people here what to do in your situation, compared to living your situation with open eyes and mind. You'll be much better able to avoid creating situations like you're in now, after having lived it. Hint: it wasn't caused by poor coding practices.
It seems that in 3 weeks or something like that we will be moving in new offices.... And there is a promise for improvement... probably this is the best time to kill off the old home-made CMS and replace it with a framework! ...
PS: Thank you all for your responses... it's a good feeling that I am not the only one that was in this situation.
---
You have to realise that the company you are working for now might be suffering from industrial inertia - also, unless you are privvy to their financials, you probably have no idea of any pressure they are under to make ends meet. In general, selling something that you've already sunk costs into is more cost-effective than writing something new and then selling it, so if their primary objective at the moment is to make money and they have a system that is working, they will probably keep pushing it. It is rare, though not unheard of, for a company to be so developer focussed that they will undertake a wholesale refactor of their code base if it is currently bringing home the bacon. Also in something very old and convoluted (as you've said pull on one part and another part will collapse), refactoring is often less time-efficient than simply writing it from scratch. Ask yourself "if I manage to refactor this into a best-of-breed code, will I be enjoy putting the time and effort into it on a daily basis? or will it just be an albatross around my neck every morning until it is done?"
Consider your goals - you could consider staying at the company and learning about the business end (i.e. actually selling the software), maybe make some valuable contacts - that's a good goal but it might not be the right goal for you. If you currently just want to write beautiful code, then find somewhere else to work - perhaps a more greenfield development without legacy code.
edit to add a potentially relevant link on stackexchange that i've just come across: http://programmers.stackexchange.com/questions/155488/ive-in...
Anyway... that stackexchange question has some very good answers. Thanks for sharing!
The first and foremost thing you must understand is that each code base has a personality of its own. Code bases, like people, change over time but they rarely deviate from their core character. And the more money that code is making for someone, the more resistant it grows to change.
So, the thing is, don't put so much of your identity on it. It is not personal and it is not about you. In due time you will have chances to try your hand and build something from scratch, but until that day comes you need to work with other people's code in order to learn what approaches are feasible and where the pitfalls are.
In this particular case, only you can decide if the current code base is so much of a mess for you to bother. But you owe to yourself to give it another try, this time from the perspective that you want to make it not perfect, but as good as it can be. Once you have given an honest try to assess the potential of this system, and can explain in detail why that is negligible or non existent, you may look for the next job with a clean conscience.
Or
Make the security argument, a procedural system the size of CMS and site running on it ->could<- be riddled with security issues especially as developers are acknowledging that any addition is a bodged job due to global variable etc etc. If they are dealing with larger clients this should concern them enough.
Also if you're lucky enough to be deploying to PHP 5.3 using closures (http://php.net/manual/en/functions.anonymous.php) can save a lot of hassle when dealing with procedural code.
In my opinion, when things have reached this point its time to go, there is nothing more you can do there.
Even staying there for the money is ultimately a self defeating decision.