DEV Community

Cover image for freeCodeCamp's Drum Machine project built in Elm
Dwayne Crooks
Dwayne Crooks

Posted on • Edited on

freeCodeCamp's Drum Machine project built in Elm

This Drum Machine project was a satisfying one to complete.

At times I doubted whether or not I would get everything to work the way I wanted. But in the end it all worked out and the project came together quite nicely.

Here's my demo and the source code.

Whether you choose to just read the code or to build the project you will learn the following:

  1. How to play audio.
  2. How to write a custom decoder for key up and down events.
  3. How to use Process.sleep to do the equivalent of JavaScript's setTimeout.
  4. How make Elm output special HTML characters like non-breaking space.

I challenge you to build something, anything, in Elm. It's the best way to learn the language.

Top comments (5)

Collapse
 
deciduously profile image
Ben Lovy

This is cool, thanks.

Have you spent any time with Purescript? Can you compare/contrast? I'm interested to try a small project in one or the other and am having trouble settling on which.

Collapse
 
dwayne profile image
Dwayne Crooks

Have you spent any time with PureScript?

Yes. A little.

Can you compare/contrast?

PureScript seems to be trying to be a better typed functional programming language than Haskell. (btw, PureScript by Example is a good read and is full of solid ideas even if you choose Elm)

Elm is trying to be a better language for developing reliable web apps.

I'm interested to try a small project in one or the other and am having trouble settling on which.

The best way might be to reduce your project's scope (if needed), do it in both and then come to your own conclusions. That way you end up choosing the best tool for your situation.

Collapse
 
deciduously profile image
Ben Lovy

do it in both

You're right, of course this is the best way to choose. Ive skimmed PureScript By Example, but it seemed outdated for the version of the language I was using. Good to know it still mostly applies.

This Elm code is so neat and clean, much more readable than the PS samples I've read, I think you've put the design trade-off succinctly. Thanks!

Thread Thread
 
dwayne profile image
Dwayne Crooks

I've skimmed PureScript By Example, but it seemed outdated for the version of the language I was using.

For me that was fine because I was reading it more for the ideas than for using the ideas in PureScript specifically. For e.g. I've tried learning Haskell in the past but the books and tutorials can be so dense you miss the point completely. I've found that with this new wave of languages like Elm, PureScript, Rust etc they try to reach a less academic audience which causes the writing to be more approachable. It's one of the reasons why I'm now able to grok Haskell and typed functional programming in general.

Thread Thread
 
deciduously profile image
Ben Lovy

Totally agreed re: Haskell. You don't need a degree in category theory to use it at all, but it feels like you need one to learn it.