News for hackers. Stuff that matters.
Re:My personal C coding style as of late 2023 by habibur on Monday October 09, 2023 @08:03AM (#37819536)
In my case :

- I prefer functions over classes.

- no mangling of exported names, the binary is re-usable as API.

- in the long term, the C source code is more re-usable in other projects than C++ ones.

and more like this.

Re:My personal C coding style as of late 2023 by kovacs_x on Monday October 09, 2023 @08:15AM (#37819631)
sure... and what about time spent debugging yet another unallocated/untimely freed/off by 1 pointer mistake?

ps. you know you can write C++ code that is functional and use free functions primarily instead of putting everything in classes?

Re:My personal C coding style as of late 2023 by habibur on Monday October 09, 2023 @11:49AM (#37821664)
you can run valgrind and it will just point to you "you freed the memory on this line and then tried to reused it 10 lines bellow here, fix it." -- every time.

And once you fix it, you have built a light weight library that you can use from any other language.

Also these pointer manipulation is what gives C its power.

Re:My personal C coding style as of late 2023 by uxp8u61q on Monday October 09, 2023 @08:48AM (#37819898)
> I prefer functions over classes.

Then use functions?

> no mangling of exported names, the binary is re-usable as API.

Not once in my life have I seen someone use a binary as an API.

> in the long term, the C source code is more re-usable in other projects than C++ ones.

I don't even know what you mean by that.

Re:My personal C coding style as of late 2023 by lelanthran on Monday October 09, 2023 @12:57PM (#37822471)
> I don't even know what you mean by that.

He means that if you write your library in C it is callable from Python, Java, C++, Ruby, PHP, Python, Perl and more.

Re:My personal C coding style as of late 2023 by uxp8u61q on Monday October 09, 2023 @01:25PM (#37822837)
You can also do that with C++.
Re:My personal C coding style as of late 2023 by lelanthran on Monday October 09, 2023 @01:42PM (#37823076)
No, you cannot.

Because C++ without exceptions is not C++, and those languages cannot catch exceptions, nor call overloaded functions, nor delete or create objects using new and delete, nor refer to fields with classes, nor call methods on objects.

Re:My personal C coding style as of late 2023 by uxp8u61q on Monday October 09, 2023 @02:05PM (#37823288)
> Because C++ without exceptions is not C++

Write exception-free external APIs. It's not that hard.

> call overloaded functions

Write an API that doesn't overload functions?

> nor delete or create objects using new and delete

Write an API around that. You'd need to do it in C anyway.

> nor refer to fields with classes

What?

> call methods on objects

If you can call a function, you can call a method.

Your complaint is basically "you cannot write C++ in Python". Duh.

Re:My personal C coding style as of late 2023 by lelanthran on Monday October 09, 2023 @02:13PM (#37823373)
> Your complaint is basically "you cannot write C++ in Python". Duh.

Maybe it is a complaint, but it's still a fact of life: your code is not reusable without wrapping it in C.

The reality is that C++ is not as reusable as C is: ever wonder why there are so few reused libraries written in C++, while they are so many in C?

Look on your system now - it's filled with C libraries, while the C++ libraries are probably a rounding error.

Re:My personal C coding style as of late 2023 by rtz121 on Monday October 09, 2023 @08:50AM (#37819920)
> - I prefer functions over classes.

I also prefer apples over brooms.