log.nikhil.io

28 things tagged “programming”

Functions, Monoids, Functors, Monads

Started with this blog post about why one would need a monad (from a typing standpoint.) Then watched “What the 𝒇 is a Monad” which made a lot of things clear. Then watched this excellent, excellent talk on Lambda Calculus (with JS and Haskell code!) by Gabriel Lebec.

Finished with a quick practical, toy example by @mpjme and this Scala horror-show (to me.)

Process and Tooling

I thought using loops was cheating, so I programmed my own using samples. I then thought using samples was cheating, so I recorded real drums. I then thought that programming it was cheating, so I learned to play drums for real. I then thought using bought drums was cheating, so I learned to make my own. I then thought using premade skins was cheating, so I killed a goat and skinned it. I then thought that that was cheating too, so I grew my own goat from a baby goat. I also think that is cheating, but I’m not sure where to go from here. I haven’t made any music lately, what with the goat farming and all.

I’ve made this mistake all too often, especially when trying to learn something new.

Things that quote kinda reminds me of:

Dank Typefaces

Was looking try something other than my beloved Operator Mono and came across Dank Mono which claims to be a “rather special coding font.” I love it. Looks like the cooler twin of Inconsolata. I remain quite tickled by how many of my co-workers find the italic variants of monospaced fonts ‘disturbing’ when they look at my screen.

Dank Mono Sample

State, Coupling, Complexity, & Code

Dependencies (coupling) is an important concern to address, but it’s only 1 of 4 criteria that I consider and it’s not the most important one. I try to optimize my code around reducing state, coupling, complexity and code, in that order.

I’m willing to add increased coupling if it makes my code more stateless.

I’m willing to make it more complex if it reduces coupling.

And I’m willing to duplicate code if it makes the code less complex.

Only if it doesn’t increase state, coupling or complexity do I dedup code.

The reason I put stateless code as the highest priority is it’s the easiest to reason about. Stateless logic functions the same whether run normally, in parallel or distributed. It’s the easiest to test, since it requires very little setup code. And it’s the easiest to scale up, since you just run another copy of it. Once you introduce state, your life gets significantly harder.

I think the reason that novice programmers optimize around code reduction is that it’s the easiest of the 4 to spot. The other 3 are much more subtle and subjective and so will require greater experience to spot. But learning those priorities, in that order, has made me a significantly better developer.

crun1r on HackerNews (emphases and formatting mine.)

❣️


Jan 12 On “incidental duplication”:

I’ve usually heard this phenomenon called “incidental duplication”, and it’s something I find myself teaching junior engineers about quite often.

There are a lot of situations where 3-5 lines of many methods follow basically the same pattern, and it can be aggravating to look at. “Don’t repeat yourself!” Right?

So you try to extract that boilerplate into a method, and it’s fine until the very next change. Then you need to start passing options and configuration into your helper method… and before long your helper method is extremely difficult to reason about, because it’s actually handling a dozen cases that are superficially similar but full of important differences in the details.

I encourage my devs to follow a rule of thumb: don’t extract repetitive code right away, try and build the feature you’re working on with the duplication in place first. Let the code go through a few evolutions and waves of change. Then one of two things are likely to happen:

  1. you find that the code doesn’t look so repetitive anymore, or,
  2. you hit a bug where you needed to make the same change to the boilerplate in six places and you missed one.

In scenario 1, you can sigh and say “yeah it turned out to be incidental duplication, it’s not bothering me anymore.” In scenario 2, it’s probably time for a careful refactoring to pull out the bits that have proven to be identical (and, importantly, must be identical across all of the instances of the code).

burlesona on HackerNews (emphasis and formatting mine.)

Whatever. I say we continue to abstract away and make better and better hammer factories and beam at our sophistication in creating unnecessary complexity #jobsecurity

Data, Data, Data

Linus Torvalds on git

I’d also like to point out that unlike every single horror I’ve ever witnessed when looking closer at SCM products, git actually has a simple design, with stable and reasonably well-documented data structures. In fact, I’m a huge proponent of designing your code around the data, rather than the other way around, and I think it’s one of the reasons git has been fairly successful

[. . .]

I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad programmers worry about the code. Good programmers worry about data structures and their relationships.

Two Levels of Not Giving a Fuck

No Code is the best way to write secure and reliable applications. Write nothing; deploy nowhere.

Start by not writing any code.

Brilliant. I love both the presence and contents of the Dockerfile in that repo. As is always the case with such projects, the issues and pull requests are 💯

And if one is tempted to go against the tenets of No Code, there’s always my beloved fuckitpy, a (strangely well-thought-out) “Python error steamroller”1:

@fuckit
def buggy_function():
    problem_solved

@fuckit
class BuggyClass(object):
    def __init__(self):
        everything_works_now

And:

This module is like violence: if it doesn’t work, you just need more of it.

  1. Inspired by FuckitJS. ↩︎

Simpler Gmail

Michael Leggett, lead designer of Gmail from 2008-2012

“It’s like Lucky Charms got spewed all over the screen,” he says to me, as he scrolls through his inbox. It’s true. Folders, contacts, Google apps like Docs and Drive–and at least half a dozen notifications–all clutter Gmail at any given moment. And of course, there’s that massive Gmail logo that sits in the upper left-hand corner of the screen. Just in case you forgot that you just typed “gmail.com” into your browser bar three seconds ago. “Go look at any desktop app and tell me how many have a huge fucking logo in the top left,” rants Leggett. “C’mon. It’s pure ego, pure bullshit. Drop the logo. Give me a break.”

Fast Company, “The former lead designer of Gmail just fixed Gmail on his own”

So he made this plugin for Chrome and Firefox that cuts out all the terrible visual noise of Gmail. I’m never uninstalling this one.

And while I’m on the subject, who signed off on this disaster?

Because we all know that the only way to attact attention to a UI element is to adorn it with a big blue goddamn fucking tumor.

The Korn Shell

Good talk by Siteshwar Vashisht at FOSDEM 2019 on maintaining the Korn shell and old codebases in general. I came by his work while reading up on the fish shell. Featured this nugget

He talks about how they removed dead/inapplicable code and micro-optimizations, refactored a lot of legacy code, improved tests, switched to a new build and CI system, and so on.

Began with this baffling one-liner that won the International Obfuscated C Contest in 1987

main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}

And reminded me of this Aaron Sorkin-esque story about David Korn which I heard via BLN

Greg Sullivan, a MicroSoft product manager (henceforth MPM), was holding forth on a forthcoming product that will provide Unix style scripting and shell services on NT for compatibility and to leverage UNIX expertise that moves to the NT platform. The product suite includes the MKS (Mortise Kern Systems) windowing Korn shell, a windowing Perl, and lots of goodies like awk, sed and grep. It actually fills a nice niche for which other products (like the MKS suite) have either been too highly priced or not well enough integrated.
An older man, probably mid-50s, stands up in the back of the room and asserts that Microsoft could have done better with their choice of Korn shell. He asks if they had considered others that are more compatible with existing UNIX versions of KSH.

The MPM said that the MKS shell was pretty compatible and should be able to run all UNIX scripts.

The questioner again asserted that the MKS shell was not very compatible and didn’t do a lot of things right that are defined in the KSH language spec. The MPM asserted again that the shell was pretty compatible and should work quite well.

This assertion and counter assertion went back and forth for a bit, when another fellow member of the audience announced to the MPM that the questioner was, in fact David Korn of AT&T (now Lucent) Bell Labs. (DavidKorn is the author of the KornShell).

Uproarious laughter burst forth from the audience, and it was one of the only times that I have seen a (by then pink cheeked) MPM lost for words or momentarily lacking the usual unflappable confidence. So, what’s a body to do when Microsoft reality collides with everyone else’s?

Game of Thrones Ratings

Via Rotten Tomatoes and with the awesome ChartJS. Dots are episodes, contiguous lines are seasons (static version.)

A search for episode titles on GitHub yielded this indescribably amazing, mostly hand-curated GoT Dataset by Jeffrey Lancaster (who published a Medium article describing his process. Has a Stranger Things dataset as well.)

Update: MFW watching the final episode.

Data, Data, Data

Vicki Boykis’ excellent article on every aspect of ‘Data Science’ I can think of: a little history, employment prospects, skills, education, and continuous learning.

It would appear that more than half the job, at least, is wrangling (replicating, cleaning, imputing, transferring, understanding, augmenting) data. It’s boring and super-important so, of course, is the least favorite thing 🙃

Source

A Lisp Interpreter in Python

Peter Norvig: (How to Write a (Lisp) Interpreter (in Python)).

See also: HyLang. Looks super cool and always makes me wonder if anyone’s ever used it in production.

JavaScript Delenda Est

Back in the second century BC, Cato the Elder ended his speeches with the phrase ‘Carthago delenda est,’ which is to say, ‘Carthage must be destroyed.’ It didn’t matter what the ostensible topic of the speech was: above all, Carthage must be destroyed.

My opinion towards JavaScript is much like Cato’s towards Carthage: it must be rooted out, eliminated and destroyed entirely. I don’t know if I’d go quite so far as to say that the fundamental challenge of mass computing is the final destruction of JavaScript — but I want to say it, even though it’s false.

JavaScript is a pox, a disaster, a shame. It is the most embarrassingly bad thing to become popular in computing since Windows 3.1. Its one virtue (that it’s on every client device) is outshone by its plethora of flaws in much the same way that a matchstick is outshone by the sun, the stars and the primordial energy of the Big Bang added together.

JavaScript is the XML, the Yugo, the Therac-25 of programming languages. The sheer amount of human effort which has been expended working around its fundamental flaws instead of advancing the development of mankind is astounding. The fact that people would take this paragon of wasted opportunity and use it on the server side, where there are so many better alternatives (to a first approximation, every other programming language ever used), is utterly appalling.

JavaScript delenda est.

I don’t know what my newfound affection for it says about me. Via HackerNews.

Assistant Executive for the Task Force on Employee Services

Via GLP, a University Title Generator that generates “prestigious” titles and associated salaries. A few random gems

  • Associate Coordinator of the Subcommittee for Community Services
  • Deputy Vice President of the Office of Alumni Planning
  • Provost for the Subcommittee for Investor Diversity
  • Vice Chair of the Subcommittee for Donor Technology

Alan Kay on OOP

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I’m not aware of them.

Dr. Alan Kay on the Meaning of “Object-Oriented Programming”

So… Erlang? (RIP Joe Armstrong 🙏) And that was before this

(I’m not against types, but I don’t know of any type systems that aren’t a complete pain, so I still like dynamic typing.)

Indeed, Dr. Kay.

CVS Receipt Generator

Garrett Whisten made a most amazing CVS receipt generator. He even wrote a scraper that gets real product names off their website 🙏 🙌

CSS Still Life

A pure CSS still life by Ben Evans who appears to be working on an online story with pure CSS illustrations as well. Via Deepu.

The "Not Invented Here Syndrome"

In programming, it is also common to refer to the “NIH syndrome” as the tendency towards reinventing the wheel (reimplementing something that is already available) based on the belief that in-house developments are inherently better suited, more secure, more controlled, quicker to develop, and incur lower overall cost (including maintenance cost) than using existing implementations. In-house developments are often collaborative with each other. When two in-house developments come together, it is informally known as “computer incest.”

Wikipedia

Found when I was looking for a dependency-free XML-to-JSON parser wherein the author notes the “fine NIH tradition of JavaScript developers everywhere.” Reminded me of this

Via

Input

A highly configurable, free-for-private-use typeface

Node Modules

For a single project I made the mistake of working on in my Dropbox folder:

Wonder what the downsides are to hardlinking by default. And, fundamentally, why creating an amazing, Python-like standard library is such an intractable problem in the first place.

[. . .] core-js is also utils library, quite a big one honestly! It has so many functions inside I bet a lot of other packages will be using it!

Not really. Only babel-runtime has it in its deps. Oopsie.
And returning to the starting point, cli uses only 3 (trivial) methods from common-tags — stripIndents, stripIndent, oneLine. Oopsie daisy.

In order to use these 3 methods node_modules needs 1826 files. And that’s just 4 of mentioned 976 installed packages.

– Mateusz Morszczyzna, What’s really wrong with node_modules and why this is your fault

🤦‍♂️ The portion of the article that listed functionally similar packages and is-* packages was particularly dismaying. As he points out, there’s a good reason why jQuery and lodash are as immensely popular as they are1.

  1. Was wondering if we’ll ever get back to the magic of hand-crafted web pages and found this article which led me to this modern Geocities clone 💖 ↩︎

Clay and Lego

Winter Coding Challenges

Literary Clock

Made a “Literary Clock” inspired by Jaap Meijer’s repurposing of an old Kindle. Might not be a bad use for an old iPad. Reminds me that I need to get Mark Formanek’s Standard Time onto a Raspberry Pi at some point.

08/24/18 There’s an app (of course)

Standard Time by Mark Formanek

History of Java

Saw this minor dis by Safari

and then this video on the history of Java. Also by the author: something of a tribute to Flash (RIP.)

Desperation

margin: 0;
padding: 0;
...
margin: 0 !important;
padding: 0 !important;
...
sudo margin: 0 !important;
sudo padding: 0 !important

via @thebarrytone

Programming Typefaces with Ligatures

This project adds ligatures to Operator Mono, my favorite coding typeface

lt="Ligatures with Operator Mono)

😍

Fira Code is also very beautiful and ships with ligatures

lt="Ligatures with Operator Mono)

A Week of Frontend Development

Python Environment Management

XKCD on Python Environments

XKCD. Add to the mix

Then there’s Python’s packaging and distribution kerfuffle…

The AWK Programming Language

Peruse from time to time to learn more than ye olde {print $3}