please please separate logic from implementation - a way how to make our code easy to understad
How many hours I spent on decoding stuff that does not need to be decoded... We are reading and repeating decode every time we see piece of logic.
On snippet above we can see just an if statement and 4 different logic cases to be resolved. Our brain will try to imagine all the string details before will enter inside the execution block. Can we help our brain to work faster? Sure we can do it!
- let's name first logic case as var johnBlogEntryCode = a.Length>15 && a.Contains("11")
- the second one as var maryBlogEntryCode = a.Length<20 && a.Contains("2")
- and finally var doWeHaveOurBlogEntries = johnBlogEntryCode | maryBlogEntryCode
How that looks now for you?
I can bet an old fart that you just read stuff on the left and not go into details on the right - true?
This is one of the simple but CHALLENGING methods when we need to understand what are we doing in a particular piece of code an NAME IT!
As we can see on the screenshot there is very little penalty for CPU when making code better for humans :D.
Have a good day!
Comments
Post a Comment