Just came across the latest Java Puzzlers presentation by Josh Bloch and Bob Lee at strange loop earlier this year. 7 new puzzlers to make your brain hurt, and your jaw drop a little bit when you see the solutions and morals.
Spoiler alert! If you like puzzlers stop reading now!
This is my take on it:
Do not use raw types, the compiler will resolve to the best match for the type and cast automatically, and this can get you into trouble with overloaded methods.
Choosing the right types might not be enough; look for quirky differences among constructors for those types, such as BigDecimal(double) and BigDecimal(String).
Avoid using Varargs and arrays together, and prefer collections to arrays, especially in APIs.
Be careful with catastrophic backtracking when using regular expressions (not only in Java!).
I do not know enough about map.entrySet() and HashSets, so I got lost in that puzzle. I will have to watch it again. But in any case:
Iterating over entry set should be done with care.
When in doubt, use a larger type to avoid overflow problems.
Leading 0s transform the number in octal literals. Use with care!
And lastly, Do not ignore compiler warnings; they can get you out of trouble before you hit it at runtime!
Josh Bloch mentioned that findbugs catches 5 of the 7 pitfalls, so if you were thinking about giving it a go, this is a good reason to get you started!
Tuesday, November 30, 2010
about frogs and programmers
I am reading Gerald M. Weinberg's classic book Psychology of Computer Programming, which I am finding really interesting, and it also has some funny bits:
"Looking back, it seems that forcing programmers to work in isolation is like trying to study the swimming behaviour of frogs by cutting off their legs and putting those legs in the water to watch them swim. After all, everyone knows that the frog swims with its legs, so why complicate the experiments with all the rest of the frog?"
Sadly, in many senses, things don't seem to have changed much in the last 40 years.
"Looking back, it seems that forcing programmers to work in isolation is like trying to study the swimming behaviour of frogs by cutting off their legs and putting those legs in the water to watch them swim. After all, everyone knows that the frog swims with its legs, so why complicate the experiments with all the rest of the frog?"
Sadly, in many senses, things don't seem to have changed much in the last 40 years.
Labels:
frogs,
programming,
psychology,
social learning,
Weinberg
Monday, November 29, 2010
concise and expressive
This is the kind of stuff that amazes me about Ruby:
line = "/pop/mente_al_sol.mp3 | 3:45 | El niƱo gusano | Pon tu mente al Sol"
filename, length, artist, album = line.split(/\|/))
Isn't that just plain nice!?
Example adapted from the Programming Ruby, the pragmatic programmers guide.
line = "/pop/mente_al_sol.mp3 | 3:45 | El niƱo gusano | Pon tu mente al Sol"
filename, length, artist, album = line.split(/\|/))
Isn't that just plain nice!?
Example adapted from the Programming Ruby, the pragmatic programmers guide.
Tuesday, November 16, 2010
Ruby and Regular Expressions
I have decided for the nth time to learn Ruby, mainly because I've been playing with ruby on rails apps for years now, but I do not have the language essentials to go beyond the typical functionality covered in tutorials or project documentation.
So for starters, I am reading the pragmatic book on ruby 1.9 which by the way, is on offer for only $10 this week (don't know for how long, so hurry up!). The book is very readable and to the point, as most of the titles in the pragmatic bookshelf.
And although the language is definitely different for me, coming from a Java background, I got immediately hooked by one aspect of it which till now had been, to say the least, a bit scary to me; the use of regular expressions.
As a Java developer I had used regexp before, but in a very limited and focused way, which happened to be the creation of validation expressions for fields in GUIs. I am not implying that this is the only use case for regexps in Java, no no no, but personally, I had only used them in that context before.
It is nice to see how in Ruby they are such a used technique, and the book encourages you to use them from very early. As I said, I had been scared of regexp in the past. I had even bought a couple of books about them that I never got to read.
So today I went looking for some easy resources in the shape or short videos that I can watch during lunch, ant I came across this one, which happens to explain the subject quite well, and it's accompanied by a long-ish post and even a few more videos. All very interesting if you are into this kind of thing!
Sunday, November 7, 2010
breakable toys
A couple of weeks ago I watched this talk in which Corey Haines tells us all about the software craftsmanship movement.
Although I haven't heard about the movement before (where have I been for the last couple of years???!!!) some of the things he talked about there felt very familiar.
A bit more digging out took me to the Apprenticeship Patterns book. And there again, a lot of familiar concepts, and even real physical situations clicked with me straight away.
One of the patterns that I enjoyed a lot is breakable toys. I have been doing this kind of small projects for years now, although I never called them toys but prototypes or spikes. Also the level at which I was getting involved with these projects was different from the one in the pattern. In my case they used to be pretty much a couple of hours work to get some framework installed and getting a hello-world kind of project out of it. The pattern goes much deeper than that. One of the examples they use is to create a wiki, and although it might seem a bit over-engineered at the beginning, they assure that it cat teach you about "HTTP, REST, parsing, web design, caching, full-text search, databases, and concurrency". That sounds a lot cooler than my 2 hours testing framework approach to toys.
I have also enjoyed the interconnection among patterns, and how some of them can lead to others. It is a great read and although the book is available online, I had to buy a copy. And of course, recommend it here; you should certainly go and buy it now!
Subscribe to:
Posts (Atom)