When should you perform input validation, and how thorough should you be? This is a question many developers are struggling with.
This ties back to one of my earlier comments on defensive programming techniques. However, here I will present a more detailed example. Most competent developers will perform the basic input validation to ensure correct input, such as ensuring a date has the correct format, an age is positive etc. However, should you explicitly add a check in your code for null values? Java will generate a NullPointerException in most cases when performing an operation such as method invocation on a null object.
There are two reasons why I prefer to explicitly check the input when data is passed to a method from an external party. Firstly, I do not trust the third party, be that another developer making use of my API, or myself using a class from another package. Secondly, if a null value slips through, I need to show to the world that I have considered such a scenario, and that I have actively coded to handle it. If I depend on NullPointerExceptions to be thrown, I might just one day discover that the API I am using has a side effect that it does not properly handle null values, and thus return nonsense.
I am pretty sure once you transcend the youth phase of software development, and you start thinking about what you are actually doing whilst writing code, you'll start running into tough decisions such as when to throw an exception, and when to return null.
I found a simple way of resolving this controversy. Before answering that question, you need to ask yourself "Would it be beneficial to the caller if the code throws an exception or would it be more beneficial if I return null". This refers both to the code and the programmer. I say this since returning null is generally regarded as a Bad Thing, since the onus is on the developer to ensure the return result is checked. However, there are scenarios in which it is better to return null.
Lets focus for a moment on framework design. This is a bit different since many people will be using your code and be absolutely dependent on the way you return from the function call, whilst writing application code you normally tend not to invoke a method that regularly, thus if you made a mistake it should not be that terrible.
I have recently purchased the book titled "Professional Techniques for Digital Wedding Photographers, 2nd edition". One thing that really frustrates me when reading a book is when there are blatant errors in - and I am not even talking about typo's. I am referring to technical lies.
I'll summarise by quoting the e-mail I wrote to the publishers:
From: Waldo Nell wn@photudio.co.za
Date: 30 December 2004 23:05:29 GMT+02:00
To: marketing@amherstmedia.com
Subject: Professional Techniques for Digital Wedding Photographers, 2nd editionHi,
I have just purchased the book titled "Professional Techniques for Digital Wedding Photographers, 2nd edition", and would like to submit some corrections to errors in the text. If this is the wrong email address, please forward to the relevant people.
Page 35
-------
Quote: "The more receptors in the CCD, the higher the resolution and image quality will be".
Comment: This is not entirely correct. Yes - with more receptors the resolution would go up, however image quality actually decreases since there are more leakage of electrons between the cells (they tend to get closer if the CCD size is kept the same size), also "purple fringing" is usually amplified, and less light in general is recorded per receptor since it is smaller. Image quality is a factor of several attributes. However, stating that you would be able to product a sharp image at a larger print size if the CCD has more receptors, is a more accurate statement.Page 37
-------
Quote: "Most professional digital cameras can burst 5-10 frames per second at full resolution [...]"
Comment: AFAIK the fastest digital camera at full resolution today is the Canon 1D Mark II @ 8.2 MP it can do 8.5 fps. From there it only goes slower... A typical burst rate for pro SLR cameras tends to be 3-8.5 fps, whereas pro-sumer cameras handle typically 1-4 fps.Quote: "...you typically create a 16-bit image, which represents millions of colors."
Comment: When they refer in RAW mode to 16-bit images, they refer to the fact that each of the Red, Green and Blue channels capture 16 bits of data. Firstly, very few cameras can do this - the top of the range Kodak, Fujifilm and Nikon cameras can only do 12 or 14 bits. In fact, I do not even think the newly released Canon 1Ds Mark II can do 16-bit colour. Secondly, 16 bit colour like I said refers to each channel, thus all three channels combined yields 16*3 = 48 bits, thus this represents 2^48 = 281,474,976,710,656 colours, which certainly is more than millions.Quote: "When photographing in JPEG fine mode [...] you typically create an 8-bit image, which may only represent several hundred colors." Comment: Likewise, 8 bits refer to each channel. For all three RGB channels this yields 3*8 = 24 bits, which is 16,777,216 (i.e. millions of colours) - not hundreds.
Furthermore, it is not about image quality that you want to shoot in 16 bit colour mode. The human eye cannot discern much more than 2^24 colours, and for all practical purposes that is enough. However, shooting in 16-bit colour mode is extremely important if you are going to manipulate the image on a computer since several operations such as tonal adjustments will throw away colour information, and the more you have the more will be in the final image. Thus to maximise your editing capabilities of the image, use a higher colour mode - not for raw image quality.
Page 79
-------
Quote: "The 1DS features a 5.47 megapixel CCD (creating a 4024x1324 pixel image)..." and "...the ISO range is 125-800..."
Comment: The 1Ds is a 11.1 megapixel camera using a CMOS sensor (not CCD), creating 4,064 x 2,704 images. The ISO range is given below:ISO 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250
ISO expand: L = ISO 50 (custom function 03)Also, its X-sync is 1/250 sec - not 1/500 sec.
Regards,
-- Waldo Nell
When I took some pictures of lightning the other day, I detected severe purple fringing around the lightning path itself. This bothered me, so I investigated.
An interpolated crop of 1200dpi is shown below:
I had the pleasure of being in a meeting room a few weeks ago in a large, respected company with some of their technical experts discussing the security considerations for a project I am consulting on.
Since I am paranoid about security, I obviously tried to push that they upped the security on the system dramatically (they are hosting it and will eventually take over the responsibility for securing it). It was just so startling to witness their responses to many of my recommendations, that I started to realise exactly how ignorant many people are towards IT security.
In specific, two statements freaked me out completely. One of their technical experts told me that I am being overly paranoid for wanting to install a firewall on the server, since the server is not exposed to the Internet but part of the Retail Network.