Podcast: Play in new window | Download
Subscribe: Apple Podcasts | Spotify | TuneIn | RSS
This week we’re drawing a line in the sand between objects and data structures. Who will win? Take a listen and decide for yourself!
For the full show notes visit:
https://www.codingblocks.net/episode51
Podcast News
iTunes Reviews:
DelBoyeire, nullthecode, Ser_j, Pneema, matthew.watkins, JC_JavaScripter, Connor Phee, Stratodavius, GS Leonric, dmitry.gokun, MobileMon, vasyl shcherbatjuk
Stitcher Reviews:
tommyrush, DoNotAsk, nullthecode, El_Programmador, tommysnacks, KetillAntoníusÁgústsson, spoonraker, TheyToldMeToWriteAReview, Connor Phee
Winners of last contest – episode 49 – viney
O’Reilly discount code – 50% off print, 40% off most e-books. See the ad on this page!
Follow us on twitter, or join the mailing list!
Want a Coding Blocks sticker?
Send us a SASE – https://www.codingblocks.net/swag
Clean Code – Drawing for ep49 winner
Viney
GIveaway rules
Clean Code
Objects and Data Structures
- Hiding implementation is about abstractions
- Not just exposing internal data via getters and setters – don’t just blanket do this
Data Object / Anti-Symmetry
- Objects hide their data behind abstractions but expose functions to operate on their data
- Data structure expose their data and have no meaningful functions
Objects and Data Structures
Data Abstraction
Users should manipulate the “essence” of the data, not the implimentation (for example, setting X/Y coordinates together)
Data/Object Anti-Summary
What…what do you mean by “Data Structure”?
“Procedural code (code using data structures) makes it easy to add new functions without changing the existing data structures. OO code, on the other hand, makes it easy to add new classes without changing existing functions.”
The Law of Demeter (aka principle of Least Knowledge) (Northeastern University 1987)
https://en.wikipedia.org/wiki/Law_of_Demeter
A method of a class, should only call…
…methods/properties in it’s own class
…objects created in the method
…objects passed into the method via arguments
Don’t talk to strangers!
Promotes loose coupling
Objects and Data Structures
Train Wrecks
Code with lots of dots…
But wait…what about fluent interfaces?
http://www.martinfowler.com/articles/refactoring-pipelines.html
Hybrids
Half Object / Half Data Structure
Worst of both worlds?
Hiding Structure
Data Transfer Objects
(aka DTO / Beans)
Active Records
Resources we Like
Clean Code http://amzn.to/2cryvJR
Tip of the Week
- Atom – Sync tree to file – CTRL+SHIFT+\
- Table Valued Parameter from C# – jbelina in slack
https://msdn.microsoft.com/en-us/library/bb675163(v=vs.110).aspx - OpenAI videos! https://www.youtube.com/watch?v=mGYU5t8MO7s
https://www.youtube.com/watch?v=mGYU5t8MO7s