# \#ask How should we improve Motoko?

**URL:** <https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573>\
**Category:** Developers\
**Created:** [July 27, 2022, 6:06pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573 "2022-07-27T18:06:27Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [August 7, 2022, 4:11pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/22 "2022-08-07T16:11:26Z")

</div>

How would you use that? Would you assign it to a variable?

Is it different than this that you can do today?

‘’’  
let z = (x : Nat) : Nat {x+1};

‘’’

---

<div class="post-metadata">

**Author:** ![hugepuppy](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hugepuppy/32/6419_2.png) [@hugepuppy](https://forum.dfinity.org/u/hugepuppy)\
**Post date:** [August 7, 2022, 9:55pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/23 "2022-08-07T21:55:24Z")

</div>

Yeah I guess that’s pretty much the same as what’s already available. I just have noticed that when I pass functions as parameters it gets pretty messy. So assigning them to a variable would probably solve the problem.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [August 7, 2022, 10:04pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/24 "2022-08-07T22:04:43Z")

</div>

I do like the distinction between → as the type identifier and then =\> as the implementation

The below looks kind of nice.

```auto
let z : (x: Nat) -> Nat = (x : Nat) : Nat => x+1;

```

---

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [August 7, 2022, 10:33pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/25 "2022-08-07T22:33:24Z")

</div>

A way to ignore the return value of a group of functions without adding the ignore keyword to each line. I think something similar to this image would be suitable, where you could ignore the return values of a whole code block.

 ![Screen Shot 2022-08-04 at 6.24.50 PM](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/f/f8ed1c60381f0e67af314378a737ea5c39ec4e2e.png)

I was able bundle the return values into one and use a single ignore key because the values where boolean

 ![Screen Shot 2022-08-04 at 6.36.15 PM](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/f/fffcdb1bcf6d6725fea7c601a866ada28531c5b8.png)

Otherwise you would have to use the ignore key for every line.

 ![Screen Shot 2022-08-04 at 6.33.53 PM](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/b/b8b40ff18429ba95dcb2833b3aaa7e0b4081a199.png)

---

<div class="post-metadata">

**Author:** ![Zane](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zane/32/6541_2.png) [@Zane](https://forum.dfinity.org/u/Zane)\
**Post date:** [August 7, 2022, 10:38pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/26 "2022-08-07T22:38:44Z")

</div>

I still haven’t quite figured why ignore is even a thing, like I understand why they added it, but I’m not sure it brings more benefits than annoyances, but I might be missing something.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [August 8, 2022, 12:21am UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/27 "2022-08-08T00:21:01Z")

</div>

Yeah….I’d love a primer on what it is useful for.

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [August 8, 2022, 9:58am UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/28 "2022-08-08T09:58:43Z")

</div>

> [@Zane](#):
>
> I still haven’t quite figured why `ignore` is even a thing, like I understand why they added it, but I’m not sure it brings more benefits than annoyances, but I might be missing something.

> [@skilesare](#):
>
> Yeah….I’d love a primer on what it is useful for.

I just used it in my work on the cycles faucet. The faucet hands out cycles wallets, and these wallets require some canisters that are created somewhere. Previously, this was all done outside of the faucet in a script that called `dfx ledger` to create the canisters. Now, whenever I `register_codes` to the faucet and want to create `create_n` canisters to the queue, it runs this:

```motoko
while (create_n > 0) {
    ignore create_canister_to_reserve();
    create_n := create_n - 1;
};

```

The `ignore` just dispatches an async call, but doesn’t wait for a response to arrive. This means that I get a response from the `register_codes` call without having to wait for all those canisters to be created, and all the `create_canister_to_reserve` calls run in parallel (I don’t await the result of one to start the next one).

IDK if there’s a better way to do it (I’m new to Motoko), but that’s the way I made it work with.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [August 8, 2022, 12:04pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/29 "2022-08-08T12:04:12Z")

</div>

> [@Vivienne](#):
>
> The `ignore` just dispatches an async call, but doesn’t wait for a response to arrive. This means that I get a response from the `register_codes` call without having to wait for all those canisters to be created, and all the `create_canister_to_reserve` calls run in parallel (I don’t await the result of one to start the next one).

Ahh…I see. I always just call it something like

```auto

let create_future = create_canister_to_reserve();

```

…and then it gets discarded after the block. It would be great to know from @rossberg if one version has performance advantages over the other.

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [August 8, 2022, 12:09pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/30 "2022-08-08T12:09:39Z")

</div>

From the documentation about `ignore` [here](https://internetcomputer.org/docs/current/developer-docs/build/languages/motoko/language-manual#ignore):

```auto
Then the semantics is equivalent to let _ = <exp> : Any.

```

So I guess technically our versions are equivalent, but maybe the `ignore` approach makes a bit easier for the compiler (or reader) to figure out that the result can be discarded.

---

<div class="post-metadata">

**Author:** ![infu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/infu/32/11321_2.png) [@infu](https://forum.dfinity.org/u/infu)\
**Post date:** [August 8, 2022, 12:12pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/31 "2022-08-08T12:12:46Z")

</div>

syntactic sugar for type changes when upgrading

---

<div class="post-metadata">

**Author:** ![rossberg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rossberg/32/795_2.png) [@rossberg](https://forum.dfinity.org/u/rossberg)\
**Post date:** [August 8, 2022, 12:31pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/32 "2022-08-08T12:31:25Z")

</div>

So far, an `ignore` expression is literally compiled as the desugaring shown in the docs, so there is no difference other than brevity and clarity.

---

<div class="post-metadata">

**Author:** ![brady](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/brady/32/9276_2.png) [@brady](https://forum.dfinity.org/u/brady)\
**Post date:** [August 10, 2022, 6:06pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/33 "2022-08-10T18:06:33Z")

</div>

**syntax:**  
golang style for loops  
more concise syntax for pattern matching & error handling

**other:**  
keep improving documentation  
framework for unit testing  
better package manager  
vscode plugins

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [August 11, 2022, 10:22am UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/34 "2022-08-11T10:22:51Z")

</div>

> [@peterparker](#):
>
> a sort of [Prettier](https://prettier.io/) code formatter to format the code automatically. To make collaboration (review) easier and code looks always good

in addition, if it can auto organize import that would be neat too.

In almost all my frontend projects I use [Prettier](https://prettier.io/) and [prettier-plugin-organize-imports](https://github.com/simonhaenisch/prettier-plugin-organize-imports). Would be cool if I could have something similar for my Motoko projects and code.

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [August 26, 2022, 8:09pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/35 "2022-08-26T20:09:54Z")

</div>

> [@peterparker](#):
>
> a sort of [Prettier](https://prettier.io/) code formatter to format the code automatically. To make collaboration (review) easier and code looks always good

nvm it has been solved 🤩

[https://twitter.com/kylpeacock/status/1563256664819507201](https://twitter.com/kylpeacock/status/1563256664819507201)

> **[GitHub - dfinity/prettier-plugin-motoko: A code formatter for the Motoko...](https://github.com/dfinity/prettier-plugin-motoko#readme)**
>
> A code formatter for the Motoko smart contract language. - GitHub - dfinity/prettier-plugin-motoko: A code formatter for the Motoko smart contract language.

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [August 27, 2022, 4:29am UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/36 "2022-08-27T04:29:44Z")

</div>

Whoa didn’t know this existed…

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [August 27, 2022, 5:09am UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/37 "2022-08-27T05:09:28Z")

</div>

It’s brand new I think 🚀

---

<div class="post-metadata">

**Author:** ![matthewhammer](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/matthewhammer/32/323_2.png) [@matthewhammer](https://forum.dfinity.org/u/matthewhammer)\
**Post date:** [September 1, 2022, 4:35pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/38 "2022-09-01T16:35:06Z")

</div>

Regarding `ignore`:

Q1: Why do we have it?

A1: If you didn’t have `ignore`, you’d be writing `let _ = ` in its place, and as @rossberg mentioned, they are equivalent from the viewpoint of the compiler.

Q2: Why do we have to write either of these, and why can’t we just ignore return values without extra syntax?

A2: Well, our type system needs more details, and perhaps if the type system made more distinctions other than `()` vs non-`()` return types, we could. For example, Rust has a more nuanced view of return results’ types:

> **[UNUSED\_MUST\_USE in rustc\_lint::unused - Rust](https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/unused/static.UNUSED_MUST_USE.html)**
>
> The \`unused\_must\_use\` lint detects unused result of a type flagged as \`#\[must\_use\]\`.

So in Rust world, the `Result` type would require an `ignore`-like syntax, but other primitive types may not.

Q3: Is that more nuanced approach an improvement?

A3 (my own at least): Perhaps! Especially for data structure APIs that may return extra success information that users do not always need (as in the graph API mentioned by @tomijaga above)

> [@torates](#):
>
> Motoko its the native language of the IC and I feel it should not be limited to constant workarounds to access core IC features by us devs.

Which IC features are the most challenging or most needed?

---

<div class="post-metadata">

**Author:** ![rossberg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rossberg/32/795_2.png) [@rossberg](https://forum.dfinity.org/u/rossberg)\
**Post date:** [September 1, 2022, 6:09pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/39 "2022-09-01T18:09:47Z")

</div>

> [@matthewhammer](#):
>
> Q2: Why do we have to write either of these, and why can’t we just ignore return values without extra syntax?

The short answer is: both to protect against accident and to make the intent explicit. Forgetting to use a result is a fairly common error, and neither compiler nor human readers would otherwise know if it was intended.

As a secondary effect, it is also meant to encourage less error-prone API design, i.e., avoid functions that both have non-trivial side effects _and_ return results. If your interfaces are designed with that in mind (similar to the query vs update distinction), then you won’t need `ignore`.

---

<div class="post-metadata">

**Author:** ![matthewhammer](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/matthewhammer/32/323_2.png) [@matthewhammer](https://forum.dfinity.org/u/matthewhammer)\
**Post date:** [September 1, 2022, 9:05pm UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/40 "2022-09-01T21:05:38Z")

</div>

> [@rossberg](#):
>
> As a secondary effect, it is also meant to encourage less error-prone API design, i.e., avoid functions that both have non-trivial side effects _and_ return results.

An impractical stance, but I admire the principles. 🙂

I think the Rust compiler has a good compromise: It complains for `Result` types that could contain unhandled errors, but does not go so far as to assume that _every_ result is worthy of being this pedantic.

BTW, for a data structure that replaces old stuff with new stuff, it’s natural to return the old stuff as an optional result. For instance, `Trie.replace` in `base`. So, that’s a good situation for the more relaxed Rust conventions in Motoko, and something that I would appreciate myself, personally.

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [September 2, 2022, 5:32am UTC](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573/41 "2022-09-02T05:32:21Z")

</div>

Unrelated, but one of the biggest headaches I had when initially developing on Motoko was dealing with the whole functional vs imperative data structure dilemma. I don’t want to think about it, but I have to if I want to work with `stable` variables, which most developers invariably will want to. The syntax is really quite different between the two.

Could you ever envision a world where imperative data structures could be stored in `stable` variables? Is there no theoretical way for the Motoko compiler to implicitly convert an imperative data structure to a functional one?

[Previous page](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573.md?page=1)

[Next page](https://forum.dfinity.org/t/ask-how-should-we-improve-motoko/14573.md?page=3)
