Yossi Kreinin shares his insights in What “Worse is Better vs The Right Thing” is really about, an essay I strongly agree with. (h/t John Cook)
NB — Keep an eye on John Cook. He delivers.
Yossi Kreinin shares his insights in What “Worse is Better vs The Right Thing” is really about, an essay I strongly agree with. (h/t John Cook)
NB — Keep an eye on John Cook. He delivers.
My code is littered with bits like this:
import com.google.common.collect.UnmodifiableIterator;
public final class TimesIterable
implements Iterable<Integer> {
private final int n;
public static Iterable<Integer> upTo(final int n) {
return new TimesIterable(n);
}
public TimesIterable(final int n) {
this.n = n;
}
@Override
public Iterator<Integer> iterator() {
return new UnmodifiableIterator<Integer>() {
private int i = 0;
@Override
public boolean hasNext() {
return i < n;
}
@Override
public Integer next() {
return ++i;
}
};
}
} All so I can write:
import static TimesIterable.upto;
import static java.lang.System.out;
public static void main(final String... args) {
for (int n : upTo(4))
out.println(n);
} To my surprise Google is not quite there yet. (I'd prefer to be wrong).
Azul's Zing remains amazing technology:
Where a typical JVM may spend time battling with garbage collection, McCandless says an in-memory test with the full Wikipedia English-language site loaded worked with no garbage collection pauses under Zing JVM, even with a 140GB heap.
Now free for open source.
I forgot what a wit Eric Raymond can be:
Conway’s law is a well-known fact of life in technology organizations. Eric S. Raymond noted that “[i]f you have four groups working on a compiler, you’ll get a 4-pass compiler”.
From Conway's original:
[O]rganizations [...] are constrained to produce designs which are copies of the communication structures of these organizations.
Scrum is ... complex and completely over the top. That is if it isn't rescued from itself.
I still prefer XP to everything else, that may be the bias of familiarity. Scrum, and anything else agile, still beats the alternatives. To reiterate:
How can you beat this for a conference session title?
atomic<> Weapons: The C++11 Memory Model and Modern Hardware
(h/t the Herb Sutter)
Stuart Archibald at OpenGamma has published a series of tour de force posts. The lastest is Accessing Native Maths Libraries. FORTRAN, gcc, code generation, dynamic linking, magic code glue. What's not to love?
Noah Sussman notes Falsehoods programmers believe about time. My favorite:
- You can't be serious.
Nearly as good:
That thing about a minute being longer than an hour was a joke, right?
No.
I found lots of misfitting advice searching Google for how to generate random strings in Java. The misfits assumed I was generating unique keys, often for web page cookies.
What I searched for was random Java strings along the lines of new Random().nextInt(), to use for probabilistic testing, but I failed to find this so I rolled my own.
Not a thing of beauty, but accomplished by goal. Hopefully someone might find this useful:
String randomString(final Random random,
final int minLength, final int maxLength) {
final int length = random.nextInt(maxLength - minLength) + minLength;
final char[] chars = new char[length];
for (int i = 0, x = chars.length; i < x; )
do {
final int cp = random.nextInt(0x10FFFF + 1);
if (!Character.isDefined(cp))
continue;
final char[] chs = Character.toChars(cp);
if (chs.length > x - i)
continue;
for (final char ch : chs)
chars[i++] = ch;
break;
} while (true);
return new String(chars);
} To examine what you get back, consider Character.UnicodeBlock.of(int codePoint).
I'm slow to read up on the Guava 12 release — it came out in April.
Among the changes is this gem: TypeToken.
Guava provides TypeToken, which uses reflection-based tricks to allow you to manipulate and query generic types, even at runtime. Think of a TypeToken as a way of creating, manipulating, and querying Type (and, implicitly Class) objects in a way that respects generics.
Note to Guice users: TypeToken is similar to Guice's TypeLiteral class, but with one important difference: it supports non-reified types such as T, List<T> or even List<? extends Number>; while TypeLiteral does not. TypeToken is also serializable and offers numerous additional utility methods.
I look forward to giving this a spin next time the need arises.
After long hiatus I find myself against writing (editing) makefiles. Using Emacs compile command makes all the difference. Emacs runs make in another process, sending output to an independent buffer (window, tab, panel) default named *compilation*.
In the *compilation* buffer, Emacs colorizes make's output. This greatly aids comprehension. As icing, Emacs recognizes output patterns from dozens of popular tools, and highlights them as information, warning or error as appropriate.
Emacs simplifies navigation with hyperlinking. The TAB key in *compilation* steps through warnings and errors. Magic.
As a bonus, I looked up common patterns stored in the Emacs variable, compilation-error-regexp-alist. The info page for this variable includes a link to "compilation.txt", a complete list of sample output for each supported tool. It was trivial for me to find right at the top:
* GNU style symbol: gnu foo.c:8: message ../foo.c:8: W: message /tmp/foo.c:8: warning: message
That last line was my ticket. I arrange to echo similar text when something needs attention in my shell command, but without failing the entire build. I take care to break the output into separate shell echo commands so Emacs does not match prematurely when make displays executed commands. I could have prefixed my shell line with "@" (ampersand) to suppress make from printing it, but coding standards here discourage that.
a-file:
if $(some_bad_condition_set_in_makefile) ; then \
echo -n $@ ; \
echo :1: warning: $@ is foobar. >&2 ; fi I emulate the output of one of the tools Emacs groks, and I get the same magical colorizing and hyperlinking with my output:
making in /some/path
if true ; then \
echo -n a-file ; \
echo :1: Warning: a-file is foobar. >&2 ; fi
a-file:1: warning: a-file is foobar. In *compilation* the TAB key jumps me to the start of a-file when it exists.
In our code base we represent Google protobuf messages as rooted trees, informally just trees. Nodes are necessarily heterogeneous: some are value nodes—strings, numbers, etc.—, some are roots of more trees, that is, node collections.
I recently replaced code like this:
StringNode childA = (StringNode) parent.get("child A's name");
Int32Node childB = (Int32Node) parent.get("child B's name"); With code like this:
StringNode childA = parent.get("child A's name");
Int32Node childB = parent.get("child B's name"); How did I do this? I changed the definition of "get" from:
public Node get(final String name) {
// Clever implementation
} To:
public <N extends Node> N get(final String name) {
// Same implementation with some "(N)" casts
} When the compiler can infer the return type of "get", it will, saving you writing now and reading later. In those cases where it cannot infer the type, you still help:
final String valueA = (String) ((StringNode) parent).get("child A's name").getValue();
final Integer valueB = (Integer) ((Int32Node) parent).get("child B's name").getValue(); Becomes:
final String valueA = parent.<StringNode>get("child A's name").getValue();
final Integer valueB = parent.<Int32Node>get("child B's name").getValue(); There is still a type cast, but you spell it differently using the generics system. Note "getValue" uses the same idiom as "get"; the return type can be inferred, no extra writing needed.
I'm going to call this pattern the Generic Getter Idiom until I find a good reference.
Lukas Eder notes the possibility of collection and structural literals in Java. A man can dream, can't he? Happily, this dream is built on more than wisps of fancy, just. I don't hold my breath.
Beginning of a series on Bash one-liners from Peter Krumins. If it's from Peter, you know it'll be good.
Matt Godbolt posts GCC Explorer - an interactive take on compilation.
One of the things I spend a fair amount of time doing at work is compiling my C/C++ code and looking at the disassembly output. Call me old-fashioned, but I think sometimes the only way to really grok your code is to see what the processor will actually execute. Particularly with some of the newer features of C++11 — lambdas, move constructors, threading primitives etc — it’s nice to be able to see how your elegant code becomes beautiful (and maybe even fairly optimal) machine code.
I’d managed to get my pipeline for taking small snippets of C code, building them with GCC, de-mangling the output, musing on the assembly, tweaking the input and then repeating over and over again.
See github for sources.
Another beautiful rant from Uncle Bob:
Here’s what an application should look like. The use cases should be the highest level and most visible architectural entities. The use cases are at the center. Always! Databases and frameworks are details! You don’t have to decide upon them up front. You can push them off until later, once you’ve got all the use cases and business rules figured out, written, and tested.
8th light must be something else.
Keif Morris thoughtfully compares/contrasts Agile to Continuous Delivery (CD).
Of course the answer to the question posed in the post title is Yes, Continuous Delivery is agile. Very agile, in fact.
Keif raises several concerns traditional Agile has with Continuous Delivery. I admit to being from the old school, XP, and am a little nervous around CD. But I embrace its spirit.
With Agile leaving small release messes to clean up each iteration, or for Waterfall one giant mess to clean up in the release phase, is bad for the nerves too. At least CD picks up after itself in an ongoing basis.
As a daily Java programmer Maven makes a hash of this as Keif points out. But as with many things related to Maven, you gain a few pains and lose several others for net betterment. How does CD treat the snapshot ailment?
ESR posts on portability of "C" across time. Most times you port across machines and operating systems. "C" is rare in making straight-forward the task of porting from the past into the future.
My command line tool is cooler than your command line tool. Thank you, Peteris Krumins, for linking. And don't forget his book.
UPDATE: A testament to my typing skills, the original title of this post was "sed is Turning complete".
Another great language introduction, this one for Mythryl:
Howdy! I’m Cynbe, lead Mythryl developer.
Why do I do it?
Let me tell you.
I spent the first four years of this millennium doing eighty-hour weeks at a Fortune 5 company in a division internally famous for producing more revenue per employee than the IRS.
I remember arriving home at three AM Christmas Day, sleeping thirty-six hours straight, and then driving right back to work.
It was a cool trip in its way, but over time the stress does get to you. By four years in, vomiting blood in the wee hours was starting to seem entirely normal.
It was time for a change.
By then I had written well over a million lines in C plus substantial amounts in other languages. I felt ready to take it to the next level.
“A language that doesn’t affect the
way you think about programming
is not worth knowing.”
—Alan PerlisSo I looked around to see what was new and improved. I’d learned APL, assembly, C, Fortran, Lisp, Pascal, Smalltalk, Snobol, SQL and so Forth in the 1970s, but after that there had been a long dry spell. C++, J, Java, Perl, Python, Ruby, sure, but they hardly catapult us into a new era of butterflies and rainbows. They did not expand my mind like Lisp and Smalltalk.
Happily, mostly-functional programming languages had just reached the Ready For Prime Time point.
My favorite was SML/NJ, from the nice folks who gave us the laser, the transistor, and Unix.
Unfortunately, it was research-grade code cloaked in academic jargon which hadn’t seen an end-user release that millennium.
Fortunately, I was looking for something to do.
So I set about hammering this magnificent raw material into a modern production quality open source software development platform.
To my mind Mythryl deftly combines C speed, Lisp power, and Ruby convenience with the critical new ingredients of Hindley-Milner typing, state of the art generics and just the right level of side effects.
I’m in love!
Shane Hastie interviews Chris Matts and Olav Maassen on Real Options, an agile technique to improve IT decision making.
Do read it all. A taste:
InfoQ: Please can you briefly explain Real Options.
Olav: Options have value, options expire, never commit early unless you know why.
Options are a way of looking at decision making. Financial options work in very narrow areas, in the financial marketplace they entail paying a fee to defer making a choice about purchasing a share or financial instrument until a later date. Our thinking about Real Options was inspired by financial options, but they are much broader in application.
Real Options are more to do with the psychology of how people make decisions than with the choices available to them.
InfoQ: Please explain.
Chris: People hate uncertainty, so much so that they would rather be wrong than uncertain. In a “rational preference” the hierarchy of decision making would be:
- Have the right answer
- Be uncertain about the answer
- Have the wrong answer
The reality is we prefer to be wrong rather than be uncertain, so the hierarchy is:
- Have the right answer
- Have the wrong answer
- Be uncertain about the answer
We can tell this because when people are faced with uncertainty, they would rather make any decision, even if it is the wrong one.
Generally people would rather have a definite wrong answer than be unsure about an answer.
Real Options is about understanding when to make a decision, rather than how to make decisions. By adding the “when” to the decision making process we remove the uncertainty and enable people to make better decisions.
Like financial options have a fixed contractual expiry date, real options have a conditional expiry date.
One of my favorite Java libraries, jline, released 2.6 recently. Among the goodies is support for ~/.inputrc. This is as close to readline as Java gets.
The physics arXiv blog at MIT Technology Review posts The Hidden Risk of a Meltdown in the Cloud.
As with anytime you bet the farm on a technology, try to have a backup plan.