Should I Use Ruby on Rails or Node.js For My Next Project/Startup?

First things first, I am not a Ruby on Rails veteran. I am fairly new to the framework, but have dabbled with Ruby before and understand it. Take this post with a grain of salt, this isn’t a debate or article putting down X language or X framework.

I see Ruby on Rails and Node.js compared so much and this question being repeatedly asked in every crevice of the Internet I thought I would take a stab at clearing up any confusion about making a choice.

The numbers

Firstly, lets look at the numbers for Ruby on Rails and Node.js.

Using the ever-handing Modulecounts site which scrapes module sites for counts on a daily basis and can graph changes over time, we can easily compare the numbers between Rails and Node.js.

ruby-on-rails-node-js-module-counts-graph-comparison

Ruby has a headstart but Node eclipsed it in the space of 2 years.

We can quite clearly see that Node.js is leading the race for number of modules in a relatively short amount of time. Does this mean much? Not really. It either means people see value in Node.js and want to make modules for it (highly plausible) or creating modules for it is a lot easier than creating a Ruby GEM (also highly plausible).

All these numbers prove is that both Ruby on Rails and Node.js are pretty close in terms of popularity. You have to take into account just how many of these modules are unique and used by people. In reality you won’t ever use more than a handful of modules in your Rails and Node.js projects, the number really means nothing and doesn’t determine if a framework or language is good or bad.

Apples to oranges

Comparing Ruby on Rails (a framework built on Ruby) to Node.js is like comparing apples to oranges. Node.js is an application runtime environment that allows you to write server-side applications in Javascript.

Node.js is not a framework nor a new language, the common misconception of Node.js being a framework is a popular one, same goes for calling it a language. A better comparison would perhaps be comparing Ruby on Rails to ExpressJS (a popular framework for Node.js), but even then, it’s still not a true comparison.

Opinionated vs Non-opinionated

Ruby on Rails is an opinionated Framework that makes you adhere to its way of doing things out-of-the-box. From the routing system to ActiveRecord, Rails assumes you build your apps in a particular way.

Node.js is completely unopinionated, out-of-the-box it can do basic tasks, but you’ll have to write some code and install some modules if you want to match the out-of-the-box feature-set of Ruby on Rails like; interacting with a database, implementing MVC or an advanced routing system. Node.js assumes nothing and gives you the bare minimum from a fresh install. Ruby on Rails gives you a lot from a fresh install (generators included), got it?

Speed of development

When it comes to speed of development, no matter how fast you are with Javascript and Node.js, Ruby on Rails has the game locked down when it comes to development speed. You can develop a CRUD application complete with database migrations in just a few commands via the command line using generators. Rails purists don’t use generators, but there is no denying they save time.

Node.js on the other hand if you’re building a web application is a little more involved, you need to find the modules, include them and then follow along with the instructions for integrating them with something like Express (also a module install).

The way Node works is that it makes you string together different components to build an application, this gives you flexibility but it takes considerably more time considering you need to download a module for practically everything.

The Learning Curve

Any Ruby on Rails devout will tell you that learning Rails is not hard. They’ll point you to the numerous tutorials and courses out there for learning Ruby on Rails, the Rails for Zombies course is a well known free course. However the flaw with most tutorials I’ve seen is they make you jump straight into Rails, but don’t touch upon the Ruby aspect.

While you might not need to know Ruby to write rails generate model User in your command line, understanding things like arrays, objects, classes, models, variables, Ruby-level methods and other things are very important. Can you truly teach a framework without first teaching the language it is built on?

The learning curve for Node.js is considerably less than Rails. This isn’t a deal-breaker for people who like learning new things, but it can be a deterrent for those easily turned away in frustration. The beautiful thing about Node is that it is accessible to not only developers from backgrounds such as C or Java, it is also easy for front-end developers to pick up.

When you write a Node.js application, you’re writing and learning Javascript. And while some things in Node might not port over to client-side Javascript, you’re using Javascript variables, object methods, objects, arrays and understanding the language not just a framework as you learn.

Finding Talent

To me one of the major factors when deciding whether to use X language or X framework for your next project or web startup is: am I going to be able to find talented X developers?

The major benefit of finding Node developers is that Node.js has reached a point where most front-end developers as well as back-end developers have used it in some form. Being able to hire a front-end developer who also knows Node means you’re getting extra value for money and if you’re a lean startup, money definitely matters.

That’s not to say that finding Rails developers is hard, but generally because Ruby is a language not known by the mainstream all too well, it can be hard to find a Ruby on Rails developer with knowledge of both the underlying Ruby language and framework itself. The cost of hiring Rails developers is also a lot higher because they’re in-demand and hard to come across.

Conclusion

There is no definitive answer. Use whatever you are comfortable of if you’re building a website or application and you’re going to be the only developer. If you’re a lean startup looking for the best language to iterate and develop quickly, it all comes down to preference and who you want to hire. Both Rails and Node can achieve the same results, I would argue that Rails is perfect for situations where you need to move quickly (prototyping, functional CRUD app in the space of an hour).

Having said that, Node.js is becoming a rather in-demand skill for a developer to have in 2014 and presumably even more-so in 2015. I think eventually as frameworks like Express mature, we’ll see the speed barrier taken down and differences between Rails and Node being reduced to almost zero.

When it comes to building your application, as long as you understand what is going on, the language or framework is irrelevant. It’s the execution that matters, so go out there and build something.

How To Implement Bower Package Manager Into WordPress Themes

All responsible/good front-ender developers use some kind of package management these days, whether it be in the form of Composer, Node Package Manager, Component or Bower. If you’re not using package management for your code, it’s not too late to start.

The power of Bower (ha, that rhymes)

The true value of a front-end package manager like Bower is shown when you implement it into your WordPress themes. Have you ever had to update jQuery on a clients WordPress site you built 3 years ago or even on your own sites? I have and it’s not pretty.

Have you ever needed to use one or more specific versions of a Javascript library like jQuery because you support older versions of browsers that newer versions of your favourite libraries cannot?

If you’re like most, you probably have a vendor directory within your js folder which contains all of your different Javascript libraries like jQuery, Bootstrap, Modernizr and any other libraries you are using.

Requirements

Node.js

Before we can even install Bower, we need Node.js. I won’t cover how to install Node.js, but if you’re on a UNIX based system, it’s easy to install.

Bower itself

We need to install the Bower Node package globally by running the following command from our command line:

npm install -g bower

A task runner

An important step I often see overlooked is the fact if you’re using Bower in your WordPress themes and or web projects, you are going to need a task runner. The bower_components directory is meant for local development and should not be uploaded to your server. You don’t upload your node_modules folder from your local version, so don’t do it for Bower components either.

A couple of good choices are GulpJS and GruntJS. There are others, but they’re the two contenders with great support. Personally I find GulpJS to be a lot easier to use and configure, perfect for someone new to the whole task-runner thing.

I won’t go into details as to how you can setup and use a task runner for your Bower components, there are a lot of resources out there telling you how to do so though.

Integrating Bower into WordPress

Install some dependencies

Now we have successfully installed Bower, navigate to your WordPress theme directory. Open up a terminal/command line prompt and navigate to the same directory and then type the following to generate a Bower package file:

bower init

This will create a bower.json file in your theme directory (provided Bower was installed correctly).

For this example we are going to install jQuery because, well, everyone mostly uses jQuery in their projects. Simply type the following to get a shiny new version of jQuery (which using the –save directive will be added to our bower.json):

bower install jquery --save

But, wait! What if we want to install a particular version of jQuery? Bower allows you to specify a version using a version directive, for the sake of this example, lets install jQuery 1.10:

bower install jquery#1.10 --save

Hang on, because I am supporting IE8 visitors, I want jQuery 1.10 and jQuery latest version for IE9 and up:

bower install jquery-ie=jquery#1.10 jquery=jquery --save

The above snippet is interesting, lets explain what’s going on. If you require multiple versions of the same library calling a regular Bower install twice will mean the second install directive will overwrite the first version instead of download two completely separate installations.

In Bower there is a cool feature that allows us to alias our packages with a label, we can have hundreds of the same library just by changing the label. Once again we are using the –save flag to add these packages to our bower.json so others can install them in their own local versions.

For more information about the available commands in Bower and what you can do, check out the official Bower site for more information than covered in this post.

Using Bower dependencies in your theme with a task runner

We now should see a bower_components folder has been created, inside of it you will see jQuery (if you did all of the above steps you’ll see more than one folder). You might think using these components is a simple matter of referencing them in a wp_enqueue_scripts directive and leave it at that.

But remember we said the bower_components folder doesn’t get uploaded? It’s a temporary folder for development and should be added to your .gitignore file so you don’t accidentally commit it to your Git repository.

Using your task runner of choice, you are going to reference the path to your bower_components module within your gruntfile.js or gulpfile.js file, inside of a task called “bower-tasks” or something. Remember to be mindful of dependencies that have Javascript, CSS and Fonts as well.

The idea is to reference, pull and then work with your Bower component files, but never upload them or include and use them directly. If you decide to choose Gulp, this article I wrote here with some Gulp how-to’s will explain how to copy files, minify Javascript, compile SASS styles and more.

Questions?

If I didn’t cover something or you couldn’t follow along, leave a comment or drop me an email and I would be happy to help you (free of charge) to implement Bower into your front-end workflow.

Using MongoDB As a Drop-in Replacement For MySQL

To the disdain of some, NoSQL databases are well and truly here to stay and everyday proving their worth. The number one question I see being asked is: can I replace MySQL and use MongoDB instead?

A couple of years ago I would have told you no. In-fact, I would have probably argued with you about using a NoSQL database for more simple tasks that don’t require table joins and advanced queries instead of using it as a fully-blown RDBMS replacement. It’s 2014 and times change, especially as existing solutions die or mature.

Everything discussed onwards is in relation to MongoDB and MySQL. Most of this could apply to other NoSQL databases, but we will focus on MongoDB for this article at least.

Understanding Limitations

Before you decide to switch, you’ll need to understand the limitations first. If you blindly decide to use MongoDB and spit in the face of MySQL, you can probably guess what will happen. You will learn pretty quickly you shouldn’t rush decisions like these.

Disk space

MongoDB can consume a lot of disk space as your data grows. When you create a database a file called dbname.0 will be created automatically and by default it will be 64mb. When half of this file has been used, MongoDB will create another file double the size called dbname.1 at a size of 128mb and so on until it reaches a final size of 2048mb. Each subsequent database file will be 2048mb and no longer double.

This isn’t a fault of MongoDB, but it is something that catches many first-timers by surprise.

Databases cannot be renamed

This is a known issue and there is a ticket on the MongoDB task tracker here. Keep this in mind when naming your databases or you will encounter this annoying issue. For most this might not even be an issue, but for some it is and a limitation regardless.

Be patient on this one, it is planned, but the ticket was created in 2010…

SSD or the slow-way

You will notice significant speed improvements if your server has solid state drives. Because MongoDB uses a combination of RAM and disk-space, a solid state drive will offer significant performance improvements and throughput. While standard hard disks are still fast enough, faster drives means faster I/O and thus significantly quicker queries when querying your MongoDB instance(s).

There is a link here on the official MongoDB documentation detailing all of the limits of using MongoDB. I suggest you read through and ensure there are no deal-breakers here for moving off MySQL.

Understanding Differences

The syntax and way things are done in MongoDB is considerably different to that of a traditional RDBMS like MySQL. The underlying concepts of storage are relatively the same, but the terminology is different (this applies to most NoSQL databases.

MySQL stores data in a table
MongoDB stores data in a collection

MySQL stores a single item of information in a row inside of a table
MongoDB stores a single item of information in a document or BSON document inside of a collection

Documents are implicitly created upon a successful first .insert(), although there is a method for creating documents if needed. There is no querying language, everything is handled through the use of object methods.

Transactions do kind of exist in MongoDB

A common misconception of MongoDB stemming back to older versions is that it does not support transactions. This is actually untrue. MongoDB doesn’t call them transactions, they’re called two-phase commits and they work very similarly.

While two-phase commits might not be perfect and not a 1:1 match for transactions and require some additional application logic, they do work and can be used as a replacement for transactions if you need to implement a transaction like process into your application (dealing with monetary values and that kind of thing).

Read more about two-phase commits here

Do you fit a valid MongoDB use-case?

Don’t be so quick to rush out and replace MySQL with MongoDB, you need to assess if your use-case will fall within one of the valid cases for MongoDB.

Keep in mind that you don’t have to use one or the other. MongoDB can be used alongside MySQL for a particular task or set of tasks, whilst MySQL does other tasks of your application that MongoDB might not be the better fit for.

You can mix and match databases, just ensure you devote the appropriate resources to whatever you choose to efficiently use them.

Rapid prototyping

If your development workflow consists of a prototyping phase, MongoDB can prove invaluable when dealing with a high-level concept for an application where the final database structure hasn’t been determined. Because you don’t have to keep modifying the database every time you add or remove a feature, you can focus on the application itself.

Content management system

Because of its nature and way it works with different forms of content, MongoDB would be perfect for use as a database for a content management system. Its ability to store different pieces of data and media metadata without requiring a schema means your posts can have different attributes to your tables and media as well whilst all coexisting in the same collection.

Inventory/stock Management

Store information about multiple items/stock in the one database with support for unique attributes only relevant to a particular item. This is a perfect fit for MongoDB, working with data that doesn’t have a defined structure. A toaster isn’t the same as a lawn mower, so the attributes for either will be substantially different (except for a few fields like name and price).

Machine generated data

Different devices comprised of different sensors all emitting varying pieces of information. MongoDB is the perfect fit for a monitoring application that is responsible for monitoring different pieces of information from various sensors and machines. Think of an airplane, it is comprised of thousands of different sensors all over the plane capturing and emiting different pieces of info. A schema database like MySQL would be a nightmare, especially if you install a new sensor and need to add an existing field.

Rapid writes

MySQL falters when it comes to rapid database writes, most RDBMS’s do (even when tweaked for write performance). If you need to write large amounts of data very quickly, MongoDB is probably the better choice.

Working with inconsistent/unstructured data

There is a reason they call MongoDB and most NoSQL databases document databases: they work extremely well in situations where data doesn’t fit a particular format. If you are storing documents that vary in content and no two pieces of data are the same, MongoDB is a perfect fit because it is schema-less and allows you to create fields on the fly.

Invalid MongoDB use-cases

There are situations where MongoDB still could work, but might end up causing you more headaches in the long run.

Relational data

Even though MongoDB can work with relational data (multiple pieces of information that relate to one another) through document embedding and references, it feels hacky and each approach has its own caveats. Embedding of a document makes it harder to relate a piece of information to other pieces of information due to it being embedded within a document already.

I am not saying a relational structure in MongoDB is impossible, but it isn’t ideal either.

Graph databases

While I don’t doubt you can probably knock something together in MongoDB, you will be met with resistance trying to make MongoDB work as a graph database (traversing paths and mapping relationships between multiple nodes/edges of data). Use something like Neo4j in this instance, not even MySQL is fit for the purpose of graphing.

Social networks

This article say no more.

Elder Scrolls Online (ESO) – Standard Edition vs Imperial Edition

You might have heard Elder Scrolls Online has hit Steam at 50% off its original price. I decided to take the plunge and buy the game, I purchased the Imperial Edition for $50 because the price seemed right.

There are no advantages in the Imperial Edition

First things first: the Imperial Edition gives you no advantage whatsoever over the Standard Edition. I purchased the Imperial Edition instead of the standard one out of impulse because it was 50% off, I didn’t really read what you got in the Imperial version (in-depth anyway), I didn’t care.

This is a game I’ve been contemplating buying since it was publicly released (I played the beta), but I couldn’t justify the expensive price on-top of the ongoing monthly subscription cost when it first came out.

I actually am glad that the Imperial Edition contains no advantages over the Standard Edition. It would be unfair to segregate players who cannot afford to buy the more expensive version (or in many cases parents).

Aesthetics

The Imperial Edition is purely a cosmetic advantage, not a tactical one (with exception of a mount). If you assume the Imperial Edition will give you rare items or advantages, think again. This would be unfair for a PtP (Pay to Play) subscription game, it would make people not want to purchase a subscription. You get a unique exclusive class, a white Imperial horse mount, a mudcrab vanity pet and a few other additions (mostly cosmetic).

Imperial Perks

  • Boost to one handed and shield weaponing
  • Ability to look like an Imperial Soldier
  • Ability to play within any alliance
  • Exclusive White Imperial horse (slightly faster than a standard mount) and the white horse cannot be obtained any other way
  • A Mudcrab vanity pet
  • A pair of Rings of Mara (an XP boost for you and a friend when playing together)

Which Version Should You Buy?

If missing out on the Imperial race, exclusive white Imperial horse and the other mostly cosmetic perks doesn’t phase you, save yourself $20 and get the Standard Edition. If you think getting the Imperial race and the aesthetic perks that come along with it and an extra $20 is nothing to you, buy the Imperial Edition.

While I could have easily just bought the Standard Edition, I want to help support the developers and hopefully fund further improvements/expansions to the game.

My Experience Obtaining Australian Suburb/City/Region/Locality Data

When it comes to obtaining a comprehensive database of suburbs, cities, towns, regions and localities in Australia, to put it simply: it’s a painful process.

As far as I am aware, there is nothing out there (for free anyway) that offers up-to-date and comprehensive information about suburbs, cities, towns and more. So, I bit the bullet and ended up purchasing the data myself from this site.

To be quite honest, I was VERY sceptical I would even receive the data. The site looked dodgy, the .info domain didn’t inspire confidence either. However, after paying my $50 AUD, I received the data instantly. However, I needed a MySQL copy of the data and their support was super quick to respond and offer me a MySQL export of the data I could import. SOLD!

I now have a database of locality information and it is surprisingly specific and accurate. It has more information than you would expect and for the price, it is well worth it (especially if your site/application needs specific location data).

Are We Witnessing The Beginning of World War 3?

Fears of another world war have been sparked after a ground to air missile took down Malaysia Airlines MH17 the other day. While Russia themselves didn’t directly attack this plane, rebels that they support and arming most likely did which in turn in is an attack by Russia, but due to the complicated laws surrounding what is deemed an act of war, the situation isn’t clea-cut.

It took a plane full of 300 innocent civilians for us to give a shit about what is happening in Ukraine. Up until now, the world has kept out of the conflict in Ukraine allowing Russia to commit unspeakable acts of murder and force, the strike on MH17 made the world stand-up and take notice of the conflict.

While many might romanticise about the possibility of a World War 3, I don’t think the attack on Malaysian Airlines MH17 is going to be what causes it. It would take an almost direct strike or attack on any country within the US alliance, say Russia decides to attack Australia, this would be an act of war and the US would instantly get involved.

The beginning of something greater…

There is talk that the attack on flight MH17 is only the beginning of something greater. There is no evidence to prove this, but it’s not something that can be instantly dismissed either.

The reality of war is that it is expensive and no country has the funds to go into war unless it benefits them or it has too. Attacking Russia wouldn’t really offer the US or other countries anything substantial that would warrant the price of war.

Cause For War

There is another reason that the likes of the United States would want to attack Russia: if it saw them as a logical threat. It’s no secret that Russia has a serious arsenal of war-capable weapons, as does the US.

The specific counts are unknown for strategic purposes, but if it ever came to a battle of the weapons, the winner would be declared based on who’s nukes hit whom first (if both countries don’t destroy themselves at the same time).

So, while we could be witnessing the birth of World War 3, we aren’t going to be seeing a war taking place anytime soon. That’s not to say we won’t see another world war involving Russia once more. We all remember how it went last time though.

How To: Basic Tasks in Gulp.js

If you’re familiar with GruntJS, you might be familiar with Gulp.js. Both are very similar, Gulp is the newer kid on the block that requires significantly less configuration to write tasks. If you’re new to Gulp or perhaps already use it, but not sure how to do specific tasks with it, see below for a list of basic tasks you can achieve in Gulp.js.

There is a complete gulpfile.js at the bottom of this page containing all include files as well as directives if you struggle to follow along.

Error Handling using Plumber

Plumber is a plugin for Gulp that allows you to capture errors and not break the Gulp process when something goes wrong. All examples below will assume “gulp-plumber” is defined in your package.json file and installed.

At the top of your gulpfile.js, you will want to define the error handler all tasks will be using for Plumber.

            var onError = function(err) {
            console.log(err);
        }
    

Copying Files

Sometimes you might want to move files from one location to another. This example allows you to glob files from a source directory and all sub-directories within it. Change the file extensions below to your desired extensions, or to copy everything in a folder and sub-folders, replace the curly braces with a * so you have . which will grab everything and copy to the desintation folder.

        gulp.task('copyfiles', function() {
        gulp.src('./source_directory/**/*.{ttf,woff,eof,svg}')
        .pipe(gulp.dest('./destination_directory'));
    });
    

Compress Images

Reduce the file size of your projects images by compressing them using this helpful task.

            gulp.task('images', function() {
            var imgSrc = './src/images/**/*',
                imgDst = './images';

            return gulp.src(imgSrc)
                .pipe(plumber({
                    errorHandler: onError
                }))
                .pipe(changed(imgDst))
                .pipe(imagemin())
                .pipe(gulp.dest(imgDst))
                .pipe(notify({ message: 'Images task complete' }));
        });
    

Compiling Sass/Compass

If you’re using Sass as your pre-processor of choice, then you’ll want to know how to compile your styles using Gulp.

Required plugins

  • gulp-compass
  • gulp-notify
            gulp.task('styles', function() {
            return gulp.src('./src/sass/*.scss')
                .pipe(plumber({
                    errorHandler: onError
                }))
                .pipe(compass({
                    config_file: './config.rb',
                    css: './css',
                    sass: './sass'
                }))
                .pipe(gulp.dest('./css'))
                .pipe(notify({ message: 'Styles task complete' }));
        });
    

Hinting Your Javascript

Ensure your Javascript conforms to appropriate coding guidelines, no missing semicolons, no repeated variables or scope issues. This is a must have in your workflow. To control how strict the hinter is, change the default value to any valid value.

Required plugins

  • gulp-jshint
  • gulp-notify
            gulp.task('jshint', function() {
            return gulp.src('./src/scripts/*.js')
            .pipe(plumber({
                errorHandler: onError
            }))
            .pipe(jshint())
            .pipe(jshint.reporter('default'))
            .pipe(notify({ message: 'JS Hinting task complete' }));
        });
    

Combine/Minify Your Javascript

Require plugins

  • gulp-concat
  • gulp-strip-debug
  • gulp-uglify
  • gulp-notify
            gulp.task('scripts', function() {
            return gulp.src('./src/scripts/*.js')
                .pipe(plumber({
                    errorHandler: onError
                }))
                .pipe(concat('app.min.js'))
                .pipe(stripDebug())
                .pipe(uglify())
                .pipe(gulp.dest('./js/'))
                .pipe(notify({ message: 'Scripts task complete' }));
        });
    

Watching / Reloading For Live Changes

Having to keep calling “gulp” isn’t any fun, using gulp-livereload, we can spin up a liveReload server instance to watch our files and run certain tasks again (thus automating our front-end workflow). Take note of other tasks being called inside of this watch block, this is where our liveReload server action happens.

Required plugins

  • gulp-live-reload
  • gulp-notify
            gulp.task('watch', function() {
            // Check for modifications in particular directories

            // Whenever a stylesheet is changed, recompile
            gulp.watch('./src/sass/**/*.scss', ['styles']);

            // If user-developed Javascript is modified, re-run our hinter and scripts tasks
            gulp.watch('./src/scripts/**/*.js', ['jshint', 'scripts']);

            // If an image is modified, run our images task to compress images
            gulp.watch('./src/images/**/*', ['images']);

            // Create a LiveReload server
            var server = liveReload();

            // Watch any file for a change in the 'src' folder and reload as required
            gulp.watch(['./src/**']).on('change', function(file) {
                server.changed(file.path);
            })
        });
    

Final gulpfile.js

See below for a fully functional gulpfile.js complete with all of the required modules for running tasks.


var gulp       = require('gulp'),
	changed    = require('gulp-changes'),
	compass    = require('gulp-compass'),
	concat     = require('gulp-concat'),
	imagemin   = require('gulp-imagemin'),
	jshint     = require('gulp-jshint'),
	notify     = require('gulp-notify'),
	plumber    = require('gulp-plumber'),
	stripDebug = require('gulp-strip-debug'),
	uglify     = require('gulp-uglify'),
	liveReload = require('gulp-live-reload');

// Gulp plumber error handler
var onError = function(err) {
	console.log(err);
}

// Lets us type "gulp" on the command line and run all of our tasks
gulp.task('default', ['copyfiles', 'images', 'jshint', 'scripts', 'styles', 'watch']);

// Copy fonts from a module outside of our project (like Bower)
gulp.task('copyfiles', function() {
	gulp.src('./source_directory/**/*.{ttf,woff,eof,svg}')
	.pipe(gulp.dest('./fonts'));
});

// Compress and minify images to reduce their file size
gulp.task('images', function() {
	var imgSrc = './src/images/**/*',
		imgDst = './images';

	return gulp.src(imgSrc)
		.pipe(plumber({
			errorHandler: onError
		}))
		.pipe(changed(imgDst))
		.pipe(imagemin())
		.pipe(gulp.dest(imgDst))
		.pipe(notify({ message: 'Images task complete' }));
});

// Hint all of our custom developed Javascript to make sure things are clean
gulp.task('jshint', function() {
	return gulp.src('./src/scripts/*.js')
	.pipe(plumber({
		errorHandler: onError
	}))
	.pipe(jshint())
	.pipe(jshint.reporter('default'))
	.pipe(notify({ message: 'JS Hinting task complete' }));
});

// Combine/Minify/Clean Javascript files
gulp.task('scripts', function() {
	return gulp.src('./src/scripts/*.js')
		.pipe(plumber({
			errorHandler: onError
		}))
		.pipe(concat('app.min.js'))
		.pipe(stripDebug())
		.pipe(uglify())
		.pipe(gulp.dest('./js/'))
		.pipe(notify({ message: 'Scripts task complete' }));
});

// Combine and minify Sass/Compass stylesheets
gulp.task('styles', function() {
	return gulp.src('./src/sass/*.scss')
		.pipe(plumber({
			errorHandler: onError
		}))
		.pipe(compass({
			config_file: './config.rb',
			css: './css',
			sass: './sass'
		}))
		.pipe(gulp.dest('./css'))
		.pipe(notify({ message: 'Styles task complete' }));
});

// This handles watching and running tasks as well as telling our LiveReload server to refresh things
gulp.task('watch', function() {
	// Check for modifications in particular directories

	// Whenever a stylesheet is changed, recompile
	gulp.watch('./src/sass/**/*.scss', ['styles']);

	// If user-developed Javascript is modified, re-run our hinter and scripts tasks
	gulp.watch('./src/scripts/**/*.js', ['jshint', 'scripts']);

	// If an image is modified, run our images task to compress images
	gulp.watch('./src/images/**/*', ['images']);

	// Create a LiveReload server
	var server = liveReload();

	// Watch any file for a change in the 'src' folder and reload as required
	gulp.watch(['./src/**']).on('change', function(file) {
		server.changed(file.path);
	})
});

FIREWORKS WILL NEVER DIE!! – A Really Nice List of Fireworks CS6 Extensions

WordPress 4.0: What's Going On?

WordPress 4.0 the next major version of WordPress has hit beta version 2 and it is the most underwhelming major release of Wordrpess in the history of WordPress.

Previously, every major iteration of the popular CMS has come with a plethora of changes (whether it be UI or core based), in 4.0 there is pretty much nothing new. There are bug fixes and a couple of little changes, but nothing like you would expect for major milestone.

Grid EVERYTHING

The newest change in 4.0 is the fact the media uploader has support for a grid layout and wait for it, the plugins page now also displays your plugins in a grid structure. I like grids as much as the next developer, but I would hardly call a couple of relatively simple layout tweaks worthy of a major release version number.

I think the WordPress team need to sit down and revise their continuous versioning/release process as it is evident the process sucks when it comes to major versions. 4.0 thus far feels more like version 3.9.2 or more appropriately 3.10 perhaps.

Maybe I just think differently, maybe major versions shouldn’t always come loaded with new features and changes. Who knows? All I know is WordPress needs some substantial improvements that 4.0 could have provided, but didn’t (media folders anyone). I’ll go sit back in my corner now.

What A Front-End Developer Workflow Looks Like in 2014/2015

In the last four or so years, front-end web development has become a lot more complicated. In 2010 to install a new Javascript library the instructions went along the lines of, “add this script tag to the head of your site to use” – now the instructions always mostly begin with, “Install Node.js then run npm install”

It is easy to get caught up in the new way of doing things, we often forget that not everyone is sure what to use or what they should be using to improve their front-end workflow.

Here is what the current landscape looks like. I haven’t included all tools, just the popular ones, same goes for things like syntax and whatnot. The reality is we are spoilt for choice, it is all about betting on what particular tool or way of doing things has the most longevity.

Automation / Task Runners / Build Tools

GruntJS

Up until recently and still for many, Grunt is the task-running/build system tool of choice. Basically Grunt allows you to do things like minify your CSS, lint your Javascript, combine and minify your Javascript files, compress images, combine image sprites, compile Sass, integrate with pre-existing deployment systems (like GIT, Capistrano).

Gulp.js

Gulp is the new kid on the block. It is very similar to that of Grunt, except it requires significantly less typing to configure and through its daily-growing list of plugins, is starting to become a viable replacement for Grunt. It does lack some build system features, but it is quickly catching up and becoming a favourite of many.

Yeoman

Yeoman is one of those tools you’ve probably heard about, seen used a couple of times, but never truly understood what it is used for. Essentially what Yeoman does is gives you a scaffolding tool using generators which allows you to generate components and complete starting structures for things like AngularJS or BackboneJS. If you’ve worked with Ruby on Rails or Laravel before, you’re probably familiar with the premise of command-line scaffolding/generators to speed up the development of your projects. Learn more about Yeoman here.

Package Management

Bower

For package management on the front-end for installing things, Bower has become the favourite. Developed in-house at Twitter, Bower allows you to manage front-end dependencies like jQuery, Bootstrap and anything else front-end related with support for versioning without having to download a zip file, extract the contents and link it up. If you are familiar with NPM (Node.js’ package manager) then Bower is basically the same, except aimed at front-end development dependencies. Read more about Bower here.

Component

Another popular choice is Component, which is pretty much the same as Bower. It all comes down to personal preference, one does not really offer any advantage over another.

Client-side Application frameworks

When it comes to client-side frameworks, there are more to choose from than you can poke a stick at. However, deciding which is the better framework to learn can be rather difficult. Below are the most popular ones with one opinions (mostly my own) about which one is the better choice.

AngularJS

AngularJS is a client-side application framework built by Google. It is currently the fastest rising framework for the client side and thus most likely the ideal choice for newbies. The community is rapidly growing and Google seems committed to maintaining this thing for the long-haul. The way you do certain things is different to that of other choices, but some argue AngularJS is the first framework to get client-side MVC right, even though the separation and strict methodology of what MVC is in the sense of the word isn’t really there as Angular requires you to learn scope and directives instead of models and view files. AngularJS will be an in-demand skill in the next couple of years and it probably wouldn’t hurt to learn it now.

BackboneJS

Before AngularJS was all the rage, BackboneJS was the defacto choice. Used by the likes of Soundcloud and numerous other large-scale web applications, BackboneJS is still a viable choice and has a great community behind it. There are tonnes of tutorials, example code on Github and you can get up-to-scratch fairly quickly.

EmberJS

I see EmberJS being compared to AngularJS quite a lot. More times than I can count in-fact. The truth of the matter is while the end goal is the same, EmberJS is completely different and in my experience, a very good framework. The way you build EmberJS applications feels clean and more true to the MVC philosophy of separating logic from the presentation layer. If you were to choose EmberJS, you probably wouldn’t regret it, the likes of Zendesk use EmberJS.

Front-end CSS Frameworks

Bootstrap

Probably the most popular choice in the front-end style framework wars thus far. Bootstrap is an opinionated mobile-first responsive set of styles and components for speeding up front-end development, especially during the conceptual/prototyping phase of development. It has a powerful grid system and out-of-the-box offers a lot of functionality.

Foundation by Zurb

Even though Bootstrap gets most of the limelight, Foundation is probably the best choice for a helping hand in the front-end side of things. It is arguably less opinionated in what it enforces upon you out-of-the-box and is mobile-first responsive ready as well complete with a powerful grid system and set of helpful utilities/components. I have started using Foundation for all new projects I start as I believe it is a much better CSS framework and will undeniably take Bootstrap’s place in the next couple of years as it grows.

Pre-processors

Sass/Compass

In 2014, you’ll be hard-pressed to find a developer that writes straight-up CSS any more. CSS pre-processors like Sass, LESS and Stylus are now the preferred way of writing CSS with their support for variables, nesting and cleaning separation. While the playing field is pretty much open, Sass in combination with Compass has become the developer favourite, in part for its power and syntax as well as large community.

LESS

Still popular with many and just as powerful in most aspects as Sass, LESS offers; variables, functions, nested styles and more. While Sass is undeniably more powerful, sometimes LESS is all you need, especially if you’re not a fan of having to install Ruby and then subsequent Gems to compile your Sass files. While LESS is pretty great, I think Sass is the number #1 choice for most developers.

Syntax

BEM

When it comes to CSS, there has been a surge of support behind the method of organising CSS pioneered over at Yandex called BEM (Block Element Modifier). Even though BEM isn’t neccesarily new, the advent of CSS pre-processors like Sass have revealed some annoying caveats mostly related to that of nested rules. Nobody likes to override CSS selectors generated by Sass compilation that look like this .header .header-container .branding .logo – if you wanted to change that logo in your media query file, you’d have to copy that entire line, which would just be a nightmare. What BEM does is simplifies the process of naming your styles using aliases and a syntax based on underscores and hyphen. You can read about BEM here.