Howdy,
I was really banging my head for a small thing about this exercise. The parameter for legacy
had a question mark next to it:
def to_label(level, legacy?) do
I didn’t understand that syntax and thought it meant something extra. I tried looking back at the previous lectures, but I didn’t see that mentioned anywhere. Maybe I’m blind, but can someone point me to where and what the question mark means? Is it just part of the variable name?
In their docs, Naming Conventions — Elixir v1.15.0-dev, it looks like a trailing question mark is for functions, not variable names, so I couldn’t figure out what to do.
I appreciate the help and look forward completing the course!
1 Like
My interpretation was that the argument is expected to be a boolean. I don’t know if this is part of the official naming convention though.
Yes, exactly. It is an official naming convention for boolean functions to have a name ending with a question mark, as you found out in the official documentation. I am not really sure if it is also a convention to name variables the same way, but something that I do very often in my own code is to name the variable exactly the same as the function whose return value I assigned to it, e.g. empty? = String.empty?(name)
, so I got used to naming variables with the same convention
It is a good point that it can be surprising to people coming from languages that don’t allow question marks in function and variable names, and we should mention this somewhere on Exericsm. I’ll open a Github issue (Mention function/variable naming possibilities and conventions in the learning module · Issue #1283 · exercism/elixir · GitHub).
Thank you both. Yes, that would be great to add it somewhere. Even in the hints would be an appropriate place.
I really felt dumb doing this challenge because I thought it was harder than I expected. I ended up googling an answer for the question and couldn’t believe it was that simple.
Much appreciated and I’m looking forward to Mechanical March!