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
Arraylibrary is missing acontainsmethod. While you can replicate it usingArray.filterandswitch/case, having a native.containsmethod 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
Bufferlibrary now recommends using static methods likeBuffer.toArrayinstead 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.appendis 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-warningsoption inmoc, which wipes out all warnings. This would be great for developers who know what they’re doing and want to useArray.appendor 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.appenddeprecated 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
Hashmodule is missing some important hash methods for common types likeNat. The deprecatedHash.hashmethod 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!