
Evil Coding Incantations - Garbage
http://9tabs.com/random/2017/12/23/evil-coding-incantations.html
======
boffinism
I know I'm biased by familiarity, but I really like that 0 is truthy in Ruby.
I often find that I want to check whether there is a number there at all,
whether it is 0 or not, and a truthiness test works well for that.

Is there a good reason, other than expectations brought from other langs, why
0 should be falsey?

~~~
aetherson
I hate truthy- and falsy-ness in general. It just seems like it's ripe for
messing up expectations. Why not just get an actual boolean?

~~~
djsumdog
I like the line in the Zen of Python, "Explicit is better than implicit."

You should get a type error if you try to use an int in boolean logic. I hate
auto type-conversion. Autoboxing in Java is kinda nice, but really the base
types should have been objects to begin with, and operator overloading should
have been allowed.

(Although I do admit operators in Scala get confusing as hell. I like one of
the recent RFCs that would require every Scala operator to have an actual
"word" function alias to go with it so you can tell what the hell it does).

~~~
Y_Y
But i assume you're ok with upcasting an int to a double. That is, unless you
make the Haskell Prelude. There is a real and useful sense in which booleans
are a subtype of integers and i think its not unreasonable to automatically
cast between them. Can't say if it's a good idea or not though.

~~~
Twisol
There is a real and useful sense in which _everything_ is an integer; see
Godel numbering. There's also a real and (debatably) useful sense in
mathematics in which everything is a set. Even still, we prefer to impose
structure and convention because it helps us understand what's going on, by
restricting the kinds of things we need to be able to expect.

Booleans are the same kind of thing. We don't normally do arithmetic on them;
at most we might treat `bool` like Z-mod-2. But Z-mod-2 behaves very
differently from `int`.

~~~
Y_Y
I'd love to hear of a case where anyone has actually computed a Goedel number.

We very often do arithmetic on booleans, the a canonical homomorphism (Iverson
bracket) with 1 ~ True and 0 ~ False where && and || are multiplication and
addition. But I guess you knew that.

~~~
yorwba
That is not the only homomorphism. You could just as well have 0 ~ True and 1
~ False, where && and || are addition and multiplication. Booleans don't have
enough algebraic structure to nail down a unique embedding. Integers and reals
don't have the same problem, because there's a unique ring homomorphism
between them.

~~~
catnaroek
Blessing noncanonical structures and mappings is indeed evil. Let's take this
to its logical conclusion and banish type classes.

~~~
yorwba
I'm not sure what you mean by that. Type classes are all about making
_canonical_ structures explicit.

~~~
catnaroek
Type class instances are only “canonical” by fiat. Once you elaborate type
classes into record-passing, by no means are the resulting instance types
uniquely inhabited.

This is just as bad as the existence of truthy or falsy values.

------
c3534l
"is" isn't equivalent to equality in Python. Is specifically checks the memory
address, not equality. Equality is checked with "==" like in any other
language. The author probably saw the is operator used somewhere and didn't
know enough Python and figured that since && and || are reserved for bitwise
operations whereas "and" and "or" are used for logical operations, "is" must
also be the Python version of "==".

~~~
Macha
Java's == is not used for equality for objects either, so it's a valid
comparison because Java's behaviour is equally unintuitive here. It's the same
behaviour as is for objects.

~~~
bunderbunder
Java's behavior feels like an almost deliberate trap, though. I have
previously lost hours to bugs resulting from a refactoring that changed a
value's type from int to Integer, and the resulting change in equality
semantics.

~~~
mjevans
That seems like such an anti-feature. I'd want the compiler to issue a warning
for it by default and the IDE to ship with 'warnings are errors' by default.

~~~
bunderbunder
Instead, we have some $$$$ static analysis tool that nags me endlessly about
using Optional<T> private fields, but lets using the == operator for non-
primitives sail past without comment.

------
maxxxxx
I am starting to hate languages that are not super picky and precise. We are
working with C#, PHP and JavaScript and between them it's almost Impossible to
remember what will evaluate as what. I would be perfectly fine if the only
input to an if was true or false, no number, no strings.

~~~
mikeash
Same here. I’ve used C for ages and now I’ve been doing a lot of Swift, where
if statements only operate on Bool values. I find it much better to be
explicit about any condition that isn’t literally true or false. The common
style of accepting all types and defining a set of “falsey” values just
encourages pointless shortcuts.

~~~
userbinator
_where if statements only operate on Bool values_

I mostly use Asm and C, and I have the exact opposite opinion: I hate
languages like that. It makes simple problems like "determine if more than 1
of 3 integers are greater than 4" require ridiculously verbose solutions.

~~~
mikeash
How can it be ridiculously verbose? Converting an arbitrary expression into
C’s notion of true or false just requires adding != 0 or != nil or similar.

~~~
userbinator
Try to write something more succinct and elegant than this:

    
    
        return ((a > 4) + (b > 4) + (c > 4)) > 1;

~~~
mikeash

      return [a, b, c].filter({ $0 > 4 }).count > 1
    

I disagree that your version is elegant. Succinct, yes, but I don’t think I’d
like to leave that for the next guy to discover.

~~~
maxxxxx
If you only do C you know this stuff. It gets confusing when you use a few
other languages that all have slightly different semantics.

------
oldandtired
The item in the list supplied for index starting at 1 shouldn't be there.

There are valid reasons for using 1 instead of 0 for the first element. It all
hinges on whether the address is being considered or the first element is
being considered.

One could consider languages that use 0 as the alternative referencing for the
end of some value that can be indexed and -1 as the last item of that value.

------
cygned
_The “Goes Down To” Operator_

Incredible elegant. If I used loops, I'd use that, too!

~~~
hateduser2
How do you not use loops?

~~~
cygned
Functional programming. Loops usually have some kind of mutated state and in
FP you use constructs like _map_ and _reduce_. No _for_ or _while_.

------
stevebmark

        def a
            def a
                "use ruby"
            end
            "dont"
        end
        a
        > "dont"
        a
        > "use ruby
    

:(

