7

First of all, is not a programming matter, is a programmer afair.

I'm the new web programmer in my company.
I'm here just for 2 weeks. And they want me to teach Wordpress, configure & install it, and things like that.

But they have a intranet too to make all the compatibility stuff, tracking clients, ordering event, auto-emailing.

Well, the intranet is very nice, and they spent 1 or 2 years with a programmer to do that.

But the problem is:

The intranet is great for the user (a bad UI experience but works well).
They have it from 4 or 5 years now.

But if you go to the code, it is annoying.

Seriously, it's really really really heavy, code duplicated, insecure. All works ok, but all is wrong in code view.

Some points:

  • The site keeps 4GB of disk space (without DB!)
  • There where thousands of files, folders, with no order
  • A lot of files are duplicated
  • There were, at least, 20-40 files you have to configure to change the database source
  • Some config files are in .ini, so i can download from anywhere
  • The sites was coded for 4.0 or 3.x, miraculously it works on 5.x with some warnings.
  • The site was coded without any kind of scalability, they just copy and paste files and keep working, no includes, nothing.

For example: I see, at least 40 files called check_in.php in different folders.

Functions called: paste() paste_2()...

What points you will use to convince your boss to take care of that and refactor all the whole site?

It's a pain in the ass. I know refactor all gonna be hard, but I think it's the better way to continue my work.
Because they want me to make modifications on that and I have to spent 3 hours just to understand from where comes that **** function called paste() and what exactly do.

Ah, one more good point.

There's no documentation at all.

S.Lott
  • 45,264
  • 6
  • 90
  • 154
nax
  • 173
  • 4
  • 16
    If you are working for a business you need to make a business case. "If we do this we will get more money". You may find that doing that is impossible, even if you believe, correctly, that the quality is very bad. – Joe Feb 20 '12 at 10:02
  • 1
    See also http://programmers.stackexchange.com/questions/129951/general-approach-to-re-factoring-an-large-very-badly-written-legacy-system – Péter Török Feb 20 '12 at 10:25
  • We have the problem of directories having hundreds of files in them. One quite good solution to this problem is to change how you access files - for the most part I tend to use the Projects Explorer in NetBeans. But with hundreds of files in one directory, this is awkward, so I now use the 'Go To File' widget, and it is massively improves the speed with which I can get to the file I need. You hit your shortcut, then type a (wildcarded) filename, and it searches in realtime until your result list is small enough to choose from. – halfer Feb 20 '12 at 10:42
  • well have you tried the money card? bad security could potentially leak information or make the intranet go down, storage costs money – Jonathan DS Feb 20 '12 at 10:46
  • 13
    So, you're very fresh (2 weeks) and want to propose a total refactoring? This is crazy. It's more likely that you simply don't understand a new (for you) legacy codebase. It's always like that at the beginning. Wait at least a few months and then rethink if you really want to propose a total refactoring. – quant_dev Feb 20 '12 at 10:49
  • As i say in the answers, @quant_dev i gonna wait for a month or two to make the proposal. I know it's crazy idea. But i'm the only one programmer here and this is a crazy crazy intranet. I'll take 3 days to do a migration, and, at the moment, not all the features are working. Because when you think you are done some file have a new string database to correct. I just gonna do what you say, because i know for sure he gonna say no if i proppose now. thanks for replys. – nax Feb 20 '12 at 10:58
  • 2
    Why did those that made this quit? –  Feb 20 '12 at 11:03
  • quant_dev is right, wait until you're settled in and had time to look at it, sometimes the way specific things have been handled in a project may not make sense to you right now but will later. But it does sound like there's a heavy amount of work that needs to be done, but if it works then it gives you time to iterate the changes. – Nicholas Smith Feb 20 '12 at 11:08
  • @quant_dev: Technically, I expect the OP is right. His employers paid somebody, or an incompetent consulting group, a bunch of money and got a pile of WTF. Now OP has to give them the bad news. Been there. It's best to break it to them gradually. Someone made an unfortunate decision and won't be happy to hear about it. – kevin cline Feb 20 '12 at 17:02
  • 1
    In this case, beginning your career in a firm by becoming the bearer of bad news can only end badly for the OP. – quant_dev Feb 20 '12 at 17:03

3 Answers3

16

The amount of change one should effect is contentious. What happens if you decide on a 'big bang' approach, estimate that it should take two months to refactor completely, and end up taking six? I'm not questioning your competence - it's just that projects like these can easily spiral out of control.

You could make a case for a gentle, iterative refactoring. So maybe you take a day to centralise the configuration files, and then move to other projects. Then two weeks later, you add autoloading. Get small changes live each time, and then wait for a bit for them to bed in. This way you remain productive on new projects, whilst slowly improving your codebase.

You should do these things on a separate branch, and if there are other tech people that your changes will touch (programmers, dbas, etc) then get them to buy into your changes before you do them.

halfer
  • 316
  • 3
  • 9
  • 15
    “Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.” – veryfoolish Feb 20 '12 at 10:10
  • 1
    I understand your point. I'm pretty sure it gonna take more than expected, i can't say for sure how much time it can cost. With the two answers i have i'm thinking on take a time, see what time take for each little change. Know more about this intranet and then do a better planification of all and give my boss to think about. I love the idea of making a little branch. Maybe i gonna do that, just in my free time. Thanks a lot. – nax Feb 20 '12 at 10:26
  • Is the whole site under version control, btw? If not, that would be the first thing I would do - it's a nice quick win. And essential, of course, if you're going to do branching. – halfer Feb 20 '12 at 10:45
  • The problem is the company just have one programmer before. And he was who do the intranet. don't have control version, servers, nothing. Just an intranet and a web page. I'm here just to do some changes, in theory. I take care of version control because i used it and i know how good can be – nax Feb 20 '12 at 10:54
  • Excellent, well get everything into a version control system you know - even files you think are dead. Then maybe get a link-checker to see if any stuff can be deleted or tidied to a different folder (of course make such changes carefully ;) ). – halfer Feb 20 '12 at 11:12
  • You don't need any server for version control. Git runs locally and keeps its data within the directory. Although if you're only using local version control you'd want to make sure you have good daily or weekly backups. – bdsl Dec 17 '16 at 11:27
10

Explain the cost benefit: Every time they want to make a change you will spend 3 hours figuring out the code, and only then will you be able to make the change, which will probably take less than 3 hours. On a neat, well-structured site with good documentation most changes and additions can start immediately without delay. In your case you have a 3 hour prep session before anything can happen (based on what you have described)

Also, try to find a real-world analogy that your boss can understand. Explain how working on undocumented code is like trying to find something in a cupboard full of non-glass jars that all have no labels.

Generally doing a complete overhaul of a site is never (financially) viable. I have almost always had to compromise to make changes to a poor solutions as and when I touched on the code-base to avoid loosing too much productivity time to re-factoring. Code Clean-up is hardly ever allowed for from a costing point of view, it generally happens as a passive side-effect of touching on something else that needs to be improved.

My Other Me
  • 201
  • 1
  • 3
  • 1
    Well, i'm in a trouble. Bot answers helped me. as i say in the other one, i gonna spend some more time and know how much time takes any change, give a complete documentation from all change i do. And in a month or two, give to my boss. In the mean time, i start working in my free time in the refactoring, and planification of the whole intranet. thanks a lot! – nax Feb 20 '12 at 10:28
  • 1
    +1, I agree about not being able to 'fix everything'. On my current project, I have to use a homegrown ORM (!!!) that was written when Propel was already a solid product. Sometimes when writing a query type we don't yet have, I find that there's a bug in the ORM - but changing it is just not viable for as long as our platform is on PHP. – halfer Feb 20 '12 at 10:37
  • In terms of warnings, we have loads, but we're working on a slow programme of removing them, and iteratively removing the template layer that is often their cause. It's low priority and the changes are small, so are non-disruptive. – halfer Feb 20 '12 at 10:39
  • 2
    @nax: Not sure what you mean by "free time". Do not donate your personal time to this enterprise unless you are an owner. If you really prefer coding to other leisure activities, contribute to an open-source project or start one. That will at least be good for your resume. – kevin cline Feb 20 '12 at 17:09
  • @kevincline i'm just talking about the last 10-20 min after finish my work, usuarlly are free timed. but i don't think i gonna do that. because it take so much time... but maybe i use it to documentation or planification of little improvements. Do you have or know any open source project or site i can go to help? – nax Feb 20 '12 at 17:45
  • @nax: well, that's tough because there really aren't very many open-source projects these days, and the ones there are have plenty of help. – kevin cline Feb 21 '12 at 04:42
3

It will help your case when you show some sort of transition path. Evolution not Revolution.

This way the decision becomes less risky.

DerMike
  • 1,053
  • 2
  • 7
  • 9