Recent

Author Topic: C operators and shift  (Read 3922 times)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 574
Re: C operators and shift
« Reply #30 on: December 06, 2024, 11:27:49 pm »
One day, you will tell your Personal Desktop Programming Assistant (PDPA) that you find compounds like += offensive and (s)he will take care that you never have to see one again.

Does anyone remember if the JACM ever adopted a standard language for publishing algorithms?

VisualLab

  • Hero Member
  • *****
  • Posts: 614
Re: C operators and shift
« Reply #31 on: December 07, 2024, 12:36:54 am »
More along the lines of:if you implement it half then finish the other half too.

Or (the most reasonable one):

It would be best if C operators in Pascal are deprecated to discourage further use.



C style operators reduce complexity and thereby cognetive load.

I have to disagree with this. When skimming through, I've read x *= a+b; as x := a+b; While the other x := x*(a+b); was clear as day what it is, and it is why I had to go back and reread the first statement that I had misread. <cut/>

I personally don't like reading cryptic code like x /= -x-- + ++y / -y++;

This is not a matter of taste, I can mathematically prove to you that this expression is less complex

Rather:

...although like much else in this thread they're "personal opinion" (and to Hell with what the wider programming community expects).



In my POV, considering the beginnings of the C language more as macro assembly that a real language, most of the specific operators can be recognized as shortcuts for a PDP-11 addressing modes. That includes pre-decrements, post-increments, shortcut-assignments (Dest op Src -> Dest). I'm not experienced with PDP-11 but have with m68k and the similarities are striking. Anyone who has seen a disassembled C program for m68k will confirm how well suited the language is for the architecture.

IMO Claims that shortcut-assignments improve readability are simply ridiculous.

It is worth recalling here what the hardware Denis R (and his buddies) used was like. The reason C code is confusing (cryptic) is probably the same reason why Unix commands were short to the point of exaggeration (and unreadability). The archaic (by today's standards) console was a slow (and prone to failure) electro-mechanical device. After a decade, the arguments for “encrypted” C notation have become completely obsolete. Unfortunately, the world has been stuck in this IT cesspool for many decades. I wonder what costs societies have borne over all these years, due to the stubborn enforcement of C in IT.



C was a completely ill-considered language design (as was the product written in it). It was created quickly for short-term use. And that's how it stayed. No one bothered to improve this cockroach for all these years. And then there was a young, stupid and sentimental person (now he's old, stupid and probably unsentimental) who said that nothing better than C had been created. Well, understandably, he was young and stupid :)

Warfley

  • Hero Member
  • *****
  • Posts: 1837
Re: C operators and shift
« Reply #32 on: December 07, 2024, 12:57:58 pm »
C was a completely ill-considered language design (as was the product written in it). It was created quickly for short-term use. And that's how it stayed. No one bothered to improve this cockroach for all these years. And then there was a young, stupid and sentimental person (now he's old, stupid and probably unsentimental) who said that nothing better than C had been created. Well, understandably, he was young and stupid :)

The little factual information you provided here is just plain wrong. C is standardized by ANSI first and now by the ISO and the first C standard is not always backwards compatible. Especially the first version C89, which took 6 years to develop, was not fully compatible with the original C. So you are just plain wrong. A bunch of people sat down for over half a decade with the expressed intend to better the language, and they decided that some parts of the language were bad and kicked them out and added new parts.
So your claim is just completely and factually wrong.

Also C is not badly designed. Remember it's the most successful programming language ever conceived. Like all their design decisions, which are as part of the standardization documented thoroughly, make sense in the context they were decided. Most things people claim are bad design are some of the reasons why C is so successful.

Like you can say you don't like C, personal preference is always valid and does not need to be justified or rational. But the success of C is objectively measurable, and those design decisions are the reason it's so successful. So calling it a badly designed language is just plainly untrue
« Last Edit: December 07, 2024, 01:00:02 pm by Warfley »

Thaddy

  • Hero Member
  • *****
  • Posts: 16312
  • Censorship about opinions does not belong here.
Re: C operators and shift
« Reply #33 on: December 07, 2024, 01:12:19 pm »
Code: [Select]
[quote author=Warfley link=topic=69520.msg540335#msg540335 date=1733572678]
 Especially the first version C89
Huh? Just the first standardized. first public version is k&r.
Quote
Also C is not badly designed.
Yes, it was. But the standardization tried at least to put in some discipline.
Quote
But the success of C is objectively measurable, and those design decisions are the reason it's so successful.
To programmers, "laziness is a warm gun", it is also measurable that people tend to find the easy way out so that observation is to be expected from a social science point of view.
That has nothing to do with any misgivings about the C language, just adding some perspective.

Write your code fast, debug your code exponentially slower.

Been there, done that.. I still use C, though. And C++, but you know that.
« Last Edit: December 07, 2024, 07:33:38 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8083
Re: C operators and shift
« Reply #34 on: December 07, 2024, 01:48:35 pm »
Huh? Just the first stadardized. first public version is k&r.

From context, he means the ANSI-standardised variant rather than ISO.

And perhaps the most important part of standardised C is that it's taken on board the concept of types, largely from Pascal.

The first compliant compiler was from Topspeed, who despite being primarily focused on Modula-2 weren't total idiots.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11980
  • FPC developer.
Re: C operators and shift
« Reply #35 on: December 07, 2024, 04:27:15 pm »
  But the success of C is objectively measurable, and those design decisions are the reason it's so successful.

C became popular because of Unix, not because its intrinsic strengths  Period.

Its design (or lack thereof) was just good enough to tag along. 

Had it have to make it on its own, we probably never had heard of it.

Warfley

  • Hero Member
  • *****
  • Posts: 1837
Re: C operators and shift
« Reply #36 on: December 07, 2024, 05:04:03 pm »
C became popular because of Unix, not because its intrinsic strengths  Period.

Its design (or lack thereof) was just good enough to tag along. 

Had it have to make it on its own, we probably never had heard of it.

But was designed to be used for Unix. Take the C buildsystem, it's designed to provide ABI stability, because it is intended to provide a stable ABI for programs to communicate with the OS. C was explicitly designed to be a good fit for developing Unix.
The C ABI allows you to link C99 programs together with units written in C89, or even Fortran or Pascal. This is essential for e.g. building drivers independently from the Kernel.
Pascal might have a better module system with its units, but on the other hand try creating a Pascal program that Interfaces some units written in FPC 1.6 with some written in 3.2. You can't because FPC is not ABI stable, because it is not a design criterium, so it doesn't need to be. But Pascal wasn't developed to write an OS in it.

And this is not just an arbitrary example, if you look at the Linux Kernel source you'll  find parts written in C89, parts in C99 or C11, parts in assembly, parts in rust, etc. And this is possible because the C buildsystem was specifically designed to make that possible

Without this design of C Unix would not have been possible, so saying that C is only popular because of Unix is just a part of the picture. Nearly all of Cs design decisions, especially those that many programmers dislike are directly a result of C being specifically developed to be used for OS development.

Unix could have never been written in Pascal, because Pascal was way to high level back then (Pascal didn't even support bit operations back then). Yes C would not be popular without Unix, but Unix could have never existed without C. No other language back then could have filled the role that C did, and since then C has been developed to further fill that role. C is not designed to be a high level language, and most of the criticism towards C comes from that fact. But in the end it never tries to be that.
« Last Edit: December 07, 2024, 05:10:16 pm by Warfley »

VisualLab

  • Hero Member
  • *****
  • Posts: 614
Re: C operators and shift
« Reply #37 on: December 07, 2024, 07:26:28 pm »
C was a completely ill-considered language design (as was the product written in it). It was created quickly for short-term use. And that's how it stayed. No one bothered to improve this cockroach for all these years. And then there was a young, stupid and sentimental person (now he's old, stupid and probably unsentimental) who said that nothing better than C had been created. Well, understandably, he was young and stupid :)

The little factual information you provided here is just plain wrong. C is standardized by ANSI first and now by the ISO and the first C standard is not always backwards compatible. Especially the first version C89, which took 6 years to develop, was not fully compatible with the original C. So you are just plain wrong. A bunch of people sat down for over half a decade with the expressed intend to better the language, and they decided that some parts of the language were bad and kicked them out and added new parts.
So your claim is just completely and factually wrong.

But developing a strict specification of a solution (standardization) does not make the shortcomings of this solution disappear. The flaws are still there, it's just that now they have formal "anointing" from the standards committee. I also did not claim that C did not undergo certain changes and corrections. Only that these were rather superficial corrections in the language itself. The larger changes you write about concerned compilers and linkers. And they were important for compiler creators, not programmers using C for purposes other than developing Unix for various machines. Only that I did not mean this in my criticism of C - I did not mean internal details concerning the methods of generating executable code by the compiler. Because such changes were also introduced in compilers of languages ​​other than C. And they had to be introduced because of the architecture of operating systems. Because their executable files (libraries) were generated by C compilers.

Also C is not badly designed. Remember it's the most successful programming language ever conceived. Like all their design decisions, which are as part of the standardization documented thoroughly, make sense in the context they were decided. Most things people claim are bad design are some of the reasons why C is so successful.

Like you can say you don't like C, personal preference is always valid and does not need to be justified or rational. But the success of C is objectively measurable, and those design decisions are the reason it's so successful. So calling it a badly designed language is just plainly untrue

You identify the popularity of a technical solution with its quality. These are two different things. At one time, the Trabant was very popular in Central Europe. Was it the most successful car model? Or maybe its popularity was due to something else? It was (and still is) similar with the C language. It is popular despite its many flaws. And not because it has many advantages. Simply put, large corporations are hostages to an old technical solution. This is simply technical debt.

Therefore, rather:

  But the success of C is objectively measurable, and those design decisions are the reason it's so successful.

C became popular because of Unix, not because its intrinsic strengths  Period.

Its design (or lack thereof) was just good enough to tag along. 

Had it have to make it on its own, we probably never had heard of it.

Warfley

  • Hero Member
  • *****
  • Posts: 1837
Re: C operators and shift
« Reply #38 on: December 07, 2024, 07:47:27 pm »
But developing a strict specification of a solution (standardization) does not make the shortcomings of this solution disappear. The flaws are still there, it's just that now they have formal "anointing" from the standards committee. I also did not claim that C did not undergo certain changes and corrections. Only that these were rather superficial corrections in the language itself.
As someone who had to combine a C89 and a C11 codebase I can only disagree. Unless you mean the very superficial features like syntactic structures, sure C will always stay c. A pointer will always be declared by the * operator. But to me Syntax doesn't matter. I know many Pascal programmers boil the differences in language down to begin-end vs { }, but that's just a difference without a distinction. There have been major changes in C such as the introduction of a bool type, introduction of the stdint types, inline variables, complex numbers, vlas, removing of implicit typing, stricter requirements on function signatures. Just to name a few changes they did to the language.

You identify the popularity of a technical solution with its quality. These are two different things. At one time, the Trabant was very popular in Central Europe. Was it the most successful car model? Or maybe its popularity was due to something else? It was (and still is) similar with the C language. It is popular despite its many flaws. And not because it has many advantages. Simply put, large corporations are hostages to an old technical solution. This is simply technical debt.
Did you really compare a car that was the result of import/export restrictions between different blocks with the most popular programming languages around the world for 50 years?
C is older than the GDR ever got and there are hundreds of programming languages out there anyone can use for free. People in central Europe simply couldn't get a Volkswagen or a Fiat. But anyone can use Pascal instead of C. And let me remind you that Microsoft tried to kill C with their proprietary MSVC++ and COM but failed

So yes being the most popular solution for well over half a *century* with free access to hundreds of alternatives is a sign of quality. That's not just a fluke. C must be doing something right. It exists nearly as long as computers exist and has been the most popular programming language over all this time.

Seenkao

  • Hero Member
  • *****
  • Posts: 648
    • New ZenGL.
Re: C operators and shift
« Reply #39 on: December 07, 2024, 08:17:06 pm »
Хотел много написать, но больше на грубость становится это всё похоже. Я лучше не буду дальше дискутировать на данную тему.
Могу сказать только одно, мнение человека - субъективно. Для объективного мнения надо уметь учитывать чужие мнения.

-------------------
Google translate:
I wanted to write a lot, but it all starts to look more like rudeness. I'd better not discuss this topic any further.
I can only say one thing, a person's opinion is subjective. To have an objective opinion, you need to be able to take other people's opinions into account.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

440bx

  • Hero Member
  • *****
  • Posts: 4876
Re: C operators and shift
« Reply #40 on: December 07, 2024, 08:42:28 pm »
That's not just a fluke. C must be doing something right.
Not necessarily.  C greatly benefits from the inertia of having been used to write Unix, thereby demonstrating a certain capability level.  That does not mean it was done right, it most certainly wasn't.

IMO, what C got right is its feature set (though many desirable features were/are missing.)  The design of the language is so atrocious it would probably embarrass the missing link.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Warfley

  • Hero Member
  • *****
  • Posts: 1837
Re: C operators and shift
« Reply #41 on: December 07, 2024, 09:09:28 pm »
IMO, what C got right is its feature set (though many desirable features were/are missing.)  The design of the language is so atrocious it would probably embarrass the missing link.
I don't argue C is perfect, the function pointer Syntax is absolutely atrocious and there's a reason c++ introduced a new type for them. Also I'm the first person to criticize things like that all pointers are implicitly nullable (hoars billion dollar mistake) or the missing bool type or the weak typechecking on enums.
But while not being perfect especially on retrospect, it's far from being badly designed. It has proven quite well and as a choice for very big projects over decades.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11980
  • FPC developer.
Re: C operators and shift
« Reply #42 on: December 07, 2024, 09:19:31 pm »
C became popular because of Unix, not because its intrinsic strengths  Period.

Its design (or lack thereof) was just good enough to tag along. 

Had it have to make it on its own, we probably never had heard of it.

But was designed to be used for Unix.

For the Unix of the early seventies yes, to work around the memory limits back then by separating the workload over multiple batch processes.

A lot of its baggage is irrelevant after the 1985-1990 period


VisualLab

  • Hero Member
  • *****
  • Posts: 614
Re: C operators and shift
« Reply #43 on: December 07, 2024, 09:46:42 pm »
But developing a strict specification of a solution (standardization) does not make the shortcomings of this solution disappear. The flaws are still there, it's just that now they have formal "anointing" from the standards committee. I also did not claim that C did not undergo certain changes and corrections. Only that these were rather superficial corrections in the language itself.
As someone who had to combine a C89 and a C11 codebase I can only disagree. Unless you mean the very superficial features like syntactic structures, sure C will always stay c. A pointer will always be declared by the * operator. But to me Syntax doesn't matter. I know many Pascal programmers boil the differences in language down to begin-end vs { }, but that's just a difference without a distinction. There have been major changes in C such as the introduction of a bool type, introduction of the stdint types, inline variables, complex numbers, vlas, removing of implicit typing, stricter requirements on function signatures. Just to name a few changes they did to the language.

Agreed, improvement is generally perceived positively. However, changes introduced in C may be perceived in different ways. What is a very big change (a real big, maybe groundbreaking, improvement) for one person is just a minor superficial patch (a useful but still minor improvement, change, not a major improvement) for another person. This is because people have various needs.

You identify the popularity of a technical solution with its quality. These are two different things. At one time, the Trabant was very popular in Central Europe. Was it the most successful car model? Or maybe its popularity was due to something else? It was (and still is) similar with the C language. It is popular despite its many flaws. And not because it has many advantages. Simply put, large corporations are hostages to an old technical solution. This is simply technical debt.
Did you really compare a car that was the result of import/export restrictions between different blocks with the most popular programming languages around the world for 50 years?
C is older than the GDR ever got and there are hundreds of programming languages out there anyone can use for free. People in central Europe simply couldn't get a Volkswagen or a Fiat. But anyone can use Pascal instead of C. And let me remind you that Microsoft tried to kill C with their proprietary MSVC++ and COM but failed

In the case of the Trabant, there were several different reasons why people in Central Europe did not have access to better cars (i.e. not only restrictions on import and export). The main source of the problems was communism imposed from above by the USSR (and supported by local regimes), which blocked everything: education, research development, inventiveness, industriousness, industry. In this area, various proposals appeared from time to time, but they quickly died due to lack of financial support and top-down decisions of state apparatuses. All activities of the residents of the "people's democracies" had to fit the communist party line. Any questioning of the communist status quo was suppressed. Therefore, the achievements of these countries were such "Trabants" (i.e.: somehow it worked and had to be enough for these people).

In the case of C, its dominance distorted the thinking of most programmers. For years, a tirade was promoted: "C is the best because Unix was written in it. Period.". Meanwhile, this is just a kind of computer dogma, a kind of computer ideology. If Unix had not been created, another OS would have taken its place. And then, perhaps, the costs of software development would be lower and its quality better? Of course, we will never know today. But we were left with this outdated technical solution (I mean: C) – for so many years! And to this day, “the IT terrain is sterile”, because most IT people believe (yes, believe!) that Unix and C were the greatest achievements of humanity in IT. Meanwhile, the basis of development is skepticism, searching for flaws in existing solutions, and not reveling in half-baked solutions (improvements in C) and falling into self-satisfaction (“well, we improved it, now it's great”).

So yes being the most popular solution for well over half a *century* with free access to hundreds of alternatives is a sign of quality. That's not just a fluke. C must be doing something right. It exists nearly as long as computers exist and has been the most popular programming language over all this time.

The most popular doesn't mean the best. JavaScript is the most popular! Why? Because it is mandatory. You can't use anything else in a WWW browser. This is a kind of specific coercion. The use of C has in a way "concreted" the IT area (in this negative sense). C was used not because it was the best, but because people very often had no choice. And the more they used it, the more code grew. At some point they became hostages to this behavior due to the amount of code. Exactly the same way as it happened with Cobol earlier. But the dependency is much greater than in the case of Cobol.



But let no one accuse me of only complaining about C and not seeing its advantages. Yes, it has advantages, or rather one. Or more precisely, its compiler has this advantage. It is the ability to generate machine code, which is quite efficient in operation.

Warfley

  • Hero Member
  • *****
  • Posts: 1837
Re: C operators and shift
« Reply #44 on: December 07, 2024, 10:06:56 pm »
complaining about C and not seeing its advantages. Yes, it has advantages, or rather one. Or more precisely, its compiler has this advantage. It is the ability to generate machine code, which is quite efficient in operation.
But also this is not just the Compiler but also because c is designed to allow for easy optimization on a language level. To give a positive and a negative example, first the positive, the probably most important information for the Compiler to do optimizations is the information what data is constant and what isn't. The C type system does allow to Tag any object as const, so you can have pointers to const data, records can contain some mutable and some immutable fields, etc. Many languages do not have that. Pascal only has const for parameters and this only on the top level, meaning you cannot express something like a mutable pointer to const data like you can in C. So many optimizations the C Compiler does are things the FPC could never do because the Pascal language does not give the developer the tools to express this information in code.

And for a negative example, the design of classes in object Pascal is inherently inefficient. Creation and destruction of a class instance requires multiple virtual function calls, the creation of implicit exception handlers, etc. The design of classes in Pascal means they cannot be as efficient as e.g. C structs (note that die to RTTI also Pascal records can be much more inefficient) or C++ classes

Again you cannot decouple the language design from the capabilities of the Compiler. And again a lot of the decisions that people usually criticize about C stem from that. E.g. is char signed or u signed? Well it's undefined because of optimizations. Is int/short/long 16, 32, 64 or whatever bit? Undefined because of optimizations.

Like most of the "problems" of the design of C either boil down to features required for developing low level systems like OS, drivers, etc. or Optimizations.
There are a lot of things in C that make it awful to use as a high level language, but that's because C was never intended to fill that role. The position C is in is not despite it's design, but because of it. And you don't need to like it for a lot of use cases, like I wouldn't want to write a GUI data management software in C, this doesn't mean it's badly designed, it's just not designed for that usecase
« Last Edit: December 07, 2024, 10:08:45 pm by Warfley »

 

TinyPortal © 2005-2018