Author Archives: sgamon

Javascript multi-line string idiom

Javascript lacks support for multi-line strings. An obvious omission that will finally be corrected in ES6. But until that great day…

We could use the escaped newline trick:

var foo = "all good men \
must come \
to the aid of the party";

That is fraught with peril. Best to avoid it.

So  we fall back to concatenation:

var foo = "";
foo += "all good men ";
foo += "must come ";
foo += "to the aid of the party";

That’s what I used forever, until this hit me today:

var foo = [
  'all good men',
  'must come',
  'to the aid of the party'
].join(' ');

It reads nicely. Less typing. You can join on newline, space, or whatever. Insert another line easily.

In a word: elegant.

I’m using this until ES6 is real.

To be clear: not claiming original scholarship. It hit me today. Probably hit someone else long ago. They are bad at publicity, so it was new to me. Rock on!

 

 

A year without BabyCenter

This time last year, I took a last long walk down 4th Street to the Powell Street BART station.

I worked at BabyCenter for 9 1/2 years. A long time! Time enough in a man’s life to be significant. Long enough to deserve a blog post.

When I left, I was full of raw emotion. I told myself not to blog about it for a year. I wanted perspective. Space. Good idea!

I still think about BabyCenter a lot. Too much. I wish it was safely behind me by now. Time does heal all wounds. But you need a lot of it. A year, clearly, is not enough.

Wounds? Well… When I left, I had reasons. A year later… Let’s say this: I had reasons for leaving. They were valid. I am happy now. It’s all good.

Other thoughts:

* I miss the high-quality people. Something about BabyCenter attracted high-quality people. Some left, some stayed. I really appreciated working with all of them.

BabyCenter is in the heart of the SOMA startup community. But the staff is composed of people who don’t want to be at startups. Older, experienced, professional, serious about the craft. We didn’t have a programmer under 30. No one wanted to work overtime. But no one wanted the business to suffer either. There is a balance. The staff at BabyCenter grokked that balance. (er… mostly)

* Not everyone was great. I danced on more than a few graves. That’s part of the fun though. I out-lasted those losers, and told bawdy stories about them at the bar.

* You can’t go back. I ran into an old colleague one day, on the way to work. He’d been gone for just a year, yet most of the people he worked with had left as well.  It was a sobering realization. Last month, I talked to another colleague, one who kept in touch. It turns out that a bunch of significant people left in the last year.  I’m not minimizing the friends who remain. It’s just that it wouldn’t be the same if I went back now.

* We were really, really good at process. I wish my current day job was half as good. At the same time, we became slaves to that process. We started worshiping the rules, and not the meaning behind the rules. We turned into a software factory. I never want to work at a factory again.

* I learned a ton, from outstanding people. And I learned a bit from ridiculous people. The ridiculous people make great cocktail-party stories. But I love those outstanding people. They made the whole thing great.

* Before BabyCenter, I was an arrogant SOB. I was the smartest guy in every room. Or close enough for hand-grenades. I had friends and admirers, sure. But also enemies. Enemies wore on my mind. When I joined BabyCenter, I made a conscious decision to re-invent myself as a nice, accommodating person. Enemy free! Mission accomplished, I think. The problem is, I was wearing a mask, playing a role. Every day for a decade. It wears on you. When I left, one of the things I hoped to accomplish is a reconciliation between my Jekyll and my Hyde. Can I be nice, but also awesome? So far, so good. Still working on it…

BabyCenter made me a better person.

 

 

Farewell Netbeans. I’m with Webstorm now.

I switched to Netbeans back when they rolled out “experimental” php support. This was in the summer of 2008.  I saw the php stuff demoed at CommunityOne that year. I downloaded the alpha/beta, and was blown away. Not just by the php stuff. It also had great javascript support.

For my money ($0), Netbeans was the hands-down best web development IDE from 2008-2014. I was programming in both php and javascript during that time. But even if I was only using what came to called the HTML5 stack (javascript/css/html), Netbeans was still the best.

That ended this year.

Netbeans 8 was released, and I enthusiastically installed it. It adds some useful stuff to php and javascript, no doubt. But with respect to javascript particularly, it is lagging. Javascript is moving super-fast these days. Hard for any team to keep up. Most editor/IDE teams don’t really try.

Obviously, the Netbeans team focused their efforts on integrating Java 8 into Neatbeans 8. Of course they did. I understand the politics.

The problem is, the published roadmap doesn’t show a lot of love for javascript. And, as I said, javascript is moving fast these days. If you don’t have rich support for nodejs development, you are missing the boat. Netbeans has abandoned the chase.

So, dear Netbeans, it’s not you, it’s me.  I’ve changed. I’ve grown. I’m not the same programmer I was in 2008.

For one thing, I haven’t programmed in php for a year now. What?! Yeah, just last year I saw php as a long-term, future-proof skill. I changed my mind about that.

On the enthusiastic recommendation of a colleague, I tried out Webstorm. It has a very reasonable licensing/pricing scheme. I figured if I fall in love with it, it won’t cost me much. I installed the trial.

After more than a month, here’s what I’ve found:

* Webstorm is more stable than Netbeans. Honestly, Netbeans and I were in an abusive relationship. Netbeans would crash. Netbeans would suddenly turn into a resource hog. When I shut down Netbeans with a force-quit, it forgot all my tabs. All my tabs! I must have upgraded a dozen times, but Netbeans never, ever, remembered my tabs after a force-quit. Shame on you Netbeans.

* Webstorm  does everything Netbeans does, mostly as well. Laments: The keyboard shortcuts are different, which is a major drag. Renaming a file is weirdly hard. Renaming javascript variables is essentially unsupported.  And Webstorm insists on spawning a whole new window to open a different project. These are problems.

* But Webstorm supports Grunt tasks, and nodejs debugging. And the next version, due in 6 months, will have Gulp tasks. When I add a file to a folder outside the IDE, it shows up instantly, which never happened in Netbeans.

In the end, I bought a license. I use Webstorm every day now. I would recommend it to any HTML5 or nodejs developer.

So long Netbeans. Good luck. We’ll always have Paris.

 

Where does the time go?

There are 168 hours in a week. (7 x 24).

I sleep 63 hours. 105 hours.

I work 40 hours. 65 hours.

I spend 5 hours each week getting up, getting ready, and leaving for work. 60 hours.

I commute 5 hours each week. (Pretty sweet, eh?). 55 hours.

I spend 10 (non-work) hours eating each week. 45 hours.

At least 20% of the remaining time, I am so tired all I can do is watch TV or surf the web. 36 hours.

So… I have 36 free, awake (but non-contiguous) hours each week. Where does that time go? Stay tuned….

 

 

 

The “right” way to javascript

I try to avoid arguments about curly braces, variable names, and other low-level code practices. But when it comes to javascript, I do have opinions.

Consider adopting the jQuery Style Guide. I don’t observe every last bit of it, but I’d be willing to conform for the sake of consistency with the rest of a team.

Here is my own style as per jsCode.org. (Hint: If the code sample looks ugly, try reloading.) You can generate your own style at jsCode.org. It would be fun to compare and contrast.

In particular, variable names should be camelCase. They should only have initial caps if they are a constructor function.

I don’t care how you indent, as long as you do. My editor automatically converts to 2-space indentation when I open a file. But I am sympathetic to other styles.

Opening curly braces do not get their own lines. Sorry. First, the javascript community has overwhelmingly adopted the “same-line” convention. Second, this. Please save “separate-line” style for the days you write java.

“if” and “for” bodies must be wrapped in curly braces. Javascript is not python.  If you omit curly braces: 1) I will have to read your code very, very slowly to understand it. 2) We can never minify your code safely. Do the right thing.

Use jshint to check your code. There are some arguable warnings, but try to fix as many as possible.

Think hard about globals. Jshint flags them. You should be able to defend every global it surfaces.

Use the array iterator functions: forEach, map, reduce, and filter. Next time you are about to write another “for” loop, ask yourself if you could use an array iterator.

Consider using an IDE. It will flag many javascript issues before you get a chance to check in.

FTP on your Centos server

If you run WordPress on a Centos server, you will discover that you need an ftp server to support automatic updates. There is a good article on how to do that here:

https://www.digitalocean.com/community/articles/how-to-set-up-vsftpd-on-centos-6–2

However, you also need to follow the instructions in the comment by nest.u333:

https://www.digitalocean.com/community/articles/how-to-set-up-vsftpd-on-centos-6–2#1372265397

And with that, you can use WordPress auto-update.

 

PHP’s future is… meh.

Acknowledged:

  • PHP is used in many, many companies.
  • PHP is used in some big companies like Facebook and Yahoo.
  • PHP has many developers.
  • PHP has apps that are not going away in the foreseeable future.
  • PHP has apps that are never going away. (WordPress and Wikipedia, to name two. There are more.)

Yes, yes, yes, yes, yes. All true. But if you are a PHP developer, now would be a good time to start learning something else…

My argument hinges on the idea that no growing company “switches” to PHP. You either start with it, and grow the company, or you never do use it.

See, if you scan the links at TechCrunch.com, you’ll never see a startup that launches on PHP. Actually, I don’t think I’ve seen one in a decade now. (Does Identi.ca count?) Starting around 2006, PHP startups were replaced by Rails startups, which gave way to Python startups, which gave way to nodejs startups. Not being part of the startup scene means that no companies are going to suddenly grow big, and find themselves supporting an installed base of PHP (as Facebook did).

I hope you’ll agree that none of today’s startups are going to switch to PHP at some point. Twitter switched from Rails to Java/Scala, for example. Not to PHP.

Which, I submit, means that PHP will slowly (ever so slowly) fade away.

But take heart my PHP friends! If you just need to eke out another decade or so until retirement, I think you have plenty of runway. There are countless organizations with WordPress/Drupal/Joomla.

Did you know that Hawaii built their state-wide Obamacare site on WordPress? How neat is that? At the same time, I think it exposes the glass ceiling for PHP: cost-constrained organizations, that will accept something “good enough”, and have reasonable scaling requirements (Hawaii has just 1.4MM people, same as San Diego).

Meh.

 

No market for mid-range chromebooks

I reluctantly convinced myself that there is no market for mid-range chromebooks. In fact, there is no high-end market either, despite the existence of the Chromebook Pixel.

In the world of computers, there are:

  1. high-end, pricey, powerful models
  2. low-end, affordable, frustratingly underpowered model
  3. mid-range models, that cost somewhat more than the low-end, but perform so much better

Those who know their stuff buy and recommend mid-range computers. The extra money is well spent.

The Pixel is crazily overpriced for what you actually get. It is clearly a boutique product, sold and supported by the sugar-daddys at Google. Note that we are going on a year now, and no one else has moved to produce a high-end chromebook. Enough said.

Low-end chromebooks are the breakout success story of 2013. Acer announced that chromebooks are their best-selling products. Seemingly every PC maker has one, or is announcing one. Weirdly, no one is trying for the mid-range…

Let me define my terms: A mid-range chromebook has 4gb of ram, 32gb (or more) of storage, and a high-resolution display (say, 1920×1080).  It sells for $400+.  Who makes that today? No one. Who has a announced something in that category? No one.

Look around the current offerings. Everyone is stuck on 1366×768 screens. I don’t understand. The Nexus 7 (2013) has 1920×1200. The Samsung Galaxy Note 10.1 (2014) has 2560×1600. Why do android tablets routinely trounce chromebooks on screen quality?

As for ram, you basically have to settle for 2gb. Walmart and Costco both offer versions of the HP 14 that have 4gb. The Costco version, with 32gb of storage comes closest to my mid-range machine. It is dragged down by that crappy screen.

Acer, whose C720 series won all the awards last year, briefly sold a 4gb edition. Then they stopped. The 4gb edition is now only available from ebay resellers, at premium pricing.

Price is king in the land of chromebook. Straying above $300 is risky, based on what I see out there. I’d love to get a mid-range chromebook, I just don’t expect to see one for a couple of years.

 

Node on CentOS 5

You can easily install node on CentOS 6 using yum. On CentOS 5? Not so much.

My journey began on this page, which is half right. You need to install python 2.7, just so:

wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xf Python-2.7.3.tgz
cd Python-2.7.3
sudo yum install gcc
./configure
make
make altinstall

The second half of that page describes a way of installing node that no longer works (because nodejs.tchol.org no longer exists). So…

Visit http://nodejs.org/download/, and copy the download link for the latest node tarfile (ie, http://nodejs.org/dist/v0.10.25/node-v0.10.25.tar.gz). Next:

wget http://nodejs.org/dist/v0.10.25/node-v0.10.25.tar.gz
tar -xzf node-v0.10.25.tar.gz
cd node-0.10.25
python2.7 configure
sudo yum install gcc-c++
make -j5
sudo make install
node --version

Voilà!

The vast right wing conspiracy to suppress RAM

14 months ago, I bought a new laptop. It only has 4GB, and it’s not upgrade-able. But it was only $600, and I figured I’d be able to buy a better one in a year or so, passing this one down the family food chain.

Really, 4GB is a minimal configuration on a modern Windows machine. I thought for sure the trend would be towards 8GB by now. In fact, desktop PCs all come with more than 8GB now. But search in vain for an 8GB laptop.

Oh, they are out there. For premium prices. In the under-one-thousand-dollar category, you seemingly get the choice of heavy + RAM, or light + no RAM. Adding insult to injury, the new “thing” is to solder the memory to the motherboard, preventing upgrades.

Let me spell it out for you: I want a light laptop, with 8GB, for under $800. I haven’t seen one yet.

Meanwhile, over in Chromebook land, they are stuck at 2GB. Again, this is really the rock-bottom minimum. You can have a much nicer Chromebook experience with 4GB. But there are only a couple of models that offer that, and they are either perpetually out of stock, or priced well above Chromebook’s value proposition.

And don’t get me started on these so-called Windows 8 tablets with just 2GB. Remember single-tasking? You will if you buy one of these tablets.

There is also a conspiracy against increasing screen resolutions. But I’ll save that for another rant.