Showing posts with label ergonomics. Show all posts
Showing posts with label ergonomics. Show all posts

Saturday, 29 November 2014

Why he vertically aligns his code (And why you shouldn't)

Over on Terence Eden's blog, the latest post is about vertically aligning code : https://shkspr.mobi/blog/2014/11/why-i-vertically-align-my-code-and-you-should-too

The "bad" example looks like this:

Which is then "fixed" to make it look like this :


Just for comparison, I typed it into my regular text editor:


The point being, because I'm using a well designed syntax highlighting where the numbers (green) contrast with the operators.  If you so choose, you can visually inspect just the green numbers and just as easily spot the outlier.

(Pro-tip: To concentrate on just one color, defocus your eyes slightly by staring "through" the plane of the monitor to engage your eye's cone cells.  With a little practice, you'll find yourself doing this automatically when you want to focus on the structure of the code instead of the details.  For best results, you might need to make the glyphs larger on screen....)

Note too, how the combination of proportional font and camelCase instead of under_scores keep the code density onscreen the same, but the individual glyphs appear larger in-place.

My code editor also uses syntax highlighting to hint the kerning.  So for example, the kerning around the equals sign and the semi-colon are particularly loose to aid in their recognition. Similarly, the single space character (' ')  has a width 50% larger than would be used for normal paragraph text.

But here's the big change that Terence missed, I've sorted all the variable declarations alphabetically to ensure there are no duplicates.  This is a zero-cost policy that can simplify merges and conflict resolution when multiple variables (possibly duplicate) have been added upstream.

Coding Atoms

The bigger problem is the coding atom is the line-of-code.

Lets take another code example from Terence's blog post, this time a function declaration :

extern int SomeDemoCode(int fred,
                        int wilma);

That's an atom right there - you can't split that up without changing its meaning. Watch what happens if I try to add a parameter in an excess white-space environment:

extern int SomeDemoCode(int fred,
+                       int barney,
                        int wilma);

The diff splits our (atomic) function signature across 3 lines, exposing us to problems where a git merge might accidentally succeed, when really we need it to flag a merge conflict.

(For a real world case of how bad automatic merging can be, take a look at the Goto Fail Bug)

Now compare if everything had been on the same line, the diff would look like :

-extern int SomeDemoCode(int fred, int wilma);
+extern int SomeDemoCode(int fred, int barney, int wilma);


TL;DR: Using whitespace to control your code presentation is a hack from the '70s.. get a better editor.

p.s. Some formatting edits have been made to make this post clearer.

Sunday, 26 August 2012

Officespace

What makes a great work environment?

I've had a lot of time to think about this one over the years, mostly when working in cramped, overcrowded, smelly, noisy, unsafe or otherwise distasteful locales.

I always used to think it would be in a context of setting up my own team in a new office.  Now that I've gone Indie, that's still true, but it's a team of one.

Space

The most critical element in the work environment is space.  You need enough space to have all your working equipment easily accessible.  I like to have everything already plugged in and ready to go, but switched off at the wall.  And don't forget to move around and stay active, so I've setup a typing station, a coffee station, a thinking station, a reading station, a print/scan/copy station, an audio recording station etc, etc,  each already prepared for a particular type of activity.

If you're a fan of John Cleese, you'll know that low ceilings encourage closed thinking modes, and high ceilings facilitate open thinking modes.  Factor that in the next time you book a meeting room for a brainstorming session (high ceiling) or triage session (low ceiling).

Time

How many times have you heard, "It's done when it's done!"

For many creative tasks, you can estimate how long something will take, but not very accurately.  I find it useful to work in blocks of around ~2 hours. I pick a task I think will take an hour to do, and work on it, until it's done.  If there's still 2 hours left before the next planned disruption, I'll pick another ~1 hour task, and work on that.

It's crucial to finish every day with a win.  Ernest Hemmingway says it much better than I ever could:

"The best way is always to stop when you are going good and when you know what will happen next. If you do that every day … you will never be stuck. "

Some employers believe in billing for hours worked, and still others believe in crunch.  If you're in a creative industry and you're being micro-managed like that, and want to have a career rather than a burn-out,  I strongly recommend considering your options.

Location

The day doesn't stop when you walk out of your office.  You still need to get home (or to the gym, or to the pool, etc)  How much is that commute costing you in terms of money, time and stress?  Is the parking lot safe? Can you even find a park when you need to? Can you commute when it's raining/snowing without getting wet?

Working from home is great, but be sure to separate work from home with a doorway or even a staircase.

If you're forced to reuse equipment, then create separate user accounts, facebook accounts, email accounts etc, and be sure to log in and out every time you transition from home to work and vice versa.

If you're a real digital nomad, why not setup separate home and work environments on different USB sticks using portable apps?

Ergonomics

There's a lot of literature about setting up your chair, desk, keyboard, monitor for comfort and usability.  It really does make a difference.  If you're still a skeptic (like I was up until recently), just try it for a week.  If you don't see an improvement, you can always go back to your old bad habits.

...And don't be shy, help out a neighbor.  If you see a colleague struggling with RSI, or squeezed in to the wrong sized chair, bring it up, maybe it's something you can help with.

Sound

Headphones are not enough.  You need a reasonably quiet, connected space.  We humans are social animals, so complete silence can be too isolating.  We need to feel connected with our colleagues, and with the wider environment too, but not distracted from the task at hand.

Oh, and a pet-peeve of mine, a place to take private phone calls.  I hate reciting credit card numbers in a hallway frequented by programmers with eidetic memories.

What else?

What makes your work environment great?  How could it be even better?