

Ask HN: What code should I be looking at? - mixmax

I started programming some months ago (PHP and javascript) and have grasped the basics. The more I learn the more I realise that one of the most important things is to write well structured code.<p>Can you recommend some open source projects in PHP that are well written and well structured that I should be looking at to see how it's done right?
======
mechanical_fish
I got into PHP by way of Drupal. I tend to think of myself not as a PHP
programmer, but as a Drupal programmer who is therefore stuck with PHP. I
don't work with any other PHP frameworks; If I wanted something that wasn't
Drupal I'd be using Ruby.

Now that my biases are clear: You should take up Drupal. It's a big system
with a lot of architecture, but the core is not _too_ big; it's being hacked
on by many thousands of people and is continuously evolving as the community
learns; and it hits a sweet spot between being well architected and being open
to the kind of simple cut-and-paste anarchy that makes PHP thrive -- it's
designed to let you obsessively customize everything, but it tries to
encourage you to contain your creativity within pluggable modules that can (at
least in theory, but often in practice as well) be manipulated by noncoders.

If you want to try Drupal and you are a coder you must read VanDyk's _Pro
Drupal Development, Second Edition_ ASAP. Trust me on this.

As for Javascript, which is arguably more important: jQuery, jQuery, jQuery.
Also: Douglas Crockford, _Javascript: The Good Parts_. And learn your CSS if
you haven't already; I did that by reading Eric Meyer's O'Reilly book,
followed by Dan Cederholm's book.

~~~
mixmax
Thanks :-)

I'll look through the drupal code with your post in mind - sounds like a good
learning experience. About javascript: I agreee, it seems that jquery makes a
lot of stuff trivial, unfortunately I only discovered it after having (poorly)
implemented quite some javascript myself. As for the CSS - I've got that
covered pretty well.

~~~
mechanical_fish
_unfortunately I only discovered it after having (poorly) implemented quite
some javascript myself._

That's only unfortunate if your poorly-implemented JS is live on a popular
site and you have to maintain it. :) Otherwise it's a great educational
experience!

You don't realize how great your tools are until you try to live life without
them.

------
neovive
I would highly-recommend reviewing the source code of the KohanaPHP framework.
It is very clean, elegant and well-structured OOP code written by some very
talented developers.

<http://www.kohanaphp.com>

------
jncraton
I actually learned a lot about coding good PHP by learning Rails. I'm not an
expert by any means, but it forces tons of good programming practice on you
which can carry over to other languages and frameworks.

~~~
gnaritas
It suggests, not enforces, you can still do boneheaded things like putting
logic in the view or inappropriate logic in the controller that should be in
the model. The presence of a model and controller doesn't make you write good
code.

------
jmtulloss
First, I really don't want to start a flame war. That being said, my opinion
is that PHP as a language is not well structured or well written. You might
want to check out Python or Ruby, both of which have great web frameworks that
encourage structure.

~~~
stcredzero
It's the same problem in _any_ language. Most of the code out there is
mediocre or bad. The code you want to learn from is a few standard deviations
to the right. When you are learning something always _Remember Sturgeon's
Law_!

I would rather work with someone who produced excellent PHP than someone who
wrote lots of weird hybrid procedural/functional Python full of esoteric array
slicing hacks.

Being able to apply your intellect to _revealing intention_ in code is a
valuable skill in any language, and I suspect that it transcends any
particular programming language.

~~~
neovive
Agreed. Just because a language has a low barrier to entry, doesn't mean it
should be blamed for bad code. I linked to the KohanaPHP framework source as
an example of very well written PHP code.

~~~
jmtulloss
I certainly agree that anybody can write bad code in any language, but my
argument is that PHP itself is bad code. The libraries are inconsistently
named, there's no coding standard in standard libraries, and the language
changes behavior according to configuration.

PHP as a project is poorly structured, and all other things being equal, it
should not define your programming worldview.

~~~
gnaritas
It's not just bad code, it's a bad language full of silly inconsistencies that
don't make sense and trip up even the most experienced programmers.

That's what happens when you build a language by piling hack upon hack instead
of actually designing it. Languages like Ruby and Python actually have a
philosophy and style that keep the languages self consistent. Consistency is a
critical core feature of any good language, PHP doesn't have it.

------
Maascamp
Browse through the Zend Framework. I don't know why more people don't
recommend it as a well written large size PHP code base. It's a little
exception happy but that's more of a style issue.

------
Dobbs
Hate to hijack the thread but can anyone offer some examples of good Python
and/or C code to look through/read?

~~~
simplegeek
For C, FreeBSD. For Python, BitTorrent. IMHO.

------
khangtoh
Wordpress?

~~~
bjclark
For good code? Really?

~~~
khangtoh
I think a suggestion from your reply will prove more constructive

