views:

131

answers:

3

I am going to be working on a project, a web application. I was reading 37signals getting real pamphlet online (http://gettingreal.37signals.com/), and I understand the recommended process to build the entire website. Brainstorm, sketch, HTML, code.

They touch on each process lightly, but they never really talk much about the coding process (all they say is to keep code lean). I've been reading about different ways to go about it (top to bottom, bottom to top) but I dont know much about each way. I even read somewhere that one should write tests for the code before they actually write the code??? WHAT?

What coding process should one follow when building an application.

if its necessary, I'm using PHP and a framework.

+1  A: 

According to the Test-Driven-Development methodology, you should write tests before you write you code. This helps make the code cleaner, more modular, etc - and lets you test the code at any point to make sure it works properly.

In practice, using TDD is a choice left up to you. I'll admit that I usually only use TDD when developing libraries or code that makes heavy use of algorithms. But there is a fair amount that can be automatically tested in a web app.

In any case, what they may be getting at is that you should start your code off small, just coding up what you need. Then iterate, and write more code as necessary, testing as you go. The simpler your code is, the easier it will be to test and extend over its lifetime.

Justin Ethier
+1  A: 

So you have looked at everything up to the coding process and you have an architecture and a design as well mock-ups of the web pages.

Pick the functionality that will give you the most bang for the buck. (Show something to the customer, which can be management or the people that are buying this from you.)

Start coding that piece of functionality and make sure it fills the requirements and do not introduce any future possible hooks. A lot of time gets wasted trying to guess what people may want in the future with the "programmers crystal ball".

The code needs to follow best practices for that language, hopefully somebody knows the language you are developing in well enough to guide you.

As you are done with each function point do a code review, review early and often in the beginning of the project.

Once you are done with coding the initial piece and the customer is happy, you can start on new pieces.

If you find common pieces of functionality, whether they are horizontal (domain specific) or vertical (architecture specific) then you need to refactor them. Remember, no cut and paste.

Romain Hippeau
Cut-n-Paste is EVIL! It is quick to do, but extremely difficult to maintain and fix.
AMissico
Now that is a "lean" answer. +1
AMissico
My answer would be a -1, but I was actually writing for something else and this question made me decide to write it now instead of later. (Hopefully) :O)
AMissico
+1 "A lot of time gets wasted trying to guess what people may want in the future."
AMissico
+1 "As you are done with each function point do a code review, review early and often in the beginning of the project."
AMissico
+3  A: 

Lean code means you are not writing code just because you are a programmer. You are writing only enough code to get the job done. Any extra code is just wasted time and money. If you find you are adding code to "use later". Stop. Later rarely comes and applications live long lives. That code you added for later only confuses later. Think of it this way. Every piece of paper on your desk must be handled. Every line of code must be dealt with.

I have read their book "Getting Real". I do not agree with everything. Yet, much of what they say does apply to web development and wouldn't apply to desktop or device applications. It seems a lot of the content, especially near the end, is just noise to fill a book.

How I Generate Lean Code

  • Document (for yourself) what you need to do and your understanding of what needs to be done. Be absolutely clear on your understanding. Better to get a yes/no now then a bug, or worst, a design issue, later that will cost you weeks, which always results in "hacked" code.

  • Generate a rough draft of a brief user-guide. Even if you are the only one who will read it. Do this with pencil and paper. Do not waste time with a word processor. You will waste more time "formatting" then writing content. If you cannot write it in words, how can you code it? It does not have to be pretty. Ugly is okay.

  • Generate any kind of documentation with pencil and paper as much as possible. (Hey, didn't I already say that.) It is much faster, it is clear, users can write on it, you can copy it, hang it on the wall, and so on. More importantly, you can erase it and start over with the user right there. Did I mention it is much faster.

  • Perform personal code reviews. One good method is to compare each file before checking into source control. I guarantee you will find bugs, items your forgot to do, and so on. This is a good time to clean up the code and generate any user or technical documentation and last minute testing.

For instance, I spent a day creating an Excel workbook to document a model I needed to create. I did this for myself. The model was already designed by specialists (on paper). I found, I should say Excel found, a circular reference. I reported this but was told that the model has been worked out carefully over the past month and the problem was my understanding. Two months later, fixing that "circular reference" costs us two weeks. We barely made the deadline. What could have been resolved in eight man-hours, costs us over sixty man-hours and lots of stress. Yet, because my code was "lean" the fix was only a few lines of code to a small table function.

Most programmers will code first. Most developers with document first. In general, every minute documenting early will save you ten minutes later. (Read "Code Complete".) Yet, do not forget to "get real". Your job is not to code, but to build solutions. Think of it this way, a writer's job is not to write but to create a document that someone will read. He doesn't add a chapter just because he or you might need it later. He continually has to make a decision on what to include or exclude to reach his reader. Better to take a few minutes to make a decision about code then spend a day coding, only to realize the code is not needed.


Generally, I do not write Test-Driven-Development (TTD) code. I find you end up writing a lot of code for no reason, instead of providing a solution. Before I get "flamed", I always write TTD on paper first. If I cannot work something out, I will create a "discard" project and write some code. If I find I have to dig deeper, I create a "wip" (Work-In-Progress) project, and if that fails, I will finally create an actual Test project. With that said, as Justin Ethier mentions, if I am writing libraries or core functions for an application, I always create a Test project.

Tidbit

For an application, I once created and embedded a RSS Pane control that downloaded company financial information from Google. My supervisor requested this feature to "wow" the managers before a demo. It did. Everyone absolutely loved it. While working with a company, users would get instant news alerts specifically for that company. It took me four hours to create and implement, which I did right before the demo. Yet, because this was a feature the users did not ask for, they constantly complained that I was wasting time implementing unnecessary features, especially features they did not ask for when I couldn't provide the features they requested. (Which was not my decision.) About two months later this control started throwing exceptions. It took me two days to troubleshoot and fix. This feature was a great success, but imagine the problems if it wasn't.

AMissico
Great reply, although I'm a little confused about bullets 2 and 3. What do you mean a brief user-guide, any kind of documentation? Do you mean a users manual on how to use the software, and wouldn't 2 and 3 be somewhat of the same thing?
BDuelz
#2 - You write a rough-draft of a complete user-guide for the application. Yet, you want to keep it brief, because we want "lean". If it does not directly relate to the user, keep it out. It is not in the user-guide, you don't code it. Moreover, brief as in lack of details. You are only doing this to identify what the user must have. You are mentally walking through the complete process for a user's point-of-view.
AMissico
#3 - This is important...now get this...do not use a computer to generate documentation. Compared to pencil and paper they are a complete waste of time in generating informal documentation. Certain documents and communications will have to be created. The idea is to do as much as possible quickly and easily. To keep it "lean" you must think before jumping into Visio, spending four hours on a pretty diagram, that gets thrown out during a meeting because it is not what users want. You can do the same diagram with pencil and paper, copy it, and distribute, if needed. Much much quicker.
AMissico
#4 - Is where you would actually create any need user or technical documentation with a computer. Since you are doing the review, this is a good time to captures screens, write notes, check and fix code. The point of this is to completely review what you have done to ensure you are truly done.
AMissico
#2 - I strongly recommend this step. In all my years, I can say that, "users do not know what they want until you don't give it to them." This step allows you to be a user and see what you are forgetting.
AMissico
Once again, great reply. Thanks.
BDuelz