# Debug.todo for constants

**URL:** <https://discourse.elm-lang.org/t/debug-todo-for-constants/6595>\
**Category:** Learn\
**Created:** [December 3, 2020, 10:42am UTC](https://discourse.elm-lang.org/t/debug-todo-for-constants/6595 "2020-12-03T10:42:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattpiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattpiz/32/860_2.png) [@mattpiz](https://discourse.elm-lang.org/u/mattpiz)\
**Post date:** [December 3, 2020, 10:42am UTC](https://discourse.elm-lang.org/t/debug-todo-for-constants/6595/1 "2020-12-03T10:42:31Z")

</div>

Since the old `Debug.crash` was replaced by `Debug.todo` the intention is clear that this is made for development purposes. And in that sense it is extremely useful when prototyping or making top-down progress on some code. The idea being that as long as your scenario does not get in the todo branch, you can make progress and test your progress in your app. This assumption breaks however as soon as `Debug.todo` is used for a constant.

```elm
module ToBeDone exposing (complicatedCode)

complicatedCode bool =
    if bool then
        "happy path"
    else
        tbd

tbd =
    Debug.todo "Constant not coded yet"

```

Whatever you do with the above code, even if you never call `complicatedCode False` it will crash at the start of the application. This is because `tbd` is a constant and thus evaluated on start.

I have a use case for teaching material where we provide a template files containing `Debug.todo`s and a test file checking that the todos are replaced with valid code. But if we have a `Debug.todo` for one of those constants like we [used to have here](https://github.com/exercism/elm/pull/279/commits/07d89d2725eff9ec130a72ed0155ee0dcebfcb90#diff-0da479ff1c98b604ea86f650a23c108e15a692d71228758b964f654f0b4ddd49L17), elm-test would crash instead of reporting a failure for the test calling the todo constant, which is not very convenient for learning material.

I’d love if it would be possible to have constant `Debug.todo` that behave like for functions, crashing only when called.

---

<div class="post-metadata">

**Author:** ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)\
**Post date:** [December 3, 2020, 2:22pm UTC](https://discourse.elm-lang.org/t/debug-todo-for-constants/6595/2 "2020-12-03T14:22:44Z")

</div>

Just make it a function:

```auto
module ToBeDone exposing (complicatedCode)

complicatedCode bool =
    if bool then
        "happy path"
    else
        tbd 1

tbd _ =
    Debug.todo "Constant not coded yet"

```

---

<div class="post-metadata">

**Author:** ![mattpiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattpiz/32/860_2.png) [@mattpiz](https://discourse.elm-lang.org/u/mattpiz)\
**Post date:** [December 3, 2020, 2:47pm UTC](https://discourse.elm-lang.org/t/debug-todo-for-constants/6595/3 "2020-12-03T14:47:30Z")

</div>

Indeed, that solves the “developing” part. Not very clean for learning material though. Is it possible in other languages? I know that the `todo!()` macro does not compile if used in a `const ...` definition in Rust.

---

<div class="post-metadata">

**Author:** ![lydell](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/lydell/32/178_2.png) [@lydell](https://discourse.elm-lang.org/u/lydell)\
**Post date:** [December 3, 2020, 4:50pm UTC](https://discourse.elm-lang.org/t/debug-todo-for-constants/6595/4 "2020-12-03T16:50:28Z")

</div>

What about a good ol’ TODO comment?

```elm
tbd =
    -- TODO: Constant not decided yet
    0

```

---

<div class="post-metadata">

**Author:** ![mattpiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattpiz/32/860_2.png) [@mattpiz](https://discourse.elm-lang.org/u/mattpiz)\
**Post date:** [December 3, 2020, 6:19pm UTC](https://discourse.elm-lang.org/t/debug-todo-for-constants/6595/5 "2020-12-03T18:19:07Z")

</div>

That wouldn’t do it for “complex” constants. For example, we used to have

```elm
defaultRobot : Robot
defaultRobot =
    Debug.todo "Please implement this"

```

And now we just give the answer for that one

```elm
defaultRobot : Robot
defaultRobot =
    { bearing = North
    , coordinates = { x = 0, y = 0 }
    }

```

and it’s just not part of the things being tested anymore, students directly work on the rest of the exercise.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [December 13, 2020, 6:19pm UTC](https://discourse.elm-lang.org/t/debug-todo-for-constants/6595/6 "2020-12-13T18:19:16Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
