Tuesday, August 18, 2015

Why do most software engineers use a MacBook instead of a Windows or a Linux laptop (Question excerpt from Quora)

---- Answered by Eric Zheng

https://www.quora.com/Question-That-Contains-Assumptions-1/Why-do-most-software-engineers-use-a-MacBook-instead-of-a-Windows-or-a-Linux-laptop

Several big things coincidently happened around the same time in late last decade:

  • iOS and Android - 2007-2008
  • Amazon Web Services - 2006
  • x86 MacBook and Mac OS - 2006
  • Startup booming - post 2008-2009 recession
  • Git and GitHub - 2005 (git) and 2008 (github)

Combined together, they are why MacBook is so much more popular today than a decade ago (circa 2005):

1. Mobile app

The population of iOS and Android app developers is huge. It makes a lot of sense to develop iOS and Android apps on Mac. iPhone and Android were born around 2007/2008

2. Amazon Web Services

Public cloud, especially AWS, made it much easier to provision servers. However, AWS, the leading and dominant public cloud provider launched in2006, didn't support windows in the first a couple years. It added Windows support in EC2 in 2008 as a beta feature. In the following a couple years, as far as I remember, the developer community was still staying away from running Windows on AWS because the glitches here and there. Therefore, in order to take advantage of the cloud computing, many people had no choice but start to pick up Linux.

3. Startup

Tech startups started taking off soon after the 2008-2009 recession. One of the reasons was that AWS made it much easier to do startup. Startup prefer use AWS for cost saving and other cloud computing benefits. Startup attracted many best programmers, for many reasons including the potential huge financial return. Because of having joined startups, many people started to pick up Linux. Also, good programmers make their work platform better. An example in the history was that VB/Delphi/VC++ programmers on Windows 95/98, in their side project, created a lot of great softwares to scratch their own itches, such as to download/upload files (remember those FTP clients and HTTP downloaders?), play MP3 and video (WinAmp, ...), editing text file, etc.. Similar thing happened to OS X platform in the last several years. That is the power of developer ecosystem, which helped make Windows successful.

4. OS X on x86

In 2005, Apple announced to change OS X to x86 architecture. The transition started from 2006, when Apple released the first x86 MacBook, and completed in 2009 when OS X 10.6 was released which only supported x86. 

This switch has two major impacts:

First, Mac hardware changing to x86 allowed us to install Windows on MacBook, using Boot Camp (released in 2006). That made it a lot more comfortable for people to buy a MacBook as their only personal computer. Because prior to that, although many people loved the build quality and form factor of a MacBook, they were afraid of the software issues. For example, there were a lot of websites using ActiveX which weren't very well supported on Mac OS X. Now with dual systems, they have a way out: when necessary, they can boot into the Windows.

Second, now lots of the tools that work on Linux can be much more easily ported to Mac OS X, because the tools are mostly written for x86 architecture and now OS X is also x86. Like many others said, now OS X is a much nicer Linux workstation.

5. Git and GitHub

Because git was created by the creator of Linux, git works really well on Linux. Because of git, GitHub was possible and got popular. Because of git (2005) and GitHub (2008), it became much easier to do open source, compared to the days when we only had SourceForge, CodePlex and Google Code. When it's easy to do open source projects, more open source tools and lib are created, which leads to more applications on the platform (Linux/Mac OS).



p.s. I previously partially misunderstood what the asker meant. The asker was saying that the hardware MacBook is the most popular. S/He didn't say Mac OS X was the most popular. The asker seemed to have said that many MacBook hardware is running Windows. 

Having admitted the misunderstanding, I would like to keep my above answer, since it still explains my view of why MacBook (running Mac OS X) has become very popular among developers. 

Personally I don't see many people running Windows as the primary OS on their MacBook.

Monday, August 17, 2015

The Netflix Tech Blog: Making Netflix.com Faster

The Netflix Tech Blog: Making Netflix.com Faster: by Kristofer Baxter Simply put, performance matters. We know members want to immediately start browsing or watching their favorite content ...

Tuesday, July 7, 2015

IE problems

I. Something only works after you open the developer tool (F12)


In IE9, some functions related to console are only activated when the Developer Tool is opened.
For example, the console.dir(...) doesn't work unless the Developer Tool (F12) is open.
Tosolve this problem, we just need to use console.log(...) instead of console.dir(...). 
You can try console.dir([1,2]) and console.log([1,2]) to see the difference.

Related Link:

About the console:

Difference between console.log and console.dir:

II. Back button behavior on a page with Iframe

http://www.webdeveasy.com/back-button-behavior-on-a-page-with-an-iframe/

III. How to check whether a browser is IE 11
http://stackoverflow.com/questions/17907445/how-to-detect-ie11
if (navigator.appName == 'Microsoft Internet Explorer')
  {
    // Do something
    
  }
  else if (navigator.appName == 'Netscape')
  {
    // If you are here, it means your browser is not IE10 or IE older
    if (re.exec(ua) != null)
      // If you are here, it means your browser is IE11
  }

Monday, June 15, 2015

Git on Mac

1. Set [TAB] as auto-completion
    curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

Add the following code to file ~/.bash_profile :
if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi
Give the script permission to run:
chmod -X ~/.git-completion.bash

Close and open a new shell. Done!

Tuesday, April 21, 2015

How to test private function in Angularjs

These days, I am working on unit tests of an AngularJS application. But it drives me crazy when I encountered private functions.
I  read the two articles by Philip Walton: 
My idea was inspired from these two articles.
It seems like whether and how to test the private function in Javascript is still a controversial topic.
For me, I choose to do it. There are two reasons:
First of all, some of the code are not written by me. I'd like to play around with my test code rather than changing others' work. And we haven't decided whether it's OK to make those code public.
Second of all, there are many private functions, I don't think it's good to skip all of them.

A brief instruction of the app I am working on

The app is built with gulp. We set the task

gulp test

for unit test.

In the app code, we have the following structure :
angular.module('MainModule').controller('MainCtrl',MainController);

mainController.$injct = ['dep1','dep2']

function MainController(dep1,dep2){
  var vm = this;
  var name = '';
  var isMember = false;

  vm.somePubFuncs = function(){
    // call those private functions from public function
  }

  function updateMemberBenefitTable(){
     // dosomething here
  }

  function loadMemberBenefitTable(){
    // dosomething here
  }
}

I will test the updateMemberBenefitTable() and loadMemberBenefitTalbe().

My basic idea of testing the private functions

Adding some public interfaces for the private function at the beginning of test, and strip them at the end of the test.
I use gulp-insert-lines for adding and gulp-strip-code for stripping.

I added the comments pair
/*test-code-insert-here*/  /*end-test-code-insert-here*/
i.e.

angular.module('MainModule').controller('MainCtrl',MainController);

mainController.$injct = ['dep1','dep2']

function MainController(dep1,dep2){
  var vm = this;
  var name = '';
  var isMember = false;

  vm.somePubFuncs = function(){
    // call those private functions from public function
  }

  /*test-code-insert-here*/
  /*end-test-code-insert-here*/

  function updateMember--BenefitTable(){
     // dosomething here
  }

  function loadMemberBenefitTable(){
    // dosomething here
  }
}

The interfaces will be inserted into the pair of comments.

The gulp task for unit test is:
var insertLines = require('gulp-insert-lines');
var stripCode = require('gulp-strip-code');

gulp.task('test',function(){

  // This section is to add the interfaces of the private function into the source file
  var str = '/*--test-only*/'+'\n'+
            'vm._updateMemberBenefitTable = updateMemberBenefitTable;'+'\n'+
            'vm._loadMemberBenefitTable= loadMemberBenefitTable;'+'\n'+
            '/*--end-test-only*/';
  gulp.src('path/of/MainCtrl')
    .pipe(insertLines({
      'after':/\/\*test-code-insert-here\*\/$/,
      'lineAfter':str
    }))
    .pipe(gulp.dest('dest'));
  //END This section is to add the interfaces of the private function into the source file
  
  return gulp.src('testfile.js')
    .pipe($.karma({
      configFile: 'karma.conf.js',
      action: 'run'  
    }))
    .on('end',function(){
      // This section is to strip off the interfaces of the private function 
      //at the end of the unit test
      gulp.src('path/of.MainCtrl')
        .pipe(stripCode({
          start_comment:'--test-only',
          end_comment:'--end-test-only'
        }))
        .pipe(gulp.dest('dest')); 
      //END This section is to strip off the interfaces of the private function 
      //at the end of the unit test
}) .on('error',function(err){ throw err; })


Please keep in mind that the /*--test-only*/  /*--end-test-only*/ comments pair is very important. Because later on, when gulp-strip-code is stripping the interfaces, the comments pair will be stripped as well. If you use /*test-code-insert-here*/ /*end-test-code-insert-here*/ pair for stripping, you will end up with being not able to find them at the next run of gulp test.