Dumbed down explanations of Motoko Base library parts

Hi I’m new to Motoko and starting from square one with some experience in javascript, a little python, some graphQL backend on aws, and vuejs. (started learning web dev 4 years ago). Anyway I want to learn Motoko as this interests me and wondered if there were any straight newbie content going over some of this stuff. I’ve watched Lars’ hackin the internet videos on YouTube and one or two videos on here and would love to see whatever guides people know of. Seems like the base library is a fundamental part and I would love a walkthrough of it because I see a lot of them talking about Arrays for example and I’m not clear as to which each is used for and how they relate and just how to implement some datasets. Also I need to figure out the syntax, though I think that will come as a watch others and start to get my hands dirty.

4 Likes

a great resource is our documentation which has a base library section:

you can also dig in the base library yourself, its located at ~/.cache/dfinity/versions/<your_dfx_version>/base and part of it is documented, its also open sourced here

if you are looking for videos i‘d recommend the community curated dfinity channel mission control

4 Likes

ok yeah I was looking at docs and watched the Conways game of life which I really found helpful. Ill just try and slow down and reread and rewatch some stuff and keep an eye out for new material. Thanks tho!

1 Like

oh that was you that made Conways game of life. Yeah I liked that thanks for that! Good speed and explanations. Helps clear up confusion when learning. Really appreciate that

5 Likes

means a lot to me, thank you :blush:

also feel free to ask anything, there a no dumb questions and we‘re always trying to help :slight_smile:

2 Likes

Hi jar, welcome. Moritz and Hans’ resources are excellent, you might also want to work through some of the tutorials on the sdk site:

They should get you up to speed on not only Motoko, but some of the general Internet Computer concepts too.

3 Likes

I should probably ease into it a bit more but I did the phonebook tutorial and am trying to kind of make sense of it and add fields and just mess around but I still have no idea whats going on and looking at docs am still quite confused as to all the different array type things like buffer, assoclist, hashmap,…idk everything basically. I’ll try and go go more basic for now in trying to learn but idk I think a human talking over them in a video would be particularly effective. We need a Brad Traversy Motoko Crash course on youtube. Or actually yeah if there are any udemy or any courses anywhere I would love that if anyone knows of any

1 Like

The two key links for reference are the base library documentation Moritz linked above: https://sdk.dfinity.org/docs/base-libraries/stdlib-intro.html and the comments in the files themselves, on this page: https://github.com/dfinity/motoko-base/tree/master/src

Also a Wikipedia search is never a bad idea if you need to decide between which data structures to use, eg https://en.m.wikipedia.org/wiki/Association_list

Hans also talks about these a bit in his Hackin’ series, that might be worth another review. If you need to cross-check anything that might have changed with the recent update just drop a message here in the forum.

Another thing you might want to do is clone the various projects posted around the forum and check what they’ve done, Enzo has some good examples, eg:

https://github.com/enzoh/superheroes

Or the recent hackathon projects here:

https://github.com/dfinity/awesome-dfinity

7 Likes

Once we’re out of alpha some official Coursera or Udemy style courses would be a great idea!

2 Likes

I guess I never thought all the way down to this level about data structures and didn’t realize these were common things I could google. I now appreciate the data structures i currently use and how easy they make things for me. This may be more barebones than I anticipated. Certainly interesting though!

4 Likes

ok my understanding has increased a bit but still confused. So List is of course fixed length. AssocList I thought was you could add and remove values by adjusting where values point but you still need to iterate though them one by one to follow where each points to. But instead on Motoko it looks like a key value pair is used. Isn’t that what a hashMap actually is? So then what’s the difference?

And then a trieMap is for tree like structures. I still need to figure out the leaf and branch thing but it seems like you could still do a tree structure in a hashMap by just having values with their own hashMap. Perhaps the difference is that key’s in Trie’s are more purposeful? Like using letters. But then couldn’t you still do that in hashMap

So I’m sort of understanding more but they do seem somewhat interchangeable

So HashMaps usually use a random key id generated from a hash function even though you could use meaningful unique text while tries are more sub categorized meaningful id’s which i guess could also use meaningful unique text as Ids just step by step. Tries seam particularly powerful to me. I think I’ll try and play around with those for now

1 Like

Hi @jar – These are good questions.

Here’s a package that I’m developing that may answer some questions and raise others. It uses TrieMap to create a CRUD-like database class, and several examples of using it:

https://github.com/matthewhammer/motoko-crud

See code in tests for a handful of simple actors that each use the same Database class, in src.

If I continue developing this as a demonstration, I could show how Trie, TrieMap and HashMap could all be suitable implementations of a simple CRUD database class. For now, I’ve only gotten as far as showing TrieMap (but TrieMap itself shows how to use Tries as an object with state).

Among other things, I wanted to demonstrate how to swap out the TrieMap for other representations, while still maintaining the same CRUD operations. It’s a WIP exercise in trying to do some of the systematic comparisons that you mention as well.

BTW: Arrays in Motoko come in two varieties (mutable and immutable), and each is distinct from List, which uses a singly-linked list representation, not a flat array-based one.

3 Likes