CoffeeScript Quirks

CoffeeScript is a solution without the problem.

— Unknown ironic source.

CoffeeScript is awesome, until it’s totally confusing, and it’s illogical, which can lead to unexpected and subtle bugs. If you’re one of the CoffeeScript haters please skip this post; for others, I’ll share a few notes on the CS quirks that I’ve observed.

For example, let’s say we have a counter and need to assign a value of index subtracted by one to it:

numberOfRadios = index -1

But the line above is not the same as:

numberOfRadios = index - 1

Did you notice that there’s a space after the minus sign in the second example? It took me awhile to track down this type of bug. The reason for this behavior is that the first line will be converted by the compiler to the function invocation and that is probably not what you wanted.

Try the minus one snippet on CoffeeScript.org. It outputs the following JavaScript code:

var numberOfRadios;

numberOfRadios = index(-1);

numberOfRadios = index - 1;

Another pitfall, that leads to writing despondently inconsistent code (by us developers), is caused by the fact that parentheses are optional for function calls.

This example involves if conditions in which we want to compare the value of the expression model.get() or the operand typeof to some strings:

a() if @model.get 'groupType' is 'radioGroupTabs'
a() if typeof @model.get 'condition' is 'function'

CoffeeScript is treating the entire thing as an argument and the results are pathetic. Duh. ;-( Here is the native JavaScript code:

if (this.model.get('groupType' === 'radioGroupTabs')) {
  a();
}

if (typeof this.model.get('condition' === 'function')) {
  a();
}

Placing parens over the function still does us no good. Look at this CoffeeScript code:

a() if @model.get ('groupType') is 'radioGroupTabs'

And its JavaScript output:

if (this.model.get('groupType' === 'radioGroupTabs')) {
  a();
}

The workaround involves using () around function calls, or flipping the order in the if statement so that the function invocation is the last bit of code in the if statement:

a() if (typeof @model.get 'condition') is 'function'
a() if 'function' is typeof @model.get 'condition'
a() if (@model.get 'groupType') is 'radioGroupTabs'
a() if 'radioGroupTabs' is  @model.get ('groupType')

The code above compiles to what we wanted originally:

if ((typeof this.model.get('condition')) === 'function') {
  a();
}

if ('function' === typeof this.model.get('condition')) {
  a();
}

if ((this.model.get('groupType')) === 'radioGroupTabs') {
  a();
}

if ('radioGroupTabs' === this.model.get('groupType')) {
  a();

Is it all good now? Not really, because I personally think this approach leads to inconsistencies: parts of CoffeeScript code that must have parentheses, while in other places they are optional.

Try these if conditon snippets yourself on CoffeeScript.org.

The next note explains the most common beginner’s mistake in CoffeeScript; that is to use an a instead of an a() for function calls. However, super inside of a class, must be called without parentheses in order to pass the arguments to it.

Moving on to the single hash (#) comments which are just skipped over by CoffeeScript. Again, this can lead to unexpected consequences.

For example, a straightforward if statement has a few lines of code:

unless A 
  b()
  blah blah

But if we comment out all of the lines inside of if, the whole thing will fail miserably at the compilation step (at least thank you for that, CoffeeScript!):

unless A 
  # b()
  # blah blah

Just by adding an empty else we can mitigate the failure:

unless A 
  # b()
  # blah blah
else


c() # the code continues here

Try this snippet yourself on CoffeeScript.org

Last but not least, there is another CoffeeScript pitfall related to jQuery events that don’t propagate when the event handler returns false. Of course, CoffeeScript philosophy makes every function an expression (the last statement is evaluated if there is no return statement present).

b = ()->
  false # usually this result is less obvious and buried deep down in code
$a = $ 'input'
$a.click ()->
  console.log 'this happens all right'
  b()

$a.parent().click ()->
  console.log('this never happened')

Of course, in real life the b() function is not so obvious and it’s buried somewhere deep within Backbone and Angular model methods. And the event isn’t propagating up the DOM tree (return false). Therefore, we’ve lost the second event handler without even realizing t. Buyers beware of this elusiveness! :-)

Try the event propagation bug yourself on CoffeeScript.org

This is the end of my list. If you know of any additional CoffeeScript idiosyncrasies, please send them my way. :-)

Further CoffeeScript reading:

DocuSign for BlackBerry 10 in a Few Hours

Last week DocuSign engineering had a second internal hackathon (a nice collage resulting from the first one) and I built DocuSign for BlackBerry 10 in just a few hours (well, sort of).

Some of you might be wondering what BlackBerry is. It’s a mobile operating system that is actually in the process of surpassing Windows and Kindle, based on market share, according to this reputable study. Oh, and by the way, BB also has many loyal aficionados thanks to their years of being a mobile solo-provider to enterprises.

Luckily, DocuSign already had an app for Android and, based on my research, which consisted of looking at this page for a minute, and talking with our mobile dev manager, I figured out that I could just port the DocuSign for Android app to the BlackBerry OS. Porting is just a fancy word for re-writing something in a new language, or for a new platform, without changing functionality very much. It typically involves re-compiling, changing APIs, updating code and re-packaging.

It’s worth noting that RIM (the company behind BlackBerry) provides many other options for building BlackBerry 10 apps including:

  • Adobe AIR
  • Native
  • HTML5

This is probably done to boost the number of available offerings within their marketplace (BlackBerry World) and jump-start their development ecosystem, which is lagging far behind those of iOS and Android.

I have worked with Java and J2EE before. In addition, I was an Adroid guy for a long time prior to getting my first Apple product (MacBook Air): I remember that my very first smartphone (running buggy Android 1.6) had constant “Force Close” errors. However, up until this hackathon, all of my forays into mobile dev land consisted only of using HTML5 with the Jo and Sencha Touch frameworks. Awesome challenge! Or so I thought.

The goal was to use Android code, re-package it, and install it in the simulator (with or without changes). I decided to go with Android Studio vs. Eclipse, and downloaded these tools (download page):

The complete tutorials are available at Runtime for Android apps.

After downloading, literally, a few gigabytes of SDKs and packages, I was stuck with our code-base in Android Studio due to some Java exceptions regarding Gradle, so I resorted to using command-line tools.

These are the commands from the BlackBerry toolchain that I ended up using:

  • apk2barVerifier: to verify apk (Android) files for compatibility for bar (BlackBerry)
  • apk2bar: to re-package apk to bar
  • blackberry-deploy: to upload and install the app on a BlackBerry

It’s worth noting that for distributing BlackBerry 10 apps to the BlackBerry world, apps must be signed with a special token (tutorial). Obviously, I skipped this step for the hackathon.

Lo and behold, everything worked on the BlackBerry with 0 code changes (except where DocuSign tries to charge via Google Play). The end results were quite pleasing. Thank you BlackBerry for making it easier for us developers. I guess, I can now say that I develop native apps (yeah, right). :-)

DocuSign for BlackBerry 10: Homescreen
DocuSign for BlackBerry 10: Homescreen
DocuSign for BlackBerry 10: Sign a Document
DocuSign for BlackBerry 10: Sign a Document
DocuSign for BlackBerry 10: Main Menu
DocuSign for BlackBerry 10: Main Menu
DocuSign for BlackBerry 10: Document View
DocuSign for BlackBerry 10: Document View

In addition, I also found this neat but scammy-looking service called APK Downloader that allows us to install Android apps from the Google Play market directly onto the latest BlackBerry 10 systems. Simply enter the name of the app as a Java package, e.g., com.docusign.ink, (link). The real hack! I could have used it from the beginning and saved myself a few hours. Therefore, it’s vital to conduct proper up-front research prior to embarking on a project! ☺

Growth Hacking The New DocuSign Experience

The DocuSign Momentum 2014 conference was a huge success, attended by over 1,200 people and filled with many announcements of new developments. One was a culmination of many years of hard work for DocuSign product engineering — the re-imagined web application dubbed the New DocuSign Experience.

The web app is fast, beautiful and well thought-through. It was a pleasure to watch its live demo on a large screens and hear tons of positive comments from glad DocuSign customers.

Being a part of the growth hacking team and its team lead / ScrumMaster, I had the chance to work on a few important features:

  • Responsive and dynamic homepage: certain sections on the homepage change based on account types and states, e.g., show “Your plan is expiring in X days” for trial users, but “You have Y documents left before reaching your limit” for freemium ones.
  • Visual notifications: special messages conveniently spread across the app, which are triggered dynamically based on user account states (similar to the dynamic homepage).
  • Analytics: removing old page-view-based tools in favor of event-based ones (go Mixpanel!).
  • In-app upgrade: before, it was not a smooth experience and required multiple logins, redirects and was a plain PITA.
  • Landing page for Sign a Document: when users self-sign docs, the recipients (CCs) see a nice page that prompts them to sign up.

Continue reading “Growth Hacking The New DocuSign Experience”

Getting Published as a Programmer: The Practical Node.js Story

This is the story about how I got my first publishing deal, what this book is about, and what problems I encountered along the way.

TL;DR: This is the story about how I got my first publishing deal, what this book is about, and what problems I encountered along the way.

I spent last weekend sitting in an awesome new coffee shop in Oakland, typing up the last two chapters of my Practical Node.js manuscript. The book is scheduled for release by the UK-based technical publisher Apress in the late spring.

I started writing the manuscript in October 2013. I devoted my weekends and holidays to it (as so many entrepreneurs and writers do). The fact that I smartly had a few example apps and some drafts written — some of them for my blog, others for proposals to Pragmatic (declined!) — helped to speed things up. (Needless to say, in publishing rejection is a common thing and often an opportunity to get better.) However, the writing itself wasn’t the hardest part. Here’s the short story why.

Continue reading “Getting Published as a Programmer: The Practical Node.js Story”

What is Growth Hacking

Growth hacking is such an interesting term. When I first heard of it, either at one of the meetings organized by 500 Startups or on the Jason Calacanis’s show, it made a lot of sense to me. Growth is vital for startups, and hacking is all about finding clever solutions (which are usually temporary but efficient).

When I became a growth hacking team lead at DocuSign, I started reading more about growth hacking. Soon I found out that there’s a ton of confusion on the Internet around the meaning of this phrase.

Some folks, especially ones who’s been doing new media and online marketing for a long time, think that it’s just a fancy trend for good old tools and techniques like:

  • A/B testing
  • Email marketing
  • Referral marketing
  • Social media marketing
  • Viral marketing
  • Content and SEO
  • Analytics

It’s true that these kinds of online marketing have been around for the last 5—15 years! What these adepts usually miss is the difference in how growth hacking approaches product by directly influencing and oftentimes even developing it!

Note: Being a programmer hacker is not required to be a growth hacker.

On the contrary, there is little to no input from marketers on product decisions in traditional marketing. For example, imagine, there are a car manufacturer and its marketing department. Most likely, the marketers will have little to no input into the car’s engineering and design.

Another example, a pure marketer might organize an email campaign, but because the funnel hasn’t been optimized, the conversion rate turns out to be dismal. On the other hand, a typical growth hacker will first test the funnel, and only after optimizing it, they launch full-blown campaigns reaping better conversion rates!

In software, and info products (and maybe in services?), the relative low cost of prototyping — vs. increasing cost of advertising and other traditional strategies — lead to the emergence of a hybrid: growth hacking. The distinct boundaries between marketing and product departments become blurred.

The best growth hacking will involve some sort of product engineering, user experience and design work, gathering and analyzing of metrics and events.

Usually there are only two tactics for growth hacking:

  • Push
  • Pull

Push tactics often involve finding temporary “loopholes” and getting a competitive advantage by using them. These are examples we often hear/read about: AirBnB posting on Craigslist, Dropbox using free space for referrals, etc.

That’s all good, but as in our example with an email campaign, if the product is not selling itself — that’s where the most ROI is for a growth hacker: pull tactics. They involve working on a funnel, and making product better to use / easier to know about expired CCs, etc. In the next post, I’ll show how my team and I growth hacked The New DocuSign Experience.

To sum it all up, there is a good quote from TNW post by GAGAN BIYANI:

Growth hackers focus on low-cost and innovative alternatives to traditional marketing, i.e., utilizing social media and viral marketing instead of buying advertising through more traditional media such as radio, newspaper, and television.

PS: I absolutely positively recommend this amazing free ebook The Definitive Guide to Growth Hacking by Neil Patel and Bronson Taylor.

Express.js Guide Goes to Apress

 

I’m extremely exited about my second book contract with Apress and also about using the product that I’m working on (the DocuSign web app) to wet this publishing deal. Pro Express.js is going to be the ultimate Express.js resource “thank you” to all my readers who contributed with suggestions!

Rare opportunity! Final sale!

Goodbye Express.js Guide Sale: 4 Books For Only $19.99 (reg. $84.97)

How to Stay Healthy and Sane Working 12-hour Days As a Programmer

The DocuSign Momentum conference is just a few days away, and my team and I has been pulling long shift in order to deliver something absolutely amazing and to make sure that it’s in a great shape. So I wanted to share what exactly helps me stay healthy, sane, productive and happy working as a programmer 10–12 hours per day sustainably:

  • Get at least seven to eight hours of sleep
  • Skip breakfast: clears mind, reduces calories intake, and saves time
  • Check work email only a few time per day and check personal email/Facebook/LinkedIn/etc only once (in the evening) preferably inboxing zero both categories
  • Meditate and workout (12 minutes is enough)
  • Cancel all activities and avoid any additional obligations and projects
  • Wear uniform-like clothing
  • Drink lots of good coffee (e.g., bulletproof coffee)
  • Avoid fruits, sugars, sodas (even diet ones), grains, legumes and potatoes, i.e., paleo lifestyle/diet
  • Change workstations: resistance ball chair, stand-up desk, sofa, etc.
  • Consume vitamins: C, Omega–3, Multivitamins and D3
  • Take walks and stay positive!

PS: The Healthy Programmer book has been on my to-do list for a long time. Please let me know whether you read/liked it.

Succeeding with Agile, Brief Overview I

Couple months ago, I was promoted to a ScrumMaster role at DocuSign. In light of it, I decided to brush up on my agile development skills and theory by reading. My choice fell on the highly acclaimed Succeeding with Agile: Software Development Using Scrum by the guru of Agile Development and Scrum — Mike Cohn.

Succeeding with Agile
Succeeding with Agile

Here is a short overview of the first half of the book, or gist as programmers call it:

  • A ScrumMaster has more responsibility and authority over processes, but a limited authority over people; the role is akin to a fitness trainer (a yoga teacher analogy fits me better): enforcing the agile process.
  • Every sprint team needs to deliver shippable (and tested) code: features, bugs, etc.; if the task is too large — split it.
  • Developers should work with product managers/owners directly on requirements.
  • Different developers should work on all parts of the application / code base.
  • Agile is not for the developers who likes to work in privacy putting their headphone and not talking to people (Bummer). :-)
  • Team functions better with a mix of generalists and specialists; avoid all-specialists teams at all cost.
  • When possible use feature teams rather than component teams.
  • Keep teams small. Four to nine people is an optimal size due to the social loafing (having more people reduces average productivity) — this was one of the reason our DocuSign team was split into three smaller teams!
  • A non-coding architect and project manager are obsolete roles on a Scum team.
  • Don’t let team members multitask. Each additional task reduces productivity; however, after three and more tasks the reduction becomes smaller and smaller. Direct quote: “Individuals assigned to work on multiple projects inevitably get less done

To be continued…

What I really liked about the book so far is that it’s not just boring theory. Each point is supported by data, references to sources and personal three-decade-long (anecdotal) experience of the author (Mike Cohn). If you liked the bullet point above, get Kindle Succeeding with Agile on Amazon.

Programmers Are Assholes?

Right now, I’m lucky to work in a great team where everybody is a wonderful human being. However, during the years in software engineering, I’ve encountered a disproportionate number of assholes comparing to other fields or professions. Does coding affect someone’s personality negatively or it’s the other way around? Do computers attract certain asocial elements, so they can put on the headphones and not talk to people? Why there are more assholes in software engineering than in real estate or food&beverage?
Continue reading “Programmers Are Assholes?”

Invest in Yourself

In the modern society, it’s not enough anymore just to graduate from a four-year college, and hope the skills and education acquired there will get you through the next 30–40 years of professional life. This is very prominent in software and technology fields, but applicable to many other industries as well.

In the age of the information workers, just to stay competitive on the market place, we constantly need to re-invent or jobs and ourselves. However, not everybody is happy about it. I often find people who don’t read professional books, magazines, blogs, and don’t learn outside of the job duties. Wake up people!

It’s so easy. MOOCs and online courses like Udemy and CreativeLive provide affordable interactive education. Free online ebooks are everywhere. Pick up a new language like Node.js or build something cool with React.

It’s no surprise that tomorrow, these people might be the first to be left on the outskirts of professional world . And when this happens, whom they’ll blame?

Blog Express.js Web Application Example

Here is one of the main examples that is featured in the book: the Blog application built with Express.js, MongoDB and Mongoskin. The application is subject to change, but if you’re an intermediate or advance Node.js programmer, go ahead and poke the source code, kick the tires of the server. It’s not a Ghost blogging platform, but blog-express can give valuable practical tips on how to implement:

Session-based authentication
Express.js middleware authorization
MVC-like pattern using lightweight MongoDB library called Mongoskin
REST API server
Express.js routes organization
Jade and server-side rendering

For the past few weeks, I’ve been writing a new book on Node.js. Hence the lack of new posts. This time, the book encompasses virtually all of the practical aspects of web development using Node.js: authentication, authorization, OAuth with third-party service providers, testing, libraries, frameworks, databases, ORMs and MVC-like patterns. In other words, if you have to read only one book on Node.js (which is not a good advice, but let’s assume), this will be the book that you have to read. :-)

The title and the alpha sign up are in secret for now (subscribe to get the news faster). The book is due in early spring 2014.

Here is one of the main examples that is featured in the book: the Blog application built with Express.js, MongoDB and Mongoskin. The application is subject to change, but if you’re an intermediate or advance Node.js programmer, go ahead and poke the source code, kick the tires of the server. It’s not a Ghost blogging platform, but blog-express can give valuable practical tips on how to implement:

  • Session-based authentication
  • Express.js middleware authorization
  • MVC-like pattern using lightweight MongoDB library called Mongoskin
  • REST API server
  • Express.js routes organization
  • Jade and server-side rendering
Blog Express.js App Home Page
Blog Express.js App Home Page

GitHub: http://github.com/azat-co/blog-express

Get Your Programming Questions Answered

If you have questions about programming and web development, we’re accepting them. Don’t suffer in the unknown!

Depending on the volume of received questions, we’ll be answering some of them on our blog and a future podcast.

Example topics:

  • What programming language should I learn?
  • How to land a dream job in software engineering?
  • What libraries should I use?
  • What is NoSQL?
  • What is Node.js?

Send your questions via the form: http://webapplog.com/about-azat-mardanov/.

Node.js FUNdamentals: A Concise Overview of The Main Concepts

Node.js is a highly efficient and scalable non-blocking I/O platform that was build on top of Google Chrome V8 engine and its ECMAScript. This means that most front-end JavaScript (another implementation of ECMAScript) objects, functions and methods are available in Node.js. Please refer to JavaScript FUNdamentals if you need a refresher on JS-specific basics.

Note: This text is a part of upcoming ebook JavaScript and Node FUNdamentals: A Collection of Essential Basics.

Node.js is a highly efficient and scalable non-blocking I/O platform that was build on top of Google Chrome V8 engine and its ECMAScript. This means that most front-end JavaScript (another implementation of ECMAScript) objects, functions and methods are available in Node.js. Please refer to JavaScript FUNdamentals if you need a refresher on JS-specific basics.

Continue reading “Node.js FUNdamentals: A Concise Overview of The Main Concepts”

Breaking Bad (Loops in JavaScript Libraries)

JavaScript Libraries are important (e.g., jQuery, Lo-Dash, Underscore), but in the case of asynchronous loops (`forEach` and `each`) they create a lot of confusion… Lo-Dash is not equal to Underscore, unless a special underscore-compatible version is being used.

It was sort of a surprise for me when I discovered inconsistencies in the most popular JavaScript libraries in how they handle their each and forEach loops. This post compares:

  • forEach Loop in Native JavaScript
  • each Loop in Lo-Dash
  • each Loop in jQuery
  • each Loop in Underscore.js
  • forEach Loop in Underscore.js

forEach Loop in Native JavaScript

JavaScript Libraries are important (e.g., jQuery, Lo-Dash, Underscore), but in the case of functional loops (forEach and each) they create a lot of confusion (for loop can be broken with ‘break’). Let’s inspect the example of native JavaScript code for the forEach method:

[1,2].forEach(function(v){
  alert(v);
  return false;
})

This will display us two alert boxes. Try the native JavaScript code yourself in JSFiddle.

This is an expected behavior in most cases because with each iteration we invoke a new function. Unlike the for (var i=0; i<arr.length; i++) {} code that has no function/iterators.

Continue reading “Breaking Bad (Loops in JavaScript Libraries)”

Understanding Fat Arrows (=>) in CoffeeScript

The fat arrows (=>) are special function expressions that confuse even the smartest of developers. Most JavaScript professionals know that closure changes the meaning of this (@ in CoffeeScript).

There’s no reason to be afraid of fat arrows in CoffeeScript. They are time savers (and clarity achievers) when it comes to the nested functions and jQuery event handlers. When they are applied to class methods, the good rule of thumb is: use => when we need @ to be the object in which method is written; use-> when we need @ to be the object in which method is executed.

The fat arrows (=>) are special function expressions that confuse even the smartest of developers. Most JavaScript professionals know that closure changes the meaning of this (@ in CoffeeScript).

Continue reading “Understanding Fat Arrows (=>) in CoffeeScript”

Express.js and Mongoose Example: Building HackHall

Note: This text is a part of the Express.js Guide: The Comprehensive Book on Express.js.

The HackHall project was written using Backbone.js and Underscore for the front-end app, and Express.js, MongoDB via Mongoose for the back-end REST API server.

Continue reading “Express.js and Mongoose Example: Building HackHall”