boolean ASSERTIONS_ENABLED = false;
assert ASSERTIONS_ENABLED = true;
This code sets ASSERTIONS_ENABLED to false and then, if and only if assertions are enabled then the assert expression will run. The assert expression sets ASSERTIONS_ENABLED to true and returns true. Thus no exception will be thrown.
Sunday, 24 February 2013
Are Java Assertions Enabled?
Thursday, 7 February 2013
Java 8 Early Access on OSX
Hurrah to Oracle and Apple. I had all but given up seeing the latest
production releases of Java appearing on OSX anytime soon. Today I
have been playing with the early access release of Java 8 on my mac. Fantastic
work, thank you!
Monday, 28 January 2013
Unit Testing: Mandatory or Optional?
I recently came across this nice post (http://agilewarrior.wordpress.com/2012/10/06/its-not-about-the-unit-tests/) and I wanted to share it with you, as it carries a very important message that separates the capable Software Engineers from the great Software Engineers.
In our industry, when we come across a practice that helps us to improve we tend to shout about it and over state its impact. In this post the author points out that Unit Testing is not commonly used in iPhone and iPad development; and yet their software is often highly regarded anyway. As an individual who was taught that high quality software had to be unit tested, this was earth shattering news for him; it literally led to many sleepless nights while he wrestled to incorporate this observation into his view of the world. Needless to say, unit testing is a very powerful tool and that it does belong in every professional software engineers tool box. But knowing when to use it, when not to use it and how to get the best gains from it is important. In fact, like any tool, misusing it can be just as bad as not using it at all. And most of all, unit testing is not a substitute for caring about the product that we are crafting.
Wednesday, 1 August 2012
Startups – no place for software engineers?
This post is inspired by http://vampwillow.wordpress.com/2012/07/05/startups-no-place-for-software-engineers/.
The post observes that startup businesses value getting something out, anything out fast is more important in the early days than maintainability. Which competes with the majority of our software engineering training and is thus a poor environment to practice and hone our skills.
Having worked in a few start ups, as well as range of other companies from small to corporation; I too have asked the same questions. However while I see wisdom in some of the conclusions, that post and other posts such as The Hustlers Manifesto sadden me.
As software engineers working for a business, we need to deliver solutions that help make the business a success (hopefully stating the obvious here, but stay with me). The skill in doing this is to deliver both what is asked for, and what is not. We are experts in technology and we are expected to also be experts in delivery of technology. That requires aligning that delivery, while keeping both costs and timescales down. That takes real skill. Learning to transition a project with a changing business is an important skill, that I would argue can only really be learnt by working in a range of environments; and that includes a startup style environment or three.
Sunday, 29 July 2012
A neat tool for detecting Memory Leaks from within a Unit Test (Java)
On the train back from work today I crafted an implementation of a HashWheel (a very cool algorithm for scheduling work), and while planning my unit tests I wanted to know that when a task had fired or been cancelled that the HashWheel released the job. Ala no memory leak. So I knocked up the following few lines that I thought were cool enough to share. The best bit was; it found a memory leak that I had missed straight away! Result! :)
I also added it to a github repository where you can find the full source code, take a look at TestTools.java under the public github repository threadtesting-mosaic.
The tool waits for up to three seconds (usually less than 40 milliseconds on my laptop; if it is going to pass that is) before throwing an exception.
To use the tool, just instantiate WeakReference and call TestTools.spinUntilReleased( ref ).
public static void spinUntilReleased( final Reference ref ) {
Runtime.getRuntime().gc();
spinUntilTrue( new Predicate() {
public boolean eval() {
return ref.get() == null;
}
});
}
Here is an example unit test that makes use of this tool:
@Test
public void scheduleTask_cancelViaTicketAndLetGoOfTask_expectTaskToBeGCd() {
MyTask task1 = new MyTask();
HashWheel.Ticket ticket = hashWheel.register( 120, task1 );
ticket.cancel();
final Reference ref = new WeakReference(task1 );
task1 = null;
TestTools.spinUntilReleased( ref );
}
For completeness, here is the implementation of spinUntilTrue. Which can also be found in the threadtesting-mosaic repository.
public static void spinUntilTrue( Predicate predicate ) {
spinUntilTrue( 3000, predicate );
}
public static void spinUntilTrue( long timeoutMillis, Predicate predicate ) {
long startMillis = System.currentTimeMillis();
while ( !predicate.eval() ) {
long durationMillis = System.currentTimeMillis() - startMillis;
if ( durationMillis > timeoutMillis ) {
throw new IllegalStateException( "Timeout" );
}
Thread.yield();
}
}
Sunday, 22 July 2012
GitHub Work Culture (people change jobs because of burn out, how to prevent burn out while still working hard?)
Most company work spaces would destroy what they have to say as dangerous, claiming that it would never work. The interesting thing is that it does work for GitHub, and it works very well.
For me it reminds me of something a very good manager once taught me; the role of a manager is to create and protect the environment and culture for productive software development. It only takes one manager to ignore that advise to damage or destroy the soul of a work place and GitHub has pushed back hard against that decay in thought provoking ways.
Tuesday, 29 May 2012
Zeebox nominated for T3 Best App of the Year award
If you have been enjoying zeebox this year, then please vote for us in the T3 awards. To do so, just click here.