5 ms·
2500 words on the subject of brevity in programming
- fierarul 17y ago"Hello world" must go away from all language examples. It's irrelevant how complex doing hello world in Java is since no user actually cares about stuff visible in text mode starting a decade or more back. Of course, Java won't win a brevity contest, but System.out.println isn't the best pick to demonstrate this.
- MikeTaylor 17y agoWell, that's why I went straight on to something else. But anyway I can't agree that "no user actually cares about stuff visible in text mode". There is a very substantial community of programmers that don't like to use IDEs.
- skermes 17y agoMore importantly, embedding very much non-trivial code in the context of an essay like this is impractical. I don't want (or need) to see an entire application written in both Java and Ruby to get the point. Any code sample that can be reasonably inserted into the text without unduly breaking the flow is going to be simple; hello world is as good as any.
- orborde 17y agoEvery time I see a reprog post, I get hungry from all those pictures of sushi.
- MikeTaylor 17y agoHeh heh, my plan is working :-) Actually, there IS a plan, sort of. At first I just threw in the odd random picture so that the blog would look a bit more interesting than long blocks of text (one of the early posts has the Buffy cast in it); but I quickly found myself falling into the habit of using only sushi, because I liked the visual thematic unity that those pictures give me. (The last photo in that particular article fills me with so much sushi-lust that I could hardly concentrate on the argument I was trying to make.)
- RodgerTheGreat 17y agoIt is mentioned in the comments, but bears repeating here- The author's example of "overly verbose" Java is rather unfair. Compare the 11-line example with loads of temporary variables to something like this: Set results = new SortedSet(); for (Method m : String.Class.getMethods()) { if (m.getName().toLowerCase().contains("index")) { results.add(m.getName()); } } return results.toArray();
- AndrewDucker 17y agoI had a play with LINQ in C# to see how similar I could make it: After adding a couple of extension methods (to make the syntax more similar) I can write: from methodName in "".MethodNames() where methodName.Grep("index",RegexOptions.IgnoreCase) orderby methodName select methodName; in C#
- AndrewDucker 17y agoAnd an even simpler one: "".MethodNames().Where(m => m.Grep("index",RegexOptions.IgnoreCase)).OrderBy(m => m)