Pair program with me! profile for carousel at Stack Overflow, Q&A for professional and enthusiast programmers

3/14/2014

Laravel refactoring hell

Recently I had an opportunity as a freelancer, to work on existing codebase project. It was supposed to be a simple Laravel CRUD project, that does nothing more then collecting user data and storing it in a database. There were some people working on this before me, and I along with other members of the team supposed to finish that project.

Since I am primarly Jeffrey Way's Laravel student, I used to watch him how he writes clean and testable code. Also Jeffrey taught me to think very abstractly, and to think about future of the code - not just because of me, but because of other developers that could read my code.

I learned throughout  my career to teach programming just from high quality sources and to follow top level developers/programmers.

So in that sense (very naively) I was expecting to see everywhere that basic pattern, which is very human in its nature. Write and teach for people, not just for yourself. Code is a poetry - that is my moto. I am staring at this screen most of my day - so let me create art.

BUT

That code was everything else except human readable and maintanable.
Let me be more expressive - it was worst nightmare that can happen to a developer. It was big ball of mud. But very low quality mud - not the mud that you can wash easily - but stinky mud. Almost crap.

Ok, enough of pathetic. Lets talks about the facts. First let me point that project was old more that 5 months. Very trivial project that could be implemented for 2-3 weeks, was lasted for more then 5 months.
With potential to never ends in this form. While looking in the code, I became aware about the state of the mind of the prior developer. And his attitude toward this project. Everything was telling me that he hated this project and that he didn't have enough experience for that. When I was told that it was his first "bigger" Laravel project, everything becames clear to me.  It was natural for that project to became abandoned.
Also requirements were very poorly explained to me. There was no clear separation between developers in the team. Just make it work attitude. Project leaders were missing programming and leadership knowledge. It was obvious that this project needs refactoring and it is impossible to make it work. Well, it can just work,  but how long ? Every composer update can break whole project.

Can it be worse ?

I could stop writing this post because it is obvious what to expect next - pure horror written by unexperienced developer.

But there are some interesting things in that code. When I think now, it was rare opportunity for me to work on such a project. So I decided to learn as much as I can. 

Here are some juicy facts:

  • Prior developer was a kind of old-school PHP developer. He was trying to insert plain PHP as much as he can. 
  • He was forcing his own (bad) development style into Laravel architecture
  • He had his own rules about environment detection, completely ignoring Laravel environment handling ( or not knowing ).
  • Code is full of constants, even Laravel has some elegant solution for that. 
  • It is almost not commented.
  • There is no standard indentation, naming and code style consistency.
  • Powerfull blade templates are rarely used.
  • There are  view partials everywhere - without obvious reason.
  • There are views everywhere, with inline CSS, PHP, Javascript.
  • There is huge number of controllers, migrations, models... Everything is huge in this code. And everything is so ugly. He didn't know how to abstract things.
  • Pivot tables and complex relations are used with no reason, just to make things more complicated  
  • There is a lot of empty and not used functions/methods.
  • There is a front end code mixed with server side scripts (assets folder in app/). This was my favourite - when I mention that, I was cursed :)
  • There is a lot of everything everywhere, where it shouldn't be.
  • Dependencies, dependencies and dependencies everywhere.
  • Not tested at all - but should I expect it to be tested ? It is impossible to test this project.
How much should developer charge to refactor this ? I think most developers would write applicaton from scratch - it is easier.

And there are some valuable lessons learned from this. First I have to think about the people, not just about my ass. Someone can read that code for a month of six month. Next, what about responsibility ? Does this guy feel responsible for his work ? Does he think about the users of his project ? I don't think so. Does he think about his career ? No. Sadly, anyone can be self-declared Laravel developer. It is a big problem

That leads me to conclusion that the community should somehow consider Laravel certification. All big framework are certified - so why not Laravel ?

It is hard to find good clients. As a freelancer, I am forced to compete with kids that use dreamweawer and with clients that mostly dont know what they want. And to look at horror code, like this one.

Thanks for reading.

No comments:

Post a Comment