Book Review: Write Great Code, Volume 2
Although it's thoroughly possible to argue against this work's major premise, that knowledge of low level assembly language is essential in order to write great high-level code, and whilst such arguments would make for interesting reading and promote further discussion of an essential topic, any text which digs deep into the oft-ignored realm of compilation and machine code generation is to be totally applauded. And there is quite simply no other work which covers the practical relations between so-called high-level languages, or HLLs, such as C and the instructions generated by a range of common compilers on both x86 and PowerPC platforms.
[img_assist|nid=29|title=|desc=|link=url,http://www.amazon.com/Write-Great-Code-Low-Level-High-Level/dp/1593270658/|align=right|width=106|height=150]
Originally intended as a final chapter closing volume one, an exemplary work which provides a rich overview of the inner workings of abstracted machine architecture, this second volume well accompanies that earlier work in expanding language as an interface to the machine. It's also worth pointing out that, although two opening chapters do provide an introduction to assembly language across the two architectures and common assemblers such as MASM, TASM and the GNU Gas assembler, it's far from a total introduction to writing in assembly. Indeed, experienced author Randall hyde makes it plain that supreme expertise in low level coding is far from necessary for the purposes of optimal HLL programming. The emphasis is rather on making complete sense of compiler output and understanding this heady relation; thinking low level whilst writing high-level. Knowledge of how compilers translate source code to low level instructions certainly should prove beneficial to executable performance, if impacting somewhat on the development process. One could rather question the efficacy of such so-called HLL if the compiler's output must be parsed by hand, and high-level code managed with an assembly end in sight. At the same time, and without entering too far into the rich and often heated discussion which such questions promote, the imperative languages which the author assesses, which range across C and C++, to rather deprecated Pascal and Basic, are far from high-level, thus explaining the necessity for such a work.
Write Great Code promotes itself as language neutral, yet as stated the emphasis is totally on procedural code, and more or less focused on C, under which the relation between source and compiler output makes a good deal more sense than for functional or concurrent programming languages. The work, through example code and core concpets, also attempts to be as OS agnostic as possible, accounting for standard library interfaces, and the differences in platform compilers and assemblers. It would be great if Randall Hyde had chosen to run solely with Gas as generated by GCC, as this would certainly ease matters for the new user and save space in discussing relevant differences and compiler issues. Yet, to his credit, he does a great job of abstracting out the ugly detail by way of his very own High-level Assembler, promoting a sort of halfway house between imperative and generic HLL and regular assembly. HLA was developed by the author with the specific aim to ease the learning of assembly language for those already comfortable with high-level coding paradigms. HLA provides a familiar syntax for those parts of the assembly code which have nothing to do with the actual machine code, for example variable declarations, whilst thoroughly mapping low-level instructions themselves and providing a standard library of useful macros and subroutines. Thankfully it's cross platform, open source software and example HC code is scattered throughout the work, plcaed in handy comparison to MASM/TASM and Gas input.
Randall Hyde writes with an appealing density which well conveys both his deep seated knowledge and sheer enthusiasm for the material at hand. The advanced material is clearly organised with plentiful example code and Hyde does a great job in setting out his stall, in terms of where he will lead the reader, at the beginning of each chapter. Following introductory material and the well considered primers for both 80x86 and PowerPC assembly, Write Great Code digs deep into the full range of compiler operations, from lexical analysis and parsing to object and executable file formats and linking. Compiler optimisations are well discussed, yet across the board consistent reference to one platform and compiler would make more sense here. In order to map low-level to high-level across the divide or interface presented by the compiler, we need to be able to read and analyse compiler output in a range of forms, making use of a well specified toolset including dissamblers, debuggers and text analysis tools. Write Great Code well explains the operation of such tools, alongside switches to common compilers to force assembly output. Given the sheer ease of such operations under GNU/Linux, more attention is necessary and thus devoted to the Windows platform, though objdump, which dissects object files, is well discussed.
Compilation is heavily concerned with a process of translation, with issues of representation which become very engaging when we're occupied with raw hardware, the electrified executable. It's a magical process of mapping which Write Great Code dissects in alchemical detail across a series of chapters which examine how HLL features such as constants, variables, various data types and control structures are made evident in machine code. Speed and allied concerns such as memory access and footprint are the watchwords here and the merits of differing code approaches are well discussed. Compiler output from code examples is placed under the exemplary microscope of clear and vidorous prose with performance very much in mind. Again, though the efficacy of such a work for those writing truly high level code is open to argument, the need for such a work which serves as a thrilling introduction to the enticing realm of compiler design is far from questionable.
[img_assist|nid=29|title=|desc=|link=url,http://www.amazon.com/Write-Great-Code-Low-Level-High-Level/dp/1593270658/|align=left|width=106|height=150]
Author: Randall Hyde
Publisher: No Starch Press
ISBN: 1593270658
Review by Martin Howse
