News for hackers. Stuff that matters.
Re:Why I’m Using C by pritovido on Friday March 13, 2020 @09:56AM (#22567254)
I use C(as a backend) because I understand it.

In reality I use anything that gets the job done faster. That usually means prototyping in C++,lisp, python, swift, java, perl, lua.

After I have the prototype I code it automatically with C, or minimal C++ and my own DSLs, done in Lisp controlling C, C++ code generation.

I have reinvented the wheel a lot. Someone told me you are not going to be smarter than a compiler, but having read several of them, they are so dumb, and they have to be because they are generic.

E.G In a project I was using std::vector and predicted the expected performance of the whole program by O notation and "on the park" calculation needs as X.

When I completed the program, it was X/1000. Fair enough I made some stupid mistake...in the end I got X/100 performance and could not optimize farther.

I got so frustrated so I started replacing components to see if numbers improved. Replacing std::vector by a c vector made the program X/1.4!!

So I started studying std::vector implementation and it was a template of a template of a template... I could not wrap my head around such a mess.

My implementation was done in lisp with proper macros and was way simpler and efficient and generated c code, that was so easy (although tedious) to understand.

Re:Why I’m Using C by klodolph on Friday March 13, 2020 @10:05AM (#22567309)
Reading std::vector or most parts of the C++ standard library is the path of insanity. It puts you in touch with some fairly arcane parts of C++, and on top of that you have the allocator class, which std::vector inherits from rather than embeds because if it were embedded, it couldn’t be zero bytes (otherwise every object wouldn’t have a different address).

By comparison, glibc isn’t so bad to read. Same with the standard library for Python, Go, Rust, etc… I have never had such a problem reading library source code as I have with the C++ standard library.

Re:Why I’m Using C by ainar-g on Friday March 13, 2020 @10:06AM (#22567324)
If this[1] article is to be believed, STL can also perform poorly in a debug build.

[1] https://zeux.io/2019/01/17/is-c-fast/

Re:Why I’m Using C by BubRoss on Friday March 13, 2020 @10:45AM (#22567630)
If a std::vector is causing performance problems there is some major disconnect between how it is being used and how it is meant to be used.

Someone else noted that debug more will stifle performance, which is true and the most likely culprit.

Other problems can include constant resizing and memory allocation and copying, but when something is 1/100th the speed it should be, that screams debug mode being left on, which will do bounds checking on every access.

Re:Why I’m Using C by taylodl on Friday March 13, 2020 @05:38PM (#22571093)
Seriously, I'd like to see more about your Lisp DSLs controlling C, C++ code generation. I'm intrigued.
Re:Why I’m Using C by wuschel on Friday March 13, 2020 @02:18PM (#22569577)
Could you perhaps elaborate on the LISP/DSL approach to programming that leads to efficent and safe C code?

Thanks.

Re:Why I’m Using C by taylodl on Friday March 13, 2020 @05:37PM (#22571085)
I second this request!
Re:Why I’m Using C by wuschel on Saturday March 14, 2020 @03:45AM (#22573819)
A quick Google search gave quite a bit of results e.g. C-Mera [1].

[1] https://github.com/kiselgra/c-mera