Iteration is part of the bread and butter of any programming
language, and this is the case in functional programming just as
much as in imperative programming, but how is it possible to iterate
without for, foreach or while?
What is a species? It’s a question that has agonized scientists
since well before Darwin. With some exceptions, the thinking has
landed on an evidently firm reproductive barrier: Members of
different species don’t mate. If they do, their offspring are
sterile and can’t contribute to future generations. The reproductive
barrier has thus created a useful demarcation of “what is a
species”—until a deep dive into butterflies showed otherwise.
Go‘s interfaces and “duck typing” makes it
very easy to create simple mock or stub implementations of a
dependency for testing. This has not dissuaded a number of people
from writing generalized mocking libraries such as
Here I want to describe a simple alternative pattern I frequently
use when writing tests for an interface, that I think is generally
applicable to many use cases.
Why is Learning Functional Programming So Damned Hard?
My Functional Programming journey was filled with dead ends, false
starts, failed attempts and frustration. And I suspect that I’m not
alone in this struggle. So why is this a common problem and what can
be done about it? And how can you avoid the these same pitfalls?
A DSL, short for Domain Specific Language, can be explained as a
special kind of API that focuses on providing a simple syntax that's
tailored to working within a specific domain. Rather than being
complete stand-alone languages - like Swift is - DSLs are often
hosted in other languages, and as such, need to use a grammar that's
also perfectly valid in their host language.
Principal Components Analysis (PCA) – Better Explained
Principal Components Analysis (PCA) is an algorithm to transform the
columns of a dataset into a new set of features called Principal
Components. By doing this, a large chunk of the information across
the full dataset is effectively compressed in fewer feature
columns. This enables dimensionality reduction and ability to
visualize the separation of classes or clusters if any.
In this tutorial, I will first implement PCA with scikit-learn,
then, I will discuss the step-by-step implementation with code and
the complete concept behind the PCA algorithm in an easy to
2019-12-02 What is Functional Programming? and Property Wrappers in Swift 5
What is Functional Programming?
Functional Programming is, like Object Oriented Programming (OOP), a
programming paradigm. There isn't a formal agreed-upon definition of
what FP entails, but there are two core concepts most people would
agree are central to the paradigm:
Avoiding mutating state and side-effects
Using functions as the central building block of programs
Shell globs allow one to specify set of filenames with wildcard
characters. This is really useful, but they have some rather
unintuitive functions that could surprise you, and even cause big
problems if you're unlucky enough.
This week, let’s continue exploring the topic of configurable
that was covered earlier this year — by taking a look at how setting
up a plugin-based architecture can help us keep a library or piece
of functionality as narrow and as small as possible, while still
enabling it to be extended and tailored for more specific use cases.
Building websites is programming. Writing HTML and CSS is
programming. I am a programmer, and if you're here, reading
CSS-Tricks, chances are you're a programmer, too.
The thing is, the details in programming layout with CSS are
different, for example, than the details in programming API
endpoints with Ruby. Or machine learning with Python. Or programming
a browser engine with C++.
But those differences are details! A lot of details, but
still... details. It's all programming.
One thing I like to do to improve the command-line programs I
maintain is to make them aware of whether they’re being run
interactively. In this post I’ll show off an easy trick to make
programs running interactively more usable.
Version 12 of PostgreSQL is not exactly fresh out of the oven, as
the first minor release was already announced. However, I think it’s
fair to say that this version can be still considered fresh for most
users, and surely only a small percentage of users has upgraded. So
I think it makes sense to go over some new features.
This paper is an attempt to explain all the matrix calculus you need
in order to understand the training of deep neural networks. We
assume no math knowledge beyond what you learned in calculus 1, and
provide links to help you refresh the necessary math where
needed. Note that you do not need to understand this material before
you start learning to train and use deep learning in practice;
rather, this material is for those who are already familiar with the
basics of neural networks, and wish to deepen their understanding of
the underlying math.
This post is inspired by something that I see crop up now and again
in discussions with other Maths teachers. It usually manifests
itself as a rallying cry to use ≡ in place of = in identities and
reserve = for equations. My standard response is to mutter something
about identities being equations and leave it at that. But in the
latest round, Jemma Sherwood
challenged me, in the nicest possible way, to explain a bit
further. This is that explanation.
Modules are nothing but files containing Python code. As your
program gets bigger, it becomes hard to maintain if you keep it in a
single file. Modules in Python are a way to re-factor your code into
multiples files and referring those files in your main program.
A Package in Python refers to a collection of modules
categorized under one logical grouping.
I'm going to preach the wonders of Python dataclasses, but for
reasons of interested to those who have already gone down the
delightful rabbit-hole of typed Python. So let me start with a quick
plug for mypy if you haven't heard about it.
Learning Go has been a fun journey, and when you’re used to writing
a mainstream language such as Java or C# the learning curve isn’t
that steep. But there are some things I had to actively unlearn when
learning Go. Most of the things here are not harmful to your code at
all, and the code functions pretty much as intended anyway. The
compiler will not come shouting at you, so perhaps the worst that
could happen would be a nitpick comment on a code review. 😃
One of the most powerful aspects of Swift is just how much
flexibility it gives us when it comes to how APIs can be
designed. Not only does that flexibility enable us to define
functions and types that are easier to understand and use — it also
lets us create APIs that give a very lightweight first impression,
while still progressively disclosing more power and complexity if
In the complex world of web development, as the popularity of
frontend framework such as React and Vue increase, Python is left to
exist to be the language of a backend framework such as Flask and
Django. Django is a fullstack web framework with built in ORM, user
management, template renderer and tons of plug and use
plugins. While Flask, Sanic are micro framework which are designed
to stay lean and fast. So what are the key point developers should
consider when choosing their next project’s backend framework?
After midnight I started in The War
the second book in The Great God's War, by Stephen R. Donaldson.
Modern Networking in Swift 5
Swift 5 system frameworks already provide us with all the tools that
we need to write concise networking layer. In this article we’ll
implement a promise-based networking agent by using vanilla Swift 5
APIs: Codable, URLSession and the Combine framework. To battle-test
our networking layer, we’ll practice with several real-world
examples that query Github REST API and synchronize the HTTP
requests in chain and in parallel.
When starting to write a new class, struct, or other type, we most
often have a very specific goal or use case in mind. We might need a
new model to represent some data that we’re working with, or we
might want to encapsulate a piece of logic that’s tailored for a new
feature that we’re building.
However, over time, we quite often find ourselves wanting to use a
highly similar version of that same type or logic, but for something
entirely different. We might want to reuse an existing model, but
handle it in a slightly different way — or we could be looking to
accomplish a task that’s very similar to something we’ve already
solved, but with a different type of result.
The question then becomes — how to take our existing code, and
refactor it to make it more generic and reusable — without ending up
with something messy or unfocused. This week, let’s take a look at a
technique for doing just that — that involves making certain types
After midnight I finished Salvation
The Salvation Sequence Book 2 by Peter F. Hamilton. In my opinion this
book is as good as the first one in the sequence: Salvation. Recommended.
Stop using Bootstrap
In this article, I’m going to walk you through the creation of a
Bootstrap-style, responsive, 12 column grid template for
component-based UIs — using just CSS Grid, simple semantic HTML and
SASS. In the end, we’ll put our template to the test by recreating
the reactjs.org front page with it!
Dig is a DNS lookup utility developed by
BIND which helps a lot while
troubleshooting DNS issues (which are more common than you probably
think #hugops). I use dig fairly often and thought to write an
introductory guide on how you can use dig with some practical
examples that’ll help you dig through DNS issues faster (sorry for
the lame pun, couldn’t resist.)