Live data from Hacker News

Don't use the greater-than sign in programming (2016)

llewellynfalco.blogspot.com

51–60 of 96 posts

Re: Don't use the greater-than sign in programming (2016)

#51

I really think this is just bikeshedding over style. If we were optimizing for readability and predictability, we'd standardize on the most commonly used format. ``if (x > 5 && x Putting a rule that variables should always be on the left hand side of a comparison also gives you only 2 ways to write any conditional, so it's just as good as getting rid of ``>``. It also has the advantage of being by far the most widesp…

The article was about programming style. You write about team meetings. There is a disconnect.

Re: Don't use the greater-than sign in programming (2016)

#52
post #25
post #21

Earlier quoted context omitted.

is there really a naming distinction between ‘>’ and ‘ the ‘greater’ than sign? Interesting if so! I always assumed it was context dependent (i.e x < 10 could be said 10 is greater than x, so it’s still acting as a greater than sign - but I see why I’m probably wrong here). I was interested in seeing an arguement like another poster made, where notation be like x = [0,1] might be proposed.

> is there really a distinction between ‘>’ and ‘ The convention I've always seen is that `>` is "greater than" and ` 2` is "x is greater than 2" and `2 I don't know if the names are reversed in languages that are read right to left?

By convention, math is always left to right regardless of the direction of the script it's in, so presumably the operators do the same.

Re: Don't use the greater-than sign in programming (2016)

#53
post #31

I had to write a scripting language for a personal project. Since I could create whatever syntax I wanted, I used this: 'if x==4' was written as 'x[4]' 'if x>2 && x 'if x>=2 && x Etc. It was very easy to read and write... at least for me.

What if you wanted ‘if x>2 || x < -2’?

That's not exactly a challenge for the syntax...

    if-not x[-2,2]
Just like you'd write x ∉ [-2,2] with pen and paper.

Re: Don't use the greater-than sign in programming (2016)

#54
post #31

I had to write a scripting language for a personal project. Since I could create whatever syntax I wanted, I used this: 'if x==4' was written as 'x[4]' 'if x>2 && x 'if x>=2 && x Etc. It was very easy to read and write... at least for me.

What if you wanted ‘if x>2 || x < -2’?

Not parent, but I would write

    x)-2,2(
or

    x![-2,2]

Re: Don't use the greater-than sign in programming (2016)

#55

Qualification: Don't use the greater sign when doing range checks. Counter-point: When checking if a variable is greater than a constant, using the less than is very confusing since we read left to right. if(x > LIMIT) { Read "If x exceeds LIMIT, then" The opposite reads like "If the LIMIT is less than x", which sounds strange and emphasizes the wrong thing, implying LIMIT changed, not x.

Yeah, I think the article has a point for complex/chained expressions.

But if the way you think about the domain is "if x is larger than LIMIT..." you should write it `if (x > LIMIT)`!

Re: Don't use the greater-than sign in programming (2016)

#56

I really think this is just bikeshedding over style. If we were optimizing for readability and predictability, we'd standardize on the most commonly used format. ``if (x > 5 && x Putting a rule that variables should always be on the left hand side of a comparison also gives you only 2 ways to write any conditional, so it's just as good as getting rid of ``>``. It also has the advantage of being by far the most widesp…

But by far the best option is to not have a meeting at all and to not care about things like this.

Indeed. This article reads like someone who doesn't understand inequalities, and proposes a quite possibly hazardous shortcut to it instead. To not understand such basic maths is baffling (this is primary-school stuff), and I wonder at the state of maths education these days to see adults struggling with these concepts.

I have never in over 3 decades of programming ever had to ask myself the question of how to write conditional expressions --- it's something that comes naturally, and in this specific case I would also write it with the variables on the left.

Re: Don't use the greater-than sign in programming (2016)

#57
post #2

Ha, I've been using this trick for a while, though I wouldn't go so far as to say "don't use the greater-than-sign." Honestly I just wish languages had a cleaner way to write "x is within this range," e.g. "if x in [2,4)"

Swift has it. I'm sure a few languages must have it. if (2...4).contains(x)

This doesn't work for me:

  $ swift
  Welcome to Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1). Type :help for assistance.
    1> let x = 3
  x: Int = 3
    2> if x in 2...4 {}
  error: repl.swift:2:6: error: expected '{' after 'if' condition
  if x in 2...4 {}
       ^
Are you sure you didn't mean to use if case?

  if case 2...4 = x

Re: Don't use the greater-than sign in programming (2016)

#59
post #31

I had to write a scripting language for a personal project. Since I could create whatever syntax I wanted, I used this: 'if x==4' was written as 'x[4]' 'if x>2 && x 'if x>=2 && x Etc. It was very easy to read and write... at least for me.

I suppose the language has neither array subscripting nor function calls? Or did you decide to invent other creative syntax for those?

Re: Don't use the greater-than sign in programming (2016)

#60
http://4.bp.blogspot.com/-vglPHDBuUgI/VsniES7XnKI/AAAAAAAAD9...

The number line representation is incorrect. (5 < x && x < 10) represents x has possible values of 6,7,8,9 (assuming x is int), whereas the number line shows that 5 and 10 are inclusive, but that's not the case as per the provided example.

Post reply on HN