News for hackers. Stuff that matters.
Re:Talking to C Programmers about C++ [video] by faragon on Sunday September 25, 2016 @07:34AM (#12574886)
In my opinion, many C++ projects would be simpler, cheaper, safer, and better maintained, if were written in C (with adequate libraries, e.g. for strings, vectors, maps, threads, timers, sockets, etc.).
Re:Talking to C Programmers about C++ [video] by sseagull on Sunday September 25, 2016 @09:17AM (#12575178)
A vector/map of what? How do I have a map of some key to a custom structure? How do you do this simply without templates? Separate libraries? Macro hell?

How do you handle types which need to free memory without destructors? Manually loop over the vector and free stuff every time one goes out of scope? That doesn't seem safer to me.

Re:Talking to C Programmers about C++ [video] by faragon on Sunday September 25, 2016 @09:25AM (#12575207)
>>A vector/map of what? How do I have a map of some key to a custom structure? How do you do this simply without templates? Separate libraries? Macro hell?

Separate libraries, without "macro hell".

>>How do you handle types which need to free memory without destructors? Manually loop over the vector and free stuff every time one goes out of scope? That doesn't seem safer to me.

Providing both heap and stack based allocation. E.g. allocating a vector in the stack would require no explicit de-allocation (example: https://github.com/faragon/libsrt). For heap allocation, you would need to call some sometype_free(&a) function, obviously (there is no RAII in C).

Re:Talking to C Programmers about C++ [video] by aksx on Sunday September 25, 2016 @09:46AM (#12575287)
>For heap allocation, you would need to call some sometype_free(&a) function

i find '__attribute__((cleanup (fn)))' fascinating in C, need to try it in some production code though.

Re:Talking to C Programmers about C++ [video] by pjmlp on Sunday September 25, 2016 @10:29AM (#12575464)
That is GCC C, not ANSI C.
Re:Talking to C Programmers about C++ [video] by loeg on Sunday September 25, 2016 @05:31PM (#12577563)
It's quite useful.
Re:Talking to C Programmers about C++ [video] by sseagull on Sunday September 25, 2016 @10:09AM (#12575369)
Yes, but it would still be hard to support custom types, wouldn't it? Ie in your library, I would have to use pointers, which might be unsafe? Adding types to a library like that (like double) causes the amount of code to grow dramatically (maybe even n^2 for maps).

You're library does look nice for what it does, and may have to look into it for some projects (I do have some C projects). Thanks!

Re:Talking to C Programmers about C++ [video] by faragon on Sunday September 25, 2016 @11:16AM (#12575676)
That library is still in beta stage, there are others.

For maps I've implemented integer, pointers, and strings, without code bloat (tree implementation is common, without macro-templates). I'm planning adding some generic type support for fixed-size elements, while keeping internal tree pointer-less and both stack and heap allocation possible, with minimal code bloat/duplication.

Re:Talking to C Programmers about C++ [video] by papaf on Sunday September 25, 2016 @04:25PM (#12577237)
I started converting picol to C++14 yesterday:

    http://antirez.com/picol/picol.c.txt
I have been programming in C++ for over 20 years and my version is bigger :-( Its nice not having to malloc/free but the moment I turned the structs to classes I was battling the bloat.

I still enjoy programming in C++ but there is a lot of truth in the criticism that programs written in C are simpler.

Re:Talking to C Programmers about C++ [video] by faragon on Sunday September 25, 2016 @04:37PM (#12577300)
I've been writing C++ for more than 20 years, too. In perspective, I made some mistakes when choosing writing many C++ components that could have been better/simpler/cheaper in plain C, with some abstraction via libraries (e.g. because complexes of not being seen as "smart enough", etc.). Writing simple/compact programs is hard both in C and C++, although, from my experience, bloat comes much more from C++ (inlining, etc.).

BTW, Salvatore Sanfilippo (antirez) is a very sharp programmer, able to write programs without redundancy and look easy (which is very difficult to achieve).

Re:Talking to C Programmers about C++ [video] by knocte on Sunday September 25, 2016 @11:01AM (#12575611)
facepalm
Re:Talking to C Programmers about C++ [video] by IshKebab on Sunday September 25, 2016 @03:51PM (#12577064)
I guess you're joking, but just in case, C++ prevents entire classes of errors that are almost guaranteed in C projects.
Re:Talking to C Programmers about C++ [video] by faragon on Sunday September 25, 2016 @05:21PM (#12577523)
I was not joking. Also, C++ introduces other classes of errors. There is no silver bullet.