O'Reilly logo

Programming Elm by Jeremy Fairbank

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactor with Good Practices

You wrote a lot of code in the previous chapter. Before forging ahead with new features, let’s pause to clean up the code. In this section, you will refactor the code by using type aliases and simplifying how users like a photo.

Create Type Aliases

We have a stinky code smell in the type annotations at the moment because we reused the record model { url : String, caption : String, liked : Bool } type in multiple places. In a larger code base, that will become annoying and hard to maintain. You can fix this problem by using a type alias.

A type alias allows you to associate a type name with another type. To create an alias, you use the type and alias keywords consecutively, followed by the name of the new type and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required