Re: How to write code: how wrong am I?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 22, 2011 at 01:29:30PM +0200, Dotan Cohen wrote:

> I wrote a short page on how to actually type of code that one writes,
> it can be found here:
> http://dotancohen.com/howto/write_code.html
> 
> The point that I stress on the page is that first you close an
> element, then you fill it's contents. The page has examples in HTML
> and PHP. I would like to know what the experienced programmers here
> think about this. Am I going about it wrong?

Not a bad idea for HTML, not so great for PHP. Some of what you're
trying to solve/avoid can be handled by a decent editor, one that does
syntax highlighting and/or does brace and parenthesis checking. It
doesn't require an expensive IDE. I use Vim, and it works fine for this.
And honestly, if you're serious about programming, you really shouldn't
be using something like Notepad on Windows. Seriously. We had a coder
working for a company where I was who coded in Word of all things. We
just looked at him like he was crazy.

Annotating end-braces is also very helpful for long conditionals. Vim
can track start and stop braces, but when they span several screen
pages, it can be a problem.

Likewise commenting code as you go is an excellent idea. 2:1 comments
are a bit much; Linus Torvalds would kick your butt. But I often do this
if I'm not exactly sure how I'm going to code something, but I know the
rough logic of it. Lay out the conditionals, comment on what should
happen within each code block, and then go back and fill in the blocks
with actual code.

It's also worth noting that sometimes code is hard to follow. And even
if you're going to be the only one updating it, you may well forget the
logic six months from now. Commenting allows you to recapture that logic
more easily.

And then there's the PHP interpreter. If you make a syntax error, like
failing to add an closing brace, the interpreter will tell you so. If
you spend *enough* time coding, you can usually track down where your
mistakes are relatively easily. If you've ever coded in C, the same is
true for the C compiler. Its behavior is very very similar to that of
the PHP interpreter. It's something you get used to over time as you
code more and more. Also, what could be called "incremental coding" or
"stepwise development" helps: Code a little. Run/compile. Code a little,
run/compile. That way, errors are easier to catch than after you've
written 5000 lines in a file.

Paul

-- 
Paul M. Foster
http://noferblatz.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux