Beruflich Dokumente
Kultur Dokumente
com)
MENU
Web (http://www.sitepoint.com/web/)
(http://www.sitepoint.com/author/tevko/)
Tim Evko (http://www.sitepoint.com/author/tevko/)
Tweet (Https://Twitter.Com/Share?Text=6+Tips+For+Writing+Better+Code&Via=Sitepointdotcom)
Subscribe (Https://Confirmsubscription.Com/H/Y/D46DD8C9BD8A0B5D)
In any given week I can expect to write at least a few hundred lines of code in around four different
languages. I can also expect to edit, review, and collaborate on code written by the other developers I
work with.
Simply put, theres a lot of code flying around all over the place, and things can get very complicated
when its not organized, managed, and most importantly, written well. Lets look at a few different ways
to improve the overall quality of our code.
course, theres a lot more to writing modular code, and you can write modular code for more than just
JavaScript.
CSS preprocessors like Sass (http://sass-lang.com/) (our introduction here
(http://www.sitepoint.com/getting-started-with-sass/)) allow you to write individual CSS files, and then
include them into one main file when you compile them. This lets you write individual CSS files for
different components like buttons, lists, and fonts. At the end, theyre all included into one main file, but
maintaining these files becomes a whole lot easier.
New technologies, such as Polymer (http://www.polymer-project.org/) allow you to write custom HTML
elements, so that your HTML, CSS, and javascript can be grouped into individual components based
on functionality. Be sure too look into Browserify (http://browserify.org/) (our introduction here
(http://www.sitepoint.com/getting-started-browserify/)), which allows you to use Node.js-style modules in
the browser.
Brad Frost also gives a great overview on the ideas and methodologies for writing modular code here
(http://bradfrostweb.com/blog/post/atomic-web-design/).
2. Speaking of Preprocessors
Preprocessors dont just help with writing modular code. Theyre great for a lot of other things too!
Preprocessors add extra functionality to your code internally, while outputting the same HTML, CSS,
and Javascript that your browser recognizes. They usually require some extra setup time, but they
make up for it once youre comfortable with using them.
Using a preprocessor can help you save time by eliminating the need to write the same repetitive code
multiple times. They also add helpful functionality like variables, functions, loops, and simplified syntax.
Most preprocessors are highly customizable as well. Several include the option to select your prefered
output style, incorporate plugins and addons, and even create custom notifications when needed. The
most popular preprocessors have large communities, are well maintained, and answers to common
problems are not hard to find.
Heres a video introduction to the most common preprocessors for CSS, HTML and JavaScript: Sass,
Haml and CoffeeScript (http://www.sitepoint.com/introduction-sass-preprocessors/).
If youre interested in Sass, heres a look at how SitePoint author Hugo Giraudel organizes his Sass
projects (http://www.sitepoint.com/architecture-sass-project/), and his favorite tools for doing so
(http://www.sitepoint.com/my-favorite-sass-tools/).
While youre looking at Sass, be sure to check out HAML (http://www.sitepoint.com/an-introduction-tohaml/) and Coffescript (http://www.sitepoint.com/what-is-coffeescript-all-about/) as well.
You dont have to use a preprocessor for every language you write, but many of them are helpful and
can lead to you writing better code.
Version control can be a complicated topic to understand, but there are plenty of tutorials to help get
you started. I recommend taking a look at our introduction to Git (http://www.sitepoint.com/git-forbeginners/) for a basic overview on getting started. We also have a guide to using Git in a team
environment (http://www.sitepoint.com/getting-started-git-team-environment/) and some tips to take
your Git skills to the next level (http://www.sitepoint.com/10-tips-git-next-level/). If youre not sold on Git,
you have other options for version control as well (http://www.sitepoint.com/version-control-software2014-what-options/).
One last tip: use the command line. The command line can be an intimidating interface, but getting
familiar with it will go on to improve your understanding of programming as a whole, while enabling you
to use other great tools like Gulp and Grunt.
CodeWars (http://www.codewars.com/) is great for brushing up on your javascript abilities, and The
Practice App (http://tevko.github.io/practice/) will give you random front end challenges to build on
Codepen (http://codepen.io/).
Conclusion
Following some or all of these tips will drastically improve your coding skills, and therefore the quality of
the sites, tools or apps youre building.
Have some more tips and tools for writing better code? Feel free to share in the comments!
(http://www.sitepoint.com/author/tevko/)
(https://twitter.com/tevko) (https://github.com/tevko)
(https://plus.google.com/108904416211598514133/posts)
You might also like:
Write a 3D Soft Engine from Scratch: Part 2
(http://www.sitepoint.com/write-3d-soft-engine-scratch-part-2/)
Claim Book
3 Comments
SitePoint
Sort by Best
Login
Share
Favorite
4 days ago
This is a very good list of points, that must be understood and followed by any web developer.
I absolutely agree on each and every point you have covered here.
Especially the "Plan Before You Write" and "Start Holding Code Reviews" points which I have seen
many of them know and also agree upon but don't practice them during real projects.
Also your links to related resources for further exploration is a great add-on benefit.
Thanks Tim, and looking forward to such helpful articles in future as well.
3
Reply Share
James Hibbard
3 days ago
To expand on point 6: helping people in forums (such as SitePoint's) is a great and rewarding way to
practise newly-learned coding skills.
1
Reply Share
HenriHelvetica
26 minutes ago
Man, I need this printed and pinned to my lap as a sticky or something. All of it is total verity. The set
up is essentially the key. Getting all the little bits done, then just enjoying the ride as you enjoy the
fruits of the early labor. I've come to realize that my workflow is all work and no flow right now. Need
to adjust that.
Essentially need to create a massive, searchable master doc with all the info i need - a quasi private
/ internal blog. Great post.
Reply Share
Subscribe
About
About us (/about-us/)
Advertise (/advertising)
Legals (/legals)
Feedback (mailto:feedback@sitepoint.com)
Write for Us (/write-for-us)
Our Sites
Learnable (https://learnable.com)
Reference (http://reference.sitepoint.com)
Hosting Reviews (/hosting-reviews/)
Web Foundations (/web-foundations/)
Connect