The Best Code is No Code at All

As always, Jeff Atwood has an interesting around code being our enemy as developers. His proposal is that code needs to have better ‘brevity’.

I don’t think Jeff is talking about Brevity – and I think he even says that – but about Clarity. Clarity is simple, obvious, and to the heart of the matter. Real clarity is brief, but easy to read. That includes comments, too.

It could be made shorter in ‘text speak’, but how clear are those messages? There is a reason we don’t use 1 letter variable names!

It’s not tiny fragments of obscure code that does massive amounts (yes, I’m thinking of Perl in that, amongst others). And it sure as hell isn’t about lines of code – many languages (with notable exceptions) let you put an entire program on one line. Ever tried reading one? I did – you can’t.

It’s just about being simple, clear, and to the point. It’s kind of like Buddhist enlightnment – someday, with enough practice, I’d might just achieve that.

Unfortunately, I do think that we’re constrained – people often expect very complex things and lots of features from their software, and when people are demanding complex programs, you get complex code. Look at the complexity cost of, say, just having a simple UI for a Windows app, as opposed to a console app.

Some of the comments are very good, too. ‘Mickey’ is right – often, we’re trapped by bloated design. KISS is my watchword (and occasionally gets me a slap too).

Fred Ross is right, too, in his comment about code maintenance – but he does miss the point that often we’re under pressure from the boss to ‘just get it done’, and the idea of ‘get it done, but in a way that will save us time later’, well, usually, that dog won’t hunt.

Someday, we’ll get past the idea of using lines of code as a metric for how ‘good’ code is. I guess the problem is that clarity is more ethereal.

Comments from my old blog:

I agree with most of your points – but diverge in perhaps the same places you might too.

Examples… a typical .NET web application – which has C#, HTML, DHTML, Javascript, horrific call backs for AJAX, SQL, Stored procedures, triggers… the list goes on. There doesn’t seem to be any sensible way of making it “simple”.

The other problem (at least in my recent experience) is RAD or AGILE development… which often leads to spaghetti code unless the client is willing to pay a huge code tax for re-writing swathes of the project.

By Jonathan at 09:20:28 Tuesday 5th June 2007

The Best Code is No Code at All

Nice list of fonts

Nice fonts here. Now if there were some way to push them onto the client…

…actually, why the hell isn’t there? A truetype font is, what, 100-200k? Why aren’t these downloaded to some form of isolated storage, and used for display purposes in the browser. You can even, oh, I don’t know, have a font cache, so you don’t have to download them repeatedly. Perhaps some sort of signing mechanism to avoid version problems.

Comments from my old blog:

Yes – very good list. Myriad is a great font – it manages to strike a balance between being pretty, and practical too. Fonts are one of those areas where I benefit from having a designer for a brother, so was exposed to lots of barracking when I was younger and playing with DTP software… “make the line height 120%”, “make the body text smaller”, “no more than 2 fonts on a page!” and other rules of thumb…

By Jonathan at 18:06:08 Tuesday 5th June 2007

Nice list of fonts

Graphics and Developers

Coding Horror has blogged about developers needing to know graphics programs, and I agree entirely. Jeff’s right, we’re not designers, and never will be (I don’t even wear glasses, let alone ‘cool’ ones). Don’t try and learn how to build beautiful websites if you’re a developer – either, you’re gifted and you already can, or there is simply too much learning involved.

But we can build ‘fair’ sites, and rough mock ups. Every site doesn’t have to be a work of art, just as every ceiling doesn’t have to be the Sistine chapel. As developers, we should make an effort to not build websites that look crap.

And if you need to build the Sistine chapel, remember it’s a team effort. You can build the structure – and get a specialist to make the ceiling pretty.

Link to some tutorials Jeff provided (note to self – take a look)

Graphics and Developers

Get around workflow version issues – and better ways to start workflows

Workflow versioning in SharePoint by Daniel Herzog. Yeah, it’s a problem that I’ve been wondering about, and his suggestions are valid. I was interested by the link to Start workflows from the context menu – to me, this is a much more natural place to start a workflow from.

Found from Julie’s Blog

Get around workflow version issues – and better ways to start workflows

Excelllent – A CAML query generating library

To those of you who’ve never written a CAML query, this won’t seem exciting. For those of you have have spent hours digging through reams of XML searching for a fault in your query, this will be heaven sent:

CAML.NET assembly – write your queries in C# – and you can find it on Codeplex.

Queries are now as simple as:
string s = CAML.Query(
CAML.Where(
CAML.Eg(
CAML.FieldRef("SomeField"),
CAML.Value(someValue)
)
)
)

This is such a blatantly good idea that I’m giving it a

Comments from my old blog:

 

Now that *is* a good idea…

By Jonathan at 17:11:14 Sunday 13th May 2007

Excelllent – A CAML query generating library

MOSS, themes and master pages

So, Joel Oleson has blogged a bit about master pages and themes in MOSS. This is an area I think that the SharePoint team have the right idea, but execution is a little short.

My problems are that we have master pages – which is great. And we’ve got seperate master pages for standard pages, and administration pages. Okay, I’m happy with that. However, there is a mechanism for changing the master page for normal pages – but nothing for administration pages. ‘Cos nobody will ever look at them, right?

Then there is the question of master pages and themes. I really like some of the themes that come OOB, much more so than the default ‘blue’ (I like ‘Simple’). But they can only be applied on a site by site basis; there is no inheritance mechanism. And if you use a master page, it’ll probably override the theme anyway. So why have themes? Why not just use master pages?

MOSS, themes and master pages

Busy, Busy, but some thoughts on demos

Though I did have a demo at a potential customer recently, this isn’t about them. These are just the things that I’ve seen repeatedly. I’m not sure what the answers to some of them are yet.

  1. The (potential) customer always wants to see 90% of the functionality in the demo – no matter how custom that development is. (This is a case of managing expectations)
  2. The complexity of the demo is inversely proportionate to the time available to build it. (Beat the salesman until he understands, then cut all the complex bits and proceed as above)
  3. The customer will want to see all logins for all the different users in a process used – and will then yawn as you switch between accounts (and yes, I know about ‘Run As…’. Even so, they’ll yawn). (Don’t show it. Or do it once, and then explain that you’re going to stop switching for the sake of sanity/getting to lunch on time)
  4. The bit that you spend ages on getting working because it “must be shown” won’t be shown. (Try to find out how important these hard parts really are)
  5. The bit that you spend 5 minutes on, doesn’t do anything, but looks pretty will get them really excited. (This is good! Make sure you show them the exciting stuff)
  6. The customer will be utterly confident that they know their business process – and then through the course of the demo show that they don’t. (Try to help them see this, and consider re-engineering/redfining the process. If they won’t, steer clear or work on a T&M basis…)
Busy, Busy, but some thoughts on demos

Problems with Vista and my Belkin f5d9630-4 modem

I got a new laptop, and it came with Vista. To be honest, I didn’t really want Vista, but it’s being pushed in a big way – XP laptops are pretty rare already. (What I REALLY wanted was a Linux laptop, but that’s another matter).

Unfortunately, on firing up the machine and connecting it to my wireless hub, it could only see parts of the web. With my work laptop, sat right next to it, I could see any site that I tried to look at, but my new Vista laptop couldn’t – it couldn’t find microsoft sites, McAfee, Mozilla.com, cNet.com, etc.. But it could find google (and other sites) right away.

So, I tried pinging these sites – and got a response. But I couldn’t ever get a web page back. Curious.

I’ve seen this before, so I tried changing the MTU (Maximum Transfer Unit) settings for my machine – only to discover that they’ve moved in Vista. So, I found a little application to change the settings. I restarted, and it continued to not work.

Curious. So I took my laptop to work, and tried the problem sites there. Over my work connection, I could see whatever sites I wanted to. This upped it to Curious and Frustrating – it was some sort of inter-relationship between Vista, and my connection at home.

Thus, I contacted Belkin support. They took a wee while over replying, but I received a response, the guts of which is below:

To get the issue resolved, we suggest you to change the MTU on the Vista computer.The first method to set the MTU is using DrTCP (http://www.dslreports/drtcp). You will need to run DrTCP as Administrator (right click the executable and select `Run as administrator`), otherwise it will not work. The other tricky thing is that the names of the network interface are shown a bit cryptic – see the screenshot – but you should be able to identify them. As usual, enter the MTU value, click Save and click Exit. After making the change, you will need to reboot the PC.

When the PC has rebooted, you can check if the MTU is set correctly by going to a command prompt and issuing the command: netsh interface ipv4 show interfaces, which you can abbreviate to netsh int ip show int, as the screenshot shows. This will list all the network interfaces with their MTU`s in a readable way. (In case you were wondering, the MTU shown for the Loopback interface is a dummy value of 2^32-1 – or 32 binary 1`s).

You can also set the MTU using the command line, for that purpose open the command prompt as administrator (right click it and select `Run as administrator`), and issue the command: netsh int ip set interface “9” mtu=1400, where the 9 is the number of the interface for the previous screenshot (be sure to include the quotes) and you can change the MTU to any value desired. The change is effective immediately but will not survive a reboot. To make it permanent, repeat the command and append “store=persistent” to it: netsh int ip set interface “9” mtu=1400 store=persistent.

If you only run the last command and not the one without the store= option, you`ll need to reboot for the new MTU to take effect.

To test if the MTU is effective, ping the router with the -f and -l options: the maximum size of the ping packet should be 28 less than the MTU. In this example ping 192.168.2.1 -f -l 1372 should give a reply, ping 192.168.2.1 -f -l 1373 should give the message that fragmentation is needed but the DF flag is set.

“Okay”, I thought, “I’ve tried the MTU settings and that didn’t work. But I’ll try their way anyway”. I used the DrTCP application, followed their instructions – and the problem continued. Arse. Finally, as a last gasp, I used the command line instructions they’d also given and success! The MTU setting changes worked this time, although why they didn’t when I’d changed them both times before is a mystery.

Of course, by this time I’d gotten so annoyed with it all that I’d tried a reinstall of Vista, so I’ll have to reinstall all of the stuff it came with. This isn’t as daft as it might seem – I’ve had a similar problem to this before, but it turned out that it was a problem applying Windows 2000 SP4, and that I had to reinstall the service pack to fix it.

Oh well, I prefer a clean system anyway.

Anyway, kudos to Belkin UK tech support. I was impressed.

Problems with Vista and my Belkin f5d9630-4 modem