Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Deeply Nested Code

Encountered a deeply nested code (see below) or arrow code. Based on past experiences, you know this is sure going to turn into a maintenance hell as readability is low and modifiability is next to impossible.

Sample simplified pseudocode.
if ( condition a ) {
    if ( condition b ) {
        if ( condition c ) {
            foreach ( ...) {
            }
        }
    }
}

How we going to solve this ? Flatten the nested code. How ? From the  Refactoring book by Martin Fowler, you can either use Extract Method or Replace Nexted Condition with Guard Clauses.

Sample refactored pseudocode.
if ( ! condition a ) return something_not_a;
if ( ! condition b ) return something_not_b;
if ( ! condition c ) return something_not_c;
do_something_with_foreach_loop();

Hiring New Developers

"Once we've received the code, we review it for the above stated qualities with an emphasis on clean, readable and well-tested code. We're not too hard on these code reviews, we just want to try to eliminate obviously poor fits. People who write no tests are immediately eliminated. Hugely over-architected solution? Eliminated. Code is bad enough the person might not actual be able to program? You get the idea."
-- prophetjohn, emphasis mine
So their procedures of hiring a new developers are:

1. Send a sample coding project.
2. Check for tests, not over-engineered code, and the ability to code.
3. Coding interview with real project (something the company is current working on). Pair-up code review and refactoring with existing developers.
4. Informal group interview by the developer team.

Real-life Enterprise Programming

"But in most of the real world, when you've got various stakeholders, a big project, lots of programmers whose work needs to be coordinated, with standards, and you can't get bogged down in n-to-n communication, this is just how it often has to be. Face it, most work in this world is "slave work", if that's how you want to call it (although I think that sounds rather insulting, when you think about how an unfulfilling office job you're free to quit is a million times better than actual slave work)."
......
"And part of being a professional and mature programmer is realizing that, look, that's life. Sometimes you will get a job with a big say in how things are done, be super-independent, and it will be amazing. And sometimes you'll look back five years later and realize how it was a great learning experience for you, but you over-engineered it in a language or with a library that nobody could use afterwards, the whole system was replaced a year later, and you effectively wasted a lot of time and money of the company's."
-- crazygringo, emphasis mine

Obsession With Tools

"I've found that a large subset of programmers share the same trait as a large subset of photographers: they become so obsessed with tools that they lose sight of the fact that the end product is what matters at the end of the day."
......
"My advice? Sit back, pick technology a couple of steps behind the bleeding edge, and focus on results. Choosing Ember over Backbone isn't going to cause your project to fail; building the wrong thing or failing to finish, however, will."-- rpeden, emphasis mine

It was one of that fscking day

It was one of that fscking day. The dreadful day where we programmer hate it the most, the day you were completely stuck, and can't seem to fix the bug. You tried suspending the script at different breakpoints, and no, not working. Frustrated, went for a walk, ate an ice-cream, read a book, and fixed some other bugs just to clear the head. Tried again, different approach, but still, nothing bloody works.

"Just one more try"

You told yourself before you start packing and left for home. Your last attempt, no more. Your mind already set to write down the next morning to do item in your journal. Suddenly, you noticed there this this line of code,

$new_name = "a" . $name;

"Why you want to prepend the letter a ?"
"Let's remove that and try again."

Whoala! After enduring frustration for the whole day and 1 hour 56 minutes spent working on it, the bug was finally fixed ! Bloody hell ! This is fscking stupid ! What was I thinking? Come to think of it, is Karma. After I caused my boss to fix my stupid "new feature" yesterday.

Yes, it was one of that fscking day.