Developer Best Practices
<%= Why%>
- Readability
- Maintainability
- Elegance
- Faster development
- DRY code
- Trolling your friend's code
Disclaimer
Practice
The basics
Naming conventions
- Bloat
- Comments (lie over time)
- Self Documenting
Inline styles
STOP IT!!
External links
- External css within <head></head> section
- What about external JS?
Tag names
- Keep your tag names lower case
<DIV>
<P>Here's an interesting fact about githeri. </P>
</DIV>
<!-- VERY BADDD -->
<div>
<p>Here's an interesting fact about githeri. </p>
</div>
<!-- VERY GOOOOODDDDDD -->
CSS formatting
- Organize your css file in a top down approach
/****** main content *********/
styles goes here...
/****** footer *********/
styles go here...
Indentation
# ruby (2 spaces)
def cook_githeri
some_var = true
if some_var
do_something
else
do_something_else
end
end
<!-- html (4 spaces) -->
<html>
<head>
<title>Githeri website</title>
</head>
</html>
//Java (4 spaces)
intermediate
Operators
Use === instead of ==
Array vs Arraylist
speed vs size/footprint
variables
- Declare them outside loops
- Declare them inside blocks if they are not used anywhere else
for(var i = 0; i < someArray.length; i++) {
var container = document.getElementById('container');
container.innerHtml += 'my number: ' + i;
console.log(i);
}
A little bit advanced
Testing
- Test coverage story
- Test anything that can be tested
- Test defensively
- close co-relation between testing and UX
- They shouldn't depend on each other
Using vanilla JS
- Always faster to using a framework
self invoking functions
- Preferred to jQuery methods e.g.
(function cookGitheri() {
return {
name: 'Githeri',
lastName: 'Man'
};
})();
(Rails) controllers
- Keep them thin
- Any method going into controller actions should probably be inside the model
Database
- Your code should not load everything from the database
@posts = current_user.posts.per_page(20).page(params[:page])
@posts = Post.all
Bad
Better
credential storage
- Do not store this in your java/ruby/javascript code
- Store these in external files
Password storage
- Do not store passwords in plain text
- Encrypt them before storage
Developer ethics
- Just because you can do something, doesn't mean you should
Questions
Developer Best Practices
By ian munene
Developer Best Practices
- 386