Less Wrong Than Yesterday

Thoughts on testing Phoenix views

TL;DR: I'm not a huge fan of extensive unit tests for rendered HTML. Despite that, I've put a fair amount of work into some test support code for Phoenix views. Mostly, that was because I thought it would be a good learning experience for me, a novice in Phoenix and Elixir. But I came up with some testing conventions and code that might be useful to others. They might also serve as a model for testing other complex data structures.

Why don't I like automated tests for views?

  1. Nowadays, it's usually very quick to visually check a change.

  2. You

Continue Reading...

Taking advantage of Phoenix rendering and iodata (part 1)

DRAFT: Expect updates as people who know more than I do correct me.

Among the wonderful things about Phoenix is that it doesn't render strings. Instead, it renders iodata. That's an Elixir idiom that speeds up string processing by avoiding concatenation. But it also makes it easier to work with conditional logic in views and templates. This two-post series is about how I'm doing that in a new Phoenix app (as a new Phoenix/Elixir programmer).

First, some basics

Consider a function helper in a View module, called like this from a template:

What sort of things can helper return?

Continue Reading...

Adjusting Phoenix+Elm tutorials, given Elm 0.17

There are a number of tutorials on how to add Elm to Phoenix apps. Many were for Elm 0.16. They're broken for Elm 0.17. This repo will help you translate from then to now.

Here are pointers to the files that matter. In all cases, look for "elm":

My (trivial) use of Elm is in the root page.

You might also be interested in the brunch-config and .gitignore files.

Continue Reading...

Adding bootstrap.js to default Phoenix installation

This note applies to Phoenix 1.2.0

mix phoenix.new starts you out with Twitter's bootstrap. However, it only includes the CSS, not the JavaScript. I had a good deal of trouble figuring out how to get that working, not being familiar with the JavaScript ecosystem or the brunch build tool that Phoenix uses.

Thanks to the kind help of OvermindDL1, I got it working. Here are the changes, shown in the github diffs.

Continue Reading...

My introduction to metrics

I started my first post-college job in 1981, working at a startup spun off from the University of Illinois. My first job as a Unix and C programmer was to write a program to count lines of code and comment in C programs.

My first release drew complaints. Some people used K&R-style placement of blocks, as in:

if (a = 5) {  

But some used the Proper Style:

if (a = 5)  

The former complained that the latter got "credit" for three lines of code, while they only got credit for two.

I had to add an option (-} as I

Continue Reading...