|
|
|
|
|
by stevekl
4296 days ago
|
|
I want to use this opportunity to open a discussion and get hacker news community's thoughts on preparing code examples. I always find many contrieved examples in coding guides such as: class Bicycle
def initialize(size_of_wheels)
# blah
end
def run
# blah
end
end
These are fine. But as such, the examples always fit well with the principles and you try to implement the principles, reality is a always far more messier.Are there a better way to write coding examples? does it ever make sense, to grab snippets from a real code base and so that it is in touch with reality |
|
I do agree with the sentiment that real world code examples are more useful. When I was learning design patterns during my degree, we were actively discouraged from using Head First as THE reference even though it did simplify things. Our lecturer was later challenged on this view. He then took the students on a counter challenge to refactor and redesign code from real world examples (taken from students' projects). Reality hit quite hard for a lot of us as we struggled to see the patterns in less obvious situations.
An interesting point to note however, was that after gaining an understanding of the design patterns at a practical level, I could then reference simple examples as given in Head First and immediately formulate how I would use it to solve a practical scenario that I might have been stuck with. Funny how it worked one way but not the other.