Skip to content

Comment on Ask HN: Examples of bad open-source code to learn what to avoid?

Comments

I feel like this could lead to very opinionated, non-constructive comments/flame, but if were to give you an example, I'd suggest taking a look at Wordpress eco-system. While Wordpress core's codebase has improved significantly over the years, some of the plugins haven't.

The top pick goes to WooCommerce, although an open source E-commerce solution on top of Wordpress, it has some terrible decisions under the hood.

The top pick would go to mixing presentational logic with business logic. For example, to render a table, instead of exposing an array of objects to allow the developer to loop through it as he/she sees fit, WooCommerce will force you to use a PHP function that renders a table for you and there's actually no way to modify the presentation logic if you wanted to.

It's a really fundamental programming paradigm that even top open source companies fail to adhere to.

Again, I'm not saying this to attack them or the maintainers behind the code, just my opinion of why I think it's bad quality code while respecting the fact that developers still do take time and effort for us to enjoy something with freedom and zero cost.

An indirect thing you can learn from this example is that how little code quality matters when it comes to product popularity or revenue.

WordPress and its plugins are most often cited as examples of bad code and to top it off it is written in PHP - a programming language hated by a lot of programmers.

Yet when it comes down to it, WP powers 33.6% of all websites on the internet. Just think for a second how big that number is!

So if the software gets the job done and the end-user can easily understand it, it really doesn't matter if you write it in what language, using what code patterns.

Revenue for the company behind Wordpress itself? Maybe.

Revenue for the end-user? No way. Wordpress sites are high maintenance due to its enormous attack surface and dubious code quality. I would never even consider it as it will just be a liability I don't want to deal with.

I think a very easy way to mitigate that problem is by using something like siteground that mantains and optimizes that for you.

I don't have direct experience with then myself but that's what I've heard most successful wp blogs do

I have moved entirely to a JAM stack i.e. static sites with JS to add functionality via apis. I’m happy with this because if my host dies or pisses me off I can very simply move to another host. And my choice is any host, from S3 to classic shared hosting to CDN edge providers to a raspberry pi hanging off my router.

It’s a lot cheaper, and cms using tools like Hugo or Jekyll is really a lot better than WP because let’s face it you’ll end up editing the theme pho files in Wordpress. I now use metalsmith for new sites instead of Hugo as it’s more hackable.

One thing thars a bit harder is Wordpress is nice for a techie working with a non techie content editor. I’m making do with markdown and github for that but a solution to that problem could be a indie hacker idea.

Ghost [1] seems like a good alternative blog platform for non-techies if you really dislike WordPress. It's a CMS like WordPress but it focuses mainly on blogging unlike WordPress which does e-commerce as well. If anyone here is interested in JAMstack with ghost here's a Gatsby ghost integration which brings CMS like content management to JAMstack [2].

[1]: https://ghost.org

[2]: https://gatsby.ghost.org/about/

to top it off it is written in PHP - a programming language hated by a lot of programmers.

You could say that about any language. PHP is loved by many programmers too.

Not to the degree that PHP is hated.

It's only hated by those who haven't grokked modern php > 7.0. Thanks to laravel the php ecosystem has grown quite a bit over the past few years. I know many rails devs who prefer laravel/php to rails for what it brings to the table. Sure ruby is prettier syntax, but php isn't as horrible as it used to be. Now if it could catch up on parallel/asynch it'd have a better time.

Sure there's sexier languages like elixir and go and rust, but well designed php code is a pleasure to work w/.

I’d argue PHP is so hated because of WordPress and the terrible code/practices associated with its ecosystem.

Amen to that, I live/breathe for laravel projects, I contemplate slitting my wrists when working on wordpress.

Laravel projects can be just as bad of a codebase as WordPress.

yeah, I'm working on one now (picking up where Indian devs left off) ... Code is laravel 5.2, every controller injects session, requests, etc into the constructor, then injects a 'manager' which is basically a loose repository structure, laravel 5.3 > somewhere makes it so using requests/sessions in constructor you generally want to wrap that in middlware...

So upgrading is a huge nightmare. This is one reason I'm not a fan of repository pattern, more classes to inject everywhere even when they're not fully needed. When just making a fatter model would suffice.

Also lots of bad php practices...everywhere else. Bad devs can work on any code base, but laravel core code is pretty beautiful, and laravel's community encourages better code, if some bad actors write shitty code the rest of us have to clean up that's on them, but woocommerce is owned by Automattic and has bad code, you'd think they'd fix it or something being a large company.

There's also tons of great packages out there that are written way more OO and with testing and best practices than there are for wordpress. Laravel is also easier to optimize, and the data structure for wordpress can get out of hand as well.

ltdr; Yes, lots of bad laravel code -- but that's on the individual dev, core laravel and lots of laravel packages use php best practices and encourage good coding. Easier to write better code in laravel than it is a wordpress plugin.

PHP is regularly found to be the most hated programming language

https://fossbytes.com/most-loved-hated-programming-languages...

We usually gain a better understanding of the world through numbers rather than booleans.

It's true that programmers hate PHP. It's true that programmers love PHP. It's true that programmers hate other languages. It's true that programmers love other languages.

This isn't very useful, as you seem to imply; but only due to the boolean perspective.

Numerically, PHP is hated far more than other languages, and loved far less (StackOverflow surveys come to mind, but I'm sure there's a whole lot more data on this)

The StackOverflow surveys only show you the data from the people who want to answer. It's always going to be skewed one way or another. I use and like PHP, and I rarely do the SO survey because I never see it in time.

I do think PHP holds a larger share of "hate" than most other languages.

I don't know... Ask me most days and I'll tell you how much I hate javascript and it's horrible ecosystem and incongruity...

but I can't live without using it as it's pretty much the only option for what it does....

In my fullstack workflow js is way worse than php.

Just to use it properly requires setting up an entire elaborate webpack setup (thank god for laravel mix), then there's a gajillion frameworks to choose from if you go that route, best practices are argued constantly on forums/reddit/hn....

I'd like to build an app on node but I can't ever get past bootstrapping the damn app before I get frustrated at the time it takes just to dive right in.

Ask me most days and I'll tell you how much I hate javascript... but I can't live without using it as it's pretty much the only option for what it does

Very true, unfortunately.

Just to use it properly requires setting up an entire elaborate webpack setup

This sounds like a self-imposed problem. I've been writing JS for over a decade and never touched webpack (I think it's some sort of compiler/linker)

there's a gajillion frameworks to choose from if you go that route

Emphasis on the word "if". Frameworks are there to make life easier; if they're making your life harder, don't bother. Most things are easy enough in "Vanilla JS", now that IE6 compatibility is less important.

best practices are argued constantly on forums/reddit/hn

Arguing over best practices is a sign of a healthy community, which is passionate about quality rather than settling for "it runs". Learning about new ideas can be useful for framing our thinking, even if we don't directly apply those approaches.

Those sort of arguments shouldn't have much impact on how we actually Get Things Done though, since we know more about the engineering requirements of our particular project than random people online, and we'll be more productive using known-good methods which we're experienced with.

I'd like to build an app on node but I can't ever get past bootstrapping the damn app before I get frustrated at the time it takes just to dive right in.

I've not used Node in years, but again that's a choice; if it makes life harder, dump it and use something easier. Node.js bootstrapping complications aren't really a fault of the JS language; heck, you can use FastCGI if you like (that's how PHP is often run).

I've not used Node in years, but again that's a choice; if it makes life harder, dump it and use something easier. Node.js bootstrapping complications aren't really a fault of the JS language; heck, you can use FastCGI if you like (that's how PHP is often run).

The bootstrapping issue is...that there's really no structure imposed.. I can setup an express script anyway I want, but I'm used to a little more syntactical sugar via rails/laravel world where you know where configs/migrations/models go. Sure I can set it up just like that, but having a go-to way of doing things is nice...

there's a gajillion frameworks to choose from if you go that route

Vanilla js is super difficult if you need reactivity and to maintain state across the app. I'm not sure there's many Single Page Applications or PWA applications that are built using vanilla JS (unless possibly you use Svelte which compiles down to vanilla, but still you're coding using a framework and not vanilla js regardless of what the output is).

It's still ugly and convoluted mess - the ecosystem. It's a lot like php was before laravel/composer (pre 2011).

Just to use it properly requires setting up an entire elaborate webpack setup

Webpack basically loads the scripts/files you need when you need them for specific parts of the app. It's similar to grunt/gulp and there are other tools out there. Laravel Mix sits on top webpack and has a simplified already configured way of using it, and it works for apps that aren't just laravel apps, so I often throw it in my workflow if I'm branching out or trying a different language or framework.

My point was just that php isn't necessarily the most hated, as I know plenty of people who hate js. They might even be equally hated.

An indirect thing you can learn from this example is that how little code quality matters when it comes to product popularity or revenue.

An that is the exact reasons why it is hard to address implementing more tests, and addressing technical debt.

Agreed. The core code is actually pretty well written considering the concrete backwards compatibility standards enforced by the devs, but most plugins are a total mess (and I'm saying that as a plugin author). I guess it is mainly due to PHP's low bar for entry and PHP's historical (but arguably not now) lack of enforcement of good programming practices.

There is potential for change though. There is a project backed by the core devs (can't remember the name) which will score plugins by their code standard and show the score in the plugin directory.

I feel it's not that PHP is low bar but rather widely accessible out of the box on almost all web hosting services... you don't have to set up a lot of stuff before running your web application.

I'd argue the only reason PHP still remains at the top is because no one has made X language to work out of the box with cpanel installations and run with little to no modification to run, lets say, django apps or RoR apps. Maybe if Python or any other language spent more time on improving that type of accessibility in the realm of web applications we could see PHP fragmenting in the later years...

I think the main reason I still prefer PHP after doing web development for over a decade is not its syntax but its set-up.

Picture me, often the only programmer, supporting several-dozen business web apps. Each app is in its own directory. To add a route, I just make a new PHP file. This eases mingling other, static, files in that same directory: CSS, JS, HTML, PDFs, documents, spreadsheets, images, and videos that the users wanted to supplement the app with. Maintaining a list of routes in some other file would complicate things, especially with the number and complexity of the apps that we have. (User-uploaded files are stored elsewhere.)

That is really a feature of CGI, and FastCGI, not PHP. But I like PHP more than Perl, and I'm not sure how well the FastCGI frameworks for other languages are written. For example, I often dream of using JavaScript in FastCGI.

But then again I am also spoiled by the extent of PHP's standard library. It's mainly a bunch of functions in the global namespace, but an alphabetic namespace is vast, and there have been just a handful of times that I wanted to make a function whose name was already taken.

PHP is also stable. I've never had a problem with a script bringing down other parts of the website or even other parts of the same app (except that one time when a coworker wrote a PHP script that built SQL dynamically and did it in a bad way, and used up all the RAM on the server).

PHP has been fast for me, even back in 2005. Then again I don't use third-party frameworks. I have written a few helper libraries, to reduce code repetition.

Dreamhost will configure Passenger via cPanel to deploy your Django/RoR apps.

https://help.dreamhost.com/hc/en-us/articles/215769578-Passe...

It's not as seamless as PHP (restarting the Passenger service to reflect code changes requires an ssh session and touching a pidfile), but shared hosting isn't entirely stuck on PHP anymore.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.