2016-03-15 Pure craziness

I really wanted to share a success story today.


Like before, I have no idea what I’m doing wrong…

I created a bunch of classes: one for points, one for lines, and one for the turtle. At first, the fields in these classes were public, but then I said to myself: “Here in Javaland, nobody does any public methods. I’d better make some getters and setters for them.”

And you know what? This is stupid. For instance, I had something like this:

position.x += distance * Math.cos(dir));

(as you might have guessed, position is a TurtlePoint – which can’t be named just Point, since this is already taken – and has two fields, x and y). With getters and setters, this becomes that:

position.setX(position.getX() + distance * Math.cos(dir));

Did I mention that this is crazy? I should have left those fields public. (If you know any better way, please tell me!)

I really miss Lisp’s setf, where a getter is a setter at the same time (so to speak), and you can write (with different syntax, of course) things analogous to this:

position.getX() += distance * Math.cos(dir);

But never mind. My DrawingView (i.e., descendant of ImageView, but having a Turtle and a list of lines that should be drawn in onDraw) finally compiled, so I fired the emulator to finally draw a line or two.

And it doesn’t work. At first, it just crashed, but I’m wise enough now to read the error messages very carefully, and it complained something about null objects or something – of course, I forgot to initialize something. Then, I tried to access a (now) private field, instead of calling a constructor. Go figure. I corrected these errors.

Guess what? It doesn’t crash anymore. Yay. It doesn’t draw anything, either. Boo.

Tomorrow I’ll add some logging to see what exactly gets executed. I hope it will shed some light on the issue.

What did I learn today?

CategoryEnglish, CategoryBlog, CategoryMakeYourselfKnown