<<

hacker bits June 2016 new bits

Hello from sunny (finally!) Redmond!

Can it really be June already?! Time does indeed fly…just ask Adrian Kosmaczewski who shows us how to navigate an industry littered with forgotten technologies and has-beens. Find out more in his blast-through-the-past account of “Life as a developer after 40.”

Curious about Progressive Web Apps? Then don’t miss this issue’s interview with Henrik Joreteg, expert on all things PWA, who gives us the lowdown on this exciting new mobile technology.

As always, our objective at Hacker Bits is to help readers like you learn and grow, and that’s why we are rolling out a new feature called Spotlight where we get tech experts to reveal their professional secrets.

Lastly, congratulations to the winners of our giveaway!

Time is precious so let's dive into another wonderful issue of Hacker Bits!

Peace and plenty of ice cream!

— Maureen and Ray [email protected] content bits June 2016

Fingerprints are usernames, not Are Progressive Web Apps the 06 passwords 34 future of the Internet?

Am I really a developer or just a 08 good Googler? 38 19 tips for everyday git use

Develop the three great virtues of a programmer: laziness, It takes all kinds 10 impatience, and hubris 48

When to rewrite from scratch: 16 Being a developer after 40 52 autopsy of a failed software

Implementers, solvers, and Clojure, the good parts 26 finders 56

20 lines of code that will beat A/B 30 testing every time

hacker bits 3 contributor bits

Dustin Kirkland Scott Hanselman Reginald Braithwaite Adrian Kosmaczewski Dustin is an Ubun- Scott is a web develop- Reg is the author of Adrian is a writer, tu dev and product er and has blogged at JavaScript Allongé, software developer manager at Canoni- hanselman.com for over CoffeeScript Ristretto and teacher. He is the cal. Formerly, CTO of a decade. He works and raganwald.com. He author of two books Gazzang, he created in Open Source on develops user experi- about mobile software an innovative manage- ASP.NET and the Azure ences at PagerDuty. His development, and has ment system for cloud Cloud for out interests include con- shipped mobile, web apps. At IBM, Dustin of his home office in structing surreal num- and desktop apps for contributed to many Portland, OR. Scott has bers, deconstructing iOS, Android, Mac OS Linux security projects 3 podcasts, hanselmin- hopelessly egocentric X, Windows and Li- and filed 70+ pat- utes.com, thisdevelop- nulls, and celebrating nux since 1996. Adri- ents. He is the author erslife.com and ratch- the joy of program- an olds a Masters in of 20+ open source etandthegeek.com. ming. His other works Information Technology projects, including He's written a number are on GitHub and from the University of Byobu, eCryptfs, ssh- of books and spoken in Leanpub, and you can Liverpool. import-id, and entropy. person to almost 500K follow him on Twitter ubuntu.com. Twitter devs worldwide. @raganwald. @dustinkirkland.

Randall Koutnik Steve Hanov Alex Kras Justin Etheredge Randall is a Senior UI Steve can be found at Alex is a Software Engi- Justin is the cofounder Engineer at and various coffee shops neer by day and Online of Ecstatic Labs, a small holds a lot of strong in Waterloo, Ontario, Marketer by night. You consulting company opinions about Star where he writes code can find his blog and based out of Richmond, Wars. He'd love to hear and occasionally re- learn more about him Virginia. His goal is to from you via hacker- sponds to emails from at alexkras.com. make software more [email protected]. customers of his web friendly, one applica- businesses webse- tion at a time. quencediagrams.com and zwibbler.com. He has three children, one wife, and two birds.

4 hacker bits Umer Mansoor Allen Rohner Ray Li Maureen Ker Umer is a software Allen is the founder of Curator Editor developer, living in Rasterize and CircleCI. Ray is a software en- Maureen is an editor, San Francisco, CA. He He is a Clojure contrib- gineer and data en- writer, enthusiastic currently works for utor, and has commits thusiast who has been cook and prolific collec- Glu Mobile as Platform in clojure.core, contrib, blogging at rayli.net tor of useless kitchen Manager, building a lein, ring, compojure, for over a decade. He gadgets. She is the cloud gaming backend. noir, and about a loves to learn, teach author of 3 books and He previously served as dozen more libraries. and grow. You’ll usu- 100+ articles. Her work the Head of Software He blogs at rasterize.io ally find him wrangling has appeared in the for Starscriber where he and you can follow him data, programming and New York Daily News, built high performance on Twitter @arohner. lifehacking. and various adult and telecommunications children’s publications. software. He blogs at CodeAhoy.com.

hacker bits 5 Interesting

Fingerprints are usernames, not passwords

By DUSTIN KIRKLAND

6 hacker bits s one of the maintainers I'm bringing this up again you need a password or pass- of eCryptfs, and a long to highlight the work released phrase. Something that can be Atime Thinkpad owner, I by The Chaos Computer Club, independently chosen, changed, have been asked many times which has demonstrated how and rotated. I will continue to to add support to eCryptfs for truly insecure Apple's TouchID advocate this within the Ubuntu Thinkpad's fingerprint readers. is. development community, as I I actually captured this as There may be civil liberties have since 2009. a wishlist bug in Launchpad in at issue as well. While this piece Once your fingerprint is August 2008, but upon thinking is satire, and Apple says that it compromised (and, yes, it about it a bit more, I later closed is not sharing your fingerprints almost certainly already is, if the bug as "won't fix" in Feb- with the government, we've been you've crossed an international ruary 2009, and discussed in a kept in the dark about such border or registered for a driv- blog post, saying: things before. I'll leave you to er's license in some US states draw your own conclusions on and countries), how do you Hi, thanks so much for that one. change it? Are you starting to the bug report. I've been But let's just say you're okay see why this is a really bad idea? thinking about this quite a with Apple sharing your fin- There are plenty of inven- bit lately. I'm going to have gerprints with the NSA, as I've tions that exist, but turned out to mark this "won't fix" for already told you, they're not to be bad ideas. And I think now. private at all. You leave them on fingerprint readers are another everything you touch. And let's one of those. The prevailing opinion from security profession- als is that fingerprints are perhaps a good re- Biometrics...cannot placement for usernames. However, they're really not a good replacement for authenticate a person passwords. or a thing alone. Consider your laptop... how many fingerprints of yours are there on your say you're insistent on using fin- This isn't a knock on Apple, laptop right now? As such, gerprint (biometric) technology as Thinkpad have embedded it's about as secret as your because you can. In that case, fingerprint readers for nearly a username. You don't leave your fingerprints might identify decade. My intention is to help your password on your you, much as your email address stop and think about the place spacebar, or on your beer or username identifies you, per- of biometrics in security. Bio- bottle :-) haps from a list. metrics can be used as a light- I could see some value, per- weight, convenient mechanism This Wikipedia entry (al- haps, in a tablet that I share with to establish identity, but they though it's about Microsoft my wife, where each of us have cannot authenticate a person or Fingerprint Readers) is our own accounts, with indepen- a thing alone. pretty accurate: * http:// dent configurations, apps, and So please, if you have any re- en.wikipedia.org/wiki/Mic- settings. We could each con- spect for the privacy your data, rosoft_Fingerprint_Reader veniently identify ourselves by or your contacts' information, our fingerprint. But biometrics please don't use fingerprints So, I'm sorry, but I don't cannot, and absolutely must (or biometrics, in general) for think we'll be fixing this for not, be used to authenticate authentication.  now. an identity. For authentication,

Reprinted with permission of the original author. First appeared on Oct 1, 2013 at blog.dustinkirkland.com.

hacker bits 7 Interesting

Am I really a developer or just a good Googler?

By SCOTT HANSELMAN

got a very earnest and well- game. It'll get hard as I prog- weeks, if not weekly. phrased email from a young ress through the levels, but not Third, try programming for a I person overseas recently. crushingly hard. Each level I day without Googling. Then two squeak by I'll find myself asking, days, maybe a week. See how it Some time in my mind "Did I deserve to pass that level? feels. Remember that there was sounds come that Is that I'm not sure I could do it again." a time we programmed without I am really a developer or You get that feeling like copying our work. just a good googler. I don't you're in over your head, but Fourth, think about the know what is the answer I just a bit. Just enough that you problem, deeply. Read about am googler or I am devel- can feel the water getting into algorithms, read Programming oper. Scott Please clear on your nose but you're not drown- Pearls, read about Design my mind on this please. ing yet. Patterns. Rather than copying First, remember you are not code from Stack Overflow, copy This is a really profound alone. I think that we grow when patterns from the greats. question that deserved an we are outside our comfort Fifth, get involved. Go to answer. Since I only have so zone. If it's not breaking you User Groups, Nerd Dinners, many keystrokes left in my life, down, it's not building you up. meet with others who feel the I am blogging my thoughts and Second, anything that you same way you do about technol- emailing a link. want to be good at is worth ogy. Stretch. I've felt the same way some- practicing. Do Code Katas. Do a What do you think?  times when playing a video Project Euler problem every few

Reprinted with permission of the original author. First appeared at hanselman.com.

8 hacker bits hackerbits.com/mobile Programming

Develop the three great virtues of a programmer: laziness, impatience, and hubris

By REGINALD BRAITHWAITE

10 hacker bits Laziness and eagerness Generating laziness In computing, “laziness” is a broad term, generally The bodies of functions are a kind of lazy thing: referring to not doing any work unless you need They aren’t evaluated until you invoke the func- it. Whereas its opposite is “eagerness,” doing as tion. This is related to if statements, and every much work as possible in case you need it later. other kind of control flow construct: JavaScript Consider this JavaScript: does not evaluate statements unless the code actually encounters the statement.

Now, here’s the question: Does JavaScript evaluate 2+3? You probably know the answer: Yes it does. When it comes to passing arguments to a function invocation, JavaScript is eager, it evalu- ates all of the expressions, and it does so whether the value of the expression is used or not.1 Consider this code: If JavaScript was lazy, it would not evaluate You are doubtless chuckling at its naïveté. Imag- 2+3 in the expression ifThen(1 === 0, 2 + 3). So ine this list was the numbers from one to a bil- is JavaScript an “eager” language? Mostly. But not lion – e.g. [1, 2, 3, ..., 999999998, 999999999, always! If we write: 1 === 0 ? 2 + 3 : undefined, 1000000000] – and we invoke: JavaScript does not evaluate 2+3. Operators like ?: and && and ||, along with program control struc- tures like if, are lazy. You just have to know in your head what is eager and what is lazy. And if you want something to be lazy that isn’t naturally lazy, you have to work around JavaScript’s eagerness. For example: We get the correct result, but we iterate over every one of our billion numbers first. Awful! Small children and the otherwise febrile know that you can return from anywhere in a JavaScript func- tion, and the rest of its evaluation is abandoned. So we can write this:

JavaScript eagerly evaluates () => 2 + 3, which is a function. But it doesn’t evaluate the expres- sion in the body of the function until it is invoked. And it is not invoked, so 2+3 is not evaluated. Wrapping expressions in functions to delay evaluation is a longstanding technique in pro- gramming. They are colloquially called thunks, and there are lots of interesting applications for This version of the function is lazier than the them. first: It only does the minimum needed to deter- mine whether a particular list contains a particular value.

hacker bits 11 From containing, we can make a similar func- tion, findWith:

is eager, so it makes applies a predicate function to lazily NumbersUpTo(1000000000) findWith a list of all billion numbers, even though we only find the first value that evaluates truthily. Unfor- need the first . This is the problem with lazi- tunately, while is lazy, its argument is eval- 101 findWith ness: We need to be lazy all the way through a uated eagerly, as we mentioned above. So let’s computation. say we want to find the first number in a list that Luckily, we just finished working with genera- is greater than and is a palindrome: 99 tors2 and we know exactly how to make a lazy list of numbers:

Generators yield values lazily. And findWith searches lazily, so we can find 101 without first generating an infinite array of numbers. JavaScript still evaluates Numbers() eagerly and binds it to list, but now it’s binding an iterator, not an array. And the for (const element of list) { ... } state- ment lazily takes values from the iterator just as it did from the billion array.

The sieve of Eratosthenes It’s the same principle as before, of course, we iterate through our billion numbers and stop as We start with a table of numbers (e.g., 2, 3, 4, 5, . . . ) and progressively cross off numbers in the soon as we get to 101, which is greater than 99 and palindromic. table until the only numbers left are primes. Spe- But JavaScript eagerly evaluates the arguments cifically, we begin with the first number, p, in the table, and: to findWith. So it evaluates isPalindromic, gt(99)) and binds it to , then it eagerly evaluates predicate 1. Declare p to be prime, and cross off all the billion and binds it to list. Binding one value to another is cheap. But multiples of that number in the table, start- what if we had to generate a billion numbers? ing from p squared, then; 2. Find the next number in the table after p that is not yet crossed off and set p to that number; and then repeat from step 1.

12 hacker bits Here is the sieve of Eratosthenes, written in eager With those in hand, we can write a generator style: that maps an iterable to a sequence of values with 3 every nth element changed to null:

That’s the core of the “sieving” behaviour: Take the front element of the list of numbers, call it n, and sieve every nth element afterwards. Now we can apply nullEveryNth recursively: Take the first unsieved number from the front of the list, sieve its multiples out, and yield the results of sieving what remains:

Let’s take a pass at writing the sieve of Eratos- thenes in lazy style. First off, a few handy things we’ve already seen in this blog, and in JavaScript Allongé:

With sieve in hand, we can use range to get a list of numbers from 2, sieve those recursively, then we compact the result to filter out all the nulls, and what is left are the primes:

Besides performance, did you spot the full-on bug? Try running it yourself, it won’t work! The problem is that at the last step, we called com- pact, and compact is an eager function, not a lazy one. So we end up trying to build an infinite list of primes before filtering out the nulls.

hacker bits 13 We need to write a lazy version of compact: And so it goes with all of our existing opera- tions that we use with lists: We need lazy versions we can use with iterables, and we have to use the lazy operations throughout: We can’t mix them.

It comes down to types This brings us to an unexpected revelation. Generators and laziness can be wonderful. Ex- And now it works! citing things are happening with using generators to emulate synchronized code with asynchronous operations, for example. But as we’ve seen, if we want to write lazy code, we have to be careful to be consistently lazy. If we accidentally mix lazy and eager code, we have problems. This is a symmetry problem. And at a deeper level, it exposes a problem with the “duck typ- ing” mindset: There is a general idea that as long as objects handle the correct interface – as long as they respond to the right methods – they are interchangeable. But this is not always the case. The eager and When we write things in lazy style, we need lazy versions of compact both quack like ducks that lazy versions of all of our usual operations. For operate on lists, but one is lazy and the other is example, here’s an eager implementation of not. “Duck typing” does not and cannot capture unique: difference between a function that assures lazi- ness and another that assures eagerness. Many other things work this way, for example escaped and unescaped strings. Or obfuscated and native IDs. To distinguish between things that have the same interfaces, but also have semantic or other contractual differences, we need types. We need to ensure that our programs work with each of the types, using the correct oper- ations, even if the incorrect operations are also “duck compatible” and appear to work at first glance. 

Naturally, we’d need a lazy implementation if we wanted to find the unique values of lazy itera- tors:

14 hacker bits The full source

Notes 1 A few people have pointed out that a sufficiently smart compiler can notice that 2+3 involves two constants and a fixed operator, and therefore it can be compiled to 5 in advance. JavaScript does not necessarily perform this optimization, but if it did, we could substitute something like x + y and get to the same place in the essay. 2 “Programs must be written for people to read, and only incidentally for machines to execute.”

3 This is the simplest and most naïve implementation that is recognizably identical to the written description. In The Genuine Sieve of Eratosthenes, Melissa E. O’Neill describes how to write a lazy functional sieve that is much faster than this implementation, although it abstracts away the notion of crossing off multiples from a list.

Reprinted with permission of the original author and raganwald.com.

hacker bits 15 Programming

Being a developer after 40 By ADRIAN KOSMACZEWSKI

i everyone, I am a forty-two year old self-taught devel- Hoper, and this is my story. A couple of weeks ago I came by the tweet below, and it made me think about my career, and those thoughts brought me back to where it all began for me (see figure). I started my career as a software developer at precisely 10am, on Monday October 6th, 1997, somewhere in the city of Olivos, just north of Buenos Aires, Argentina. The moment was Unix Epoch 876142800. I had recently celebrated my 24th birthday.

16 hacker bits The world in 1997 ploit called “WinNuke,” a deni- My first developer job al-of-service attack on TCP port The world was a slightly differ- 139 (NetBIOS) that causes a Blue My first job consisted of writing ent place back then. Screen of Death. ASP pages in various editors, Websites did not have cookie Incidentally, 1997 is also ranging from Microsoft Front- warnings. The future of the the year Malala Yousafzai, Chloë Page, to HotMeTaL Pro to Edit- web was portals like Excite. Grace Moretz and Kylie Jenner Plus, managing cross-browser com. AltaVista was my preferred were born. compatibility between Netscape search engine. My e-mail was Many film storylines take Navigator and Internet Explorer [email protected], which place in 1997, to name a few: 4, and writing stored procedures meant that my first personal Escape from New York, Predator in SQL Server 6.5 powering a website was located in http:// 2, The Curious Case of Benjamin commercial website published in sc2a.unige.ch/~kosmacze. Button, Harry Potter and the Japanese, Russian, English and We were still mourning Lady Half-Blood Prince, The Godfather Spanish — without any consistent Diana. Steve Jobs had taken III and according to Terminator UTF-8 support across the soft- the role of CEO and convinced 2: Judgement Day, Skynet be- ware stack. Microsoft to inject $150 million came self-aware at 2:14 am on The product of these efforts into Apple Computer. Digital August 29, 1997. That did not ran in a Pentium II server hosted Equipment Corporation was happen; however, in an interest- somewhere in the USA, with a suing Dell. The remains of Che ing turn of events, the domain stunning 2 GB hard disk drive Guevara had just been brought google.com was registered on and a whopping 256 MB of RAM. back to Cuba. The fourth season September 15th that year. It was a single server running of “Friends” had just started. We were two years away Windows NT 4, SQL Server 6.5 Gianni Versace had just been from Y2K and the media was and IIS 2.0, serving around ten murdered in front of his house. starting to get people nervous thousand visitors per day. Mother Teresa, Roy Lichtenstein about it. My first professional pro- and Jeanne Calment (the world’s gramming language was this oldest person ever) had just mutant called VBScript, and of passed away. People were play- ing Final Fantasy 7 on their Play- Station like crazy. BBC 2 started broadcasting the Teletubbies. James Cameron was about to release Titanic. The Verve had just released their hit “Bitter Sweet Symphony” and then had to pay most of the royalties to the Rolling Stones. Smartphones looked like the Nokia 9000 Communicator; they had 8 MB of memory, a 24 MHz i386 CPU and run the GEOS operating system. Smartwatches looked like the CASIO G-SHOCK DW-9100BJ. Not as many apps but the battery life was much longer. IBM Deep Blue had defeated Garry Kasparov for the first time in a game of chess. A hacker known as “_eci” published the C code for a Windows 3.1, 95 and NT ex-  Excite in 1997, courtesy of the Internet Archive

hacker bits 17 course a little bit of JavaScript open source projects, and one you feel guilty if you do not pay on the client side, sprinkled with of them landed me an article on attention to them. lots of “if this is Netscape do Ars Technica by Erica Sadun her- this, else do that” because back self. I was featured in Swiss and • In 1997 it was CORBA & RUP. then I had no idea how to use Bolivian TV shows. I watched • In 2000 it was SOAP & XML. JavaScript properly. live keynotes by Bill Gates and • In 2003 it was Model Driven Interestingly, it’s 2016 and by Steve Jobs in Seattle and San Architecture and Software we are barely starting to un- Francisco. I spoke at and co-or- Factories. derstand how to do anything in ganised conferences in four con- • In 2006 it was Semantic Web JavaScript. tinents. I wrote and published and OLPC. Unit tests were unheard of. two books. I burned out twice • In 2009 it was Augmented The Agile Manifesto had not (not the books, myself,) and lots Reality. been written yet. Continuous in- of other things happened, both • In 2012 it was Big Data. tegration was a dream. XML was wonderful and horrible. • In 2015…virtual reality? not even a buzzword. Our QA I have often pondered about Bots? strategy consisted of restarting leaving the profession altogeth- the server once a week, because er. But somehow, code always Do not worry about hype. otherwise it would crash ran- calls me back after a while. I Keep doing your thing, keep domly. We developed our own like to write apps, systems and learning what you were learning, COM+ component in Visual J++ software. To avoid burning out, I and move on. Pay attention to to parse JPEG files uploaded have had to develop strategies. it only if you have a genuine in- to the server. As soon as JPEG In this talk I will give you terest, or if you feel that it could 2000-encoded files started pop- my secrets, so that you too can bring you some benefit in the ping up, our component broke reach the glorious age of 40 medium or long run. miserably. as an experienced developer, The reason for this lies in We did not use source con- willing to continue in this pro- the fact that as the Romans said trol, not even CVS, RCS or, God fession. in the past, nihil novi sub sole forbid, SourceSafe. Subversion (nothing new under the sun). did not exist yet. Our Joel Test Most of what you see and learn score was minus 25. Advice for the young in computer science has been at heart around for decades, and this fact is purposely hidden beneath 6,776 days Some simple tips to reach the piles of marketing, books, blog glorious age of 40 as a happy posts and questions on Stack For the past 6,776 days, I had a software developer: cup of coffee in the morning and Overflow. Every new architec- ture is just a re-imagination and wrote code with things named 1. Forget the hype a re-adaptation of an idea that VBScript, JavaScript, Linux, SQL, The first advice I can give you has been floating around for HTML, Makefiles, Node.js, CSS, all is do not pay attention to decades. XML, .NET, YAML, Podfiles, JSON, hype. Every year there is a new Markdown, PHP, Windows, Dox- programming language, frame- 2. Choose your galaxy wisely ygen, C#, Visual Basic, Visual work, library, pattern, compo- In our industry, every technology Basic.NET, Java, Socket.io, Ruby, nent architecture or paradigm generates what I call a “galaxy.” unit tests, Python, shell scripts, that takes the blogosphere by These galaxies feature stars C++, Objective-C, batch files, storm. People get crazy about but also black holes; meteoric and lately Swift. it. Conferences are given. Books changes that fade in the night; In those 6776 days, lots of are written. Gartner hype cycles many planets, only a tiny frac- things happened; most impor- rise and fall. Consultants charge tion of which harbour some kind tantly, my wife and I got mar- insane amounts of money to of life; and lots of cosmic dust ried. I quit 6 jobs and was fired teach, deploy or otherwise fuck and dark matter. twice. I started and closed my up the lives of people in this Examples of galaxies are own business. I finished my Mas- industry. The press will support .NET, Cocoa, Node.js, PHP, ter’s degree. I published a few these horrors and will make , SAP, etc. Each of these

18 hacker bits features evangelists, developers, opposite; it was full of people be the one remixing the next bloggers, podcasts, conferences, who were musicians, artists and big thing. No, scratch that: you books, training courses, consult- painters; they would write soft- are going to be the creator of ing services, and inclusion prob- ware to support their passion, the next big thing. lems. Galaxies are built on the and they would write software And to help you get there, assumption that their underlying with passion. It made all the here is my (highly biased) selec- technology is the answer to all difference, and to this day, I tion of history books that I like problems. Each galaxy, thus, is still enjoy tremendously this and recommend: based on a wrong assumption. galaxy, the one we are in, right The developers from those now, and that has brought us all • Dealers of Lightning by Mi- different galaxies embody the together. chael A. Hiltzik prototypical attitudes that have And then the iPhone came • Revolution in the Valley by brought that technology to life. out, and the rest is history. Andy Hertzfeld They adhere to the ideas, and So my recommendation will enthusiastically wear the to you is: choose your galaxy • The Cathedral and the Ba- t-shirts and evangelize others wisely, enjoy it as much or as zaar by Eric S. Raymond about the merits of their choice. little as you want, but keep your • The Success of Open Source Actually, I use the term “gal- telescope pointed towards other by Steven Weber axy” to avoid the slightly more galaxies, and prepare to make • The Old New Thing by Ray- appropriate if not less controver- a hyperjump to other places if mond Chen sial term “religion,” which might needed. describe this phenomenon • The Mythical Man Month by better. 3. Learn about software Frederick P. Brooks Jr. In my personal case, I spent history This takes me to the next point: the first ten years of my career You will also learn to value learn how your favorite technol- in the Microsoft galaxy, and those things that stood the test ogy came to be. Do you like C#? the following nine in the Apple of time: Lisp, TeX, Unix, , Do you know who created it? galaxy. C, Cocoa, Emacs, Vim, Python, How did the .NET project came I dare say, one of the biggest ARM, GNU make, man pages. to be? Who was the lead archi- reasons why I changed galaxies These are some examples of tect? Which were the constraints was Steve Ballmer. I got tired long-lasting useful things that of the project and why did the of the general attitude of the are something to celebrate, language turned out to be what Microsoft galaxy people against cherish and learn from. open source software. it is now? On the other hand, I also Apply the same recipe to any 4. Keep on learning have to say that the Apple gal- language or CPU architecture Learn. Anything will do. Wanna axy is a delightful place, full of that you enjoy or love: Python, learn Fortran? Go for it. Find artists, musicians and writers Ruby, Java, whatever the pro- Erlang interesting? Excellent. who, by chance or ill luck, hap- gramming language; learn their Think COBOL might be the next pen to write software as well. origins, how they came to be. big thing in your career? Fantas- I attended conferences in the The same goes for operating tic. Need to know more about Microsoft galaxy, like the Barce- systems, networking technol- Functional Reactive Program- lona TechEd 2003, and various ogies, hardware, anything. Go ming? Be my guest. Design? Of Tech Talks in Buenos Aires, and learn how people came up course. UX? You must. Poetry? Geneva or London. I even spoke with those ideas, and how long You should. at the Microsoft DevDays 2006 they took to grow and mature. Many common concepts in in Geneva. The general attitude Because good software takes ten Computer Science have been of developers in the Microsoft years, you know. (see Figure) around for decades, which galaxy is unfriendly, “corporate” The stories surrounding the makes it worthwhile to learn old and bound in secrecy, NDAs and genesis of our industry are fas- programming languages and cumbersome IT processes. cinating, and will show you two frameworks; even “arcane” ones. The Apple galaxy was to things: first, that everything is First, it will make you appreciate me, back in 2006, exactly the a remix. Second, that you could the current state of the industry

hacker bits 19 (or hate it, it depends) and sec- ond, you will learn how to use the current tools more effective- ly — if anything, because you will understand its legacy and origins. Tip 1: learn at least one new programming language every year. I did not come up with this idea; The Pragmatic Programmer book did. And it works. One new programming lan- guage every year. Simple, huh? Go beyond the typical “Hello, World” stage, and build some- thing useful with it. I usually build a simple calculator with whatever new technology I learn. It helps me figure out the syn- tax, it makes me familiar with the APIs or the IDE, etc. Tip 2: read at least 6 books per year. I have shown above a list of six must-read books; that standingly well written, they are as you will grow old, the num- should keep you busy for a year. fun and are full of insight. ber of things that qualify as Here goes the list for the second Look at it this way: if you are new and/or important will drop year: now 20 years old, by the age of dramatically. Prepare for this. It 30 you will have read over 60 is OK to weep silently when you • Peopleware by Tom DeMarco books, and over 120 when you realise this. and Tim Lister reach my age. And you will have • The Psychology of Software played with at least 20 different 5. Teach Programming by Gerald M. programming languages. Think Once you have learnt, teach. Weinberg about it for a second. This is very important. • Facts and Fallacies of Soft- Some of the twelve books This does not mean that ware Engineering by Robert I’ve selected for you have been you should set up a classroom L. Glass written in the seventies, others and invite people to hear your • The Design of Everyday in the eighties, some in the nine- ramblings (although it would be Things by Don Norman ties and finally most of them awesome if you did!) It might • Agile!: The Good, the Hype are from the past decade. They mean that you give meaningful and the Ugly by Bertrand represent the best writing I have answers to questions in Stack Meyer come across in our industry. Overflow; that you write a book; • Rework by Jason Fried and But do not just read them; that you publish a podcast David Heinemeier Hansson take notes. Bookmark. Write on about your favorite technology; • Geekonomics by David Rice the pages of the books. Then that you keep a blog; that you re-read them every so often. write on Medium; that you go (OK, those are seven books.) Borges used to say that a bigger to another continent and set pleasure than reading a book is up programming schools using Six books per year looks like a re-reading it. And also, please, Raspberry Pis; or that you help lot, but it only means one every buy those books you really like a younger developer by becom- 2 months. And most of the in paper format. Believe me. ing their mentor (do not do this books I have mentioned in this eBooks are overrated. Nothing before the age of 30, though.) presentation are not that long, beats the real thing. Teaching will make you and even better, they are out- Of course, please know that more humble, because it will

20 hacker bits painfully show you how limited thought has made every lesson places you will be harassed, par- your knowledge is. Teaching is I gave since then much more ticularly if you are a woman, a the best way to learn. Only by worthwhile and meaningful. member of the LGBT community testing your knowledge against or from a non-Caucasian ethnic others are you going to learn 6. Workplaces suck group. I have seen developers properly. This will also make Do not expect software corpora- threatened to have their work you more respectful regarding tions to offer any kind of career visas not renewed if they did not other developers and other tech- path. They might do this in the work faster. I have witnessed nologies; every language, no US, but I have never seen any harassment of women and gay matter how humble or arcane, of that in Europe. This means colleagues. has its place within the Tao of that you are solely responsible Some parts of our industry Programming, and only through for the success of your career. are downright disgusting, and teaching will you be able to feel Nobody will tell you “oh, well, you do not need to be in Silicon it. next year you can grow to be Valley to live it. You do not need And through teaching you team leader, then manager, then Medium to read it. You could can really, really make a dif- CTO…” experience that right here in ference in this world. Back in Not. At. All. Quite the oppo- Switzerland. Many banks have 2012 I received a mail from a site, actually: you were, are and atrocious workplaces. Financial person who had attended one will be a software developer, institutions want you to vomit of my trainings. She used to that is, a relatively expensive code 15 hours a day, even if the work as an Adobe Flash devel- factory worker, whose tasks Swiss working laws explicitly oper. Remember ActionScript your managers would be happy forbid such treatments. Phar- and all that? Well, unsurprisingly to offshore, no matter what they maceutical companies want after 12 years of working as a tell you. you to write code to cheat test freelance Flash developer she Do not take a job just for results and to help them bypass suddenly found herself unem- the money. Software companies regulations. Startups want your ployed. Alone. With a baby to have become sweatshops where skin, working for 18 hours for feed. She told me in her mes- you are supposed to justify your no compensation, telling you sage that she had attended my absurdly high salary with insane bullshit like “because we give training, that she had enjoyed hours and unreasonable expec- you stock options” or “because it and also learnt something tations. And, at least in the case we are all team players.” useful, and that after that she of Switzerland, there is no work- It does not matter that you had found a job as a mobile web er union to help you if things go are Zach Holman and that you developer. She wrote to me to bad. Actually there are worker can claim in your CV that you lit- say thank you. unions in Switzerland, but they erally wrote Github from scratch: I cannot claim that I changed do not really care about situ- you will be fired for the pettiest the world, but I might have ations that will not land them of reasons. nudged it a little bit, into some- some kind of media exposure. It does not matter that the thing (hopefully) better. This Even worse, in most work- app brings more than half of your employer traffic and reve- nues; the API team will treat you and your ideas with contempt and sloppiness. I have been asked to work for free by very well-known people in the industry, some of them even featured in Wikipedia, and it is simply appalling. I will not give out their names, but I will prevent any junior from getting close to them, because people working without ethics do not deserve anyone’s brain.

hacker bits 21 age or preferred football team. End of the story. But it is not like that. It is not.

8. Send the elevator down If you are a white male, remem- ber all the privilege you have enjoyed since birth just because you were born that way. It is your responsibility to change the industry and its bias towards more inclusion. It is your duty to send the elevator down. Take conscious decisions Whenever an HR manag- myth, right? Well here is the in your life. Be aware of your er tells you “you must do this thing: it is not a myth, but it actions and their effect. Do not (whatever wrong thing in your does not work the way you think blush or become embarrassed frame of reference) because we it works. for changing your opinions. Say pay you a salary,” remember to It works, however, from the “I’m sorry” when required. Lis- answer the following: “you pay employer’s point of view: a “10x ten. Do not be a hotshot. Have me a salary, but I give you my Software Engineer” generates integrity and self-respect. brain in exchange, and I refuse worth 10 times whatever the Do not criticize or make to comply with this order.” employer pays. That means that fun of the technology choices And to top it all, they will put you, she or he gets 100 KCHF of your peers; for other people you in an open space, and for per year, but she or he are actu- will have their own reasons to some reason they will be proud ally creating a value worth over choose them, and they must about it. Open spaces are a can- a million francs. And of course, be respected. Be prepared to cer. They are without a doubt they get the bonuses at the change your mind at any time the worst possible office layout end of the fiscal year, because, through learning. One day you ever invented, and the least ap- you know, capitalism. Know might like Windows. One day propriate for software develop- your worth. Read Karl Marx and you might like Android. I am ment — or any type of brain work Thomas Piketty. Enough said. actually liking some parts of An- for that matter. Keep moving; be like the droid lately. And that is OK. Remember this: the fact that shark that keeps on swimming, you understand something does because your skills are extreme- 9. LLVM not imply that you have to agree ly valuable. Speak out your sal- Everybody is raving about Swift, to it. ary, say it out loud, blog about but in reality what I pay more Disobey authority. Say “fuck it, so that your peers know attention to these days is LLVM you, I won’t do what you tell me” how much their work is worth. itself. and change jobs. There are fan- Companies want you to shut I think LLVM is the most im- tastic workplaces out there; not up about that, so that women portant software project today, a lot, but they exist. I have been are paid 70% of what men are as measured in its long-term lucky enough to work in some paid. So speak up! Blog about it! impact. Objective-C blocks, Rust of them. Do not let a bad job kill Tweet it! & Swift (the two most loved, your enthusiasm. It is not worth I am making 135 KCHF per strongly typed and compiled it. Disobey and move on. year. That was my current sal- programming languages in the Or, better yet, become inde- ary. How about you? And you? 2016 StackOverflow developer pendent. The more we speak out, the survey), Dropbox Pyston, the less inequality there will be. Any Clang Static Analyser, ARC, Goo- 7. Know your worth person doing my job with my gle Souper, Emscripten, LLVM- You have probably heard about experience should get the same Sharp, Microsoft LLILC, Rubymo- the “10x Software Engineer” money, regardless of race, sex, tion, cheerp, watchOS apps, the

22 hacker bits Leave REST aside and em- brace Socket.io, ZeroMQ, Rab- bitMQ, Erlang, XMPP; explore realtime as the next step in app development. Realtime is not only for chat apps. Remove poll- ing from the equation forever. Oh, and start building bots around those APIs. Just saying.

12. Fight Complexity Simpler is better. Always. Re- member the KISS principle. And I do not mean only at the UI level, but all the way until the deepest layers of your code. Refactoring, unit tests, code reviews, pull requests, all of Android NDK, Metal, all of these at my face, literally. In both cas- these tools are at your disposal things were born out or powered es I followed my gut feeling and to make sure that the code you by LLVM. I guess things worked out well. ship is the simplest possible There are compilers using Follow your gut. You might architecture that works. This is LLVM as a backend for pretty be lucky, too. how you build resilient systems much all the most important lan- for the long term. guages of today. The .NET CLR 11. APIs are king will eventually interoperate with Great APIs enable great apps. If it, and Mono already uses it. the API sucks, the app will suck, Conclusion Facebook has tried to integrate too, no matter how beautiful the The most important thing to LLVM with HHVM, and WebKit design. remember is that your age does recently switched from LLVM to Remember that chunky is not matter. the new B3 JIT JavaScript com- better than chatty, and that piler. clients should be dumb; push as One of my sons said to me, LLVM is cross-platform, much logic as you can down to “Impossible, Dad. Mathe- cross-CPU-architecture, the API. maticians do all their best cross-language, cross-compil- Do not invent your own se- work by the time they’re er, cross-eyed-tested, free as in curity protocols. 40. And you’re over 80. It’s gratis and free as a bird. Learn a couple of server-side impossible for you to have Learn all you can about technologies, and make sure a good idea now.” LLVM. This is the galaxy where Node is one of those. true innovation is happening now. This is the foundation for the next 20 years.

10. Follow your gut I had the gut feeling .NET was going to be big when I watched its introduction in June 2000. I had the gut feeling the iP- hone was going to be big when I watched its introduction in 2007. In both cases people laughed

hacker bits 23 from the Year 2038 Problem and people will be really nervous about it. Of course I do not know what will happen 19 years from now, but I can tell you three things that will happen for sure:

1. Somebody will ask a question in Stack Overflow about how to filter email addresses using regular expressions. 2. Somebody will release a new JavaScript framework. 3. Somebody will build some- You will provide some anecdotal thing cool on top of LLVM. If you’re still awake and facts about 2016, for example alert mentally when you’re that it was the year when Da- And maybe you will remember over 80, you’ve got the ad- vid Bowie, Umberto Eco, Gato this talk with a smile. vantage that you’ve lived a Barbieri and Johan Cruyff passed Thank you so much for your long time and you’ve seen away, or when SQL Server was attention. This is the talk I gave many things, and you get made available in Linux, or at App Builders Switzerland on perspective. I’m 86 now, when Google AlphaGo beat a Go April 25th, 2016.  and it’s in the last few champion, or when the Panama years that I’ve had these Papers and the Turkish Citizen- ideas. New ideas come ship Database were leaked the along and you pick up bits same day, or when Google con- here and there, and the sidered using Swift for Android time is ripe now, whereas for the first time, or as the last it might not have been ripe year in which people enjoyed five or 10 years ago. this useless thing called privacy. We will be three years away Michael Atiyah Fields Medal and Abel Prize win- ner Mathematician, quoted in a Wired article.

As long as your heart tells you to keep on coding and building new things, you will be young, forever. In 2035, exactly 19 years from now, somebody will give a talk at a software conference similar to this one, starting like this: “Hi, I am 42 years old, and this is my story.” Hopefully one of you will be giving that presentation; otherwise, it will be an AI bot.

Reprinted with permission of the original author. First appeared at medium.freecodecamp.com.

24 hacker bits Spotlight

Adrian Kosmaczewski Adrian is a writer, a software developer and a teacher. He is the author of two books about mobile software develop- ment, and has shipped mobile, web and desktop apps for iOS, Android, Mac OS X, Windows and Linux since 1996. Adrian holds a Master in Information Technology from the University of Liverpool.

But lately I'm more interested on how these technologies enable social inclusion and solve actual problems in society.

What technology has you excit- day. The ones I find most inter- What is a personal habit that ed today? esting are Daring Fireball, Apple contributes to your success? There are many things that I World Today, All About Micro- Am I successful? That's a good keep an eye on, for example soft, The Monday Note, asymco, question. In any case, I guess Socket.io, LLVM and also the NSHipster, Presentation Zen and that if I do not enjoy what I'm latest revisions of C++. But lately Rands in Repose. I also enjoy doing, I move on. That's all. I'm more interested on how Swift and iOS newsletters, such these technologies enable social as Dave Verwer's iOS Dev Week- If there's one book you'd rec- inclusion and solve actual prob- ly, Natasha Murashev's Natasha ommend, what is it and why? lems in society. The Robot and This Week in Swift. Ficciones by Jorge Luis Borges. An absolutely astonishing col- What are 1-2 blogs, pod- Do you have an Internet re- lection of short stories that has casts, newsletters, etc. that source that you recommend, something for everyone. you use to stay on top of the such as Google Docs? Why do fast-changing and ever evolv- you recommend it? Where can people find out ing industry? more about you? I'm a heavy iCloud user. Lately it I'm not into podcasts, I'm more works much better than it used The article I published in Medi- of a reading guy so I have lots of to and I like the integration with um gives a fair amount of details entries in my RSS reader every the iOS and OS X app ecosystem. about me. Medium: @akosma, I also find Trello very useful. Twitter: @akosma 

hacker bits 25 Opinion

Implementers, solvers, and finders

By RANDALL KOUTNIK

was talking to a former stu- after antipattern that left him decision-making skills. Learn- dent when he brought up an sitting with the bill. ing that sub-par managers will I article written by a well-sea- Hearing about a dismal dictate your whole life is almost soned programmer regretting career like that is depressing. So as traumatizing as dealing with his choice of career. This fellow much so, that my student who said managers. had rejected the management previously was one of my most To make matters worse, path in order to stay in the enthusiastic programmers had his team had recently mulled coding trenches and as a result, turned morose. Who’d blame over their future career plans at ended up in some absolutely him? All he had to look forward lunch. None of them anticipated crummy situations. He writes to was a life filled with misery that they’d remain program- about management antipattern caused by other folks’ poor mers. As soon as they could,

26 hacker bits they were going to take the leap with this goal – and succeeded, tion where fantastic fanatic pro- into management, avoiding what eventually earning the rank of a grammers can’t see themselves our blogging friend referred to lead position (before the com- programming in three years, we as his “biggest regret”. pany ultimately collapsed, but need to couple our words to real I’ve talked to a lot of people that’s another story). world meaning. Instead of the who live, eat and breathe pro- During my last job hunt, I Jr/Sr nonsense (which already gramming. It’s hard to stand had two fantastic options: reeks of the years-of-experience next to them without hearing antipattern), why don’t we talk about the latest library or tool • Leader, with a few con- about what the job will actually they’re checking out, and how straints entail? Let’s define your job title what they’re building is awe- • Not Leader, with full auton- by how much autonomy your some and is going to revolu- omy day-to-day work gives you. tionize everything (or is useless Do you find that most of but _ aren’t neural networks This was it! I could capital- your time is simply closing cool!?!_). Almost all of them ize on my previous work and tickets, and your team rarely echoed the earlier sentiment – finally…not program. Something considers your input? Your title programming as a profession was wrong here – what did I is Solution Implementer. wasn’t for them. ultimately want? When it came Are you given general prob- How could this be? A group down to it, I wanted to write lems and left to your own devic- of people, granted the ability to code. I love building things and es on how they’re fixed? When do what they love for great pay I didn’t want to give that up. brainstorming, is your input and perks, all wanting to move Sure, startups mean doing a considered by your teammates? on? It all comes down to: little bit of everything but the You’re working as a Problem success case everyone’s working Solver. People want to make deci- towards means outsourcing all Are you given near-total sions rather than execute of your own work until you’ve autonomy in choosing what you them. forgotten all of the shortcuts to work on? Can you tell your boss your favorite IDE. I chose the lat- “That’s an interesting idea but Turns out science agrees on ter job, the one that would grant my time would be better spent this: People want power because me the most autonomy. elsewhere” (and not get fired they want autonomy. Most of on the spot)? You’re a Problem the time, folks desire to move Finder. up the career ladder not for pay, Implementers, Our regretful fellow author better title, or keys to the exec- solvers, and finders of the post spent most of his utive washroom (are those still time as an Implementer. People a thing?) but because they wish Could it be that we’ve utterly (often non-technical) assigned to be able to exercise greater mischaracterized how career concrete tasks without room for autonomy over their lives. development as a program- feedback or innovation. Every Psychologist Daniel Pink mer should work? The guiding one of his stories shares the agrees — he’d found that the trifecta of Junior, Regular, and same problem: He wasn’t given three qualities that contribute Senior is incredibly easy to game autonomy. most to workplace satisfaction (a misguided company offered I don’t mean to say that and overall productivity are au- me a senior level job just under everyone who’s at the Solution tonomy, mastery and purpose. a year into my career). A word Implementer level should imme- I too, was bitten by the ceases to be useful when we diately quit their jobs, or that “management = autonomy” bug. can’t agree on its purpose – title life as an Implementer de facto My original career goal was relativism means a given title means you’re a bad program- to rise up in the ranks of pro- can convey entirely separate mer. grammers, eventually crowning messages to different compa- Beginning programmers who myself king of my own startup, nies. Which is more impressive, are still learning the basic con- the ultimate in autonomy (or so a “Senior UI Engineer” or a “Ja- cepts will thrive as Implementers I thought). I carefully chose the vascript Architect?” if handed solutions matching work I did at each job to align If we’re to escape this situa- the challenge level they’re

hacker bits 27 willing to accept. The mere task of skills to learn – suddenly toolbox. Finders need to work of implementing something effective communication means with a variety of other folks provides plenty of opportunities a whole lot more than “follow- without swinging the “I’m smart to learn (in fact, I’d say it’s the ing the JIRA process correctly”. and because I said so” hammer only way to truly understand Solvers need to learn how to (otherwise they’re Brilliant Jerks). something). Beginners of all skill evangelize their favorite solu- Finders need autonomy, by levels will get lost if thrown at a tions and defend them against definition. Any job that puts problem with too big of a scope other Solvers who have different significant restraints on what a for them to handle. preferences. programmer can and can’t do One can’t remain a beginner Solver is an enormous is a poor fit for a Finder. Poor- forever. There needs to be a way growth area and the typical ly-managed startups love to hire for these implementers to level Solver may spend years making smart people and then tell them up. We, as a community, don’t mistakes, learning, and causing what to do in precise detail. No have an agreed-upon way to new catastrophes until their one wins. take budding programmers and knowledge grows to the point My hope is this post will hand them continually-increas- where they’re ready to make the create shared vocabulary. This ing challenges. The standard final leap to Finder. triumvirate of concepts can help practice in leveling up seems Mid-size startups (> 50 peo- great folks find the job that’s to be to quit and start hunting ple) are a great place for Solvers best for them. A company may for a new job at the next level. — there’s plenty of problems be honestly seeking an Imple- This is why my standing advice begging for solutions and often menter, and effectively com- to beginning programmers is to Solvers can branch out into municating that to a Solver or find a new job after six months areas that would be verboten Finder will save both parties a (hopefully in the same compa- to them at a larger, established lot of time. ny). company. As the startup grows, More importantly, I want pro- It can be difficult to tell if a so does their responsibility — grammers everywhere to realize company is actually looking for this is a common way for a Solv- that it’s possible to have auton- a Problem Solver or the work is er to grow into a Finder. Another omy while still writing code for a just Implementation in disguise. case is for a company to create living. Some may find fulfillment One org smell to look out for fertile ground for Finders and in leadership (I know I do, the is the ratio of programmers to recruit them directly. siren song has abated but is not project/product managers. I’ve The final stage of program- gone) but plenty of hackers out fallen for this, thinking I’d get to mer evolution is the Finder. there just want to make great take charge of a frontend when These folks are considered things. There’s hope for us yet! what they really wanted me to experts in their chosen domain Postscript: If this article rang do was slog through 17,000 (and are prudent about others). true to you and you feel like issues in JIRA. Determining the Writing Finder job descriptions you’re ready to level up, I’d love true culture of a company is is an exercise in futility. As my to hear from you. What brought troublesome, but you can start boss puts it: “I can’t tell you the you to your current job? What by interviewing your interviewer. specifics of what you’ll be doing changed? How are you looking On the other hand, if our here because your first task will for the job that fits you? programmer does land that Solv- be to figure that out.” Let me know at: isf at rkout- er job, they will start spreading A Finder will be able to nik.com.  their wings beyond the basics. anticipate problems before they At this point their opinion starts happen, usually because they’ve to mean something, and the been in that situation before. challenges they face take on a Finders are the canonical “Done new shape as their sphere of and get things smart” that Steve responsibility grows. Yegge likes to talk about. Empa- There’s an entirely new set thy is a critical key in a Finder’s

Reprinted with permission of the original author. First appeared at rkoutnik.com.

28 hacker bits Spotlight

Randall Koutnik Randall is a Senior UI Engineer at Netflix and holds a lot of strong opinions about Star Wars. He'd love to hear from you via [email protected].

I'm biased to real-time data processing, so RxJS is my favorite here.

What technology has you excit- (best I've found are on Slack). our concern to seem smart that ed today? The interactive nature means I we keep ourselves from making I work in JavaScript, so there's a can learn about things as well the effort to learn the things lot of exciting things going on. as get feedback on my current that'll make us smart. Angular 2 brings improvements work. It's the best way to learn to every area of frontend dev, (it's ok to ask dumb questions!). If there's one book you'd rec- compiling lessons learned from ommend, what is it and why? across the spectrum. RxJS and Do you have an Internet re- Oh wow, a zillion suggestions async iterators bring new power source that you recommend, just popped into my head. Ev- to some of the most difficult JS such as Google Docs? Why do eryone should read The Hitch- tasks. I'm biased to real-time you recommend it? hiker's Guide to the Galaxy and data processing, so RxJS is my Not really an Internet tool, but realize that life isn't as serious favorite here. I love git. As a simple commit/ as we make it out to be. push/merge thing, it works fine What are 1-2 blogs, pod- but once you dive into bisect, re- Where can people find out casts, newsletters, etc. that basing, revert and more, it’s one more about you? you use to stay on top of the of the best developer productivi- I write at rkoutnik.com fast-changing and ever evolv- ty tools out there. tweet as @rkoutnik and re- ing industry? spond to reader email at I'm subscribed to a few regard- What is a personal habit that [email protected].  ing JS/Node but the best tool contributes to your success? I've found for keeping up on Ask questions, especially dumb things is joining chat rooms ones. We get all wrapped up in

hacker bits 29 Interesting

20 lines of code that will beat A/B testing every time

By STEVE HANOV

/B testing is used far too look at the stats and figure out water. If the treatment works, often, for something that which group presses the button group B lost out. This sacrifice Aperforms so badly. It is more often. Sounds good, right? is made to get good data. But it defective by design: Segment The problem is staring you doesn't have to be this way. users into two groups. Show in the face. It is the same dilem- In recent years, hundreds of the A group the old, tried and ma faced by researchers admin- the brightest minds of modern true stuff. Show the B group the istering drug studies. During civilization have been hard at new whiz-bang design with the drug trials, you can only give work not curing cancer. Instead, bigger buttons and slightly dif- half the patients the lifesaving they have been refining tech- ferent copy. After a while, take a treatment. The others get sugar niques for getting you and me

30 hacker bits to click on banner ads. It has how every change you made of a percentage point of perfor- been working. Both Google and is doing and pick options. You mance. Microsoft are focusing on using don't have time to write ram- One strategy that has been more information about visitors bling blog entries about how shown to perform well time to predict what to show them. you got your site redesigned after time in practical problems Strangely, anything better than and changed this and that and it is the epsilon-greedy method. A/B testing is absent from main- worked or it didn't work. Let the We always keep track of the stream tools, including Google algorithm do its job. These 20 number of pulls of the lever and Analytics, and Google Website lines of code automatically finds the amount of rewards we have optimizer. I hope to change that the best choice quickly, and received from that lever. 10% of by raising awareness about bet- then uses it until it stops being the time, we choose a lever at ter techniques. the best choice. random. The other 90% of the With a simple 20-line change time, we choose the lever that to how A/B testing works, that has the highest expectation of you can implement today, you The multi-armed rewards. can always do better than A/B bandit problem testing — sometimes, two or three times better. This method The multi-armed bandit prob- Why does this work? has several good points: lem takes its terminology from a casino. You are faced with a Let's say we are choosing a wall of slot machines, each with colour for the "Buy now!" button. • It can reasonably handle The choices are orange, green, more than two options at its own lever. You suspect that some slot machines pay out or white. We initialize all three once.. e.g. A, B, C, D, E, F, choices to 1 win out of 1 try. It G... more frequently than others. How can you learn which ma- doesn't really matter what we • New options can be added or initialize them too, because the removed at any time. chine is the best, and get the most coins in the fewest trials? algorithm will adapt. So when Like many techniques in we start out, the internal test But the most enticing part data looks like this. is that you can set it and forget machine learning, the simplest it. If your time is really worth strategy is hard to beat. More $1000/hour, you really don't complicated techniques are have time to go back and check worth considering, but they may eke out only a few hundredths

def choose(): if math.random() < 0.1: # exploration! # choose a random lever 10% of the time. else: # exploitation! # for each lever, # calculate the expectation of reward. # This is the number of trials of the lever divided by the total reward # given by that lever. # choose the lever with the greatest expectation of reward. # increment the number of times the chosen lever has been played. # store test data in redis, choice in session key, etc..

def reward(choice, amount): # add the reward to the total for the given lever.

 Epsilon-greedy method

hacker bits 31 Then a web site visitor lost! The greedy algorithm will performance. Learning about the comes along and we have to always choose it forever now! other algorithms, such as UCB, show them a button. We choose But wait, let's see what hap- Boltzmann Exploration, and the first one with the highest pens if Orange is really the sub- methods that take context into expectation of winning. The optimal choice. Since the algo- account, is fascinating, but op- algorithm thinks they all work rithm now believes it is the best, tional if you just want something 100% of the time, so it chooses it will always be shown. That is, that works. the first one: orange. But, alas, until it stops working well. Then the visitor doesn't click on the the other choices start to look button. better. Wait a minute, why isn't everybody doing this? Statistics is hard for most people to understand. People Another visitor comes along. distrust things that they do not We definitely won't show them After many more visits, the understand, and they especially orange, since we think it only best choice, if there is one, will distrust machine learning algo- has a 50% chance of working. have been found, and will be rithms, even if they are simple. So we choose Green. They don't shown 90% of the time. Here are Mainstream tools don't support click. The same thing happens some results based on an actual this, because then you'd have for several more visitors, and web site that I have been work- to educate people about it, and we end up cycling through the ing on. We also have an estimate about statistics, and that is choices. In the process, we of the click through rate for hard. Some common objections refine our estimate of the click each choice. might be: through rate for each option downwards. • Showing the different op- tions at different rates will Edit: What about the skew the results. (No it won't. You always have an randomization? estimate of the click through I have not discussed the ran- rate for each choice). But suddenly, someone domization part. The random- clicks on the orange button! ization of 10% of trials forces • This won't adapt to change. Quickly, the browser makes an the algorithm to explore the (Your visitors probably don't Ajax call to our reward function options. It is a trade-off between change. But if you really $.ajax(url:"/reward?testnam- trying new things in hopes of want to, in the reward func- e=buy-button"); and our code something better, and sticking tion, multiply the old reward updates the results: with what it knows will work. value by a forgetting factor). There are several variations • This won't handle chang- of the epsilon-greedy strategy. ing several things at once In the epsilon-first strategy, you that depend on each-other. can explore 100% of the time (Agreed. Neither will A/B in the beginning and once you testing.) have a good sample, switch to When our intrepid web devel- pure-greedy. Alternatively, you • I won't know what the click oper sees this, he scratches his can have it decrease the amount is worth for 30 days so how head. What the F*? The orange of exploration as time passes. can I reward it?  button is the worst choice. Its The epsilon-greedy strategy font is tiny! The green button is that I have described is a good obviously the better one. All is balance between simplicity and

Reprinted with permission of the original author. First appeared at stevehanov.ca.

32 hacker bits Spotlight

Steve Hanov Steve can be found at various coffee shops in Waterloo, Ontario, where he writes code and occasionally responds to emails from customers of his web businesses webse- quencediagrams.com and zwibbler.com. He has three chil- dren, one wife, and two birds.

I am excited by the incredible change that everyone has the Internet in their pockets.

What technology has you excit- check the best of Hacker News dispersed them all to school and ed today? to get a sense of new develop- daycare, I need to be productive, I am excited by the incredible ments, but this is pure deca- getting everything I can done change that everyone has the dence. before I get the inevitable call Internet in their pockets. I am that one has a fever or a tummy always connected to my wife, Do you have an Internet re- ache. and when they are old enough, source that you recommend, my kids, not to mention the sum such as Google Docs? Why do If there's one book you'd rec- total of human knowledge. The you recommend it? ommend, what is it and why? way we interact is changing. I run my business through the I recommend two books: The I'm increasingly talking to my spreadsheets in Google Docs. Willpower Instinct and Predict- phone, asking it for quick an- Google Keep is wonderful for ably Irrational. With the two of swers. I hate when I have to look personal notes. I love Stripe, them, you will understand your- at the screen to do something. because I can watch my money self and other people. flow through it. What are 1-2 blogs, pod- Where can people find out casts, newsletters, etc. that What is a personal habit that more about you? you use to stay on top of the contributes to your success? I have written many interesting fast-changing and ever evolv- It is not habit, but circumstance tech articles on my blog steve- ing industry? that contributes to my success. hanov.ca. My secret is every I listen to the Startups For The Before having children, I would time I write one, I delete one, Rest of Us podcast to get moti- waste a lot of time. I read a lot, and so by now many of them are vation to work on things. When but produced little. With three good.  I have a rare spare moment, I children, the moment I have

hacker bits 33 Interview

Are Progressive Web Apps the future of the Internet? An interview with Henrik Joreteg

34 hacker bits Henrik Joreteg is a PWA developer, consultant, and edu- cator. He is the author of Human JavaScript and creator of Ampersand.js, SimpleWebRTC, Talky.io and over 200 JavaScript libraries. He's also spoken at O'Reilly's Fluent- Conf and FFConf.

ere at Hacker Bits, Progres- sual treatment by the Operating you tap my app icon, it will sive Web Apps (PWA) have System as if it were a fully native open immediately, every Hconsistently come up as a app. Meaning it has a home time, regardless of net- hot button topic among you, our screen icon, shows a splash work conditions. readers, and on social media. screen when opening, runs from 4. Native push notifications. But is PWA the real deal? Or is it cache first, etc. just another fad that’ll soon be You should also read Al- forgotten? ex’s post in which he coins the What technologies and tools To find out, we chat with phrase. are used to build PWAs? with Henrik Joreteg, a PWA 1. Application manifest expert who's been working with What are the top 3-4 things 2. Service Worker his clients to architect, build and that excite you about PWAs? 3. HTTPS… yup. Gotta do it train teams on building perfor- 1. We now have a way to or this stuff won’t work :) mant mobile web apps. write an app that’s treated as a first-class citizen by In last month's issue of Hacker an operating system with What are the top 3 challenges Bits, you briefly covered Pro- over a billion active users. preventing PWAs from being gressive Web Apps. Can you more broadly adopted today? 2. The tech required to do go over the basics and explain How far are we along? what is a Progressive Web App this is either supported, (PWA)? or being built by every 1. Awareness. There’s noth- browser vendor other than ing in the way at this point. To steal from Alex Russell, it’s Safari. I think we’re going to see just a website that took all the them popping up all over 3. The web can now be made right vitamins. It starts life in a the place in the latter half to be completely reliable. browser tab like any other site, of this year. but can progressively become an And network connection app. is optional. With Service- 2. Confusion. These things A bit more specifically, if Worker the web can now are hard to talk about: is it it meets the technical require- implement the same cache- an app? Is it a web app? Do ments and a user visits the app ing strategies previously users like them? again, they’ll be prompted by reserved for native apps. 3. It’s early but I think we’re the browser if they want to add Some people really focus going to see an absolute it to their home screen. From on the “offline-first” thing. explosion of them this year that point on, when a user But it’s not about being and next. opens the app from the home fully functional without a screen it receives the same vi- network connection – it’s about knowing that when

hacker bits 35 The reason I’m so bullish about this tech is because of how dramatically it seems to improve on-boarding and decrease cost of customer acquisition.

Can you tell us about one of install your 40mb app and log queued up while fully offline your experiences building back in there, you’ve already could be re-tried and complet- PWAs for your clients or your- got ‘em. This is why I think ed long after your app and the self? What is working well and businesses will flock to this tech browser has been closed. not so well? once we see more data about In the future this script can I can’t talk specifics about my business impact. be extended to do things like current client. But I can say that background geolocation track- the biggest challenge is the Lots of articles spotlight the ing, etc. Imagine being able to mind-shift required by devel- ServiceWorker. What is a Ser- build an app like “Runkeeper” opers and product alike. A lot viceWorker, and how does it fit entirely with web tech. of product leads don’t know into the world of PWAs? they want one yet or what it can ServiceWorker is a separate How are data storage and mean for them. JavaScript file that your web app offline capabilities dealt with Also, PWAs put the web can “register.” Once registered by PWAs? solidly in the realm of the “app” it acts as a proxy. All requests There’s a new ”CacheStorage“ in terms of architecture. Frankly, your app makes from that point API (which is also available as most web developers are not on (even to external domains) ”window.caches“ outside the used to building apps as fully go through that ServiceWorker worker). This is a Promise-based self-contained client side appli- proxy first! From that script you API optimized for storing/re- cations. This will take a bit of can control caches and choose trieving Request and Response time. whether to answer from cache objects and matching them to Ultimately, the reason I’m or network or both, or whatever their related URLs. so bullish about this tech is else you can dream up. because of how dramatically it In addition, ServiceWorker Since they are technically web seems to improve on-boarding runs in the background, which apps, how are search engine and decrease cost of customer means you can do interesting indexing and bookmarking acquisition. things like send it a push notifi- handled by PWAs? Rather than showing spam- cation that will be shown to the The story here is still evolving. my app banners and “please in- user even when the browser is But it’s very much like any Single stall our app” door slams, it just closed! Page App at this point. If you asks the users at a point when Other interesting features want your content indexed it’s they’re likely to want it and the are being added via Service- probably best to pre-render “install” is non-existent because Worker too. One such example as much of it on the server as they’re already using the app! is background sync where your possible. That said, GoogleBot There’s no, “please install”. service worker can keep trying a is pretty great at running JS. But Instead of shipping them off to request in the background until in reality, most people building an app store and hoping they’ll it resolves. Which means actions these types of experiences are

36 hacker bits This is about building completely reliable experiences with web tech...

building things for logged in What is a parting piece of Where can people find out users with personalized content advice to our readers looking more about you, and what is anyway. to get started learning and the best way for people to con- All this said, I would not building PWAs? nect with you? be in the least bit surprised if 1. Life will be easier if you I use Twitter as a professional at some point PWAs get pref- build your PWA as a set of tool and tweet almost exclusive- erential treatment by Google’s completely static assets. ly about tech stuff. So connect search algorithms. I hope this It makes it easier to know with me there: @HenrikJoreteg. happens because in my opinion, what you should cache, Since going independent last this would all but ensure wide etc. year, I’ve brought my blog back adoption. to life and will post my best 2. Try writing a ServiceWorker thoughts there. from scratch to get your What else do you think our If you’re interested in my head around it, but then readers should know about professional help, you can get in check out all the goodies PWAs? touch about consulting.  in: https://github.com/ The “offline” word is a distrac- GoogleChrome/sw-tool- tion, in my opinion. Frankly, so box. is the word “progressive.” This is about building completely 3. Right now all IoT stuff has reliable experiences with web a related native app. This tech and teaching users they simply will not scale when can rely on web apps for things there are hundreds of con- they normally think they’d want nected devices you want to native apps for. interact with. The web will win here, eventually, and PWAs are the logical way to interact with a world full of connected devices.

Interview was edited for brevity and clarity.

hacker bits 37 Programming

19 tips for everyday git use

By ALEX KRAS

’ve been using git full time for the past 4 years, 7. Remember the branch structure after a local and I wanted to share the most practical tips merge that I’ve learned along the way. Hopefully, it will I git merge --no-ff be useful to somebody out there. If you are completely new to git, I suggest 8. Fix your previous commit, instead of making reading Git Cheat Sheet first. This article is aimed a new commit at somebody who has been using git for three git commit --amend months or more. 9. Three stages in git, and how to move between them Table of contents git reset --hard HEAD and git status -s 10. Revert a commit, softly 1. Parameters for better logging git revert -n git log --oneline --graph 11. See diff-erence for the entire project (not 2. Log actual changes in a file just one file at a time) in a 3rd party diff tool git log -p filename git difftool -d 3. Only Log changes for some specific lines in 12. Ignore the white space file git diff -w git log -L 1,1:some-file.txt 13. Only “add” some changes from a file 4. Log changes not yet merged to the parent branch git add -p git log --no-merges master.. 14. Discover and zap those old branches 5. Extract a file from another branch git branch -a git show some-branch:some-file.js 15. Stash only some files 6. Some notes on rebasing git stash -p git pull --rebase 16. Good commit messages 17. Git Auto-completion

38 hacker bits 18. Create aliases for your most frequently used commands

19. Quickly find a commit that broke your feature (EXTRA AWESOME) git bisect

1. Parameters for better logging

Sample Command: git log --oneline --graph

Chances are, by now you’ve used git log. It sup- ports a number of command line parameters, which are very powerful, especially when used in combination. Here are the ones that I use the most:

• --author=“Alex Kras" Only show commits made by a certain author 2. Log actual changes in a file • --name-only Only show names of files that changed Sample Command: git log -p filename git log -p or git log -p filename lets you view • --oneline not only the commit message, author, and date, Show commit data compressed to one line but actual changes that took place in each com- mit. • --graph Show dependency tree for all commits Then you can use the regular less search command of “slash” followed by your search term • / --reverse to look for changes to a par- Show commits in reverse order (Oldest commit {{your-search-here}} ticular keyword over time. (Use lower case n to go first) to the next result, and upper case N to go to the • --after previous result). Show all commits that happened after certain date 3. Only log changes for some • --before Show all commits that happened before cer- specific lines in a file tain data Sample Command: git log -L 1,1:some-file.txt For example, I once had a manager who re- You can use git blame filename to find the person quired weekly reports submitted each Friday. So responsible for every line of the file. every Friday I would just run: git log --author="- Alex Kras" --after="1 week ago" --oneline, edit it a little and send it in to the manager for review. Git has a lot more command line parameters that are handy. Just run man git-log and see what it can do for you. If everything else fails, git has a --pretty pa- rameter that lets you create a highly customizable output.

hacker bits 39 git blame is a great tool, but sometimes it does You can do so via git show some-branch- not provide enough information. name:some-file-name.js, which would show the file in An alternative is provided by git log with a -L your terminal. flag. This flag allows you to specify particular lines You can also redirect the output to a tempo- in a file that you are interested in. Then Git would rary file, so you can perhaps open it up in a side only log changes relevant to those lines. It’s kind by side view in your editor of choice. of like git log -p with focus. git show some-branch-name:some-file-name.js > dele- teme.js git log -L 1,1:some-file.txt Note: If all you want to see is a diff between two files, you can simple run:

git diff some-branch some-filename.js

6. Some notes on rebasing

4. Log changes not yet merged to Sample: git pull -—rebase the parent branch We’ve talked about a lot of merge commits when working on a remote branch. Some of those com- Sample: git log --no-merges master.. mits can be avoided by using git rebase. Generally I consider rebasing to be an ad- If you ever worked on a long-lived branches, with vanced feature, and it’s probably best left for multiple people working on it, chances are you’ve another post. experienced numerous merges of the parent Even the git book has the following to say branch (i.e. master) into your feature branch. This about rebasing. makes it hard to see the changes that took place on the master branch vs. the changes that have been committed on the feature branch and which "Ahh, but the bliss of rebasing isn’t without have yet to be merged. its drawbacks, which can be summed up in a single line: git log --no-merges master.. will solve the issue. Note the --no-merges flag indicate to only show changes that have not been merged yet to Do not rebase commits that exist outside ANY branch, and the master.. option, indicates your repository. to only show changes that have not been merged If you follow that guideline, you’ll be fine. If to master branch. (You must include the .. after master). you don’t, people will hate you, and you’ll be scorned by friends and family." You can also do git show --no-merges master.. or git log -p --no-merges master.. (output is identi- cal) to see actual file changes that are have yet to https://git-scm.com/book/en/v2/Git-Branch- be merged. ing-Rebasing#The-Perils-of-Rebasing

5. Extract a file from another That being said, rebasing is not something to be afraid of either, rather something that you branch should do with care. Probably the best way to rebase is using inter- active rebasing, invoked via git rebase -i {{some Sample: git show some-branch:some-file.js commit hash}}. It will open up an editor, with Sometimes it is nice to take a pick at an entire file self-explanatory instruction. Since rebasing is out- on a different branch, without switching to this side of the scope of this article, I’ll leave it at that. branch.

40 hacker bits great clarity on how a series of commits may re- late to a particular task. If you ever merged a pull request on github or a similar tool, you will in fact be able to nicely see the merged branch history in git log --oneline --graph view. If you ever try to merge a local branch, into another local branch, you may notice git has flattened out the branch, making it show up as a straight line in git history. If you want to force git to keep branches his- tory, similarly to what you would see during a pull request, you can add a --no-ff flag, resulting in a nice commit history tree.

git merge --no-ff some-branch-name

One particular rebase that is very helpful is git pull --rebase. For example, imagine you are working on a local version of a master branch, and you made one small commit. At the same time, somebody else checked in a week worth of work onto the master branch. When you try to push your change, git tells you to do a git pull first, to resolve the conflict. Being a good citizen that you are, you do a git pull to end up with the following commit message auto generated by git. 8. Fix your previous commit, Merge remote-tracking branch ‘origin/master’ instead of making a new commit

Sample: While this is not a big deal and is completely safe, git commit --amend it does clutter log history a bit. This one is pretty straightforward. Let’s say you In this case, a valid alternative is to do a git made a commit and then realized you made a pull --rebase instead. typo. You could make a new commit with a “de- This will force git to first pull the changes, and scriptive” message typo. But there is a better way. then re-apply (rebase) your un-pushed commits on If you haven’t pushed to the remote branch top of the latest version of the remote branch, as yet, you can simply do the following: if they just took place. This will remove the need for merge and the ugly merge message. 1. Fix your typo 2. Stage the newly fixed file via git add some- 7. Remember the branch structure fixed-file.js 3. Run git commit --amend which would add the after a local merge most recent changes to your latest commit. It will also give you a chance to edit the com- mit message. Sample: git merge --no-ff 4. Push the clean branch to remote, when ready I like to create a new branch for every new bug If you are working on your own branch, you or feature. Among other benefits, it helps me get can fix commits even after you have pushed, you

hacker bits 41 would just have to do a git push -f (-f stands for 2. git reset {{some-commit-hash}} force), which would over-ride the history. But you Return to a particular point in history. All WOULD NOT want to do this on a branch that is changes made after this commit are moved being used by other people (as discussed in re- to “not yet staged for commit” stage. Mean- base section above). At that point, a “typo” com- ing you would have to run git add . and git mit, might be your best bet. commit to add them back in.

3. git reset --soft {{some-commit-hash}} 9. Three stages in git, and how to Return to a particular point in history. All changes made after this commit are moved move between them to “staged for commit” stage. Meaning you only need to run git commit to add them Sample: git reset --hard HEAD and git status -s back in.

As you may already know by now, a file in git can This may appear as useless information at be in 3 stages: first, but it is actually very handy when you are trying to move through different versions of the 1. Not staged for commit file. 2. Staged for commit Common use cases that I find myself using the 3. Committed reset are below:

You can see a long description of the files 1. I want to forget all the changes I’ve made, clean start and state they are in by running git status. You move a file from “not staged for commit” stage to git reset --hard HEAD (most common) “staged for commit” stage, by running git add file- 2. I want to edit, re-stage and re-commit files in or to add all files at once. name.js git add . some different order Another view that makes it much easier to git reset {{some-start-point-hash}} visualize the stages is invoked via git status -s where -s stand for short (I think), and would result 3. I just want to re-commit past 3 commits as in an output that looks like that: one big commit git reset --soft {{some-start-point-hash}}

Check out some files If you simply want to forget some local changes for some files, but at the same time want to keep changes made in other files, it is much easier to check out committed versions of the files that you Obviously, git status will not show files that want to forget, via: have already been committed, you can use git log to see those instead. :) git checkout forget-my-changes.js There are a couple of options available to you to move the files to a different stage. It’s like running git reset --hard but only on some of the files. Resetting the files As mentioned before you can also check out a There are 3 types of reset available in git. A reset different version of a file from another branch or allows you to return to a particular version in git commit. history.

git checkout some-branch-name file-name.js and 1. git reset --hard {{some-commit-hash}} git checkout {{some-commit-hash}} file-name.js Return to a particular point in history. All changes made after this commit are discard- You’ll notice that the checked out files will ed. be in a “staged for commit” stage. To move them back to “un-staged for commit” stage, you would

42 hacker bits have to do a git reset HEAD file-name.js. You can git difftool -d run git checkout file-name.js again, to return the file to its original state. Note that running git reset --hard HEAD file- name.js does not work. In general, moving through various stages in git is a bit confusing and the pattern is not always clear, which I hoped to reme- dy a bit with this section.

10. Revert a commit, softly

Sample: git revert -n

This one is handy if you want to undo a previ- ous commit or two, look at the changes, and see which ones might have caused a problem. 12. Ignore the white space Regular git revert will automatically re-com- mit reverted files, prompting you to write a new commit message. The -n flag tells git to take it Sample: git diff -w or git blame -w easy on committing for now, since all we want to do is look. Have you ever re-indented or re-formatted a file, only to realize that now git blame shows that you are responsible for everything in that file? 11. See diff-erence for the entire Turns out, git is smart enough to know the project (not just one file at a difference. You can invoke a lot of the commands (i.e. git diff, git blame) with a -w flag, and git will time) in a 3rd party diff tool ignore the white space changes.

Sample: git difftool -d 13. Only “add” some changes My favorite diff-ing program is Meld. I fell in love from a file with it during my Linux times, and I carry it with me. Sample: I am not trying to sell you on Meld, though. git add -p Chances are you have a diff-ing tool of choice Somebody at git must really like the flag, already, and git can work with it too, both as a -p because it always comes with some handy func- merge and as a diff tool. Simply run the following tionality. commands, making sure to replace Meld with your In case of , it allows you to interactive favorite diff tools of choice: git add select exactly what you want to be committed. That way you can logically organize your commits in an easy to read manner.

After that all you have to do is run git difftool some-file.js to see the changes in that program instead of the console. But some of the diff-ing tools (such as Meld) support full directory diffs. If you invoke git difftool with a -d flag, it will try to diff the entire folder, which could be really handy at times.

hacker bits 43 If you want to get really fancy, you can get a list of all the remote branches, and the list of last commits made on those branches by running:

git for-each-ref --sort=committerdate --for- mat='%(refname:short) * %(authorname) * %(commit- terdate:relative)' refs/remotes/ | column -t -s '*'

14. Discover and zap those old branches

Sample: git branch -a

It is common for a large number of remote branches to just hang around, some even after they have been merged into the master branch. If you are a neat freak (at least when it comes to Unfortunately, there is no easy way (that I code) like me, chances are they will irritate you a know of) to only show merged branches. So you little. might have to just compare the two outputs or You can see all of the remote branches by run- write a script to do it for you. ning git branch with the -a flag (show all branch- es) and the flag would only show branch- --merged 15. Stash only some files es that are fully merged into the master branch. You might want to run git fetch -p (fetch and purge old data) first, to make sure your data is up Sample: git stash —keep-index or git stash -p to date. If you don’t yet know what git stash does, it simply puts all your unsaved changes on a “git stack” of sorts. Then at a later time you can do git stash pop and your changes will be re-applied. You can also do git stash list to see all your stashed changes. Take a look at man git-stash for more options. One limitation of regular git stash is that it will stash all of the files at once. And sometimes it is handy to only stash some of the files, and keep the rest in your working tree.

44 hacker bits Remember the magic -p command? Well it’s For example: really handy with git stash as well. As you may have probably guessed by now, it will ask you • When applied this commit will Update README to see which chunks of changes you want to be file stashed. • When applied this commit will Add validation Make sure to hit ? while you are at it to see all for GET /user/:id API call available options. • When applied this commit will Revert commit 12345

17. Git auto-completion Git packages for some operating systems (i.e. Ubuntu) come with git auto completion enabled by default. If your operating system did not come with one(Mac doesn’t), you can easily enable it by following these guidelines:

https://git-scm.com/book/en/v1/Git-Basics-Tips- and-Tricks#Auto-Completion

18. Create aliases for your most frequently used commands TLDR; Use git or bash aliases for most commonly used long git commands Best way to use Git is via command line, and the best way to learn the command line is by Another handy trick, for stashing only some of doing everything the hard way first (typing every- the files, is to: thing out). After a while, however, it might be a good idea to track down your most used commands, and 1. add the files that you DO NOT want to get stashed (i.e. ) create an easier aliases for them. git add file1.js, file2.js Git comes with built in aliases, for example 2. Call git stash --keep-index. It will only stash files that have not been added. you can run the following command once: 3. Call git reset to un-stage the added files and continue your work. git config --global alias.l "log --oneline --graph" Which would create a new git alias named l, that 16. Good commit messages would allow you to run: A little while ago I came across a great article on how to write a good commit message. Check it git l instead of git log --oneline --graph out here: How to Write a Git Commit Message. Note that you can also append other parameters One rule that really stood out for me is, “every after the alias (i.e. git l --author="Alex"). good commit should be able to complete the fol- Another alternative, is good old Bash alias. lowing sentence”: For example, I have the following entry in my .bashrc file. When applied, this commit will: , allowing {{ YOUR COMMIT MESSAGE}} alias gil="git log --oneline --graph" me to use gil instead of the long command, which is even 2 character shorter than having to type git l. :).

hacker bits 45 19. Quickly find a commit that Since you divide the number of commits by half on every iteration, you are able to find your broke your feature (EXTRA bad commits in log(n) time (which is simply a “big AWESOME) O” speak for very fast). The actual commands you need to run to Sample: git bisect execute the full git bisect flow are: git bisect uses divide and conquer algorithm to find a broken commit among a large number of 1. git bisect start commits. let git know to start bisecting. Imagine yourself coming back to work after a week-long vacation. You pull the latest version of 2. git bisect good {{some-commit-hash}} the project only to find out that a feature that you let git know about a known good commit worked on right before you left is now broken. (i.e. last commit that you made before the You check the last commit that you’ve made vacation). before you left, and the feature appear to work 3. there. However, there has been over a hundred of git bisect bad {{some-commit-hash}} let git know about a known bad commit (i.e. other commits made after you left for your trip, the HEAD of the master branch). and you have no idea which of those commits git bisect (HEAD just means the last commit). broke your feature. bad HEAD At this point you would probably try to find 4. At this point git would check out a middle the bug that broke your feature and use git blame commit, and let you know to run your tests. on the breaking change to find the person to go yell at. 5. git bisect bad If the bug is hard to find, however, you could let git know that the feature does not work try to navigate your way through the commit in currently checked out commit. history, in attempt to pin point where things went bad. 6. git bisect good let git know that the feature does work in The second approach is exactly why git bisect is so handy. It will allow you to find the breaking currently checked out commit. change in the fastest time possible. 7. When the first bad commit is found, git So what does git bisect do? would let you know. At this point git bisect After you specify any known bad commit and is done. any known good commit, will split the git bisect 8. in-between commits in half, and check out a new git bisect reset returns you to the initial starting point of (nameless) branch in the middle commit to let git process, (i.e. the HEAD of the master you check if your future is broken at that point in bisect branch). time. Let's say the middle commit still works. You 9. git bisect log would then let git know that via git bisect good log the last git bisect that completed suc- command. Then you only have half of the com- cessfully. mits left to test. Git would then split the remaining commits in You can also automate the process by provid- half and into a new branch (again), letting you test ing git bisect with a script. You can read more the feature again. here: http://git-scm.com/docs/git-bisect#_bisect_ git bisect will continue to narrow down your run.  commits in a similar manner, until the first bad commit is found.

Reprinted with permission of the original author. First appeared at alexkras.com.

46 hacker bits Spotlight

Alex Kras Alex is a Software Engineer by day and Online Marketer by night. You can find his blog and learn more about him at alexkras.com.

The scale of the web and ability to reach billions of people continues to amaze me.

What technology has you excit- member of a Slack room where developer for 4 years, so I still ed today? a few of my former co-workers very much enjoy what I do, and I am at the point that I am like to share all kinds of web-re- I’m always eager to learn more. beginning to question all tech- lated links. I am a father of two, so I don't nology and realize that none of have as much time to invest in it is perfect. That being said, I Do you have an Internet re- reading and researching various am still very excited about the source that you recommend, technologies as I would like. But web. The scale of the web and such as Google Docs? Why do I try to take full advantage of ability to reach billions of people you recommend it? the free time that I have. I listen continues to amaze me. I've been pretty happy with to podcasts, watch PluralSight WorkFlowy lately for outlining courses, and read books at night on my Kindle. What are 1-2 blogs, pod- my blog ideas and what I want casts, newsletters, etc. that to write about. I also still use Evernote for regular notes. I've If there's one book you'd rec- you use to stay on top of the ommend, what is it and why? fast-changing and ever evolv- been a fan of Gmail for a very ing industry? long time. Even though I don't For web developers: Effective love PHP, I think Wordpress is JavaScript by David Herman. PluralSight and Coursera for an amazing project with a great longer videos and courses. For community. Where can people find out podcasts it's JavaScript Jabber, more about you? The Changelog and Data Skep- What is a personal habit that My blog at: alexkras.com. You tic. I also subscribe to JavaScript contributes to your success? Weekly and Hacker Newsletter. can also find me on Twitter at I also visit Hacker News fairly Continuous education and curi- @akras14.  often. Last but not least, I am a osity. I've only been a full-time

hacker bits 47 Opinion

It takes all kinds

By JUSTIN ETHEREDGE

48 hacker bits fter reading a blog post But at the end of the day, What are you provocatively called “To- they are tools. The only value optimizing for? Aday I accept that Rails is they have is in what you can yesterday’s software,” I felt the create with them. Your tool can Everyone is optimizing for need to reply. I’m not sure why, be safe, efficient, shiny, but if something different. Is Rails a I’m not going to convince any- no one uses it, it is just a dead good choice for every shop? No one of anything, definitely not lump of code. way. Is it a good choice for your the author of that post. These tools we have allow shop? I don’t know. What are I want to reply because Rails us to create amazing things. you optimizing for? Are you a is my current platform of choice, Many of these tools are quite big team that is looking for safe and let’s be honest, seeing a complex. They try to hide a lot tools that allow you to reliably blog post with a title like that of that from us, but at the end refactor and give you a lot of getting passed around makes of the day, modern web applica- compile time safety? Then Rails you squirm a little. I think it tions are complex beasts. would be a terrible choice. made me squirm in a good way, Anyone involved in the cre- Are you a small/medium de- because it caused me to step ation of a web application knows velopment shop that needs to be back and evaluate what I’m that there are so many moving able to stand up and maintain doing, and why. Enough with the parts and pieces involved that an application easily while lever- back story, on with the show… it is mind boggling. There is no aging a huge amount of commu-

The framework is there to provide us with a doctrine and the ecosystem that builds up around it is what makes it powerful.

It always comes back to way you could fit everything you nity code/knowledge to get that the tools. Everyone blames the need to build a website into a done? Then a framework like tools. And there is good reason single framework, even a frame- Rails/Django/Laravel might be for that. Tools empower us. work as large as Rails or Django. just the thing you need. Tools hold us back. Tools excite And you would never want it Alternatively, maybe all of us. Sharp tools allow us to stab that way, everyone needs to do your developers know Python, ourselves. Dull tools don’t allow something different. You need then go with Django! The whole us to get much done. Some a framework that is optimized point is that you should pick tools are optimized for safety. for what you’re trying to do. The tools/techniques that fit your Some are optimized for speed. framework is there to provide us team; don’t just grab the newest Some tools are optimized for with a doctrine and the ecosys- hippest tool off the shelf unless flexibility, others push you down tem that builds up around it is it solves some very concrete a happy path. what makes it powerful. problems you currently have, or

hacker bits 49 ...if you’re running into silly problems with your tools then you should be looking for solutions, not throw everything out and reboot.

you are going to feel some pain. them out, or they just lose their My problems aren’t Maybe a lot of pain. mind and flip out. And I don’t mean the kind Once you look for a solu- your problems of hand-wavy “we can do better” tion, you’ll often find that it I constantly find myself waxing type problems; I’m talking about was a problem in your workflow to other developers about how solid technical problems that all along, because more often we, as a group, seem to be stuck you can put your finger on. than not, broken tools don’t in the mindset that all develop- stick around in the open source ers have the same problems. world. Can’t say the same thing The tools and frameworks that Looking for for other ecosystems though. Facebook, Twitter, Google and something better, The whole point is, don’t etc. use must be the best, and throw out the baby with the because I want to be the best, or just different? bathwater. These frameworks I must use them. Well guess In the post I mentioned above are complex. Software is com- what, you don’t have the same it sounds like the author has a plex. Sometimes they don’t problems they do. They have a lot of frustration with his tool- play well together, but if you’re virtually unlimited amount of ing. I’m sure that is something running into silly problems with developer time; you probably that everyone has experienced. your tools then you should be don’t. I can’t speak to his exact issues, looking for solutions, not throw Would I ever tell you to not we don’t seem to have many everything out and reboot. use Elixir/Phoenix, Node.js, of the same issues, but that If you’re a consultant, then Revel, Iron, etc…? No, of course doesn’t mean they don’t exist. those types of reboots can more not; I don’t know what your Just as an anecdote though, easily occur, and are often very problems are. But what I would I have often found that devel- lucrative, but they are rarely tell you to do is to thoroughly opers working in a framework good for your clients. evaluate each one based on your for years get a ‘boiling the frog’ needs. What libraries do you moment where they just accept need? What are you willing to poor ergonomics in their envi- write yourself? What is the lon- ronment for years until someone gevity of the tools? What tools new comes along and points are available to you for deploy-

50 hacker bits I tend to be harsh sometimes on developers who always jump on the new shiny tool, but the reality is that we need those people.

ment/hosting/management/ ing to a bunch of loud consul- ecosystems. And one day, for troubleshooting? What is the tants and bloggers proclaiming what I do, another framework skill-set of your team? that they have the future in their will pop up that will be a better These are all critical ques- pocket. choice than Rails. And I’ll prob- tions to ask when evaluating ably move on to build amazing a platform, and if you’re not things with that framework. asking them then you probably It takes all kinds But guess what, when that don’t know what you’re getting I tend to be harsh sometimes on time comes, there will be some- yourself into. developers who always jump on body writing a blog post telling the new shiny tool, but the real- me my new platform is old news ity is that we need those people and I’ll quietly close my browser, Yesterday? Today? (even if I don’t want to have fight the urge to write a blog Tomorrow? to maintain their projects). We post, and get back to work. Just like I should have done today.  Is Rails yesterday’s software? need the trailblazers, because if Sure. So is PHP. So is C#. So is we didn’t, there wouldn’t be a Python. So is every web frame- trail for the rest of us to follow. work that has come before. It is If Rails didn’t have those mature. It doesn’t mean that it people 10 years ago then it isn’t today’s software, or even wouldn’t be anywhere near tomorrow’s. It just means that it where it is now. It never would has been around for a while. have been able to push through Are there better platforms those tough early years where out there? Depends on what running, deploying, hosting, and you’re doing. Are there better maintaining a Rails app was a frameworks for what we do? really painful process. Probably not. But I don’t know This is where a lot of these you and your problems; you frameworks are now, and that have to make these decisions on is exciting. I really hope to your own. Taking ownership of see many of them mature into that is always scarier than listen- stable/reliable platforms and

Reprinted with permission of the original author. First appeared at codethinked.com.

hacker bits 51 Programming When to rewrite from scratch: autopsy of a failed software

By UMER MANSOOR

t was winter of 2012. I was ny was poised for growth. Life things. We would finish up a working as a software develop- was great. feature, get it tested quickly and Ier in a small team at a startup. And then we made a huge move on to the next. We had a We had just released the first blunder and decided to rewrite shared office and I remember version of our software to a real the software. From scratch. software developers at other corporate customer. The devel- companies getting into lengthy opment finished right on sched- design and architecture debates ule. When we launched, I was Why we felt that and arguing for weeks over de- over the moon and very proud. rewrite from scratch sign patterns. It was extremely satisfying to Despite agile-on-steroids de- watch the system process couple was needed? sign, the original system wasn’t of millions of unique users a day We had written the original badly written and generally was and send out tens of millions of system with a gun to our heads. well structured. There were SMS messages. By summer, the We had to race to the finish line. some spaghetti code that carried company had real revenue. I got We weren’t having long design over from the company’s previ- promoted to software manager. discussions or review meetings ous proof of concept attempts We hired new guys. The compa- – we didn’t have time for such that we left untouched because

52 hacker bits it was working and we had no half-heartedly because we were • Systems rewritten from time. But instead of thinking digging its grave. We dodged scratch offer no new value to about incremental improve- new feature requests from the the user. To the engineering ments, we convinced ourselves customer as much as we can team, new technology and that we needed to rewrite from because we were going to throw buzzwords may sound cool scratch because: the old one away anyway. This but they are meaningless to contributed to delays and we customers if they don’t offer • The old code was bad and missed our January deadline. In new features that the cus- hard to maintain. fact, we missed it by 8 whole tomers need. months! • The “monolith java architec- But let’s skip to the end. • We missed real opportunities ture” was inadequate for our When the project was finally while we were focused on future needs of supporting finished, it looked great and met the rewrite. We had a very a very large operator with all the requirements. Load tests basic ‘Web Tool’ that the 60 million mobile users and showed that it can easily sup- customer used to look at multi-site deployments. port over 100 million users. The charts and reports. As they configuration was centralized became more involved, they • I wanted to try out new, and it had a beautiful UI tool to started asking for additional shiny technologies like look at charts and graphs. features such as real-time Apache Cassandra, Virtu- It was time to go and kill the charts, access-levels, etc. alization, Binary Protocols, old system and replace it with Because we weren’t interest- Service Oriented Architec- the new one… until the cus- ed in the old code and had ture, etc. tomer said “no” to the upgrade. no time anyway, we either rejected new requests or did We convinced the entire organi- It turned out that the original a bad job. As a result, the zation and the board and sadly, system had gained wide adop- customer stopped using the we got our wish. tion and their users had started relying on it. They wanted abso- tool and insisted on reports lutely no risks. Long story short, by email. Another lost op- The rewrite journey after months of back and forth, portunity was an opportunity we got nowhere. The project to build a robust Analytics The development officially was officially doomed. platform that was badly began in spring of 2012 and we needed. set end of January, 2013 as the release date. Because the vision Lessons learnt • I underestimated the effort was so grand, we needed even of maintaining the old sys- more people. I hired consultants • You should almost never, tem while the new one is in and a couple of remote develop- ever rewrite from scratch. development. We estimated ers in India. We rewrote for all the wrong 3-5 requests a month and However, we didn’t fully an- reasons. While parts of the got 3 times as many. ticipate the need to maintain the code were bad, we could original system in parallel with have easily fixed them with • We thought our code was new development and underes- refactoring if we had taken harder to read and maintain timated customer demands. Re- time to read and understand since we didn’t use proper member I said in the beginning the source code that was design patterns and prac- we had a real customer? written by other people. We tices that other developers The customer was one of had genuine concerns about spent days discussing. It the biggest mobile operators in the scalability and perfor- turned out that most pro- South America and once our sys- mance of the architecture fessional code I have seen tem had adoption from its users, to support more sophisti- in larger organizations is 2x they started making demands cated business logic, but we worse than what we had. So for changes and new features. could have introduced these we were dead wrong about So we had to continue updat- changes incrementally. that. ing the original system, albeit

hacker bits 53 When is rewrite the to learn a new technology or tions lose the appetite for language, they want to write the continuing budget drain answer? some code in it. While I’m that an incremental redesign Joel Spolsky made strong ar- not against it and it’s a sign creates. This loss of appetite guments against rewrite and of a good environment and is inevitable for a rewrite as suggests that one should never culture, you should take this well, but the sponsors will do it. I’m not so sure about it. into consideration and weigh be more inclined to contin- Sometimes incremental im- it against risks and opportu- ue, because they don’t want provements and refactoring are nities. to be split between a par- very difficult and the only way tially complete new system to understand the code is to Michael Meadows made excel- and a partially obsolete old rewrite it. Plus software develop- lent observations on when the system. ers love to write code and create “BIG” rewrite becomes necessary: new things – it’s boring to read • The users of the system are Technical someone else’s code and try to too attached to their “current understand their code and their • The coupling of components screens.” If this is the case, ‘mental abstractions’. But good is so high that changes to a you won’t have the license programmers are also good single component cannot be to improve a vital part of the maintainers. isolated from other compo- system (the front-end). A If you want to rewrite, do it nents. A redesign of a single redesign lets you circumvent for the right reasons and plan component results in a this problem, since they’re properly for the following: cascade of changes not only starting with something new. to adjacent components, but They’ll still insist on getting • The old code will still need indirectly to all components. “the same screens,” but you to be maintained, in some have a little more ammuni- cases, long after you release • The technology stack is so tion to push back. Keep in the new version. Maintaining complicated that future state mind that the total cost of two versions of code will design necessitates multi- redesigning incrementally require huge efforts and you ple infrastructure changes. is always higher than doing need to ask yourself if you This would be necessary in a a complete rewrite, but the have enough time and re- complete rewrite as well, but impact to the organization sources to justify that based if it’s required in an incre- is usually smaller. In my on the size of the project. mental redesign, then you opinion, if you can justify a lose that advantage. rewrite, and you have super- • Think about losing other op- star developers, then do it. portunities and prioritize. • Redesigning a component results in a complete rewrite Abandoning working proj- • Rewriting a big system is of that component anyway, ects is dangerous and we wasted riskier than smaller ones. because the existing design an enormous amount of money Ask yourself if you can is so fubar that there’s noth- and time duplicating working incrementally rewrite. We ing worth saving. Again, you functionality we already had, re- switched to a new database, lose the advantage if this is jected new features, irritated the became a ‘Service Oriented the case. customer and delayed ourselves Architecture’ and changed Political by years. If you are embarking our protocols to binary, all on a rewrite journey, all the at the same time. We could • The sponsors cannot be power to you, but make sure have introduced each of made to understand that you do it for the right reasons, these changes incrementally. an incremental redesign understand the risks and plan requires a long-term com- for it.  • Consider the developers’ mitment to the project. bias. When developers want Inevitably, most organiza-

Reprinted with permission of the original author. First appeared at codeahoy.com.

54 hacker bits Spotlight

Umer Mansoor Umer Mansoor is a software developer, living in San Fran- cisco, CA. He currently works for Glu Mobile as Platform Manager, building a cloud gaming backend. He previously served as the Head of Software for Starscriber where he built high performance telecommunications software. He blogs at CodeAhoy.com.

Machine learning hands down. Specifically predictive analytics to forecast the efficacy of mobile campaigns.

What technology has you excit- ed regularly these days but is successful :), but I would say ed today? full of extremely useful insight patience, staying hungry for Machine learning hands down. into software development and knowledge and taking full re- Specifically predictive analytics management. To stay up to date sponsibility for my actions have to forecast the efficacy of mo- on recent events, I follow Hacker helped me grow. I also try to bile campaigns. Google recently News and TechCrunch. read at least a couple of books a open sourced their machine month on technical and leader- learning library, TensorFlow, and Do you have an Internet re- ship subjects. it looks very promising. source that you recommend, such as Google Docs? Why do If there's one book you'd rec- you recommend it? ommend, what is it and why? What are 1-2 blogs, pod- casts, newsletters, etc. that I couldn't recommend GitHub It's tough. But if I had to pick you use to stay on top of the more. I've been using it for the one, I'd go for Peopleware: Pro- fast-changing and ever evolv- last 6 years and it's such a cool ductive Projects and Teams. It's ing industry? site and a great community. Re- an absolute gem and focuses on cently, I have been pasting lines building and growing productive I enjoy Scott Hanselman's blog, of source code into GitHub's software teams. even though it is heavy on search bar to find answers to my Microsoft technologies. I like questions in the form of code. Where can people find out his writing style and he cov- more about you? ers interesting topics. I highly What is a personal habit that I blog on CodeAhoy.com. I'm encourage everyone to read contributes to your success? Joel's blog which isn't updat- also on Twitter @codeahoy.  Don't really consider myself

hacker bits 55 Programming Clojure, the good parts

By ALLEN ROHNER

kid, somewhat. This title is around what 'the good parts' of If you use Clojure in significantly of course based on Douglas Clojure looks like. This article different applications, these rec- I Crockford's seminal work, is my take on what a good app ommendations might not apply JavaScript, The Good Parts, looks like. to you. which demonstrated that In several places I'll recom- Recommendations are split JavaScript isn't a terrible lan- mend specific libraries. While I into several categories: core lan- guage, if only you avoid the icky recommend that specific library, guage, libraries and deployment. parts. there are often competitor li- I'll also try to avoid uncon- This is my heavily opinion- braries with similar functionality, troversial advice that's been ated guide to what a "good" and most of the time getting the covered elsewhere, like 'avoid production Clojure app looks functionality is more important flatten' and 'don't (def) anywhere like in 2016. than that exact library, so feel but the top-level', etc. I love Clojure, and I've been free to substitute, as long as using it pretty much exclusively you're getting the same benefits. since 2009. In the 7 years I've To make my biases explicit, been using it professionally, a I mostly write webapps and data consensus has started to form analysis on servers in the cloud.

56 hacker bits Core the DB is error prone (The Two They should be returned from Generals Problem). constructor functions, or stored Avoid binding Failing to commit to the DB in Component. This means that clojure.core/binding is a code- is a Major Error, while failing to you should end up with only one smell. Avoid it. In almost all commit to the STM is typically piece of global state, the sys- cases, binding is used to sneak less so, because the Clojure pro- tem. extra arguments into a func- cess can be restarted and loaded tion, reducing its referential from the DB as the source of Avoid pmap transparency. Instead, pass truth. Therefore, the easiest way pmap has been subtly broken all arguments explicitly into a to avoid coordination problems since chunked seqs were in- function, which improves purity is to just have one source of troduced to the language, and and readability, and avoid issues truth, the database. it's parallelism is not as high as with multi-threaded behavior. If promised. Use reducers + fork/ you're dealing with optional ar- Use atoms, sparingly join, or core.async's pipeline, or guments, consider an extra arity By process of elimination, raw Java concurrency instead. of the function with an optional because I've just recommended map. avoiding binding, agent and Avoid metadata STM, that leaves only one core It's not always obvious which Avoid agents mutable-state construct, the functions will preserve metada- It's rare to see a problem that atom. Atoms are good, and ta, and which won't. As a Clojure can be precisely modeled by should be used, but treat them user since pre-1.0, I've long agents. Most of the instanc- like macros: only use them when stopped caring about "oh, assoc es I've used them have been they're the only tool available. in 1.x didn't preserve metadata, as hacks to get the specific but it did in 1.(inc x)". Metadata multi-threading properties I Avoid global mutable state is nice to have, for introspection want. These days, core.async In 2009, I would not have be- and working at the repl. As a can be used to more explicitly lieved how little global mutable bright line though, metadata model the desired behavior. state is used in my applications. should never be used to control The vast majority of your state program behavior. Avoid STM should be in the DB, or a queue, Like agent, it's rare to see a or Redis. I'm now at the point Exercise caution with futures problem that can be properly where Futures are great, but they're a modeled by STM, in production. potential footgun. There are a Most production apps will need few things to watch out for. to persist data in a database. It's (def foo (atom ...)) First, always always always rare that you can do 'real' work is a code smell. Most of the time use java.lang.Thread/setDe- in an STM commit that shouldn't when using atoms, they should faultUncaughtExceptionHandler. also be stored in the DB. Coordi- not be -ed at the top level. It looks something the code nating commits to both STM and def below.

(Thread/setDefaultUncaughtExceptionHandler (reify Thread$UncaughtExceptionHandler (uncaughtException [this thread throwable] (errorf throwable "Uncaught exception %s on thread %s" throwable thread)))) (Thread/setDefaultUncaughtExceptionHandler (reify Thread$UncaughtExceptionHandler (uncaughtException [this thread throwable] (errorf throwable "Uncaught exception %s on thread %s" throwable thread))))

 java.lang.Thread/setDefaultUncaughtExceptionHandler

hacker bits 57 This guarantees that if your fixes app startup. It fixes con- test, etc., they can use different future throws an exception (and figuration. It fixes staging vs. logging policies, while both are it will, eventually), that will be production woes. CircleCI's unit running in the same process at logged and recorded some- tests were a mess because of a the same time. Production sys- where. huge amount of with-redefs and tems log to Splunk or Loggly or Second, always consider binding to get testing behavior what have you, while tests only what you're doing inside the right. If the component under log to stdout, etc. future, and what would happen test used Component, there to the system if power was lost would be no need for redefin- Use clj-time while the future was running. ing at all. Literally thousands of clj-time is essential for readable Imagine you're running an lines of test fixtures would get code that interacts with dates. e-commerce shop, and a cus- dramatically simpler. Let's say you have a DB query tomer buys something, and then that takes a start and end date: we send them a confirmation Use Schema email in a future. The pseu- Schema All The Things. As (query (-> 7 time/days time/ago) do-code would look like: Emacs tells me, "Code never (time/now)) lies, comments [and docstrings] sometimes do". Schema can re- clj-time wraps Joda, which is (charge-credit-card! user duce the amount of doc strings excellent. Libraries for wrapping transaction) necessary on a function, and Java 8 Instant are probably good (future (send-confirmation-email schema-as-doc-strings are more too, I haven't used them though. transaction)) likely to be correct, because Use Clojure.test If power dies while the future they're executable (and there- Your tests don't need a cutesy is running, the customer might fore, verified). They completely DSL. Your tests especially do not not get their email. Not ideal. eliminate that annoyance in doc need eight different cutesy DSL. In general, futures are a place strings where the doc states Yes, clojure.test has warts. where transactional guarantees 'this argument takes a Foo', But it has well-known, im- are likely to be lost. In almost without every specifying what a mutable warts. Not having new all cases, if you're using a future Foo is. It can be used to handle releases is a feature of testing for side effects (sending email, input validation from 3rd par- libraries. calling 3rd party APIs, etc.), ties. It can be used to prove your New testing libraries are fun consider whether that action tests are valid (i.e. passing valid and exciting, until you find a should go into a job queue. Use data to the function under test). bug in your test library. clojure. futures for querying multiple Use core.async test works, and is battle tested data-sources in parallel, and use I've mentioned it several times in in a way that no other clojure durable queues for performing this post already, but testing library is. I've shipped side-effects asynchronously. core.async should be your default choice bugs to production on code that for most complex multi-thread- I thought was tested, because I Libraries ing tasks. didn't understand the way the testing DSL works. I've seen Some libraries I like, in no Use Timbre infinite loops in macros shipped particular order. Note that these Clojure programmers love to by the testing library, because recommendations are about li- make fun of the horrors that are the DSL was too cutesy and braries to use in apps you write. j.u.logging, logback and SLF4J. complex. I fully agree with Stuart Sierra's Just dump it all, and use Timbre. Never again, use the sim- position on library dependen- Timbre is Clojure[script]-only plest thing that solves the cies. logging, so it has no Java vesti- problem. gial tails, no XML, and no class- Use Component path weirdness. Don't wrap clj-http Seriously, Component is the Timbre plays well with This is kind of a meta point. single biggest improvement Component, so when you have Don't use libraries for 3rd party you can make to a large Clojure separate component systems, APIs that provide no value on codebase. It fixes testing. It one for development, one for top of your HTTP client. For ex-

58 hacker bits Typically, the only reason you'll need a plugin is to control (def stripe-api-endpoint "https://api.stripe.com") the classpath. Standard functions are much (defn stripe-api [auth path args] easier to write, test, run, and (http/request (str stripe-api-endpoint path) chain together. Chaining clojure (merge {:basic-auth auth} args))) functions is just do. Chaining lein plugins is lein do, which is  Using directly slower and awkward, and can't clj-http (easily) be done from the repl or other functions. ample, interacting with Stripe's server on one day and starting Prefer Clojure over build tools API is easy. Just write one helper on another day should have bit- In the last section, I said 'pre- fer Clojure functions over lein function that merges in whatever for-bit identical code". authentication the service needs, You will need to rollback, plugins'. Now I'm also saying 'prefer Clojure functions over and then just use clj-http direct- because you will deploy bad ly (see above). code at some point. You need to bash and most CLI tools'. Obvi- That is literally the entire- know that the prior version still ously some allowance needs to ty of what you need from a works, because you're already be made for tools that are very stripe API library. A library must rolling back production because hard to replace, but your asset provide significant value over of an error, and you really don't fingerprinting probably isn't one just writing your own, and most want your problems to get of them. Clojure is an incredibly libraries that wrap HTTP rest worse. powerful language. Most of the APIs don't. A few provide nice We improve repeatability by time, you'll get more power, features, like HTTP pagination, avoiding downloading or re- flexibility and insight into your but that code isn't that difficult solving anything mutable. Any build process if you use clojure code over command line tools. to write. (Actually, it'd be inter- scheme involving git or lein or For example, Rasterize's esting to see if there are REST apt-get when turning on a server asset compilation, fingerprinting patterns that can be abstracted is immediately suspect, and npm into a single clj-http higher-or- is right out! Downloading pre- and deploy to S3 are all standard der-function library). viously-resolved deps is better, Clojure functions, using less4j but still not as good as baking java.io and AWS libraries. The the deps directly into your arti- Rasterize static site generation Deployment fact. That guarantees that even (.md to .html, etc) is all clojure. if there is an npm-style disaster, These are functions that I can Build a single artifact your old build still works. run from the repl, and debug Whatever you're building, re- using standard clojure tools. I Avoid writing lein plugins leases should consist of a single haven't used boot in anger yet, During the lein days, plugins but I'm supportive of its philos- artifact. A.jar or .war or docker 1.x container or AMI or whatever were the standard way of add- ophy. it is, and it should be self-con- ing functionality to your build. tained, and reproducible. Your The combination of lein run process should not resolve or and :aliases has changed that. Conclusion download dependencies at run- Whenever possible, write a stan- And there we have it. A haphaz- time. Starting a production serv- dard clojure function, then add ard collection of poorly justified er should be simple, reliable and it to :aliases in your project.clj: opinions. Let me know if you repeatable. Reliable, meaning agree or disagree on Hacker "very little chance of failing" and {:aliases "build-foo" ["run" "-m" News.  repeatable, meaning "starting a "rasterize.build.foo/build-foo"]}

Reprinted with permission of the original author. First appeared at rasterize.io/blog/.

hacker bits 59 food bit *

Credit: By Matyáš Havel (Own work) [CC BY-SA 3.0], via Wikimedia Commons

Akutaq

lso known as Eskimo ice cream, akutaq, is a traditional food of the indigenous people of Alaska. Made from animal fat A(whale, reindeer or seal), berries and ground fish, akutaq is a highly nutritious survival food of the Arctic. It is made by whip- ping the fat until it is light and airy, and mixing in the berries and fish. The concoction is left to freeze in the cold until it resembles ice cream. This sweet and tart treat is usually served at celebra- tions and gatherings.

* FOOD BIT is where we, enthusiasts of all edibles, sneak in a fun fact about food.

HACKER BITS is the monthly magazine that gives you the hottest technology and startup stories crowdsourced by the readers of Hacker News. We select from the top voted stories for you and publish them in an easy-to-read magazine format.

Get HACKER BITS delivered to your inbox every month! For more, visit hackerbits.com.