Tuesday, February 12, 2008

EDSK ... to check that something exists, before trying to use it

Every developer should know to check that something exists before trying to use it.
Following on from the previous advice about not making assumptions about a file system. Be sure and extend your assumption checking beyond just the file system. Immediately that means files and their contents. But also think about: other programs; operating system components; peripheral devices; hardware components (ports, cards, etc.)



Why is this important?

Because at some point in the future, whatever your expecting to be there won't.
When that happens, one of the following is likely:

  • It will have no impact.
  • Part of the program won't work.
  • It will cause an error message to be displayed.
  • The program will crash.
  • The program will crash and will corrupt user data.
  • An important customer will be disappointed in your software and in you/your company.
  • You (or someone else in your company) will have to spend time with the user working out what went wrong and how to work around it.
  • You (or someone else in your company) will have to spend time updating the program so that it can deal with the missing element, to prevent customers having the same problem again in the future.
As a top class developer (or one in the making) I'm sure you can guess which are the most likley items in the above list and the ones you should focus on preventing.

What do you do once you know this?

Make sure you check!
You'll save yourself some support and your users some inconvenience by dealing with problems before they can happen.

Friday, February 08, 2008

PwrShl: Create a log file

I'm trying to teach myself (learn) how to use Power Shell.

I thought I'd start by learning how to do a few simple tasks.
Append to a file
Get the current date and time
Pass arguments to a script/

The above is enough to create a simple log file utility. By which I mean a script which can be called to append text, preceded by a time stamp, a specified file.

Appending to a file is easy, because of 'add-content'.
add-content C:\test.txt "some text"
Getting the current DateTime is done with 'get-date' and is easily turned into a string.
(get-date).tostring()
Strings are concatenated with a plus sign
$dt = (get-date).tostring()
add-content C:\test.txt $dt + "some text"
Arguments are accessed via the $args array. So assuming the text is passed as an argument.
$dt = (get-date).tostring()
add-content C:\test.txt $dt + $args[0]
Put it all into a single line and pass the file name as a single path
add-content $args[0] ((get-date).tostring()) + $args[1]
Save it to C:\AppendToLog.ps1 and then call it.
PS > set-executionpolicy unrestricted
PS > & 'C:\AppendToLog.ps1' 'C:\test.log' 'the text to log'
or
powershell.exe -command "& 'C:\AppendToLog.ps1' 'C:\test.log' 'the text to log'"
Jobs a good'un.

Wednesday, February 06, 2008

EDSK ... that different platforms have different requirements

Every developer should know that different platforms have different requirements.

It is important to understand the platform that you are developing for:
  • Developing for the desktop is different from developing for the web.
  • Developing for a device with a large screen is different from developing for a device with a small screen.
  • They are both different than a device with no screen.
  • An interface that will be navigated with a mouse or keyboard is different from one which will be navigated with a peripheral device, or thumbs!
When you start developing for a platform that you have not developed before and you don't understand the differences and nuances of that platform, you should not assume that it will be the same as other platforms you have developed for previously.

Remember, assumptions usually turn into bugs or the user not getting what the really need/want.

What do you do once you know this?

Make sure that you understand the platform you are developing for, particularly if it is new to you.
Don't assume that the way you've done things on other platforms is appropriate or even possible.

What do you think?
Is this something every developer should know? Have you say in the comments.

Friday, February 01, 2008

All the Matt

Got an email today that just said

"All the Matt"

Obviously this was sent in error, or at least before being completed.

Don't know why but thought it sounded good.