8 tips for writing clean code: - Early return principle - Merge if statements - Use LINQ for conciseness - Bool expression -> Method - Prefer custom exceptions - Magic number -> Constant - Magic string -> Enum - Use result objects
Good developers can spot code smells with one glance at the code. Yesterday, 24.415 engineers learned how to write clean code. If you missed the issue, grab it below 👇 milanjovanovic.tech/blog/8-tips-to…
@mjovanovictech What do you mean by merging if statements and what’s LINQ?
@mjovanovictech @CHBernasconiC I agree. And here an #fsharp version - ActivePatterns (replaces early return , merge if statements, bool expression) - use pipelines (LINQ) - use Result type (maybe result Computation Expression) - use discriminated unions (magic strings)
@mjovanovictech Although I agree with almost all your points here (except LINQ), the code snippet is really an example of not using OO correctly. IMO, all of that logic on an Order really belongs inside the Order type.
@mjovanovictech I don't like Maxnumerofitems constant, I would use a provider, that is the typical use case when the user say this is not going to change and in 6months change 🤣😂
@mjovanovictech Merging if statements, that's so simple and yet so effective.
@mjovanovictech The purists would say “you’re not optimizing for stack allocation”.
@mjovanovictech I was wondering why bool methods instead of bool expressions?
@mjovanovictech I would add: - few "if" statement usages - zero "else" statements.
@mjovanovictech IsProcessable could use pattern matching
@mjovanovictech What is processorderresult? Is it static?
@mjovanovictech I appreciate all the tips to make my code cleaner!