The Art of Readable Code by Dustin Boswell & Trevor Foucher

The Art of Readable Code by Dustin Boswell & Trevor Foucher

Author:Dustin Boswell & Trevor Foucher
Language: eng
Format: mobi, epub
Tags: COMPUTERS / General
ISBN: 9781449314170
Publisher: O'Reilly Media
Published: 2011-11-02T20:00:00+00:00


if (indent === undefined) indent = "";

// Handle (non-null) objects.

var str = "{\n";

for (var key in obj) {

str += indent + " " + key + " = ";

str += format_pretty(obj[key], indent + " ") + "\n";

}

return str + indent + "}";

};

This covers the shortcomings listed previously and produces output like this:

{

key1 = 1

key2 = true

key3 = undefined

key4 = null

key5 = {

key5a = {

key5a1 = "hello world"

}

}

}

Create a Lot of General-Purpose Code

The functions ReadFileToString() and format_pretty() are great examples of unrelated subproblems. They’re so basic and widely applicable that they are likely to be reused across projects. Codebases often have a special directory for code like this (e.g., util/) so that it can be easily shared.

General-purpose code is great because it’s completely decoupled from the rest of your project. Code like this is easier to develop, easier to test, and easier to understand. If only all of your code could be like this!

Think about many of the powerful libraries and systems that you use, such as SQL databases, JavaScript libraries, and HTML templating systems. You don’t have to worry about their internals—those codebases are completely isolated from your project. As a result, your project’s codebase remains small.

The more of your project you can break away as isolated libraries, the better, because the rest of your code will be smaller and easier to think about.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.