7

The "shut up and get back to work" coding style guide

 3 years ago
source link: https://drewdevault.com/2019/04/29/Shut-up-and-get-back-to-work-style.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
The "shut up and get back to work" coding style guide

The "shut up and get back to work" coding style guide April 29, 2019 on Drew DeVault's blog

So you’re starting a new website, and you open the first CSS file. What style do you use? Well, you hate indenting with spaces passionately. You know tabs are right because they’re literally made for this, and they’re only one byte, and these god damn spaces people with their bloody spacebars…

Shut up and use spaces. That’s how CSS is written1. And you, mister web programmer, coming out of your shell and dipping your toes into the world of Real Programming, writing your first Golang program: use tabs, jerk. There’s only one principle that matters in coding style: don’t rock the boat. Just do whatever the most common thing is in the language you’re working in. Write your commit messages the same way as everyone else, too. Then shut up and get back to work. This hill isn’t worth dying on.

If you’re working on someone else’s project, this goes double. Don’t get snippy about their coding style. Just follow their style guide, and if there isn’t one, just make your code look like the code around it. It’s none of your goddamn business how they choose to style their code.

Shut up and get back to work.

Ranting aside, seriously - which style guide you use doesn’t matter nearly as much as using one. Just pick the one which is most popular or which is already in use by your peers and roll with it.

…though since I’m talking about style anyway, take a look at this:

struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
                                           double sx, double sy,
                                           double *sub_x, double *sub_y) {
    // Do stuff
}

There’s a lot of stupid crap which ends up in style guides, but this is by far the worst. Look at all that wasted whitespace! There’s no room to write your parameters on the right, and you end up with 3 lines where you could have two. And you have to mix spaces and tabs! God dammit! This is how you should do it:

struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
        double sx, double sy, double *sub_x, double *sub_y) {
    // Do stuff
}

Note the extra indent to distinguish the parameters from the body and the missing garish hellscape of whitespace. If you do this in your codebase, I’m not going to argue with you about it, but I am going to have to talk to my therapist about it.


  1. For the record, tabs are objectively better. Does that mean I’m going to write my JavaScript with tabs? Hell no! ↩︎

Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~sircmpwn/[email protected] [mailing list etiquette]

Articles from blogs I read Generated by openring

Go on ARM and Beyond

The industry is abuzz about non-x86 processors recently, so we thought it would be worth a brief post about Go’s support for them. It has always been important to us for Go to be portable, not overfitting to any particular operating sys…

via The Go Programming Language Blog December 17, 2020

Status update, December 2020

Hi all! This status update is the 24th one, so it’s been 2 years I’ve started writing those now (ignoring a little hiatus). Time flies! This month I’ve invested a lot of time into wlroots. My main focus has been renderer v6, which has now been internally rol…

via emersion December 16, 2020

What's cooking on Sourcehut? December 2020

A brisk wind of winter chill sets a stir down my spine, as I sit down with a fresh cup of coffee to yarn a story of careful engineering and passionate spirit that took place over the course of 30 days. The last 30 days. Cause this is the monthly “what’s cook…

via Blogs on Sourcehut December 15, 2020
The content for this site is CC-BY-SA. The code for this site is MIT.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK