109

I just wrote:

move((x==0?(y==0?y:y-1):y),(x==0?0:x-1));

I should be arrested

Comments
  • 13
    no you shouldnt it looks great
  • 35
  • 16
    Arrested? That’s to kind after that. I’m just digging a hole and loading a gun
    πŸ’€ πŸ”« ⚰️
  • 15
    Realizing you have a problem is the first step to recovery.
  • 8
    @irene nope, cursor movement in a text editor
  • 4
    Not horrible, but certainly not great.
  • 4
    You can shorten the double ternary to
    x == 0 && y > 0 ? y - 1: y
    Not that much better but better
  • 2
    @YouAreAPIRate y > 0 is not opposite to y == 0
  • 5
    @akhrameev it is, but op said he is building a text editor and i assumed y will always be >0. If that's not true then you're right and you need to use y!=0
  • 3
    @YouAreAPIRate your assumption was correct, and that would be a better way of doing it
  • 1
    @YouAreAPIRate if we're talking about C, could not just use "!x" or "!y"?

    Everything besides 0 is "true" anyways. Notice the quotation, because booleans have no real place in C.
  • 2
    @Awlex you could. But if y is defined as uint the compiler will generate the same code and y>0 is better to understand. In the end it comes down to personal preference. And i rather do other things than discuss style
  • 2
    I read it really quick. Does it move the cursor to the beginning of the next line if it's at the end of the current one? Or back one line if it's at the beginning of a line? Something like that?
  • 2
    @YouAreAPIRate better not talk about personal preferences, because i would have written something like this for the first parameter:
    y - !(x|y)

    πŸ˜…
  • 1
    @Awlex i dont think that works in c, because thats a binary or. If x and y are greater than 1 then x|y could be too. But ++ for the idea
  • 1
    @YouAreAPIRate i used the binary or on purpose thoughπŸ˜‚
  • 1
    @Awlex that would work on bools but not on ints
  • 1
    So for example !(5|2) is not 0? @YouAreAPIRate
  • 1
    @Awlex damn, i forgot the !, that casts to bool. My bad
  • 0
    Did that shit in 9th & 10th grade (currently 12). I liked it because then the tasks were a challenge and you can fuck off your teacher xD
  • 1
    @irene I guess the compiler would do that anyways.
  • 0
    If it is c then why are you doing so many "x == 0". Can't you just use "!x"?
  • 1
    @Terrestrial you're right, didn't realise
  • 0
    @irene sorry maybe the irony didn't come through in that one.
    Yes it would make it harder to read. That's why he should have done it to make the line itself also harder to read.
  • 0
    @irene well looks like I blaimed you for not spotting my irony while I didn't spot yours 😬
Add Comment