Live data from Hacker News

I am a horse in the land of booleans

iloveponies.github.io

41–50 of 89 posts

Re: I am a horse in the land of booleans

#41
post #36

Earlier quoted context omitted.

> I personally don't find these shortcuts to be worthwhile They are, because they are the difference between driving with the parking brake on or not. Other languages don't have this so that's why people might not see the value in it first. > Writing `if x != 0` is not a large burden If you're comparing what can only be an int value, then it's not a burden. When your variable can assume multiple values, explicitly co…

I've worked in a lot of different languages, from ones that work the way I prefer all the way to Python-style languages where anything is a predicate and there are a bunch of semi-arbitrary rules about what qualifies as "false." This isn't a lack of familiarity talking. Regarding your examples, having an optional sequence is probably not the correct move anyway. Is there actually a semantic difference between no sequ…

> Is there actually a semantic difference between no sequence and an empty sequence?

It really depends on your function, but you might want to have the function behave differently if given an empty list rather than no list. One very common case for doing that is when you want to facilitate unit testing of a function.

> Not sure what you're referring to with get() in a dictionary.

A very common case, in which you don't care if the element is not present or it is a "False" element.

Re: I am a horse in the land of booleans

#42
post #36

Earlier quoted context omitted.

> I personally don't find these shortcuts to be worthwhile They are, because they are the difference between driving with the parking brake on or not. Other languages don't have this so that's why people might not see the value in it first. > Writing `if x != 0` is not a large burden If you're comparing what can only be an int value, then it's not a burden. When your variable can assume multiple values, explicitly co…

I've worked in a lot of different languages, from ones that work the way I prefer all the way to Python-style languages where anything is a predicate and there are a bunch of semi-arbitrary rules about what qualifies as "false." This isn't a lack of familiarity talking. Regarding your examples, having an optional sequence is probably not the correct move anyway. Is there actually a semantic difference between no sequ…

There are Python idioms for exactness, and idioms for truthiness. When in a situation where it's possibly ambiguous to test truthiness 'if x is None:' or 'if x is True': is completely unambiguous.

Most code doesn't need that and the truthiness nature of various data types is helpful in writing clear code.

Re: I am a horse in the land of booleans

#43
> if does not have a return value in a language like Java. In other words, it is not an expression, but a statement. Because everything in Clojure is an expression, there is no equivalent construct to Java’s if in it.

Anyone know the language design rationale behind the way Java does it? It seems much easier to make everything an expression. Ive always disliked that part of Javascript and being forced to use ternary operators to do a single line return statement for a conditional. Same with case statements.

Re: I am a horse in the land of booleans

#44
post #18
post #13

Clojure seems to have replaced the "p"[0] suffix in predicates with "?", the former being an old Lisp convention. Interesting choice, I'm mildly miffed they didn't go with the old convention. [0] http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec...

Question mark is a Scheme tradition. Clojure is a new lisp, drawing inspiration from many sources. One of Rich Hickey's goals, stated in many ways and in many of his presentations, was to design a modern lisp not bound by design decisions in old ones. That's why Clojure is not built on or directly based on any specific lisp. He has made a big point about moving on from lisp-isms such as `car` and `cdr`, which are bas…

"p" makes sense if you know that it stands for "predicate". It's not nearly as arcane as car and cdr.

Also can we finally settle on a name for these things now? If car and cdr are too arcane we can do away with them (though I like being able to do caddadadr) but why do we need "first" and "rest" rather than the already established "head" and "tail"? I particularly dislike "rest" since it's a relative term, i.e. in normal speech saying that you're going to do something with "the rest" of the list means something different depending on how much of the list you already used.

Re: I am a horse in the land of booleans

#45
post #18

Earlier quoted context omitted.

Question mark is a Scheme tradition. Clojure is a new lisp, drawing inspiration from many sources. One of Rich Hickey's goals, stated in many ways and in many of his presentations, was to design a modern lisp not bound by design decisions in old ones. That's why Clojure is not built on or directly based on any specific lisp. He has made a big point about moving on from lisp-isms such as `car` and `cdr`, which are bas…

"p" makes sense if you know that it stands for "predicate". It's not nearly as arcane as car and cdr. Also can we finally settle on a name for these things now? If car and cdr are too arcane we can do away with them (though I like being able to do caddadadr) but why do we need "first" and "rest" rather than the already established "head" and "tail"? I particularly dislike "rest" since it's a relative term, i.e. in no…

In Clojure, first and rest apply to sequences, which are a logical list abstraction. They apply to lists, but they can also be used on sequential views of indexed vectors, maps, sets, database result sets, files in a dir, lines in a file, and an open world of "things that can be seen in some order". head and tail I suspect are much more tied to linked lists and data structure than the more plain first and rest.

Re: I am a horse in the land of booleans

#46
post #43

> if does not have a return value in a language like Java. In other words, it is not an expression, but a statement. Because everything in Clojure is an expression, there is no equivalent construct to Java’s if in it. Anyone know the language design rationale behind the way Java does it? It seems much easier to make everything an expression. Ive always disliked that part of Javascript and being forced to use ternary…

If your control structures are expressions then they can lead to code that the maintainers of the language might not want to promote. Remember that language design is not just about being as flexible as possible. If it were we would have stopped with Lisp. Languages are also designed with readability, portability, and simplicity in mind.

Imagine if you could write this (nonsense) code in Java:

bool a = (while (b) { if (c) { b=d;} else { b=e; }});

While it is efficient, some may balk at how “implicit” it is.

Re: I am a horse in the land of booleans

#47
post #36

Earlier quoted context omitted.

I've worked in a lot of different languages, from ones that work the way I prefer all the way to Python-style languages where anything is a predicate and there are a bunch of semi-arbitrary rules about what qualifies as "false." This isn't a lack of familiarity talking. Regarding your examples, having an optional sequence is probably not the correct move anyway. Is there actually a semantic difference between no sequ…

> Is there actually a semantic difference between no sequence and an empty sequence? It really depends on your function, but you might want to have the function behave differently if given an empty list rather than no list. One very common case for doing that is when you want to facilitate unit testing of a function. > Not sure what you're referring to with get() in a dictionary. A very common case, in which you don'…

Behaving differently on an empty list than on no list is a huge smell. That's really weird and unexpected behavior. Doing it for testing is even weirder.

If you're fetching an element from a dictionary and want not-present to be the same as some false value, fetch with a default value (in Python, pass a second parameter to get()) that you want to see when there's nothing present. Or just extract the value and check for nil or empty separately, nothing wrong with being explicit.

Re: I am a horse in the land of booleans

#48

    Because Java’s if does not return a value,
    you cannot say:

      return if (x 
This would have been a nice place to make an analogy to the question mark operator, since a java programmer would probably be familiar with it and it allows you to write:

    return if (x 
as

    return x 

Re: I am a horse in the land of booleans

#49
post #43

> if does not have a return value in a language like Java. In other words, it is not an expression, but a statement. Because everything in Clojure is an expression, there is no equivalent construct to Java’s if in it. Anyone know the language design rationale behind the way Java does it? It seems much easier to make everything an expression. Ive always disliked that part of Javascript and being forced to use ternary…

> Anyone know the language design rationale behind the way Java does it?

Because C did it, because Algol did it, because Fortran did it, because that is how assembly code works. Expressions require code to be compiled to something that uses a temporary value stack (or equivalent, like what some continuation-passing style compilers do by allocating values from garbage-collected memory), which, along with subroutines, was an exotic technology well into the 1960s.

Re: I am a horse in the land of booleans

#50
post #34
post #9

Earlier quoted context omitted.

I'm not sure 0 being falsy is ever a good idea, it's just an assembly-ism that became a C-ism and spread from there. Zero is not a "special enough" value in the ring of integers. In general, these days I prefer as few implicit coercions as possible. In many Lisps, nil is the empty list literal, but interestingly not in Clojure, where it just maps to JVM null, and vectors are the most commonly used data type anyway. H…

It's not just an assemblyism, the near equivalence between 0 and false, and 1 and true is the thing that Boole wrote about for which Boolean values are named. I would argue that it's a math thing, not an assembly thing.

> I would argue that it's a math thing, not an assembly thing.

When you have a type system and boolean types, equating 0 and false is not a "math thing," it is more of a "mathematical illiteracy" thing.

Post reply on HN