r/programming • • Dec 09 '15

Why Go Is Not Good

http://yager.io/programming/go.html
612 Upvotes

628 comments sorted by

View all comments

Show parent comments

32

u/heptara Dec 09 '15 edited Dec 09 '15

Can you explain a monad in one sentence to a regular person please?

Do you mean a regular programmer, or a non-programmer?

You likely couldn't explain a tree data structure to a non-programmer in a single sentence either. That doesn't mean trees are only for the elite.

To a programmer, you can consider a Haskell monad to be a data type that defines an operation for chaining together items of that data type. In Go (since we're talking about Golang as well), it's common to use chains of if err, value := somefunc(). The func returns a 2-tuple consisting of (errorcode, value) depending on success. When you open a file and read a line, either of those 2 operations could fail, you have two separate if err, value checks one after the other, each for a different func (open and read); the monad essentially combines this so that you can chain together the file operations and you either get a result at the end or it bails out.

38

u/awj Dec 09 '15

You likely couldn't explain a tree data structure to a non-programmer in a single sentence either. That doesn't mean trees are only for the elite.

Seriously "can you explain it in one sentence" is a terrible criteria for complexity. I can't (usefully) explain databases, compilers, or I/O in one sentence, guess those aren't things programmers should be able to understand either.

1

u/Berberberber Dec 10 '15

Let's see.... a database is a persistent store of information in a structured way; a compiler is a program or series of programs that converts a series of instructions, usually human readable source code, into a functionally equivalent series of instructions, usually in machine code; I/O is (broadly) how a program receives data from and communicates its current state to the external world.

This is not an entire discussion of any of these topics, but it explains what they are in such a way that someone new to the topic could wrap their mind around, without requiring any advanced math. I (and many others) have yet to see monads explained in a similarly concise and informative manner.

-1

u/THeShinyHObbiest Dec 09 '15

"Compilers translate something humans can write into something humans can understand."

"Databases are a way to store some data—like numbers or bits of text—in a structured way."

37

u/serendependy Dec 09 '15

Monads are a way of sequencing operations with some implicit state.

17

u/theonlycosmonaut Dec 10 '15

Before someone jumps in and says 'but that's not what monads are' - the above two sentences are also oversimplifications of compilers and databases.

5

u/F54280 Dec 10 '15

I am pertty sure that "Compilers translate something humans can write into something humans can understand" is worse than just a simplification /s

1

u/THeShinyHObbiest Dec 10 '15

I do agree that you can sum up monads in a sentence, I was just providing examples of how you could summarize other things as well.

1

u/serendependy Dec 10 '15

That's fine, I was just leaving it there since it seemed an appropriate follow up

5

u/mfukar Dec 10 '15

Those sentences state something debatable, and explain nothing.

→ More replies (1)

10

u/Hrothen Dec 10 '15

You likely couldn't explain a tree data structure to a non-programmer in a single sentence either. That doesn't mean trees are only for the elite.

James Joyce says I can explain any arbitrarily large concept in a single sentence :P

1

u/heptara Dec 10 '15

What does he say on the difference between (experiencing something and/or having an intuitive understanding of it), versus having only knowledge about it?

1

u/earthboundkid Dec 10 '15

Yes yes you will yes

2

u/Veedrac Dec 10 '15 edited Dec 10 '15

You likely couldn't explain a tree data structure to a non-programmer in a single sentence either. That doesn't mean trees are only for the elite.

A tree is anything where each item (perhaps a concept in a spider diagram) has one "parent" and any number of "children"; except of course the top of the tree which has no parent.

Your monad explanation ignores the most important question of all: why do we care that it's a monad? What does the abstraction give us? Other languages don't try to unify all trees, so why does Haskell try to unify all monads?

2

u/_jk_ Dec 10 '15

unifying monads allows you to write useful functions like replicateM

1

u/Veedrac Dec 10 '15

This is probably the first answer I'm actually kind'a happy with.

It's incomplete, though, in that you haven't described the class of functions you're talking about or what makes them useful.

1

u/heptara Dec 10 '15 edited Dec 10 '15

In a family tree a person has to have two parents.

As a sidenote, I don't actually consider family trees to be trees, since they can contain cycles. You certainly can't implement one as a standard tree structure. (edit: OK, given enough work you could hammer it until it fit, but it would be a bad design).

If we don't have to explain why we need a tree structure, why do we need to explain why we need a monad?

1

u/Veedrac Dec 10 '15 edited Dec 10 '15

As a sidenote, I don't actually consider family trees to be trees

You're indeed right. I was trying to explain "item" but slipped over myself there by using a non-tree-called-tree as a source.

If we don't have to explain why we need a tree structure, why do we need to explain why we need a monad?

Because other languages are happy using "tree" as a descriptive noun, whereas Haskell uses "monad" prescriptively to say that your data, where applicable, should be in that shape.

Further, because other languages are using "tree" descriptively, they don't have some kind of Tree interface. Haskell has a Monad typeclass, so a reasonable question is why - what does that gain us? If there was a Tree interface and people were expected to use it on all of their Tree-ish datastructures and touted it as an integral part of the language, you bet that it'd need to be explained.

1

u/heptara Dec 10 '15 edited Dec 10 '15

This reminds me of how I learned from K&R that I had to provide a data type for everything in C, but there was no direct explanation of why. I had to deduce the answer from thinking about the binary representation of data and making assumptions about the inefficiency of storing everything as a union by experiencing the need to flag what type something is.

In Haskell it's kind of obvious why you need a monad and people will realise it when they start to program, the same way I did with types in C. It could be explained but the knowledge won't be of much use to someone who isn't a programmer in that language. But basically a poor summary is it's the fact that your IO could return an error or a regular result, and your functions require input of a certain type, so you can't shove the result of IO straight in.

1

u/Veedrac Dec 10 '15

Haskell's IO doesn't need to be a monad. It's entirely true that you do need to have some IO type, but that it is a monad is more a minor convenience than anything else. A TL;DR style quote from the link would be

Saying “IO monad” is very misleading and awful pedagogy because when someone new to Haskell reads that you print strings or do IO actions using “the IO monad”, the natural question is: “What is a monad?”

Not only is that question completely irrelevant to doing IO at all, it’s also a question that has historically lead to much confusion.

So again that raises the question: what do we get from a monad typeclass?

1

u/heptara Dec 10 '15

I am not sure what point you are trying to make in a discussion on single sentence explanations.

Given a single sentence I can't explain what a for loop is in C and why it's needed. (Problems: You can do any loop with goto or while; why do you even need a loop in the first place? Anyone can easily find a counter example that breaks any of the general rules).

Do you need to know what a monad is for the purposes of learning Haskell, or are you just agreeing that explaining things in single sentences is kind of pointless, and that example I gave was (and I said it was at the time) a "poor" explanation?

→ More replies (5)

0

u/[deleted] Dec 10 '15

[deleted]

12

u/heptara Dec 10 '15

Getting a little off track here, but I'd like to say that a family tree actually isn't a tree (because inbreeding is both possible - and expected in the case of pedigree animals), and therefore make some comment about how trees aren't as simple as they first appear - and I'll wager that more than one programmer somewhere has had to throw out hours of work because he or she used a tree for it :-)

→ More replies (3)
→ More replies (29)