41 stories

Michael Feathers

1 Share

Adrian previously discussed Working Effectively with Legacy Code when he talked about how to choose a programming language for your book. It deserves revisiting though, so here it is in the library section.

Quite simply, if you have not read this book yet, read it. If you have a colleague who has yet to read it, get them a copy. If someone asks you what one book to read about software engineering, it is this one. It is not Code Complete, Second Edition, nor is it Clean Code, nor any other book that claims to teach you how to get software right the first time around (you will not). It is not Programming Rust, nor Programming Elixir, nor any other book that claims to teach you a technology that solves all of your problems (it will not).

All of your code will either be abandoned or become legacy code, so if you do not plan on failing you should learn how to work effectively with legacy code.

The central premise to the book is that legacy code is usually not enjoyed because it is insufficiently tested. And that the way to work with it is to identify few, hopefully not too invasive, changes that allow for parts of the software to be tested in isolation. Once those parts are under test, it becomes easier to make more, perhaps more significant, changes to the parts that are tested to subdivide into smaller testable units. After enough iterations of this you have a system whose behaviour is both described and stabilised by the tests and will be easier to work with.

Why bother with all of this? For the same reason we avoid rewrites whenever a new programming language comes along: the existing software encapsulates both the current behaviour of the software system, and the desired behaviour: whatever the software is supposed to do, people have adapted to whatever it actually does and so that must be a starting point for any future work.

It is all too easy to say “oh the legacy code is really buggy, we should start from scratch” but those bugs are the way the system—not just the software, but the socio-technical system in which it is embedded—works. The ones that have been fixed are hard-fought lessons about what people want from this software. It may not be well-designed—but it may be. What gets called bad design might actually be good design from a few years ago: software design is fad-led, rather than engineering-led. But it may also be the case that a clean design is hiding under the weight of various patches and hot fixes. This is exactly the situation that Working Effectively with Legacy Code will let you take control of: fixing the software towards a clean design without having to let go of the good, valuable behaviour. And of course in this age of Agile®©™, we work to the principle that the primary measure of progress is working software. The legacy software already works.

So why do software engineers prefer to start from scratch? Partly it is because programming is a monetised hobby: people enjoy writing software so they will find ways to do that for income. But it is also a matter of capability. A Masters-level course in software engineering contains nothing about reading or adapting existing software; not even anything about buy-versus-build decisions. And most professional programmers are not trained software engineers. Without education or experience at reading, understanding, and modifying existing code, programmers see it as difficult, unnecessary effort. Why waste my time learning from person-centuries of experience at solving this problem, when I can type cargo new and have something that solves 5% of the problem badly in maybe a month or two?

And that is where this book comes in. It is your secret superpower. Learn how to work effectively with legacy code and you will be faster and more capable than almost all of the software writers working today, through this one weird trick: not writing most of the software you need.

Cover photo by Adrian Kosmaczewski.

Read the whole story
713 days ago
Melbourne, Australia
Share this story

As a quite handsome man, ‘from a certain angle and in a certain light’, how did you pull Mrs Cave?

1 Share

I am thirteen. [ ] What is your favourite dinosaur? NICKLAS, STOCKHOLM, SWEDEN   Can you recommend a female poet I should read? TAMMY, ROME, ITALY   Do you think The Red Hand Files have been a success? JONATHAN, CHOBHAM, UK Dear Steven, Nicklas, Tammy and Jonathan,With the passing of the years, that certain angle […]

The post As a quite handsome man, ‘from a certain angle and in a certain light’, how did you pull Mrs Cave? appeared first on The Red Hand Files.

Read the whole story
1077 days ago
Melbourne, Australia
Share this story

Road Bike Gears Explained : Why the Right Choice Matters

1 Share

I often come across cyclists saying things such as,

I ran out of gears on the descend.

Only if I have 1 or 2 lower gears, I’d finish the climb strongly.

If I’d have another gear, I wouldn’t have cramped.

Look, gearing is a very important aspect in cycling but it’s often overlooked by many as it can quickly become very technical. After all, we all want to ride our bikes and not sweat much over the technicals and mathematics behind it.

Understanding the basics behind the gearing would help you make a better-informed decision the next time you think about replacing or upgrading your drivetrain.

Having the ideal gears would definitely make your riding much more enjoyable.

On this page, I’ll explain to you the various jargons and terminologies road cyclists used and how to determine the ideal gearing setup for your type of riding.

Anatomy of a Road Bike Drivetrain

Before I jump into more complicated topics, I’ll spend some time going through the various components that make up a bike’s drivetrain. 

If you’re already familiar with these, then you can skip this section.

  • Chainring. The chainring is the large pair of cogs at the front where your pedals connect to. Most road bikes have double chainrings (sometimes called 2X). Kids, cyclocross, gravel, and mountain bikes usually have just a single chainring (1X). Commuter bikes are likely to have up to triple chainrings (3X).
  • Cassette. The cassette is the smaller set of gears on the right side (also called the drive side) of the rear wheel. They can range from 7 all the way up to 13 cogs. More cogs mean a broader range of ears. Each cog can be made up of 9 up to 52 teeth. The more teeth, the lower the gearing is. For example, 11-50T means that the smallest cog has 11 teeth and the largest cog has 50 teeth.
  • Chain. The chain connects the chainring and cassette together and is the driving force that takes the energy from the pedals and turns it into forward motion. Typically made of steel or aluminum, the chain has holes that fit perfectly into the teeth of the cassette and chainring to avoid slipping.
  • Front Derailleur, sometimes referred to as just FD, is attached to the frame on the seat tube. It de-rails the chain from one chainring to the other, both up and down. A 1X bike will not have a front derailleur.
  • Rear Derailleur, also known as RD, hangs from the frame via a derailleur hanger from the chainstay. It moves the chain along the cassette, giving you access to a range of high and low gears.
  • Shifters. The shifters are the mechanism that uses cable tension or electrical signal to make the derailleurs change gear. These days, the shifters are integrated with the brake levers. Shimano calls this STI (Shimano Total Integration).

Mechanical vs Electronic Drivetrain

Did you know that Mavic was actually the first to introduce an electronic drivetrain way back in 1992?

It’s called the Mavic Zap, but unfortunately, it didn’t hit the mainstream.

It was not until 2009 that Shimano launched its first generation of Di2 (Digital Integrated Intelligence), the Dura Ace 7970. Then in 2012, Campagnolo introduced the EPS. 

SRAM was the last of the 3 big drivetrain manufacturers to introduce an electronic drivetrain. In 2015, SRAM introduced its first wireless, electronic drivetrain, the SRAM eTap.

Over the past few years, there are many discussions surrounding whether should one get a mechanical or an electronic drivetrain.

So, let’s take a look a the pros and cons of each.

Mechanical Drivetrain - The Good vs Bad

  • Cheaper. Mechanical drivetrains significantly cheaper than electronic gears while providing a smooth shifting experience.
  • Don’t use batteries. Remembering to keep your Di2 battery charged or having to wait while it charges before you ride is one more complication a rider doesn’t need.
  • Susceptible to cable wear and failure. Over time, the shifter cable will get worn out as it rubs against the cable housing when you shift. Also, as the derailleurs use cable tension to shift, the cable will be stretched. A good practice is to get a new set of cables yearly.
  • Needs constant indexing. As the cable stretches, you’ll need to perform micro-indexing to ensure the derailleurs shift accurately. 

Eletronic Drivetrain - The Good and Bad

  • Very smooth and accurate shifting. Electronic shifting is smooth and quiet and while a well-tuned mechanical groupset can do the same, once you try electronic you don’t want to go back. Once set up, you will probably never need to index the gears again (unless you get a new set of wheels).
  • Self-trimming – The front derailleur on an electronic groupset will automatically align itself to avoid chain rub. It does this by over-shifting to quickly move the chain and then self-trim to compensate for that over-shift.
  • Expensive. They’re not cheap and very often cost at least 2x the price of the equivalent mechanical drivetrain.
  • Batteries. Another battery to maintain and remember to keep charged. While most groupsets will warn you in advance of a flat battery, you need to remember to check before longer rides!

How Many Speed Do You Need?

One of the arguments I hear from people is that the more speed the drivetrain has, the better it is.

But, is it really?

Speed refers to the number of cogs in the rear cassette. Multiply the speed with the number of front chainrings, you’ll get the total available gears on the drivetrain.

For example, a 22-speed drivetrain is made up of 2 front chainrings with an 11-speed cassette. That makes 2 x 11 = 22 speed.

Or, 1x chainring with 12 cogs cassette, that would be 1 x 12 = 12 speed.

Confusing, I know.

These days, the minimum for road bikes is either 11 or 12-speed. Older bikes (pre-2012) could still be running 10-speed drivetrains.

Shimano road drivetrains are 11-speed, while SRAM and Campagnolo are 12-speed.

Regardless of whether it’s 22 or 24-speed, you’ll have enough gears for most terrain with some crossovers. Crossover is where a ratio is the same between the small and big chainring.

For example, 53×19 is the same gear ratio as a 39×14, meaning the big chainring at the front and 19T at the rear is the same gearing as a small chainring upfront and 14T if you have a 53/39 chainset.

So, what’s the difference between 11 and 12-speed then?

The more speed, the tighter the gear ratio is.

In other words, there’s a smaller jump between adjacent gears. It might sound like a trivial matter for most cyclists, but it can be greatly felt especially when you’re riding at your limits. A smaller jump allows you to maintain a more consistent cadence overtime.

Rather than sweating over the number of speed, I think the cassette choice is a more important factor, especially for recreational cyclists.

Choosing the Ideal Rear Cassette

Cassettes come in many configurations and understanding what they mean,  how they ride help you greatly over your gearing choices.

The numbers on the cassette represent the highest and lowest gears on it.

  • 11-23 : 11-12-13-14-15-16-17-18-19-21-23
  • 11-25 : 11-12-13-14-15-16-17-19-21-23-25
  • 11-28 : 11-12-13-14-15-17-19-21-23-25-28
  • 11-32 : 11-12-13-14-16-18-20-22-25-28-32
  • 12-25 : 12-13-14-15-16-17-18-19-21-23-25
  • 14-28 : 14-15-16-17-18-19-20-21-23-25-28

For example, a 11-23T cassette has 11T as the highest gear and 23T as the lowest gear.

A cassette with a closer gap (eg: 11-23T) will have a tighter ratio compared to 11-34T.

Notice the larger gaps?

The key to deciding the type of cassette depends a lot on the type of riding you do and the terrain.

Here’s a quick way to determine the type of cassette you need.

  • 11-23T or 11-25T. If you ride mostly on flat terrains, you want a cassette with a tighter ratio.
  • 11-28T. If you’re after a versatile, all-rounder, this cassette is very popular among a lot of cyclists.
  • 11-30T. If you ride very hilly terrains, you might want to consider this, or even 11-34T for the steepest hills.

Standard, Semi-compact or Compact Chainring?

The typical road bike setup will be two chainrings upfront. They will generally come in different ratios called standard, compact, and semi-compact.

  • Standard would be 53/39T, which is 53 teeth on the big ring and 39 on the small. This is typical for road bikes for stronger or more experienced riders or for relatively flat terrain as they are geared for speed.
  • Compact would be 50/34T and would be suitable for hillier terrain. The smaller rings mean lower gearing, which is suited for long days in the saddle, new cyclists, or hills.
  • Semi-compact at 52/36T is the middle ground, suitable for sportive riders, long days in the saddle, or undulating terrain. The 52/36T sits between the compact and the standard, hence the name.

To make things more complicated, SRAM offers different chainring options for its 12-speed drivetrain. They’re available in 50/37T, 48/35T, and 46/33T. The principles of gearing are the same but the exact ratios differ slightly.

Finally, there is the TT chainring for flat and fast terrains. It will use either a 54 or 55 and a 39 tooth ring. A larger big ring means a faster top speed and for the average TT held on relatively flat terrain, helps maintain that speed over the distance.

These aren’t suitable for other types of riding though unless you have the power output of Fabian Cancellara or Tony Martin.

What Are Gear Ratios?

The ratio describes how many times the back wheel rotates for a single rotation of the pedals. 

For example, if you’re on the big ring on a standard chainring and in 12T at the rear, that’s 53/12 or a ratio of 52:12 which breaks down to 4.42. For every rotation of your pedals, your rear wheel will rotate 4.42 times.

Another example would be a 36T chainring using that same 12T rear cog. This gives a ration of 3:1. One full revolution of the pedals will rotate the rear wheel 3 times.

Ratios are further complicated by progression metres. This is used in Europe to express how far the bike would travel with one full revolution of the pedals. This also takes into account wheel size as this has an influence over how far the bike will travel.

In our example above, 53/12 using standard 700C wheels, the bike would travel 9.28 metres. In the 36/12 example, it would travel 6.3 metres.

Like I said, you don’t need to know gear ratios in this depth unless you really want to.

The post Road Bike Gears Explained : Why the Right Choice Matters appeared first on The Geeky Cyclist.

Read the whole story
1253 days ago
Melbourne, Australia
Share this story

Bootstrapping a minimal math library

1 Share

Sometimes you don’t have all the math functions available that you would like. For example, maybe you have a way to calculate natural logs but you would like to calculate a log base 10.

The Unix utility bc is a prime example of this. It only includes six common math functions:

  • sine
  • cosine
  • arctangent
  • natural log
  • exp
  • square root

Users are expected to know how to calculate anything else they need from there. (Inexplicably, bc also includes a way to calculate Bessel functions.)

This post collects formulas that let you bootstrap the functions listed above into all the trig and hyperbolic functions and their inverses.


Most programming languages provide a way to compute natural logs but not logs in bases other than e. If you have a way to compute logs in base b, you can compute logs in any other base via

\log_a(z) = \frac{\log_b z}{\log_b a}

So, for example, you could compute the log base 10 of a number by computing its natural log and dividing by the natural log of 10.


If you have a way to calculate ex and natural logs, you can compute xy via

x^y = \exp(y \log x)

Since square roots correspond to exponent 1/2, you can use this to compute square roots.

Trig functions

If you have a way to calculate sine and cosine, you can calculate the rest of the six standard trig functions.

\begin{align*} \sec z &= 1/\cos z \\ \csc z &= 1/\sin z \\ \tan z &= \sin z / \cos z \\ \cot z &= \cos z / \sin z \end{align*}

Inverse trig functions

If you have a way to calculate inverse tangent, you can bootstrap it to compute the rest of the inverse trig functions.

\begin{align*} \text{arcsin}(x) &= \arctan(x / \sqrt{1 - x^2}) \\ \text{arccos}(x) &= \arctan(\sqrt{1 - x^2 }/ x) \\ \text{arccot}(x) &= \pi/2 - \arctan(x) \\ \text{arcsec}(x) &= \arctan(\sqrt{x^2 - 1}) \\ \text{arccsc}(x) &= \arctan(1/\sqrt{x^2 - 1}) \end{align*}

Also, you can use arctan to compute π since π = 4 arctan(1).

Hyperbolic functions

If you have a way to compute exponentials, you can calculate hyperbolic functions.

\begin{align*} \sinh(x) &= \frac{\exp(x) - \exp(-x)}{2} \\ \cosh(x) &= \frac{\exp(x) + \exp(-x)}{2} \\ \tanh(x) &= \frac{\exp(x) - \exp(-x)}{\exp(x) + \exp(-x)} \\ \end{align*}

Inverse hyperbolic functions

If you can compute square roots and logs, you can compute inverse hyperbolic functions.

\begin{align*} \text{arcsinh} (z) &= \log \left( z + \sqrt{1 + z^2} \right) \\ \text{arccosh} (z) &= 2 \log\left( \sqrt{(z+1)/2} + \sqrt{(z-1)/2} \right) \\ \text{arctanh} (z) &= \log \left( (1+z) \sqrt{1/(1 - z^2)}\right) \end{align*}

Complex branch cuts

Up to this point this post has implicitly assumed we’re only working with real numbers. When working over complex numbers, inverse functions get more complicated. You have to be explicit about which branch you’re taking when you invert a function that isn’t one-to-one.

Common Lisp worked though all this very thoroughly, defining arc tangent first, then defining everything else in a carefully chosen sequence. See Branch cuts and Common Lisp.

The post Bootstrapping a minimal math library first appeared on John D. Cook.
Read the whole story
1283 days ago
Melbourne, Australia
Share this story

Moving our privacy advocacy forward to protect Australia and you

1 Share
Moving our privacy advocacy forward to protect Australia and you

At FastMail, we care deeply about protecting your right to data privacy. Recently, we continued our advocacy to protect privacy rights by voicing our concerns about the Telecommunications and Other Legislation Amendment (Assistance and Access) Act 2018, also known as TOLA or "the AABill” to Parliament.

To bring you up to speed, the act, which focuses on services built with end-to-end encryption, allows law enforcement to compel companies to modify their services and intercept data from their customers in its unencrypted form. Our previous post discussed how FastMail uses encryption, and why the act does not change your privacy or data security with FastMail. However, we believe this act has real implications for the Australian tech industry and the potential to weaken the security of other technology products created or used in Australia.

Being a voice for privacy in Parliament

We believe it’s important to use our voice, even if we’re not being directly impacted. We have made submissions in each round of public consultation regarding this bill, most recently we submitted feedback to the Australian government’s Parliamentary Joint Committee on Intelligence and Security on Feb 21, 2019. In our submission, we cited possible impacts of the act on the local technology sector including creating a distrust of Australia and Australian companies, causing financial losses to tech business, and creating confusion and stress among technical talent.

Although the outcome is unclear, we are hoping for the best. The good news is that many groups within the technical community are working together toward change.

Trusted by customers

As we have stated in the past, FastMail’s business is not directly affected by this legislation and we won’t be making changes to our technology or policies in response to this act.

While we had a small number of customers tell us they were discontinuing service due to this legislation, as well as a handful of potential customers tell us it was impacting their evaluation of our services, the AABill did not have a material impact on our business. However, we shared these developments in our submission to Parliament as an example of the AABill’s potentially chilling effect on Australian businesses. Parliament deserves to know how the marketplace views their decisions.

FastMail continues to enjoy a strong, loyal and growing customer base due to our relentless focus on the privacy of your personal information, a robust and standards-compliant technical platform, and a superior customer experience. We thank you for your ongoing support, and we are happy to be able to advocate on your behalf in legal, political and technical spheres!

Standing up for you

We are a proud Australian company committed to our home. All advocacy work happens on the ground and we’ll continue to fight for you and your privacy rights. We remain optimistic and inspired when we see our colleagues in the tech sector also working for change.

Privacy is central to our commitment to you. We have taken—and will continue to take—a public position on the AABill because it has raised concerns from technology companies and privacy supporters around the world. We will continue our work to advocate for privacy, for Australian citizens and for customers of Australian businesses everywhere.

What you can do

We hope you will join us in advocating for privacy rights, in Australia and your own home countries. While we are talking about Australia today, legal challenges to privacy rights come up in different countries all the time.

Here are the actions you can take to join our efforts in Australia:

Read the whole story
1963 days ago
Melbourne, Australia
Share this story

Facehugger sleep apnea mask, Jared Gray


Facehugger sleep apnea mask, Jared Gray

Read the whole story
1991 days ago
Melbourne, Australia
Share this story
Next Page of Stories