Software Engineering Best Practices @ Nylas
Transcript of Software Engineering Best Practices @ Nylas
![Page 1: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/1.jpg)
Software Engineering Best Practices
Ben Gotow (@bengotow)
![Page 2: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/2.jpg)
Computer Science ≠ Software Engineering• Clean
• Predictable
• Maintainable
• Extensible
• Fast & Efficient
• Mathematically Optimal
• Uses latest language features
![Page 3: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/3.jpg)
Essentials• The Mafia Model
• Design Patterns
• Building a Shared Language
• Exceptions aren’t evil
• Anti-patterns
![Page 4: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/4.jpg)
![Page 5: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/5.jpg)
![Page 6: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/6.jpg)
“Design software like you’re running a mafia.”
![Page 7: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/7.jpg)
• Has one well defined job. Doesn’t ask questions.
• Has limited knowledge of the rest of the operation. Others don’t know or care how he gets the job done.
• Has no secret dealings with others, clean cut actor.
• Can be replaced—others could do this specific job if he was “removed.”
![Page 8: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/8.jpg)
• Single Responsibility Principle (Robert C. Martin)
• Separation of Concerns (Dijkstra)
• Avoid Side Effects
• “Program to an interface, not an implementation.” (Erich Gamma)
![Page 9: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/9.jpg)
![Page 10: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/10.jpg)
Design Patterns
Patterns make it easy to communicate abstract ideas about software.
![Page 11: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/11.jpg)
Design PatternsCommand EmitterSingleton
![Page 12: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/12.jpg)
Design PatternsCommand
Encapsulate a request as an object, thereby letting users parameterize clients with different requests, queue or log
requests, and support undoable operations.
(Tasks in N1 are an implementation of the Command pattern.)
![Page 13: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/13.jpg)
Anti-Patterns (“Code Smells”)- Copying code into more than three places
- Calling private methods on other classes
- Inspecting state which was not designed to be observed
- Waiting for something to happen using the wall clock
setTimeout I’m looking at you.😒
![Page 14: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/14.jpg)
Anti-Patterns (“Code Smells”)Ex: Adding optional parameters that change the behavior of existing code slightly. “Don’t do this, this one time.”
thread.save({tellUser: true}) thread.save().then(() => { this.tellUser();});
Take a break, think about refactoring, explain the problem to someone else.
![Page 15: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/15.jpg)
Naming Conventions
Naming things is hard, and really important when building software on a team.
![Page 16: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/16.jpg)
• Functions that return a value should indicate how costly that value is to retrieve:
thread() // easygetThread() // hmm, probably not O(1)fetchThread() // better cache the result of this!
Naming Conventions
![Page 17: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/17.jpg)
• Names should reflect intended use and give you an idea what is returned:
onClicked() // called in response to an eventnewWindow() // always returns a new objectisSending() // always returns a booleanensureReady() // may or may not do anything
• Long names are almost always worth it:finalizeAndPersistNewMessage() // shit is going down
Naming Conventions
![Page 18: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/18.jpg)
• Functions with many parameters should use named hashes: _onComposeReply: ({thread, message, popout, behavior}) =>
• Leading (or trailing) underscores denote private members:_doInternalFileWrite myInstanceVar_
this._onComposeReply({ thread: A, behavior: reply-all, popout: true })
Naming Conventions
![Page 19: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/19.jpg)
Exceptions aren’t EvilThrow exceptions aggressively to protect the code you write from things it wasn’t intended for.
• If your code makes assumptions, make assertions.
• If you ever have the option of crashing now, or /probably/ crashing later downstream, crash now.
![Page 20: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/20.jpg)
Exceptions aren’t Evil
😍
![Page 21: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/21.jpg)
Code Review
https://paper.dropbox.com/doc/Code-Reviews-using-Phabricator-LdupUMb1X9SWMyrShmhQB
Write better code, learn new tricks, avoid shipping mistakes, develop a shared understanding of the codebase.
![Page 22: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/22.jpg)
Code ReviewCode Level:
• Clarity • Function / variable naming • Test coverage
Architectural Level:• Does this fit performance requirements? • Does this follow conventions and patterns used elsewhere? • Are we comfortable with the limitations of this approach? • Are changes well contained?
![Page 23: Software Engineering Best Practices @ Nylas](https://reader034.fdocuments.in/reader034/viewer/2022052706/58f0606d1a28ab8f6c8b46bd/html5/thumbnails/23.jpg)
Further Reading- Design Patterns: Elements of Reusable Object-Oriented
Software (Gang of Four)
- Clean Code: A Handbook of Agile Software Craftmanship (Bob Martin)
- https://sourcemaking.com/design_patterns
- http://en.clouddesignpattern.org