Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Wednesday, 9 May 2007

Commenting Code

Commenting code is something that all programmers, especially the students and newbies, are constantly reminded to do.

But how do you best go about it, and more importantly, how do you know when to add comments? Steve C McConnell says a good place to start is with good code:


Good code is its own best documentation. As you're about to add a comment, ask yourself, 'How can I improve the code so that this comment isn't needed?' Improve the code and then document it to make it even clearer.


The worst code i've seen would not have been helped by adding comments. The code itself needed to be drastically changed.

Code which has a logical structure and meets the requirements of Obejct Orientated design can often be worked out. It is when the programmer him or herself does not know what the class is meant to be doing that problems arise.

So sort out the code and comments will naturally follow.

Tuesday, 1 May 2007

Getting To The Top - Programming or People?

What is interesting about this article , from Aleksey Shevchenko, aimed at application developers on how to succeed at job interviews?

People skills are number one. This is not say that technical ability or business knowledge is not a pre-requisite. It isn't possible to be a doctor without having detailed knowledge of medicine, or a mechanic without knowing the internal working of a car. The same goes for programmers.

But who gets to the top of their profession, and how do they do it? Is it by being factually/technically correct but obtuse and arrogant, or by merging your technical skills with an awareness and understanding of how other people operate?

You guessed it... Become an excellent programmer, but don't forget those other 'softer', but no less important, skills.

Friday, 27 April 2007

Favourite Books - Head First

Ok Ok. If you like at my favourite books on the right, it does seem like a brand of books, started by Cathy Sierra, make up the majority of my book shelf.

Now I must start off by saying that I have not and will most not ever receive payment for this. It is actually because reading the Head First Java book brought me up to speed on Java in only four weeks, when others will still learning the basics (and still are) after three months.

The second, Servlets and JSPS, brought my 92% in a class test, and the third, HTML and CSS, gave me the skills to write a well structured, strict compliant, good looking website that meet usability guidelines (oh and the client liked it also).

The books quiet simply break the mould for technical manuals, though strictly speaking they are not manuals, but learning materials that life long teachers probably never manage to produce. So say what you will about my shameless plug for the Head First range, but they've brought me far and will do so for others who can't be bothered to wade through 500 pages of sleep inducing size 8 writing.

Thursday, 26 April 2007

Remote Method Invocation has Landed!

I have finally nailed (ok not not nailed, but more pinned down with a sturdy pin) Remote Method Invocation(RMI)

RMI

Unfortunatelly, the RMI lecture came straight after a class test and was thus promptly slept through by most students. Going back over the lecture slides, which are not meant to be read but worked through in class, were not much help. After much confusion, trying to work it out, going back to the Head First
Java book
I finally tried the java website, and hey presto, found exactly what was needed, a tutorial
by jGuru.

To summorise how neat and simple RMI is (for the simple stuff anyway!)

The remote object you want to be available to a different JVM must implement an interface.

That interface:

  • is public
  • implements Remote
  • each method signature defined must throw a RemoteException
  • and for programming ease import java.rmi.*;


The remote object:

  • again be public
  • implement the interface above and extend UnicastRemoteObject
  • supply a no arg constructor which throws RemoteObject and calls super()
  • implement all the methods defined in the interface it is implementing


Now getting that remote object "out there", which will be done by a server object, is so fantastically easy, once you see it in practise.

The server object:

  • does not implement or extend anything
  • places all the work in try/catch statements
  • imports java.rmi.*;
  • makes an instance of the remote object to be made available to the world
  • declares it to the world by doing such: Naming.rebing("rmi://hostname:port/madeupname", RemoteObject Instance);
  • has a main method for starting the server


The client, or the listener which wants to use the remote object as if it were on its heap:


  • Gets a copy of the class for the object it will use as a stub/ if one is not on that system
  • RemoteObject r = (RemoteObject)Naming.lookup("URL same as above/madeupname");
  • you can then use r as if it were on your system!


Of course this won't make much sense without looking at some actuall examples, but it
is so straightforward that, like a lecturer said, you could put this all on a post stamp!

Wednesday, 25 April 2007

Can you think positively?

Jeff Atwood wrote an excellent article that resonated with my own experiences on what separates a good programmer from a mediocre one. His advice was to take a step back from the programming itself, and broaden your skill set; not through learning more languages but learning more about the user, the industry and the business as a whole.

Atwood quotes Bill gates from the book Programmers At Work rings so true;


Does accumulating experience through the years necessarily make programming easier?

Bill Gates: No. I think after the first three or four years, it's pretty cast in concrete whether you're a good programmer or not.


It was clear, I hate to say, who the good and the bad programmers were on my Masters. Now why was it? Naturally, and rather immodestly, I counted myself on the side of the fence that shepherd the good programmers. But why?


  • Was I that intelligent, other and above others? No.
  • Did I have more experience then they? No
  • Did i have access to more/better study materials? No


I went through many similar questions, before finally finding the answer: I was patient and willing to learn.

Because I always assumed I would learn to programme, and programme well (which I still am doing - you never do stop learning), any time I came across problems I was able to surmount them while others stumbled, lost confidence, and eventually gave up.

Boris Veldhuijzen van Zanten wrote an interesting article looking at and comparing the thinking patterns of successful and unsuccessful entrepreneurs.

The attitude of the failing businessman matched exactly those of my failing classmates, who would focus on short term problems and not the final goal.

When I trained to do a static parachute line jump, pretty much everyone on the course were motorbike riders, including the trainer. When it was explained to us how to avoid not ending up swinging from a tree, the analogy of two motorcycles riders was used.

They are both going round a bend with a tree on the outside corner, the first looking at the tree he wants to miss, the other looking at the point on the road where he wants to come out of the corner. Which one hits the tree?

My fellow masters students who kept focusing on the hurdles, without keeping their eye at the end of the track, were the ones who fell.

Is the way you think, your attitude, the real barrier to your progress?