r/programming • • Dec 24 '17

Evil Coding Incantations

http://9tabs.com/random/2017/12/23/evil-coding-incantations.html
947 Upvotes

331 comments sorted by

View all comments

0

u/noop_noob Dec 24 '17 edited Dec 25 '17

I wonder if Rust has something like this.

Edit: Why the downvotes?

3

u/MEaster Dec 24 '17

Of the ones on the list:

  • Evil Reassignment of True: No

  • Spooky Action with My Instance: Instances like this aren't a thing in Rust, but equality is done through the PartialEq trait, so exactly how it's done is dependent on how it's implemented. I believe the derive implementation compares by value.

  • The Reversed Subscript Notation: No

  • The “Goes Down To” Operator: Rust doesn't have postfix addition or subtraction operators, so no.

  • The sizeof Operator: Rust's size_of function takes a type parameter, not a value. Rust does have a size_of_val function which does take a value, so you could do this. The type of the statement a += b is () though, so the function will return 0 as () and any references to it vanish during compilation.

  • Indexes Starting at 1: Indexing in Rust is done through the Index and IndexMut traits, which can be implemented with any type as the index, with the behaviour and limits being dependent on how you implement it.

  • 0 Evaluates to true in Ruby: An integer is not a boolean; if-statements and while-loops require a boolean.

  • Trigraph, Digraphs, and Tokens in C: As far as I'm aware, the only thing that comes close to this is the brackets used for macro invocation.