# Ruby vs Go - Structuring Data

I’m trying to write a Taskpaper parser in Go.

A very basic Taskpaper file looks like this:

Home:
- Mow the lawn
Don't hit the flowers

Work:
- Fix all the bugs
Seriously, all the bugs


Projects end with a : and tasks begin with a - and any line that doesn’t have that is a note. Projects have tasks and notes and tasks can have notes.

I got totally stuck yesterday on how to structure this data in Go.

If this was Ruby I would do it like this:

class Item
attr_accessor :parent
attr_accessor :notes
end

class Project < Item

def initialize(desc)
super(desc)
end
end

def initialize(desc)
super(desc)
end
end

class Note < Item
def initialize(desc)
super(desc)
end
end


An Item holds generic fields and then there’s a Project, Task and Note classes.

In Go there’s no way to say that a Note struct has just a generic Parent i.e. Parent *Item. To work around this I had to create a ProjectNote and also a TaskNote:

type Item struct {
Desc string
}

type Project struct {
Item
Notes []ProjectNote
Tags  []ProjectTag
}

Item
Parent *Project
}

type ProjectNote struct {
Item
Parent *Project
}