Easy Peasy Code

Junior Consultant

Read this first

Starting with design

To design is difficult. It’s not like most everyday problems you might face. To learn to design a dummy house for instance, might require knowledge of good placement of windows and doors. Better design is always an evolution.

Design is a problem that is always meant to solved from bottom up. You pick a starting point and continue to build on top of it. It’s a practice and you only get better at it by making mistakes. Mistakes are always supposed to be part of design.

I learned that making assumptions about design might lead you to place you can’t easily comeback from without making drastic decisions.

View →


Walking the fine line

If it stinks, change it.

—Grandma Beck, discussing child-rearing philosophy

A way of thinking about writing a good piece of code is to remember that not everything out there is good.

Not all language features will help you write quality code. Some features may in fact be considered harmful (a code smell) and are hence discouraged.

Responsibility

OK, let’s rephrase in a more appropriate context

With great power of language features, comes great responsibility of deciding what not to use.

Let’s consider the case of getters and setters. They are common in most languages.You might say

What’s wrong about getters and setters?

Well everything!

Getters and setters break the very concept of encapsulation and data abstraction. They essentially give access to the internal implementations which should never happen in any good OO design. Only place where you might think of using getters is...

Continue reading →


JavaScript Series Part 2

In the last blog I discussed about basics of JavaScript including objects, object properties, object creation etc. Continuing on the same basics now.

More on properties

The method Object.defineProperty() allows precise addition to or modification of a property on an object. As explained in the previous blog :

If the data property is created using Object.defineProperty, Object.defineProperties, or Object.create functions, the writable, enumerable, and configurable attributes are all set to true.

For Example :

var  person = {"Name" : "Dark Lord"};

Console Log

person.Name
"Dark Lord"
person.Name = "Ronan"
"Ronan"

If the object is created like :

var  person = Object.create({},
    "Name", { value : "Dark Lord"});

Since by default properties ARE NOT writable, enumerable or configurable, the person name cannot be changed. Name property will also not appear in Object.keys().

...

Continue reading →


Adding Google maps in rails

Today I hope to clear basic concepts related to integrating google maps in rails app. We will be using Gmaps4Rails gem for it. I will also discuss some common gotchas related to it.

First things first

First thing to go about adding google maps in your rails app would be to add these two lines in your Gemfile.

gem 'underscore-rails'
gem 'gmaps4rails'

underscore js is a dependency for Gmaps4Rails gem, hence it is included in Gemfile.

Next step is to install the newly added gems. Use bundle install to install the gems.

Add Map Javascript

Now you to have include the js files related to Gmaps4Rails and underscore js in application.js . To add the requirements for Gmaps4Rails, add below lines in application.js. Also you should have asset pipeline. If you are using coffeescript change the below lines accordingly.

//= require underscore
//= require gmaps/google

Next step is to add...

Continue reading →


JavaScript Series Part 1

This is my first blog among a series of blog posts about javascript. The reasoning behind the blog series is to document and share the concepts I learn about javascript.

Lets start with the basics.

What’s JavaScript

Javascript is an object-oriented language with first-class functions. In a nutshell, JavaScript is a dynamic scripting language supporting prototype based object construction.

Objects

An object is a collection of properties and has a single prototype object. The prototype may be either an object or the null value.

JavaScript objects can be thought of as simple collections of name - value pairs. All primitive types except null and undefined are treated as objects.

Each name - value pair is called an property. That is property is named collection of attributes. The name part in any property is a JavaScript String and it is unique within that object. The value part can be...

Continue reading →