modular icon indicating copy to clipboard operation
modular copied to clipboard

[Docs] How about merging the manual with the HelloMojo.ipynb ?

Open lucianyao opened this issue 2 years ago • 2 comments

Where is the problem?

https://docs.modular.com/mojo/programming-manual.html

What can we do better?

I suggest we could merge the manual with the "HelloMojo.ipynb"

The reasons are:

  1. They are very similar. Not only they may cost writers excessive time, but confuse readers a little bit as well.
  2. Without running test, the manual may have some issues. For example, I can not run the example below:
struct MyString:
    var data: Pointer[UI8]

    # StringRef has a data + length field
    def __init__(inout self, input: StringRef):
        let data = Pointer[UI8].alloc(input.length+1)
        data.memcpy(input.data, input.length)
        data[input.length] = 0
        self.data = Pointer[UI8](data)

    def __del__(owned self):
        self.data.free()

The example below seems not quite right if without proper comments:

fn useStrings():
    var a: MyString = "hello"
    print(a)   # Should print "hello"
    var b = a  # ERROR: MyString doesn't implement __copyinit__

    a = "Goodbye"
    print(b)   # Should print "hello"
    print(a)   # Should print "Goodbye"

Anything else?

No response

lucianyao avatar May 27 '23 02:05 lucianyao

@scottamain I agree with this - we shouldn't have duplicate source of truth here, no rush but would love to know what you think about this.

lattner avatar May 27 '23 22:05 lattner

Yeah I've actually been thinking about this a lot. (FYI, @lucianyao, we created that notebook precisely so we could execute the examples from the manual, so the similarity is by design. It was a late decision with short-term goals, so this document duality is not sustainable.) Solving this (and maintaining it) is more complicated than it might seem, but believe me, it will not be like this forever.

scottamain avatar May 28 '23 03:05 scottamain

The programming manual is now written as a Jupyter notebook and will be available in the Mojo Playground in the next release. This also means there's a new and much shorter "HelloMojo" notebook.

scottamain avatar Jul 12 '23 15:07 scottamain