Beautiful Code |
||
|
Greg WilsonUniversity of Torontogvwilson@cs.utoronto.cahttp://www.cs.utoronto.ca/~gvwilsonJune 19, 2008 |
|
|
|
|
|
|
|
|
|
![]() |
![]() |
![]() |
From: Greg Wilson
Subject: Beautiful Code
Date: May 17, 2006
I hope you don't mind mail out of the blue, but I'm working on a
new book project with O'Reilly called "Beautiful Code" and would
like to ask you to contribute an article-length section. Profits
from the book will be donated to Amnesty International.
The book will be a collection of master classes in software design.
In each chapter, a well-known software developer will present one
of his or her favorite pieces of code, then explain what makes it
particularly appealing. The aim is to "think aloud" while walking
through its design and implementation, so that junior developers
can learn to see through more experienced developers’ eyes.
Thanks,
Greg
From: [name withheld]
Subject: re: Beautiful Code
Sorry, I'm too busy. Good luck.
From: [name withheld]
Subject: re: Beautiful Code
I don't think I've ever written any code I'd call beautiful,
but I'd really like to read the book when it's done.
From: [name withheld]
Subject: re: Beautiful Code
Sure, count me in!
| Tim Bray | Jim Kent | TV Raman |
| Karl Fogel | Ronald Mak | Arun Mehta |
| Jon Bentley | Adam Kolawa | Kent Dybvig |
| Brian Hayes | Lincoln Stein | Andrew Patzer |
| Alberto Savoia | Ashish Gulhati | Bryan Cantrill |
| Andreas Zeller | Brian Kernighan | Charles Petzold |
| Henry S. Warren | Andrew Kuchling | Michael Feathers |
| Douglas Crockford | Greg Kroah-Hartman | Diomidis Spinellis |
| Travis E. Oliphant | Simon Peyton Jones | Yukihiro Matsumoto |
| Elliotte Rusty Harold | Jeff Dean & Sanjay Ghemawat | Jack Dongarra & Piotr Luszczek |
| William Otte & Douglas C. Schmidt |
Laura Wingerd & Christopher Seiwald |
Rogerio de Carvalho & Rafael Monnerat |
int j=0;
for (int i=0; i < a.length; ++i) {
j++;
}
System.out.println("array size=" + j);
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
| What do you do when a day is 24 hr 39 min long? |
int match(char *regexp, char *text)
{
if (regexp[0] == '^')
return matchhere(regexp+1, text);
do {
if (matchhere(regexp, text))
return 1;
} while (*text++ != '\0');
return 0;
}
|
int matchstar(int c, char *regexp, char *text)
{
do {
if (matchhere(regexp, text))
return 1;
} while (*text != '\0' && (*text++ == c || c == '.'));
return 0;
}
|
||||||||||||
|
int matchhere(char *regexp, char *text)
{
if (regexp[0] == '\0')
return 1;
if (regexp[1] == '*')
return matchstar(regexp[0], regexp+2, text);
if (regexp[0] == '$' && regexp[1] == '\0')
return *text == '\0';
if (*text!='\0' && (regexp[0]=='.' || regexp[0]==*text))
return matchhere(regexp+1, text+1);
return 0;
}
|
SUBROUTINE SGBSV( N, KL, KU, NRHS, AB, LDAB, IPIV, B, LDB, INFO )
*
* -- LAPACK driver routine (version 2.0) --
* ..
* .. Scalar Arguments ..
INTEGER INFO, KL, KU, LDAB, LDB, N, NRHS
* ..
* .. Array Arguments ..
INTEGER IPIV( * )
REAL AB( LDAB, * ), B( LDB, * )
![]() |
![]() |
The turnstile hash table is partitioned into two halves: the lower half
is used for upimutextab[] locks, the upper half for everything else.
The reason for the distinction is that SOBJ_USER_PI locks present a
unique problem: the upimutextab[] lock passed to turnstile_block()
cannot be dropped until the calling thread has blocked on its
SOBJ_USER_PI lock and willed its priority down the blocking chain.
At that point, the caller's t_lockp will be one of the turnstile locks.
If mutex_exit() discovers that the upimutextab[] lock has waiters, it
must wake them, which forces a lock ordering on us: the turnstile lock
for the upimutextab[] lock will be acquired in mutex_vector_exit(),
which will eventually call into turnstile_pi_waive(), which will then
acquire the caller's thread lock, which in this case is the turnstile
lock for the SOBJ_USER_PI lock. In general, when two turnstile locks
must be held at the same time, the lock order must be the address order.
Therefore, to prevent deadlock in turnstile_pi_waive(), we must ensure
that upimutextab[] locks *always* hash to lower addresses than any
other locks. You think this is cheesy? Let's see you do better.
syntax-case expander
Simplicity is one of the most misunderstood
concepts in programming. People who design
languages frequently want to keep those
languages simple and clean. While the
sentiment is noble, doing this can make
programs written in that language more complex.
![]() |
![]() |
| "Beauty is truth, truth beauty." | Pride |
|
| I'm Greg Wilson, and I approve this talk. |