Posted in Functional Programming on May 3rd, 2012 by norman – Be the first to comment
For several reasons I do not want to get into, I have been toying with the idea of getting out of Java programming altogether and making the shift to functional programming.
Since this is would not be a hobby and must pay the bills, employment potential must influence my decision on which language(s) to learn.
A search on Dice both at the national and local level for Clojure, Haskell, Erland, and Scala shows the following numbers:
| Language |
National |
Local |
| Clojure |
25 |
15 |
| Haskell |
27 |
9 |
| Erlang |
63 |
10 |
| Scala |
170 |
50 |
Mind you, this was not very scientific and I did not even attempt to remove the duplicates. But what I find interesting is that NY seems to account for roughly one third of the demand (Yes!) and that Erlang seems to be proportionally more popular at the national level (6x instead of 3x).
No surprise that demand for languages running on top of the JVM is higher, as the perceived risk is probably less, making it easier for the rank and file to sell it to management. However being somewhat of a contrarian I’ll probably end up going with a language other than Scala. Clojure is sounding more and more interesting.
Posted in Misc on April 22nd, 2012 by norman – Be the first to comment
A Place to share terrible code
More proof that programming is more than just knowing APIs and enumerating the GoF Patterns.
Posted in Java on March 7th, 2012 by norman – 1 Comment
I like using the Test Builder pattern for my tests but not so sure I like the similar Fluent Interface on my regular code.
My guess is that behind the scenes any optimizing compiler worth its name is basically generating similar code for the first and third (and maybe second) examples below so the issue is one of readability and debugger friendliness.
So which one do you prefer?
Bar bar = new Bar();
bar.setX(1000.00);
bar.setY(2000.00);
bar.setZ(3000.00);
Foo foo = new Foo();
foo.setBar(bar);
Or
Foo foo = new Foo();
foo.setBar(new Bar());
foo.getBar().setX(1000.00);
foo.getBar().setY(2000.00);
foo.getBar().setZ(3000.00);
Or
Foo foo = new Foo();
foo.setBar(new Bar().setX(1000.00).setY(2000.00).setZ(3000.00));
Posted in Java on February 17th, 2012 by norman – Be the first to comment
Why is that “What is the difference between Vector and an ArrayList.” is still standard in Java interview questions?
A better question would be “ArrayList is not thread safe. How would you allow multiple threads to access an ArrayList?” Then the candidate could answer with Collections.synchronizedList() and/or for bonus points CopyOnWriteArrayList.
It’s 2012 people! I’d be more worried if someone is still using Vector in the post J2SE 1.2 world than if they don’t know what a Vector is.
Posted in Unit Testing on December 28th, 2011 by norman – Be the first to comment
I have been programming for a long time now for various fortune 500 companies and in all cases there has been some attempt at test driven development. This has mostly failed due to management and/or developers not being 100% behind it with tests usually written after the fact and badly maintained if at all.
Luckily at my current job I have been leading the development effort and was able to start unit tests from the beginning. However one problem was apparent from the get go. Our tests had too many mistakes. This was mostly due to repetitive code to set object properties and/or use of cut and paste. Having used the Object Mother Pattern before, this was my first solution. However I had another problem. I needed my BAs to review the unit tests and make sure that they reflected the various use cases. My BAs are non-technical and at the sight of Java code they would put their hands up in the air and walk away.
Searching for ‘alternatives to the Object Mother Pattern’ I came across the following link: Test Data Builders: an alternative to the Object Mother pattern and I had my answer. Not only did I get better unit tests as a result but here was something I could show to my BAs without making them break into sweat.
Certainly this is better:
Asset c124 = new CertificateBuilder()
.withCertificateNumber(124)
.withQuantity("10000")
.withTransId(124)
.withTaxLot(
new TaxLotBuilder()
.withTransId(125)
.withCoveredIndicator(Constants.COVERED_IND)
.withEffectiveDate(20120103)
.withQuantity("10000")
.withCostBasisPerShare("10.000")
.build())
.build();
Than this:
taxLot = new TaxLot();
taxLot.setTaxLotId(124);
taxLot.setAcqEffectiveDate(20120103);
taxLot.setCoveredIndicator(Constants.COVERED_IND);
taxLot.setQuantity(new BigDecimal(10000));
taxLot.setCostBasisPerShare(new BigDecimal("10.000"));
Asset c124 = TestHelper.createCertificate(124, "C", "124", new BigDecimal("10000"));
c124.getAssociatedTaxLots().add(taxLot);