Hey Motoko Team,
I wanted to share some feedback and suggestions based on the last edition of Motoko Bootcamp, where we introduce developers to our language.
- Array.contains:
- Right now, the
Array
library is missing acontains
method. While you can replicate it usingArray.filter
andswitch/case
, having a native.contains
method would be a simple and helpful addition.
- Handling Deprecated Methods:
-
The Motoko Base Library has what we call “deprecated” methods, which can be confusing for developers. From my experience they can be separated into two categories:
- Functions with a clear alternative: For example, the
Buffer
library now recommends using static methods likeBuffer.toArray
instead of class methods like.toArray()
. In such cases, it might be a good idea to remove these deprecated methods from the documentation, unless they are needed for compatibility reasons. - Functions without a clear alternative: let’s take a look at
Array.append
. I understand it to be deprecated to avoid its performances drawbacks, but in some cases, usingArray.append
is straighforward and doesn’t hurt performance much.
- Functions with a clear alternative: For example, the
-
Additionally, we could consider:
- Allowing developers to remove individual warnings rather than using the broad
--remove-warnings
option inmoc
, which wipes out all warnings. This would be great for developers who know what they’re doing and want to useArray.append
or other deprecated methods on purpose. - Removing deprecated methods with clear alternatives from the Base Library, or at least excluding them from the documentation to keep things cleaner for new developers.
- Changing the warning message. Instead of calling
Array.append
deprecated we could simply indicate that it’s a really inefficient method (something that every developer that goes through the Bootcamp is being repeated!). In my view, a deprecated method implies that it will eventually be phased out and removed from the language. If the intention is to retainArray.append
(which I believe is the case), then it might be beneficial to modify the warning message. Perhaps we need to introduce a new type of warning specifically focused on performances impact?
- Allowing developers to remove individual warnings rather than using the broad
- Missing Hash Functions:
- The
Hash
module is missing some important hash methods for common types likeNat
. The deprecatedHash.hash
method might not be ideal for new developers, who might not want to create their own hash methods. Can we explore adding a recommended method for hashingNat
?
I’m also curious to know if other Motoko developers share my feedback - the discussion is open.
Thanks!