Tutorial suggestion(s): Coding-best practices

We know you have an opinion on how things should be run around here. These are suggestions for the forums, and the website.This forum is not a place to ask for suggestions to your own coding (or otherwise) problems.

Moderator: General Moderators

Post Reply
User avatar
phpPete
Forum Commoner
Posts: 97
Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey

Tutorial suggestion(s): Coding-best practices

Post by phpPete »

Almost every tutorial out there is a " how to " sort of piece, a sort of "just the facts" way of doing it.

How about tutorials on best pratices, style, efficient coding?

Say a two step approach:

The "how to " example, then the " how to do it better " example?
User avatar
phpPete
Forum Commoner
Posts: 97
Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey

Post by phpPete »

To paraphrase Mac and limlib;

It's all about personal style, which is developed after much coding and "tons of mistakes".

I can definitely do tons of mistakes...;):)

So, perhaps this isn't such a great suggestion afterall...:(

Happy Coding!
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

I'll agree with those who said that its about personal style and making mistakes first. However you can help the process. Here's some possible suggestions (many of which sound trite):

Sit down and design the system on paper, even if its small. Play what if games. "What if I wanted to add feature foo later..." how would you do it, would it be easy/hard? If hard could you make it easier by changing your design? Maybe its not worth changing it, but having through it through you'll know why and would have seen your options. Pretend that you someone else will write half the code, what do you need for your half to work? Write up a formal design document, have coders you trust critique it. Come up with multiple ways of doing a task and explore their strengths and weaknesses.

Learn a very different computer languange, if PHP is your first languange or you've only dealt with similar languanges (Perl, C, Java, etc all very similar in coding paradigms) try a little bit of Lisp/Scheme or Haskell. You'll find that they make you break the problem down differently and your solution will be different. Even if you never go back to it, you'll have learned another way of thinking about a problem. (Scheme is wonderful for teaching about iterative/recursive behavoir and Lambda-Calculus/Closures).

Don't be afraid to write it twice. First attempts at most efforts end up falling short of the authors vision. Something doesn't work quite right, parts of the code are uglier than the author can tolerate. Figure out why and update the design, rewrite it the application. I find that this is both the hardest and the best tool for gaining insight into "good" practices. Its very tough to throw away code and redo it, however you'll likely never forget the lesson.

I think you made a very good suggestion, actually. As has often been said of PHP and Perl, they make it very easy to write bad code. Most tutorials give the basics, many cut corners, (though the ones here are better than many) and very few address a complicated enough problem-space to really get into the interesting bits. Finding a good way to present such a essay/tutorial would be tough. Maybe a project description that has some interesting subtleties and have a panel of people present alternative designs.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

I agree entirely withe nielsene. In fact, I plan to learn a Lisp-variant shortly for just the reason he mentioned (and the fact that i'm taking AI this semester).
What I meant was, I don't personally believe the articles about "use these little tricks" work very often. I, personally, never remember to do something until it's come back to bite me - hence my advice to "make a lot of mistakes".
As for general programming practices, definitely read books about programming practice and theory, and, even better, take a class or two in programming and logic. Planning helps immensely, as does rewriting code and learning new languages.
User avatar
phpPete
Forum Commoner
Posts: 97
Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey

Post by phpPete »

Planning is the key, and I really have to force myself to sit down and do it, preferring to just sit down and start coding. That's like a caprenter building a house with no blue print..."Hey lets put a the tub in the pool..saves on water!" " GREAT idea!!!"

Thanks guys..

PAS
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

I've been thinking some more about this suggestion, maybe could something like the following work:

A seperate forum designed for peer review? Initial posts should give a link to a functioning site or design description. In the case of a functioning site, the source should be availible and ideally the author would provide at least a web page or two about what their goals were and why they did things the way they did (an after-the-fact design document).

The requirement of a functioning site/design docs is meant to keep the place from a becoming a "write my site for me" wasteland; moderators maybe could aggressively lock/remove such thread or just boot them back to an appropriate forum.

The idea probably needs lots more fleshing out, if people think its even worth pursueing...
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

That sounds interesting. I know it would help me make the code for my site better if I was making it with the knowledge that people would be looking at it. It would require a lot of work to get a site ready for that, but (almost) every coder likes to have their code critiqued.
Whether it would work? I'm not so sure. Whether it would be interesting to see? I think so. Maybe we should start a new thread to toss around ideas.
Post Reply