Friday, March 2, 2012

Notes from "Clean Code": A Handbook of Agile Software Craftsmanship

Clean Code is an excellent book. Here are some notes I took while reading a few of the chapters online. (The rest I ended up reading on paper, so notes are not easy to share). All in all, the book is full of excellent advice.
The chapter on generics bares a special mention. It's clear, insightful and revolting at the same time. The revolting part comes from the clarify with which the whole ugly nature of Java generics implementation is exposed to the reader. So the blame for that lies with the authors of the implementation, not the book's! The book actually manages to make the muddy mess as clear as it can be.

Here are the notes
    • The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible. More than three (polyadic) requires very special justification—and then shouldn't be used anyway.
    • "You know you are working on clean code when each routine turns out to be pretty much what you expected." Half the battle to achieving that principle is choosing good names for small functions that do one thing.
    • Don't be afraid to make a name long. A long descriptive name is better than a short enigmatic name. A long descriptive name is better than a long descriptive comment.
    • The LOGO language used the keyword "TO" in the same way that Ruby and Python use "def." So every function began with the word "TO." This had an interesting effect on the way functions were designed.
    • There are two very common reasons to pass a single argument into a function. You may be asking a question about that argument, as in boolean fileExists("MyFile"). Or you may be operating on that argument, transforming it into something else and returning it. For example, InputStream fileOpen("MyFile") transforms a file name String into an InputStream return value.
      • The distinction is not too clear. A question is a special form of transformation? In both cases there is knowledge in the function about how to answer the question or transform the argument. But there are no side effects in either case (presumably).
    • My general rule for switch statements is that they can be tolerated if they appear only once, are used to create polymorphic objects, and are hidden behind an inheritance relationship so that the rest of the system can't see them
    • If a function does only those steps that are one level below the stated name of the function, then the function is doing one thing.
    • A somewhat less common, but still very useful form for a single argument function, is an event. In this form there is an input argument but no output argument. The overall program is meant to interpret the function call as an event and use the argument to alter the state of the system
      • So this modifies the state and that's the key differentiator? In otherwords, this function has side effects.
    • So, another way to know that a function is doing more than "one thing" is if you can extract another function from it with a name that is not merely a restatement of its implementation [G34].
    • Try to avoid any monadic functions that don't follow these forms, for example, void includeSetupPageInto(StringBuffer pageText). Using an output argument instead of a return value for a transformation is confusing.
      • Yes, but it's the key to reducing garbage production...
Posted from Diigo. The rest of my favorite links are here.

Thursday, November 19, 2009

QCon San Francisco 2009 - Part 1

I had a chance to attend the QCon conference in SF this week. I'll try to publish my notes from the talks.

Last year I managed to only publish one article! Ouch, not too impressive. This year I'm hoping to do better because my notes are already (mostly) in a digital form, thanks to FreeMind and a Mac.

So, without further ado, here's the first installment.


Intro

  • Overall observations
    • I have to say that last year seemed a little more interesting. Perhaps it's just because it was my first QCon.

      But there was at least the Un-conference, which there isn't this year. Too bad. Last year it had to compete with highly interesting sessions with high-profile speakers, so I only found time to attend one or two sessions.

      However, this year, I would have attended at least two just in the first day.

      I still think the conference is very interesting and useful, but it's not quite the same.



  • Corporate Opensource
    • This year seems to be a year of corporate opensource. Or maybe it's opensourced corporativeness?
      • Not sure how to say it right.

    • Exhibit 1: SpringSource
      • SpringSource, which was actually purchased this summer by VMWare.

        • The whole thing about the VMWare acquisition seems odd.

        • + -
          I had a chance to talk with some of the falks from Spring and they spin it like this:
          • VMWare needed development community to compete with Microsoft (on the cloud offering presumeably)

            • I guess if MS builds Azure support in the Visual Studio / .NET, then it will lead to natural use of MS products instead of VMWare's.
              I guess. So what, does VMWare propose to build VMWare support into Spring? What exactly to Spring applications need to know about VMWare? Isn't the whole point of VMWare to be transparent?

              The only angle would be with some kind of cloud management / deployment tools. That must be it.


            Second point they make is that it's actually good that there is no overlap between VMWare's core expertise and the Spring's. Right...

            • The argument goes that this way Spring can continue doing what they do without interference form VMWare.

              And yet, Rod is no longer a CEO but has some strange title along the lines of "VP of the Middle Tier" or something.

            Third point they make is that now that they are part of a large company with actual revenue, they can feel free-er to spend their time on the opensource work.

            • Ok, so that sounds like they ran out of money.

            I don't know. I'm sure I'm missing something, but it looks a lot like eBay and Skype.

        Spring is huge. It's the new Java EE. It's the new standard library for Java.

        On the bright side, they are building great stuff and it tends to really solve real problems and be really useful.

        It is also trully opensourced. So we do get all of the code and we are free to make changes and build it and distributed it, etc. It's Apache licened.

        So if SpringSource decided to go crazy and build something silly or try to move the project away from usefulness, there are planty of other projects that will be able to pick apart the codebase and take what's useful (not to say anything about the actual userbase which could also control their own destiny).

        However, they are pushing ahead at a break-neck speed. Perhaps it's just me, but I'm still not sure of all the pieces that are in Spring 2.5, which was released last year, let alone having had an opportunity to have used them.

        This year - Spring 3.0 comes out. And it has a lot more cool stuff that looks very interesting.

        As a user, I'm finding it hard to keep up with them. As an opensource developer, it's not possible to compete with the full-time staff of SpringSource building the Spring platform.

    • Exhibit 2: Terracotta
      • Terracotta, which has just acquired ehcache this summer.

        I don't have as much to say about them, except that it's yet another open source project that has a community but not is a community.

        They are not as well established as Spring yet. But they have made significant changes since I looked at them last.

        • They apparently have a better clustering story. To the point where clients no longer stall and crash when there is a problem on the server.

          They also now position themselves as a Hibernate plugin that simply does better caching than ehcache. This makes for a straight (and fully opensourced) upgrade path from Hibernate with nothing, to Hibernate with ehcache, to Hibernate with Terracotta.

          • Sounds a lot better than what I remember from before. I believe that before you had to write to their API directly or else it was a different VM that had to be used? Not sure.

    • Exhibit N: Google with it's many projects
      • Firefox
      • Android
      • Chrome / Chromium
      • etc

    • Is this bad?
      • If there is no free lunch, it follows that somehow we are paying for all of this.

        Is that bad? Probably not. But it's good to be aware of the motives of those paying for the pizza.

        I'm of two minds about this. One the one hand, I find that it's still open source and it's still good, even if it's not quite the kind of (maybe fictional?) opensource that we are used to.

        On the other hand, there seems to be something sinister about the whole thing. I can't quite put my finger on it, but basically these corporations are giving out free stuff (code, products) in order to cause developers to behave in certain ways (i.e. use the products), which somehow leads into the company's business model.

        But on the whole, I think this model still leads to better software being built, code being open and available for learning and improvement, engineers having a free hand in what they use, and business success of these companies being more closely tied to the actual value they deliver.

        So on the whole - I think we are good.

Wednesday, August 12, 2009

Canonical releases source code for Launchpad | Ubuntu

http://www.ubuntu.com/news/canonical-open-sources-launchpad

Very interesting. I think platforms like this should find their way into more of the corporate development landscapes. Especially when distributed teams are becoming the norm.

Wednesday, June 17, 2009

Automated Acceptance Tests - Myth or Reality? Useful or not so much?

  • tags: tdd

    • Are automated acceptance tests written at the beginning of each iteration just a theoretical assertion that have been proven ineffective by the lack of adoption?
    • why don’t we just make the tests on a white board, have the programmers implement them one at a time, checking them manually even showing them to the product owner manually and when we are done with it, why not just erase it and forget it?
      • The hope is that they will catch regressions. If not - no need to automate. - post by dserebren
    • Now, consider if the tests written by the QA department are written before the development begins. 
      • How could tests be possibly be written before the software is written? It seems that at best they can be written at the same time as the software (in a TDD way). - post by dserebren
    • One of the things that come out when watching Brian Marick's interview, is that there are many teams doing just fine with unit testing for regressions and manual QA Testing for acceptance tests (ad-hoc).
    • ThoughtWorks is building Twist to give QA and test automators the right kind of tool support to make functional test automation work.

Posted from Diigo. The rest of my favorite links are here.

InfoQ: Stop and Refactor?

  • tags: no_tag

    • So what can we conclude, comparing just these two? First, not refactoring provides MORE feature value until some time after refactoring ceases. Second, to know when refactoring starts to win we need to know some numbers: how long will refactoring take, and what will be its impact on velocity? And, how long will it be until the code gets crufty again, which will bring the numbers back down?
    • So what can we conclude, comparing just these two? First, not refactoring provides MORE feature value until some time after refactoring ceases. Second, to know when refactoring starts to win we need to know some numbers: how long will refactoring take, and what will be its impact on velocity? And, how long will it be until the code gets crufty again, which will bring the numbers back down?
      • This is like discussing when to clean up the kitchen and how that impacts delivery of new food. We are comparing stopping to clean now (and therefore food delivery will slow for a while) to not cleaning and therefore keeping the food delivery unchanged. It strikes me that this discussion somehow entirely misses the main point - that it currently stinks in the kitchen. Your cooks do not like it. Your customers do not like it. The food being prepared is being compromised by the garbage around it. As all cooks know, there is only one answer - clean as you go. And if you find that you didn't - stop, clean, then continue. - post by dserebren
    • Now, if we set the Refactoring Accelerator above x, RA > x, what happens? Can we go faster, or do we always slow down? We know that at one point, RA = 1.0, we do slow down, to zero (but we can speed up later).
      • Seems like in addition to the "feature injection rate" and "defect injection rate" we need to also measure "garbage injection rate". We can reason about the garbage injection rate very similarly to the defect rate, but the two are different and should be tracked separately. One can have defect injection without garbage injection and vice versa. Different stakeholders are in position to measure these - QA/Users vs. the developers. - post by dserebren

Posted from Diigo. The rest of my favorite links are here.

Thursday, April 16, 2009

InfoQ: Augmented Reality with Flash


Posted from Diigo. The rest of my favorite links are here.

Wednesday, March 25, 2009

Yoxos

It turns out that Yoxos can be configured as a simple Eclipse update site. So here's my new best practice:


- setup eclipse from a stock download from eclipse.org


- add http://update1.yoxos.com as update site


- use normal Eclipse update management to get Mousefeed, AnyEdit, TestNG, Subclipse, etc. from Yoxos

Tuesday, March 10, 2009

AnandTech: NVIDIA's Ion Platform: Blu-ray Investigation

(This is really just a test post from Diigo. But the ION platform is interesting.)

  • tags: no_tag

    • Intel never intended for Atom to be compared to modern day processors; the core will eventually compete against ARM processors, nothing from the x86 world. It’s being heavily used in netbooks today simply because it’s not small enough or low power enough to be used in anything significantly more svelte.

    • For the Ion review I was playing unencrypted Blu-ray content
      • Interesting. What about encrypted? - post by dserebren

Ah, very nice! Diigo posts have pictures!

Tuesday, March 3, 2009

Gnome Applets

Just found a few useful applets in Gnome:


* gnome-blog - post blog entries on many blog services right from the gnome pannel (this is actually a test of this applet)


* Gimmie - looks really cool. Document-centric desktop organization that seems to actually work.


* file-browser-applet - browse file system from the Gnome pannel. Like KDE. Finally. But not yet in Ubuntu distro (as of Hardy). So need to download manually.

Wednesday, February 18, 2009

Hacking on FlexUnit Ant Task

I am working with FlexUnit Ant task by Peter Martin (great work, Peter!).
One thing was missing though - under Linux I found that the default gflashplayer executable didn't exist. Instead, we have a different flash player available as part of the project tree. But there was no way to override the default used by the FlexUnit's launcher class and changing PATH variable in Ant is just a bear.

So, to make a long story short, I added ability to specify flashPlayerCmdPattern argument to the flexunit ant task. In the process, I created a GenericLauncher class based on the MacSWFLauncher (which looks to be generic enough and the most up to date).

Works like a charm. One possible enhancement for someone who knows Ant better - ability to specify the flash player as inner task element (with the <env> and <argument> tags and whatnot). But this worked well enough for me.

Here's the patch that goes with FlexAntTasks-src.zip from 2008-02-18. Enjoy!



Index: src/com/adobe/ac/ant/tasks/FlexUnitLauncher.java
===================================================================
--- src/com/adobe/ac/ant/tasks/FlexUnitLauncher.java (revision 38987)
+++ src/com/adobe/ac/ant/tasks/FlexUnitLauncher.java (working copy)
@@ -8,24 +8,12 @@
private static final String WINDOWS_OS = "Windows";
private static final String MAC_OS_X = "Mac OS X";

- /**
- * Run the SWF that contains the FlexUnit tests.
- * @param swf the name of the SWF
- * @throws Exception if there is an error launching the tests.
- */
- public void runTests( String swf ) throws Exception
- {
- SWFLauncher launcher = createSWFLauncher();
-
- launcher.launch( swf );
- }
-
/**
* Creates a SWF launcher suitable for the OS.
*
* @return a new SWF launcher
*/
- private SWFLauncher createSWFLauncher()
+ public static SWFLauncher createSWFLauncher()
{
SWFLauncher launcher = null;

Index: src/com/adobe/ac/ant/tasks/FlexUnitTask.java
===================================================================
--- src/com/adobe/ac/ant/tasks/FlexUnitTask.java (revision 38987)
+++ src/com/adobe/ac/ant/tasks/FlexUnitTask.java (working copy)
@@ -61,7 +61,23 @@
private String failureProperty = "flexunit.failed";
private String swf;
private File reportDir;
+ private String flashPlayerCmdPattern = null;

+ public String getFlashPlayerCmdPattern() {
+ return flashPlayerCmdPattern;
+ }
+
+ /** Set flash player command line pattern. If set to a non-empty string,
+ * will use an OS-independent launcher based on this command line.
+ * Otherwise, will try to guess an OS-specific command line to use.
+ * Use MessageFormat syntax. Argument {0} is replaced with swf file.
+ *
+ * @param flashPlayerCmdPattern
+ */
+ public void setFlashPlayerCmdPattern(String flashPlayerCmdPattern) {
+ this.flashPlayerCmdPattern = flashPlayerCmdPattern;
+ }
+
/**
* Set the port to receive the test results on.
*
@@ -183,11 +199,17 @@

private void launchTestSuite()
{
- final FlexUnitLauncher browser = new FlexUnitLauncher();
+ SWFLauncher launcher;
+ if (flashPlayerCmdPattern != null && flashPlayerCmdPattern.trim().length() > 0)
+ {
+ launcher = new GenericLauncher(flashPlayerCmdPattern);
+ } else {
+ launcher = FlexUnitLauncher.createSWFLauncher();
+ }

try
{
- browser.runTests( swf );
+ launcher.launch( swf );
}
catch ( Exception e )
{
Index: src/com/adobe/ac/ant/tasks/GenericLauncher.java
===================================================================
--- src/com/adobe/ac/ant/tasks/GenericLauncher.java (revision 0)
+++ src/com/adobe/ac/ant/tasks/GenericLauncher.java (revision 0)
@@ -0,0 +1,90 @@
+package com.adobe.ac.ant.tasks;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.text.MessageFormat;
+
+/** Launch flash player generically.
+ * Takes a command line pattern, where argument {0} is
+ * replaced with the swf file name.
+ *
+ * @author dmitry
+ */
+public class GenericLauncher implements SWFLauncher
+{
+ private String commandLinePattern;
+
+
+ public GenericLauncher(String flashPlayerCmdPattern) {
+ this.commandLinePattern = flashPlayerCmdPattern;
+ }
+
+ public void launch( String swf ) throws Exception
+ {
+ String cmd = createCommandLine(swf);
+
+ Process process = null;
+
+ try
+ {
+ System.out.println( "Generic Launcher: " + cmd );
+ process = Runtime.getRuntime().exec( cmd );
+ }
+ catch ( Exception e )
+ {
+ throw e;
+ }
+
+ String error = readStream( process.getErrorStream() );
+
+ if ( error.length() > 0 )
+ {
+ throw new Exception( error );
+ }
+ }
+
+ private String createCommandLine(String swf) {
+ if (commandLinePattern == null) {
+ throw new IllegalArgumentException("CommandLinePattern must not be null");
+ }
+
+ MessageFormat f = new MessageFormat(commandLinePattern);
+ String cmd = f.format(new String[] { swf });
+ return cmd;
+ }
+
+/**
+ * Reads all the data available from an input stream and converts it into a
+ * String.
+ *
+ * @param input input stream to read
+ * @return converted string
+ * @throws Exception if an error occurs while reading from the stream
+ */
+ private String readStream( final InputStream input ) throws Exception
+ {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+ int i;
+
+ while ( ( i = input.read() ) != -1 )
+ {
+ output.write( i );
+ }
+
+ return new String( output.toByteArray() );
+ }
+
+ /** Set command line pattern. Use MessagePattern syntax.
+ * Argument {0} is replaced with the swf file name.
+ *
+ * @param commandLinePattern
+ */
+ public void setCommandLinePattern(String commandLinePattern) {
+ this.commandLinePattern = commandLinePattern;
+ }
+
+ public String getCommandLinePattern() {
+ return commandLinePattern;
+ }
+}

Saturday, January 24, 2009

Advantures in Eclipse - Yoxos

Yoxos
Once again, I was looking to update my Eclipse installation and I remembered Yoxos. It's a really great service and it turns out it's been greatly improved since the last time I looked. The list of plugins is much larger and it is not littered with trial and shareware versions. Everything shown seems to be the open source stuff that you'd want to have. There may be a few pay-for packages, but I haven't run into them yet.

You can also create "profiles" which are groups of features. Then you can create a download list by selecting either features individually or with profiles (yours or created by others). Downloading this list creates a single archive (.tar.gz) that contains a fully configured eclipse directory. Just unpack and use.

One problem though appears to be that you can't remove individual features from the eclipse installation created in this way. The standard eclipse update facility is installed but the Uninstall button seems to be disabled on everything but the "Eclipse Platform" feature. One can download additional features from Yoxos from inside Eclipse. But they too cannot be uninstalled. The only way to undo changes is by reverting the entire configuration. So you can back up a step but you can't remove things out of order. This lack of Uninstall support is strange. I can only assume that it is required for Yoxos to do its magic. But it is not explained anywhere that I've seen.

There seems to be a few new features that I haven't tried yet. You can publish your workspace configuration, team project sets, mylyn queries, and other things. This allows sharing your setup between multiple computers - something that I constantly need to do between my work desktop and laptop.

All in all - Yoxos is a wonderful service for eclipse users. I highly recommend it. In fact, I'd say never download Eclipse from the main site any more. Yoxos is the way!

Or, just use the Yoxos update site in a stock Eclipse. For example, enter the following as an update site:
http://update1.yoxos.com/dist/3.4.1.081002/site.xml

Monday, November 24, 2008

Keynote: Architects and Agilists

First up - keynote presentation on day 1. Martin Fowler and Rebecka Parsons.
The main topic was how Architects and Agilists don't but should live happily together.
  • Architects should also code, agilists should also respect long-term goals Architects pursue.
  • Architects should be thought of as stakeholders, just like business, representing the long-term needs of the enterprise information systems, such as maintainability, architectural unity of vision, etc.
Interesting idea: express architectural principles through unit tests (automated or not). This gives an agile development organization a way to measure whether these goals are being met. This also allows goals to be clarified and well defined by the executable specification. Rebecka mentioned expression architectural goals as a "fitness function".

An Aside:
There was actually a product being showcased at the show that goes along these lines - SonarJ. This is a pretty cool product. It's an Eclipse add-in (or a stand alone Eclipse-based executable) that allows an "architect" to define project architecture in terms of layers and allowed dependencies between them. If some piece of code violates the allowed dependencies, it is marked as an error by the Eclipse builder. The "architect" license is around $6000! Developer licenses are much cheaper ($250 or something). The only difference is that the architect can use a nice GUI to update the architecture definitions, while developer's can only check the code against them. Definitions are stored as XML files in the project source tree. With enough cleverness, they can be edited directly, but that's probably not worth the effort.

Martin took a slightly different angle, casting an architect as a "coach".
He also tried to pull in the financial crisis, comparing the architectural debt that we've accummulated out there with bad software designs with the financial debt that is currently unraveling.

QCon Materials Online (Updated)

I will update this post with links to materials from QCon that can be downloaded freely.

There are two resources that I know right now:
  • QCon web site, which has slides from most presentations available for download on the schedule pages.
  • InfoQ web site is supposed to have video presentations available. But I am not able to find them right now. This site has A LOT of information. Looks like a lot of interesting articles and presentations from prior years.
[Updated 11/30/2008]
InfoQ site is starting to post presentations and articles from the QCon SF conference. They are tagged under QCon San Francisco 2007.

Adobe Flex example sites

At QCon we got a nice booklet of showcase sites for Adobe Air / Flex platform.
I'm still quite a bit confused about exactly where do boundaries lie between Flash, Flex, and Air. But here's a list of links given in the booklet (those that work anyway):


Earthlive - interactive global warming explorer
Nice simple format. Works on Linux / Firefox. The only problem is that the flash window floats over any traditional popup menus, which makes them unusable.
The UI functions are limited to publishing articles with globe overlays. If you select an article, corresponding overlay is shown on the free-spinning globe.





Bay Desktop - can try it out because it only runs on Windows and Mac. Will have to wait then. But it looks promising as an example of a data-rich UI. Any lucky Mac owners out there to help out a poor Linux geek?








Finetune - online music playing site. Seems to play music on demand without time limit. I'm sure there is a catch but it hasn't hit yet. But more to the point - the Flash bit is the player and probably some scripting. Works great under Linux.

From description in the brochure it seems they also have a desktop player, and that's probably where the Air was used.



IntelliSea - Wow, this is really something! This is Startrek meets today's sea ships! This seems to be a client-side piece of software, mainly for local operation, not working over the internet (although it might connect out for weather and such). The main appeal - complex data visualization and interactive dashboard. Unified status display and control for a large number of sensors and equipment. Integrated radar, telemetry, cameras.

Nasdaq Market Replay - provides market activity replay and visualization across three exchanges. Users can also upload their own trade stream.

Most of the work is done on the client side, as the brochure specifies. Uses local data storage for offline processing.



StudioCloud - application for managing photographer's studio. Has online and offline operation. This one is part of Adobe Showcase: StudioCloud Adobe Showcase. Doesn't work on Linux but the installer didn't even detect that. It tried to "install Adobe AIR" and kept getting an "error".

A number of Adobe's own sites got included into the brochure as well:
  • Photoshop Express - Picasa competition? Looks cool but doesn't work on Linux.
  • kuler - Download color themes (swatches) from the web into Adobe Creative Suite. Wants "latest flash player".
  • Acrobat.com - nothing too fancy. Just a flashy push-button UI for doing things on this site (document sharing, pdf conversion, conferencing).
That's all for now. I really like the IntelliSea interface. Definitely worth a look!

Sunday, November 23, 2008

QCon 2008

QCon 2008 has just finished in San Francisco last week. There is a lot of interesting information that I wrote down during the conference and a lot of leads that I want to follow up on. This is a perfect time to start this blog then. As I follow up through my notes, I will keep record of my findings here.

Let's kick things off with this quick summary:
For me, there were two big topics at QCon:
  • First - how do you scale your application to web sizes without running into relational database walls.
  • Second - the Moor's law is still in effect but you have to use multiple cores efficiently in order to continue riding it.