Code And Cocktails

My Thoughts Derived From the Talk Given by @chadfowler at @bostonrb 2012-02-21

| Comments

Overview

(I finally went to another Boston Ruby meetup. Only my second - hopefully it will be less than ~9 months before I go to my third.)

Chad Fowler gave a talk entitled “Measuring & Analyzing Things That Matter When You Have Too Many Things To Keep Track Of” at tonights Boston Ruby Meetup. It was the reason why I went to the meetup.(But I did enjoy the other two talks - but they are not the topic of this post)

His talk was, self-described, half-baked ideas. Which is fine by me. At @boston_sc we’ve started doing “half-baked” ideas talks and they have been great - I only wish that this talk was more discussion style like the ones we have at @boston_sc.

He talked about how even with a team of very good developers, good code is not guaranteed. The bad stuff builds up, even without people noticing, via bad habits and laziness. His person example of gaining a lot of weight hits very solidly with me and I am again working to drop my weight which keeps just sneaking back (due to bad habits and laziness on my part).

How to measure how readable code is

He mentioned several thoughts about how to fight the bad habits/laziness, but the one that got me thinking was about the Flesch-Kincaid Readability Scale.

Basically in a nutshell Rudolph Flesch devised a algorithm for English which let you compute a score which then equates to what level of English reader could easily read and understand your English. He suggested that perhaps some combination of metrics (e.g. flog, flag, roodi, churn, reek, (i.e. things from metric-fu)) might render a number which would equate to a level of developer (his scale topped out at Rich Hickey) that could understand your code.

The reason that this got me thinking especially was because it fits into a less-than-half-baked idea I’ve had. A few months ago I was working with a junior developer at my job and while she was away I had implemented a nice little bit of Groovy code to do something. It involved a chain of collection functions (e.g. map, inject, collect etc.). I thought it was great. When she came back and saw it she couldn’t understand it. I explained it to her and she started to understand. I explained again and she sort of understood. Then I said “ok, hold on…” and replaced it with 2 for loops. Totally dumb un-cool code that did the same thing. She immediately understood! So that is what we committed.

The problem was that I was at a higher level of understanding of that sort of pseudo-function collection function chaining. (and also it the code might have been a bit ‘clever’ shudder). By shifting to ordinary code it was easy to understand.

The thing I am interested in is if this scale of code comprehensibility is if it is absolute or relative. My first thought it is relative. If one can raise the base skill of a team then that team can understand more esoteric code.

Other thoughts

There were other interesting points in there - obviously rather ruby specific:

  • Mention of tools like flog, flay, roodi, reek, etc all good at giving numbers about your code.
  • Measuring whatever worries you
  • Graphing everything you can
  • (again) Getting information from your commit history

These are also things that will keep me thinking for a bit. I can use these ideas both in my for-pay coding and my for-free/me coding.

The Delete Refactoring

| Comments

The Code is unnecessary.

Delete it.

void printLog (String msg) {                   
    int logLevel = 2;                   
    LOG.printLine(msg);          
}        

=>

void printLog (String msg) {                   
    LOG.printLine(msg);          
}    

Motivation

Sometimes code doesn’t do anything. Maybe a variable is no longer used, or a whole function or class is no longer referenced by the rest of the code. If that happens, delete it.

Mechanics

  • select unused code
  • press the delete key
  • compile and test

Example

I start with the following code:

// This method is no longer used          
// int getErrorLevel() {          
//     return -1;          
// }    

Select the text and hit delete. I now have the resulting code:

 

Code'n'Cocktails - Crazy Idea?

| Comments

I jokingly I mentioned the idea of Code’n’Cocktails on Twitter…

https://twitter.com/#!/verdammelt/status/158292007981289472

This was shortly after a short conversation while partaking of aprés Boston Software Craftsmanship beers in which I was asked about cocktails and someone suggested getting cocktails after the meeting next time. It was also immediately after I was asked when we were going to get cocktails by @zdsbs (prompted by my tweeting I had just purchased a book of Absinthe Cocktail recipes).

I did but jest (poison in jest; no offense i’the world [Hamlet III.ii.234-235])…

But now I am thinking it through.

I have heard of ‘Code & Coffee’ and thought it a good idea. A place to meet people who like code and coffee. While I really like coffee, I also like cocktails and I seem to be surrounded by people who get up later than I do - so why not meet after work for cocktails and code? Brilliant!

So what would a Code’n’Cocktail look like? I see a few possibilities:

  1. A cocktail party where code/coding is the topic of conversation
  2. A coding dojo/coderetreat/code kata session with booze
  3. A salon for coding

I think the first and last are very similar and given my inclinations I like the connotations of referring to it as a salon. I think that would be my preference. I would not want to limit it entirely to discussion; so some coding would be good.

What do I hope attendees would get out of such an event? I think attendees should have fun and at least one of: learn something, teach something, make contacts.

This sort of event would have to happen at a bar or someone’s home. I don’t see how it could happen at someone’s workplace or a place like NERD as it obviously needs a well stocked bar. The problem is location. The Location would need to be able to accommodate an prior-to-event unknown number of people (making a reservation would be difficult); and accommodate the possibility of coding (standing at a bar may not work). I think an off night at a bar might work - the place would love to get business on a slow night…

The gears in my mind are turning. If you have interest or thoughts please comment or contact me.

Gnus Configuration (2.75 of N) - Spam Splitting

| Comments

I think I have no solved the problem of Bogofilter not running after group exit. I had my spam-process group parameter written wrong.

(spam-process ((spam spam-use-bogofilter)
        (ham spam-use-bogofilter)))

Note that this is a sexpr of two elements, the second one being a list. I had it being a sexpr of three elements.

Oh the joy of silent failure.

I have also found mention of the BBDB problem on the mailing list – so there is a possible fix there if I get a new copy of spam.el from the repository or something like that.

Gnus Configuration (2.5 of N) - Spam Splitting

| Comments

An addendum to follow up on how to fix an item that was giving me a problem before.

In order to get ham & spam moved and processed as such when you mark it you need to set up additional group parameters:

'(("nnfolder.*"
 (spam-contents gnus-group-spam-classification-ham)
 (spam-process (ham spam-use-bogofilter)
           (spam spam-use-bogofilter))
 (spam-process-destination "nnfolder:spam.spam"))
("spam.spam"
 (spam-contents gnus-group-spam-classification-spam)
 (spam-process (spam spam-use-bogofilter)
           (ham spam-use-bogofilter))
 (ham-process-destination "nnfolder:mail.misc"))

Specifically the spam-process-destination and ham-process-destination pair. These cause the mail to be moved from the ham to spam groups and /visa versa/.

One problem still remains – the bogofilter still doesn’t seem to be doing anything. I don’t see any evidence that it is being called in the `Messages buffer either.

So the score is:

  1. Bogofilter not being called when groups exited
  2. Wish I could get BBDB to work.

Gnus Configuration (2 of N) - Spam Splitting

| Comments

Setting up Splitting

The next thing I felt I needed to set up was spam splitting. I didn’t want obvious spam being dumped into my inbox anymore.

To set up spam splitting you need to be using Fancy Splitting. Then you add (: spam-split) to you fancy split rules. At this point you have something like:

(setq nnmail-split-methods 'nnmail-split-fancy
         nnmail-split-fancy '(| (: spam-split)
                                "mail.misc"))

You also have to call spam-initialize to make it start working.

/However/ one has to do a little more. You have to specify which spam back ends you want to use. Since my ISP runs SpamAssassin I chose to use spam-use-spamassassin-headers. Setting this to t makes the spam package check for the X-Spam-Status: YES header. (There are plenty of choices so check out the doc)

What didn’t work quite right

I also wanted to use Bogofilter so that my local machine could learn to identify stuff that my upstream Spamassassin did not. However I’m not sure if that is working correctly. My Bogofilter database file is still zero size.

To get a spam back end to process spam and ham when you are done reading a group you need to add some group parameters. So I set:

(setq gnus-parameters
       '(("nnfolder.*"
          (spam-contents gnus-group-spam-classification-ham)
          (spam-process (ham spam-use-bogofilter)))
         ("spam.spam"
          (spam-contents gnus-group-spam-classification-spam)
          (spam-process (spam spam-use-bogofilter)))
        ...

But like I said that doesn’t appear to be working. I’m probably just missing something small that is mentioned in the documentation.

What seems to be broken

Before my nuke and pave (and upgrade to emacs v24) I was using BBDB as a whitelist. So if you were not in my BBDB then you went to spam. However with v24 when I try to use BBDB I get an error saying that bbdb-search is undefined. It /is/ defined in bbdb-com.el however so I am not sure what is wrong. I’m going to investigate a bit more and post a question on gmane.emacs.gnus.general and gmane.emacs.gnus.user (maybe also gmane.emacs.bbdb.user).

Coderetreat - the Need for Preparedness

| Comments

Abstract

This observer has noted a repeated waste of time by attendees of the Coderetreats he has attended. Herein is described a simple way to be better prepared when you attend your next Coderetreat

Observational Data

This past weekend was the Global Day of Coderetreat and I attended the one in Cambridge, Mass. This was my third and I again saw an annoyance I want to get out of my head.

First, let me recapitulate the idea of the code retreat. The participants work on the Conway’s Game of Life programming problem in 45 minute intervals in pairs, throwing away the code after every iteration. Some iterations have interesting constraints added; such as ‘no primitives’, ‘no ifs’, or ‘silent paring’.

I have noticed that at each coderetreat I’ve attended some people spend time (usually only in the first session luckily) fighting with their environments to get the point where they can start coding. To me any time spent setting up the environment is wasted time when you have 45 minutes. I’m not saying that this was a /huge/ issue – but a very little bit of preparation can save plenty of time during the event.

An Initial Attempt for a Personal Solution

Given that I saw (and felt, when pairing with someone who was unprepared) this problem at the Chicago coderetreat (held the day after SCNA), I made sure I had a ruby and Java project all set up so that I had a failing test (true == false). That way I knew that everything was all set: all needed libraries, any special configuration (autotest & rspec always gives me a little bit of hassle), any other annoying little thing was done. I even went so far as to push them up to GitHub so others could use them to. (git makes deleting the code after an iteration very easy: git reset --hard HEAD && git clean -fqx).

It turns out that I didn’t need to do this. There was already a GitHub repository that did what I needed and much more: coreyhaines/coderetreat.

Conclusion

Given that the above repository is set up for 10 programming languages currently, it is likely that the ones you want to use are already there. Simply cloning the repository and doing a quick smoke test will ensure that your environment is ready for the session.

If you don’t find your favorite language – or the skeleton provided doesn’t work as well as it could – send a pull request (I tweaked the ruby starting point to let autotest work with rspec right away).

There Comes a Time in Every Emacs-user's Life When...

| Comments

…you just need to nuke-and-pave your configuration.

That time has come for me – especially with respect to my GNUS configuration. I’ve been using GNUS to read news since probably 1990 or earlier, before then I remember using rn.

As for email I’ve used RMAIL and VM. I don’t remember exactly when I switched GNUS but it has been probably at least 5 years.

Over that time my gnus init file has grown pretty hairy. It is time for a shave.

Over the last week I’ve switched to a pretest release of Emacs v24 and during that time I cleaned out a lot of configuration – but feared to clean out much of my gnus configuration. However in trying to get the spam checking working better I realized that a nuke-and-pave is probably the best thing to do now.

So I am about to remove nearly ALL of my gnus configuration. Pray for me.

p.s. I’ll try to blog about my luck or lack-there-of. And also any interesting bits I discover along the way.

GNUS Configuration Note 1 (of N)

| Comments

So far I have flailed around moving my email to a different structure. I have been using nnmail-use-long-file-names set to t up until now. But I decided to try it out with the default value of nil.

I had several problems this evening

  • Sent mail was going to nnfolder+nnfolder instead of nnfolder+archive as advertised. I think that this may have been caused by old settings in my .newsrc.eld. After mucking about in there I started getting my sent mail in the right place.

  • Not sure how it happened but the system acted as if nnfolder-directory was set to ~/News/nnfolder but then suddenly switched to ~/Mail/. I got that all sorted out (now set to ~/News/mail) but it took some time and my brain didn’t figure out how it was working for while. The important part here is if you move a mail file you must also move/edit the active file to list that mail group.

Some of the problems may have been caused by a rather cavalier attitude to the task. If I had sat down to do it more carefully and slowly it could have gone more smoothly.

No mail was lost so I am happy. But the system as it is currently configured is definitely not the way I want to keep it. Things to do next:

  • spam handling
  • expiry for archving (which I conflate that with sent mail processing)
  • splitting (but less splitting than I was doing previously)

But now… time for sleep.