my greatest character flaw is that I think ++ and -- is good syntax

@wallhackio It is an amazing syntax! Makes programs so much more concise... (Who ever said otherwise? :blobcatknife: )

@vaporeon_ To quote Douglas Crockford in his 2018 book How JavaScript Works:

"I do not recommend use of the increment operators ++ or --. They were created in antiquity for doing pointer arithmetic. We have since discovered that pointer arithmetic is harmful, so modern languages no longer allow it. The last popular language to boast of having pointer arithmetic was C++, a language so bad that it was named after ++."

I don't agree with it but I also appreciate C++ slander so I will permit it.

@wallhackio This isn't C++ slander, this is C slander, and I will not allow it :blobcatknife:

@wallhackio Also: you can increment any variable with ++, it doesn't need to be a pointer, you can just grab an integer variable and increment/decrement it, why does this guy think that they're only for pointer? :psyduck:

@vaporeon_ continuing the quote:

"We got rid of pointer arithmetic, but we are still stuck with ++. Now it adds 1 to something. Why do we need a different syntactic form to add 1 than to add every other value? How does that make any sense?

The answer is: It does not make any sense.

Making matters worse, ++ has a pre-increment form and a post-increment form. It is very easy to get them reversed, and that can be very difficult to debug. And ++ has been implicated in buffer overrun errors and other security failures. We should discard features that are unnecessary and hazardous."

@wallhackio :blobcatknife:

"Why do we need a different syntactic form to add 1 than to add every other value?"

Because 1 is a value that gets added much more frequently than any other number? To the extent that lost of instruction sets (including x86) even have a special instruction for adding/subtracting 1 instead of any other number? It is extremely annoying in Python to have to type (x+=1) instead of x++...

"It is very easy to get them reversed, and that can be very difficult to debug."

Skill issue

Sorry, this is genuinely a skill issue

I've never had trouble distinguishing ++x from x++

"And ++ has been implicated in buffer overrun errors and other security failures."

That's... not the fault of the ++ operator? Array boundaries are hard and it's easy to make off-by-one errors in your mental model. Being forced to write x+=1 instead would not fix the buffer overflow...

@wallhackio Who is this Douglas guy and who let him write a book about programming? :psyduck:

@vaporeon_ this 2018 book is very controversial. his 2008 book "JavaScript: The Good Parts" absolutely slaps though

@wallhackio I couldn't even imagined having opinions about the ++ operator before today, but now I have them and I'm angry at this guy

@wallhackio

is it ok to use ++ and -- when they are combined with other operations and operator [precedence] has to be considered?

An example of what they mean would be helpful TBH

But personally I think, when in doubt, always add brackets. C has some pitfalls regarding operator precedence, unfortunately... (Especially with & and |)

Follow

@vaporeon_ I personally haven't run into an issue with operator precedence that wasn't also a readability issue

@wallhackio if (x & BITMASK == 5) seems easy to read, but it gets treated as if (x & (BITMASK == 5)) — the opposite of what I would have wanted — for historical reasons!

@wallhackio Have you ever read my post where I talked about why this happened?

(And if not, does your instance have post search?)

@wallhackio OK, try searching for posts from Vaporeon that have something like chist or historical baggage in them

I can't do it myself because this instance doesn't have post search...

@wallhackio Might've been historical reasons, actually
Just search for historical, maybe

@wallhackio Yes! Turns out that I didn't talk about it as detailedly as I thought...

But you can read the linked article about very early C, from one of the guys who made C

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.