need to update my knowledge

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: need to update my knowledge

Post by xr_a_y »

Henk wrote: Tue Aug 07, 2018 2:05 pm Probably the more patterns you use the more difficult it gets to understand your code.
I hope patterns are here just for the opposite ! makes code clearer
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: need to update my knowledge

Post by Sesse »

From Wikipedia:
One go proverb states that "learning josekis loses two stones in strength," which means that the rote learning of sequences is not advantageous; rather, learning from a joseki should be a player's goal. Hence, the study of josekis is regarded as a double-edged sword and useful only if learned by understanding the principles behind each move, instead of by rote. Every joseki should be used as a specific tool that leaves the board in a particular shape.
Design patterns are similar. If your goal is to use patterns everywhere, your code will be unreadable. If you are asked in a code review “why do you do it this way?” and you say “because it's a pattern”, you probably should not have used a pattern. But they are useful to solve specific problems, and most of all, giving them names makes it easier to communicate your structure to other programmers.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: need to update my knowledge

Post by Henk »

xr_a_y wrote: Tue Aug 07, 2018 7:53 pm
Henk wrote: Tue Aug 07, 2018 2:05 pm Probably the more patterns you use the more difficult it gets to understand your code.
I hope patterns are here just for the opposite ! makes code clearer

Patterns usually use interfaces and abstract classes. Often you wonder which concrete class is being used for the abstract code doesn't tell you.

Simplicity is most important property. Optimization is the devil. Code optimization can make your code totally unreadable which you may notice after a few months when something unexpected went wrong and you see your code back. Best is then to restore an unoptimized version and do optimizations again.

Few weeks ago I noticed a bug in optimized code of neural network. It was a hell. So I had to go back to the unoptimized version to try to understand how it worked.
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: need to update my knowledge

Post by xr_a_y »

Henk wrote: Wed Aug 08, 2018 1:46 pm Often you wonder which concrete class is being used for the abstract code doesn't tell you.
Simplicity is most important property.
Well, I agree. Although abstraction is more or less here in order to hide and make flexible the "really" executed code parts. Good logging facility helps when it comes to debugging such "abstract" program (with many factories, visitors, politics or decorators, just to name some of these patterns with a lot of abstraction).

Yes ! simplicity is important, so much important, but patterns are here for simplify code, also to provide everyone with a common language.

Simplicity shall not be confused with "imperative procedural paradigm" which often collapse as code grows and become more and more expensive to maintain and to understand. OOP and patterns are here to simplify code and make it more readable for everyone, although the "entrance ticket" is more expensive.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: need to update my knowledge

Post by Henk »

xr_a_y wrote: Wed Aug 08, 2018 3:29 pm
Henk wrote: Wed Aug 08, 2018 1:46 pm Often you wonder which concrete class is being used for the abstract code doesn't tell you.
Simplicity is most important property.
Well, I agree. Although abstraction is more or less here in order to hide and make flexible the "really" executed code parts. Good logging facility helps when it comes to debugging such "abstract" program (with many factories, visitors, politics or decorators, just to name some of these patterns with a lot of abstraction).

Yes ! simplicity is important, so much important, but patterns are here for simplify code, also to provide everyone with a common language.

Simplicity shall not be confused with "imperative procedural paradigm" which often collapse as code grows and become more and more expensive to maintain and to understand. OOP and patterns are here to simplify code and make it more readable for everyone, although the "entrance ticket" is more expensive.
There are people hating object oriented programming. They say it only makes it more complex. Many (small) objects interacting and it is not clear to assign which method to which class for there are many solutions when method uses many objects. Also properties are bit like global variables. But functional programming suffers from long parameter lists.