Write Great Code

By Blane Warrene

Writing great code that is not only functional and bug-free but also leverages all aspects of its environment to run efficiently is something all of us would aspire to. Randall Hyde is hoping to make that road a bit easier beginning with the first book in a series of four entitled Write Great Code, Understanding the Machine.

Hyde is taking on a topic that continues to lie at the core of all development, the foundations of computer architecture. In this case Hyde is predominantly speaking to those on x86 platforms, though the fundamentals carry over to Power PC and others. Previous to this series one would be initiated into programming by way of training courses, how-to books and trial and error.

However, the author is hoping he delivered the equivilant of a university course on systems architecture for the programmer without needing to first learn assembly language.

Prior to the world wide web becoming a central element in professional development, programmers traversed a traditional road of learning a procedural language, perhaps in university or through trial and error on their own, such as C. However, since the late 1990’s, many a developer’s first taste of code has been Perl, PHP or Python.

In some cases missing the functional building blocks of programming and the code’s interaction with the hardware elements of processor, memory and more may be invisible obstacles to writing great code. In my own experience, Code Complete was a book similar to Hyde’s effort that took me to the next level of thinking about code prior to writing it. Hyde’s book is challenging me on a whole new level.

According to Randall Hyde, it is this new generation of developer’s his book is aiming to reach – “Because this is the group of programmers who’ve probably never seen this material elsewhere,” he told SitePoint.

Before some might suggest the books may stray to far from relevance to web development languages, Hyde says three of the four volumes will directly address developer’s who choose to stay with the interpreted languages of the web.

“Volumes I, III, and IV will be applicable to those wanted to stick with [Perl, PHP and the like]. Volume II will be of little interest — since it covers how compilers generate code, which is N/A to script/interpreted languages,” Hyde added.

Volume I covers basic machine data types, basic machine architecture, I/O, and other such topics which are relatively independent of the language.

“The book uses examples in C, Pascal, Assembly, and Basic, but someone with familiarity with *any* imperative language will understand what’s going on,” Hyde said.

While the first volume does not deal heavily with object-oriented development, which is an item of interest to LAMP programmers, there is a discussion of how objects are implemented at the machine level and their costs.

Significant to me was the focus on providing an understanding of how computers execute code – which causes one to pause and consider the organization of one’s applications.

A parting comment from Hyde: “No matter what language facility a programmer uses, understanding how the machine represents data, executes code, and processes I/O is crucial to those who want to write great code.”

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

  • http://www.sitepoint.com/ mmj

    The high level languages and APIs of today tend to discourage programmers from worrying about the lower level operations of the computer, but I agree that anybody who really wishes to write great code needs to be familiar with the machine at a lower level.

    I see that it includes examples in Assembly language. I think that’s good. Playing with Assembly is a great way to learn about what happens when a function is called and how the arguments are passed, how conditional statements are evaluated and how the stack is used. Sounds good.

  • http://www.computerbase.de Steffen

    Sounds like this book is exactly what I

  • Mike

    Nice find, seems like the next book i’ll be looking into. I’ve been wanting to get a book like this for awhile.

  • http://www.dvd-software.info hurricane_sh

    I believe it’s all about experience. I didn’t code anything for a whole year, now I have to rely on the compiler again and again for a very small program to erase the compiling errors. If you keep programming, you will be confident enough to finish your code without compiling. If you work on a module of a project, you can’t compile or test before merge with other’s code, that’s a wonderful feeling when you see your code is ready and others keep debugging.

  • pippo

    I see that it includes examples in Assembly language. I think that’s good.
    Playing with Assembly is a great way to learn about what happens when a function is called and how the arguments are passed, how conditional statements are evaluated and how the stack is used. Sounds good.

    I agree.

    One thing I like of some compilers is the way to make a listing file that will show how your C code is traduced into assembly:

    // C function
    void yeild()
    H8_PDR2 ^= PORT2_WD;

    // Assembly/C mix
    void yield()
    114: 01 00 6d f6 mov.l er6,@-er7
    118: 0d 76 mov.w r7,r6
    H8_PDR2 ^= PORT2_WD;
    11a: 7f d5 71 30 bnot #0x3,@0xd5:8
    11e: 01 00 6d 76 mov.l @er7+,er6
    122: 54 70 rts

    00000124 <__z5clockv>:

    Even if I see that in the chapter that we can download the examples are not “pure” assembly but are HLA (not sure what it stands for).
    It will help to write pseudo-assembly code more faster but it is less portable.

    I can only add that the way the arguments are passed to a C function it depends on the C compiler.

    Thanks Blane for talking about that book!

Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in Front-end, once a week, for free.