Showing posts with label craftsmanship. Show all posts
Showing posts with label craftsmanship. Show all posts

Tuesday, 10 May 2016

Review of "Functional Principles for Object-Oriented Development"

After a long time of agility and philosophy, here's something technical for a change.

Previously...

Yesterday, I was talking OO and functional programming with Alex Chythlook, who told me that some problems I faced in Anathema could have been solved much easier applying functional programming idioms.
When I asked for details, he pointed me to a talk Jessica Kerr (@jessitron) held at GOTO 2014.
Go here in case you're watching the talk and would like to actually see the slides.

tl;dr:

All of her points are well made, and she's an entertaining presenter. I am happy that she pointed out some things that I didn't have names for previously.
However, I am surprised that many of these ideas are functional, as they just appear to be thorough applications of OO principles to me. If they have been functional all the time, then it is certainly good to call them thus.

What stood out

"Errors are data too" Jessica said and told us to "not interrupt the execution flow". 
I've long spoken out against checked exceptions, and this nails it: If I treat an error as data, I am forced to deal with it. Right now, just where I would process the good result. No handing the exception outward, no wrap-to-catch-later.
That way, Exceptions are limited to things that I, as a programmer, have not foreseen, and that's the way they are meant to be used.

Idempotence, something she touches on in the very end, is quite important, too. Good to have a word, now. It describes the idea that an executable block of code (so, a function or a Single Abstract Method object) should change the world only once, even if it's called multiple times.
From her talk, I picked up the notion that this should be true for every function, and I don't fully agree with that because complexity increases when I build things out of things that build things, even if those are just functions.

The third main takeaway was her call for Lazy Evaluation. Doing that forces you to think in Objects or First Order Functions, and prevents procedural style – and that should always be a good thing.

What appears to be OO

I first stumbled when Jessica introduced a service object to limit a function's access to the database. Isn't that an application of the interface segregation principle (ISP) and the Single Responsibility Principle (SRP)? 
Smalltalk people always told me that even in Java, the client should define the exposed interface, and this is just that: If I need a service that just inserts, the method should have access to only that.

Next, she speaks about specific typing - again, isn't that just OO? If something represents a name, I should call it "Name", not "String". The DDD people have said it since 2004 and hardly anyone listened, so Jeff Bay had to point it out again in his paper on Object Calisthenics some seven years ago, calling on us to "wrap all primitives and Strings" (and numeric objects, of course).
Applying this principle in classes and productive code, I can well say that it is a game changer - your code becomes much more clear and expressive this way, even more so when you apply his next rule – "use first order collections" - as well.
Back to Jessica: Good on her picking up on that, I fully agree. It surprised me, though, that she watered down the principle by us to Options and Tuples later on in her talk. Those two are never domain specific, so effectively, she just put two new primitive types on our plate. 
More recent languages have more elegant ways of expressing these concepts, and they might feel more at home there.
I was surprised once more when she presented the lack of concern about when or how my code is executed as a principle of functional programming. With the OO concept of encapsulation comes the idea of Single Abstract Method objects, which are handed around as executable blocks. She even pointed us to the GoF patterns Command and Strategy, so clearly, this has been around for a while and was considered OO back then. 
Did the GoF silently sneak in functional ideas? How dare they!

What I didn't quite get

Apart from these three good points, there was one I didn't get: Structural Sharing? What was it about, memory efficiency? Didn't she just tell us that we should rely on our compilers instead of doing their work?

Summary

So, all in all, it doesn't matter. Whether it's OO or functional, this is a good talk to watch. 
If you want to brush up on intermediate concepts of coding or see some examples of how things might get easier if you break your common patterns: Go watch!

Tuesday, 27 September 2011

20 hours a week?

In The Clean Coder Uncle Bob postulates that you need to spend 20 hours each week honing your skills - 20 hours apart from work - in order to become a professional programmer. He reasons that it takes 10000 hours of training to become a professional - and if you ever want to get there, he says, you need to take measures.
Back at SoCraTes 2011, we spoke about getting there. Here's what came from that session.
The points are taken from my session notes and loosely reflect the order they came up in the discussion.
  1. Write a blog, Write a book, Do Katas
    In short: Practice. While this seems self-explanatory at first, it serves to illustrate that there is more than coding to coding.
  2. Reflection about daily work
    We could not agree on this one. While it's not work per se, it's still related. Does it count? I guess it depends on what you reflect on and what questions you ask yourself.
  3. Becoming, being and staying a professional is an effort
    These days, everyone with two bits of Java can call himself a coder. But calling yourself a professional is more. It takes painful effort to get there, and more of it to stay there.
    To me, this is the essence of Uncle Bobs message.
  4. Schedule for self-education
    Uri Lavi suggested to schedule your self-education just like you schedule sports or a beer with your friends. It's nothing that just happens.
  5. Pick goals
    Having a goal clearly ahead of you is the best way to notice when you stray from the path and the best tool to measure your achievement.
  6. Read
    Find out what other's do to stay in the game. Apart from Uncle Bob, Chad Fowler's The Passionate Programmer and Andy Hunt's Refactor your Wetware appear to be hot contenders. I just got Chad's book, maybe I'll post about it later.
  7. Have a buddy or mentor to commit to and reflect with
    Making a commitment to someone makes it much harder to quit. Inspect afterwards: Why didn't you reach your goal in time? Why did you enjoy this week, but not the last?
  8. Dedication and
  9. Set priorities and
  10. Cut down on other hobbies
    Without Dedication, nothing. If you constantly feel that you are not up to it, that you have to force yourself, you'd better quit striving and look for another field to apply yourself in.
    There will be a time when you have to choose whether you truly want to invest all this into coding, or whether you would rather do other things with your spare time. To me, this is really hard. I look at my schedule, and I love every filled hour in there.
    Without sports, without languages, without games, would I still be me?
  11. Should not be an obligation and
  12. Enjoy yourself
    Markus Gärtner suggested that if it feels like work, you're doing it wrong - himself, he doesn't even notice all the hours that go into this, because it's that much fun to do it. Lucky him!
  13. Don't go on if it becomes work - move on!
    Your dear pet project might become a chore at some point. If it does, don't force it - just let it go and move on. Both you and the project will benefit.

    And finally, Enyo Markovski asked us to always the remember
  14. Can I? (Constant And Never-ending Improvement)
It was a really helpful session (at a great conference), that moved me to start writing here, to get into one more open-source project, and to not think of the 20-hours-issue as a lost cause.
What do you do to stay sharp? What did you try and couldn't keep up?
P.S. to all attending: Thanks for sharing your thoughts. Is there anything I missed or misattributed?