In JavaScript there are two main ways to declare a function, namely by declaration and by expression. For the majority of uses there is little difference, but there is a little sneaky-ness you should be aware of.

Function Declaration

To start off we’ll show an example of a function declaration (yes I’m using node-js … again!).

var sys = require('sys');

function helloWorld() {
    sys.puts('Hello World!');
}

helloWorld();

As you’d expect you run the example and get the following :

Hello World!

Function Expression

So the same as a function expression is …

var sys = require('sys');

var helloWorld = function() {
    sys.puts('Hello World!');
}

helloWorld();

and again runs (as you’d expect) with :

Hello World!

So What’s the Difference

The difference is in the evaluation vs execution order of the code. Basically :

  • Declarations are always evaluated before the enclosing scope is run
  • Expressions are evaluated as they are encountered.

To demonstrate what I mean, let’s flip the function definition with the call.

Declaration

var sys = require('sys');

helloWorld();
 
function helloWorld() {
    sys.puts('Hello World!');
}

Expression

var sys = require('sys');

helloWorld();

var helloWorld = function() {
    sys.puts('Hello World!');
}

Again, the function declaration runs as expected, but the expression gives the following error message :

TypeError: undefined is not a function.

Aha! So as you can see, function declarations are ‘floated’ to the top of their scope, so that they are guaranteed to be defined before any call to them. Whereas expressions are controlled more explicitly by the coder.

Well? .. What Does this Mean?

Now you may be thinking that this ‘safety’ feature is great, but the general rule I see in the JavaScript community is to use expressions over declarations. Expressions hold more true to JavaScript’s paradigms, whereas declarations stem from the mistaken attempt to make JavaScript look like Java when in fact they are very unlike.

Also, explicit over implicit is always a good rule by which to stick. The ‘auto’ moving of function declarations may seem all well and good, but could cause some confusion in reality. Expressions give you full control over your own code.

JavaScript has had a pretty bad rap in the past, having been considered dirty and hacky by us ‘proper’ programmers, who code in C++ or Java. Not to mention being responsible for those annoying web popup ads.

But over the last few years opinion has started to change. The introduction of Ajax, JQuery and similar technologies helped show us that interesting, elegant apps could be written in JavaScript. Now it has become a fully qualified serverside language with the newfound popularity of nodeJS. I know this probably isn’t news to many people, but I was surprised how nice it is to be able to code JavaScript in my terminal – feels like freedom!

It’s as simple as installing nodeJS.

(In Arch this goes something like)

wget http://aur.archlinux.org/packages/nodejs/nodejs.tar.gz
tar -xvzf nodejs.tar.gz
cd nodejs
makepkg
sudo pacman -U nodejs-*.tar.xz

Then just typing `node` to kick off a repl style terminal – check it out :

$> node
node> var sys = require(‘sys);
node> sys.puts(“Mwahaha I’m freeeee!”);
Mwahaha I’m freeeee!
node>

Or use it in a script if you like :

#!/usr/bin/env node
var sys = require(‘sys’);
sys.puts(“Mwahaha I’m freeee!”);

Pretty cool eh! I see some Ruby inspiration in there too – good stuff!

Always wanted to learn how to hack, but afraid of ‘getting done’!?

For any software professional an awareness of the tricks of the hacking trade are pretty much essential these days. Otherwise you leave all kinds of holes in your app because you didn’t know the different kinds of SQL injection, or how to perform a cross site scripting (XSS) attack (and they’re just the simple ones).

… and yes I too have been guilty of this. To be honest a 12 year old from Eastern Europe could challenge my hacking skills, and unfortunately I think this is true of most developers / engineers / infrastructure folks.

But life is all about learning, and here are some links to some promising resources to teach you how to hack (legally).

Engima Group

The quickest to get your teeth into, the Enigma Group is a website challenging you with a whole range of hacking tasks. Every task you complete earns you points, and you can view your progress compared to all other members on a league-table. With a helpful forum, this is pretty useful for quick, but meaningful challenges.

Check it out at

www.enigmagroup.org

Damn Vulnerable Linux

A whole linux distro, Slackware based I believe, to train you in the dark arts. This distro is deliberately insecure, containing out of date packages, mis-configured apps, and loads of training material. It comes as a live dvd download, so you can run it up as and when you want to practice your skills.

Download the iso from

DVD ISO

and check out the core site at

Damn Vulnerable Linux

OWASP

A wealth of resources here. The ‘Open Web Application Security Project’ is a non-profit organisation to improve web application security. There are many interesting resources, but some of the most interesting are :

WebGoat

An unsecured J2EE web application to test your wits against.

Web Scarab

A framework for analysing HTTP/HTTPS traffic.

Live CD Project

Another live linux distro, bundling a load of web security tools for penetration testing

… and that’s just scratching the surface, check out the rest at owasp.org

MetaSploit

Not really a training tool, but the ultimate skiddie swiss army knife. If you don’t want to learn how to do things the ‘proper’ way, Metasploit will do the hard work for you.

A framework for running exploits. You choose your exploit from the massive library, point the framework in the right direction, and let it rip!

A bit like cheating, but pretty awesome otherwise.

Check it out at

MetaSploit

At last, gnome shell is in the pacman repo – thanks to enhanced linux for spotting this :

enhanced linux

The simple process is now just

1) Add the following (gnome-unstable) to /etc/pacman.conf

[gnome-unstable]
Server = http://mirrors.kernel.org/archlinux/$repo/os/$arch/

2) Install it!

sudo pacman -Sy gnome-shell clutter

3) Run it!

sudo gnome-shell --replace

Simples!

It’s not as up to date as the method outlined in my original post, but if you’re looking for an easy setup, and not the ultimate up to the moment version, then this is for you. If you do want the bleeding edge check out :

http://zazaq.com/2010/04/27/gnome-screen-gnome-3-0-on-arch/
http://live.gnome.org/GnomeShell#building

Enjoy!

This year, on August 19, celebrate Whyday. Set aside that day to remember Why’s contributions to our community and culture by hacking just for the fun and joy of it.

  • See how far you can push some weird corner of Ruby (or some other language).
  • Choose a tight constraint (for example, 4 kilobytes of source code) and see what you can do with it.
  • Try that wild idea you’ve been sitting on because it’s too crazy.
  • You can work to maintain some of the software Why left us (although Why is more about creating beautiful new things than polishing old things).
  • On the other hand, Why is passionate about teaching programming to children. So improvements to Hackety Hack would be welcome.
  • Or take direct action along those lines, and teach Ruby to a child.

http://whyday.org/

Hmm I wonder what to do!!??

It’s amazing to think that HTML 4 is around thirteen years old.

Obviously the technology landscape has changed a massive amount since then – no wonder the RIA platforms such as Flash, Silverlight and JavaFX looked to dominate the web.

But enter HTML 5. This gives HTML and its associated technologies of CSS and its JavaScript API a much needed facelift, and to be honest it’s looking pretty impressive!

Google recently published a website to explain, demonstrate and teach you all about these lovely new features. The world of web programming is changing (as ever) – check it out!

www.html5rocks.com

As you may have figured I’m a bit of a pragmatic publishers fanboy (If only I had more time to read!). Anyway here’s a short post about some more goodies from them.

Books cost money and take time to read, and occasionally you invest your money and time only to realise you should have tried something else – argh!

Good news everybody! The pragmatic programmers have helpfully created a magazine that you can download for free! (free as in free beer!!). It basically outlines different subjects / articles based on some of the up and coming books. This gives you a nice taster on a range of subjects to help you make your mind up about which technologies to check out.

Take a look, I highly recommend!

Here are a selection of the magazines published so far :

Click the image to download

… and for the main site :

http://www.pragprog.com/magazines

I’ve been looking for original tech tutorials on the net. I read _Why’s guide to Ruby some time ago and really loved the style, finding it a great approach to check out Ruby, and to learn in general.

Unfortunately most tutorials on the net are pretty dry in comparison, so I decided to try and hunt down more of these fun ‘books’.

_Why’s Poignant Guide to Ruby

_Why’s guide is an awesome introduction to Ruby. You’ve probably already heard of it (it’s world renown), and if not then you should definitely check it out. It’s how I first got into Ruby (and dynamic languages in general).

Unfortunately _Why has disappeared from the programming world for now, shutting down all his sites and code repositories last year. But his book lives on, and those who have read it await his return (kinda like Jesus).

Learn You a Haskell for Great Good

Now functional languages are well-known for being a bit abstract and ‘out there’. Not as straight forward as procedural code, and not as intuitive as the object-oriented paradigm, but arguably much more powerful, functional programming is well worth checking out.

A good place to start is Haskell and the guide ‘Learn You a Haskell for Great Good’. Inspired by _Why’s Ruby guide, it is really easy to understand, and a joy to read (doesn’t feel like learning at all!).

AES Encryption

The only other similarly styled tutorial I could find was one about the Advanced Encryption Standard (AES). A pretty heavy subject, but made easier by the stick man drawings.

Seven Languages in Seven Weeks

The pragmatic publishers produce some great books, and one on the cards for this summer is ‘Seven Languages in Seven Weeks’. This book will run through seven languages including Ruby and Haskell, teaching the basics of each in turn.

I think a great compliment to this book would be a collection of alternative tutorials, (we already have the two for Ruby and Haskell).


Any More?

So if you know of any other similar ‘alternative tutorials’ I’d love to check them out – please drop me a comment if you have any ideas!?

I’ve been using Gnome 3.0 for a few weeks, and it’s been a very fluid experience – I’m impressed!

Gnome 3.0 has brought about a paradigm change to the desktop. Most desktop systems are based around that all important button, followed by  some frustrating navigation through a tree like menu. The developers here seem to have taken their UI inspiration from the iPhone, iPad and Apple in general. It’s all about big broad gestures instead of fiddley clicks; simple but effective actions, rather than hunting for the appropriate option under the right-click menu.

The base of Gnome is still there, and you can see it, but there are a few key features that make all the difference :

Desktop

When you first log in, the desktop looks pretty much like standard Gnome 2 (albeit with a better styling). In fact the styling looks a lot like the new Ubuntu Lucid Lynx theme – very cool. The only immediate difference here is that notifications pop up from the bottom, and there’s the magic hot spot in the top left corner!

Now the hot spot (or short cut button of your choice) is where the action happens. Just flick your mouse up to the top left, and you get a really nice, smooth zoom out to workspace view – now that’s different!

I’ve personally changed the short cut key to be Ctrl+Space, and find this really effective – especially because I’m switching into and out of workspace view a ridiculous amount.

Workspace Manager

The first feature I’ll mention is the application search. Ok so it’s very similar to kde’s kicker, or spotlight on a Mac, but this doesn’t mean it’s not good. Just type in the first few characters of the app or doc you’re looking for, and up it comes (with maybe a few alternatives) – hit return, and you get zoomed back into the desktop with your open app – slick!

Type in ‘chr’, hit return and chromium here we go!

Now if you can’t remember the name of the app you want, or just want to browse them all, then a list of all apps is available. Just touch the arrow to the right and you’ll get a pretty nice looking menu (iPhone apps anyone?).

Ok so that’s the basics of apps covered, now lets mention the desktop manager. As you can see above, we have a nice overview of all currently open desktops, and a neat listing of all apps inside each desktop. Well that’s not all, from this view you can drag the apps around, moving them from desktop to desktop with ease, or closing them down if you don’t need them any more. This makes finding an open application so easy – a simple Ctrl+Space to zoom out, I can see the app instantly, one click, and I’m back there – awesome!

You can also change the number of desktops you have using the +/- at the bottom right. Funnily enough I haven’t noticed any speed difference between one desktop and the maximum at sixteen, so I wouldn’t fret about performance.


Task Switcher

If the idea of zooming in and out to switch applications brings on waves of motion sickness, then don’t worry, a new and improved task switcher is included too. Just hit the usual Alt+Tab and up comes the task switcher.

There is a slight difference here in that applications are grouped. Left and right moves between the application groups (Firefox, Terminal, etc), and pressing down expands the group to display specific instances. As you can see above there are two terminal sessions open under the single group.

Conclusion

I really like Gnome 3 and it’s convinced me to switch from my usual mainstay of KDE 4 (sorry guys).

The only concern I have is the fact that 3D is a requirement for Gnome 3 to run. This is not generally a problem for the experienced, but what about newbies running a nvidia, or ati card, expecting it to work ‘out of the box’? If Ubuntu, the entry point to the Linux world for many, are going to use this as default for the 10.10 release, then a lot of fallback support will be needed to support those newbies.

Having said that, I think Gnome 3 brings Linux up to scratch with Windows 7 and Mac OSX for the desktop experience, and I’d choose it over those operating systems any day!

I saw this link when reading a book on Python – and think these are pretty good guidelines for any programming language, not just python.

I decided to include them here to remind myself of these principles frequently. You can find the original link at http://www.python.org/dev/peps/pep-0020/

  •  Beautiful is better than ugly.
  • Explicit is better than implicit.
  • Simple is better than complex.
  • Complex is better than complicated.
  • Flat is better than nested.
  • Sparse is better than dense.
  • Readability counts.
  • Special cases aren’t special enough to break the rules.
  • Although practicality beats purity.
  • Errors should never pass silently.
  • Unless explicitly silenced.
  • In the face of ambiguity, refuse the temptation to guess.
  • There should be one– and preferably only one –obvious way to do it.
  • Although that way may not be obvious at first unless you’re Dutch.
  • Now is better than never.
  • Although never is often better than *right* now.
  • If the implementation is hard to explain, it’s a bad idea.
  • If the implementation is easy to explain, it may be a good idea.
  • Namespaces are one honking great idea — let’s do more of those!
Follow

Get every new post delivered to your Inbox.