Author Archive
Mike, the Prep Cook
As Gina wrote, yesterday was “Meals for a Month” time again, when she and I make 15 different meals to feed us for a month. This month went better than last time, but then we only make them for us not for Gina’s sister and her husband. Half as many meals makes a difference.
When we do this, I’m the prep cook — I chop all the onions, garlic, green pepper, etc. for all the recipes before we get started. It can be a lot of work, but it’s well-worth having all the veggies done before the assembly starts (Gina is the assembler, in case you didn’t figure that out). As I’m chopping up five cups of onions, I was thinking about the book Heat: An Amateur\’s Adventures as Kitchen Slave, Line Cook, Pasta-Maker, and Apprentice to a Dante-Quoting Butcher in Tuscany[1] where they have 2-4 people work all day doing this, preparing the meat, etc for all the night’s work. It grueling, usually you aren’t paid (especially if you just graduated from cooking school!) This is where the term “kitchen slave” from the title comes in. Of course, I only did five cups of onion — they might do twenty to thirty. And each piece has to be the same size. I wasn’t that careful.
I love to cook, but I wouldn’t enjoy being a kitchen slave in a restaurant. And neither do the cooking school graduates. However, they come out of cooking school like I came out with a computer science degree — both now have enough knowledge to start learning how to work in the field. In other words, we’ve learned how to learn — but we haven’t learned much yet. And I’m not a master chef in either field.
[1] Real review coming later. The short, three-word review: It’s very good.
About Recursion
“Fabulous Adventures In Coding : How Not To Teach Recursion” said:
A Joel On Software reader asked the other day for examples of recursive functions other than old chestnuts like Fibonacci or factorial
I’ve never figured out what is difficult about recursion — I’ve always just “gotten it”. Am I that special? Or did I have a good instructor? I vote the latter — the second semester programming (in Pascal) our class was small enough that he had people go to the white board and demonstrate how recursion, linked lists, etc. worked. So you made dang sure that you knew what you were doing! So that may explain when opportunities arise to use recursion, I jump in whole-heartedly.
When you do an analysis of a recursive function, I think it’s easy to get down on big-O numbers. Well, big-O doesn’t take into account hardware, caching, etc. If you use recursion in a function, then you know that you have the function in cache (because you’re running it!) — you just add another item to the stack. And then there’s the fact that recursive functions are usually short and concise — so they are easier to understand (if you are Recursion Enlightened, anyway). So less code to do the work. I consider that a good thing.
So here is my recursion example that finds the greatest common divisor between two integers. My apologies for the bad format — stupid WordPress plugin doesn’t like Python.
def gcd(a,b): if b == 0: return a else: return gcd(b,a%b)
You can to more with it than just hit “Generate Getters and Setters”
I’ll put aside my distaste for getters and setters and just assume they are a fact of life. And, for me now, they are — all of the data classes in the project I inherited have them. Okay, I can deal. And it seems that each one has internal classes representing data that is a part of the data. Not ideal, but I can live with it.
But this is the crap I don’t want to deal with:
owner = item.getLastUpdate().getOwner().getName();
But what is even worse:
owner=null;
if (item.getLastUpdate()!=null ) {
if (item.getLastUpdate().getOwner()!=null) {
owner = item.getLastUpdate().getOwner().getName();
}}}
This is comical the first time you see it. It makes me want to scream the fifth time. But by the tenth time I just want to cry.
You see, just because you have a class has that a bunch of private properties and the results of “Generate Getters and Setters” does not mean that the class has to stay like that. You can add your own methods that may make life easier. Like so:
public String getLastOwnerName() {
if (this.getLastUpdate()==null) { return null; }
if (this.getLastUpdate().getOwner()==null) { return null; }
return this.getLastUpdate().getOwner().getName();
}
You might be alarmed that this getter has no setter. That’s okay — you will survive. It’s worth it if you can replace the above if statement that is in your code ten times with the following:
owner = item.getLastOwnerName();
Wow — isn’t that so much nicer? And, what is even better is that, if how to change how you get the last owner name, you only have to change one method, not ten. How about that!
This concludes my rant.
Scared of Java Change?
From Stephen Colebourne’s Weblog:
[Bill Joy] was often comparing Oak to more complicated and elegant languages like Python and Beta. He would often go on at length about how great Oak would be if he could only add closures and continuations and parameterized type.
What’s funny is that I’m still working on Java 1.4.2 and I really want generics — whether they are broken or not.
Java is this generation’s Cobol — it’s never really going to go away. And, as sick of Java as we are, there has yet to be a good alternative that will please the suits (i.e. the guys who pay us programmers). There are a lot of candidates, but nothing now that can replace J2EE. And that’s too bad . . .
We may have to keep HBO after all . . .
Variety.com – HBO turns ‘A Song of Fire and Ice’ into fantasy series
I hate to say it, but HBO is the only network that may do it justice.
