Live data from Hacker News

Talking to C Programmers about C++ [video]

youtube.com

111–120 of 128 posts

Re: Talking to C Programmers about C++ [video]

#111
post #25

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.).

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]

#112
post #111
post #25

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.).

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.

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]

#113
post #25

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.).

I guess you're joking, but just in case, C++ prevents entire classes of errors that are almost guaranteed in C projects.

I was not joking. Also, C++ introduces other classes of errors. There is no silver bullet.

Re: Talking to C Programmers about C++ [video]

#114
post #52
post #44

Earlier quoted context omitted.

>>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 all…

>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.

It's quite useful.

Re: Talking to C Programmers about C++ [video]

#115
post #110
post #62

Earlier quoted context omitted.

People that don't write portable C code think that they know 95-100% of the language. I don't miss the days in the late 90's, early 2000, writing portable C code across multiple compilers from each OS vendor, across all major UNIX flavours and Windows. Many that think to master C, actually master C in compiler X targeting OS Y.

What a sweeping generalization. Perhaps. But it's certainly easier to master portable C than portable C++.

Yes, that is quite true.

However I prefer that pain, to the lack of strong typing that C++ offers over C.

But better would be to use something else instead of C and C++, more type safe, without UB and without the wide range of implementation differences and compiler extensions.

Re: Talking to C Programmers about C++ [video]

#117
post #56

Earlier quoted context omitted.

Personally I think that looks pretty good. There's no templates, no inheritance. Not sure what would make bloat there nor latency. Whatever the faults of the syntax for folding, it's got to be better than VA_ARGS hasn't it?

There are templates: for example void print1(auto x){std::cout is a function template template void print1(T x){std::cout This is not valid C++14 however, so it doesn't compile. If you replace these, you'll probably still get a stack overflow while expanding the templates because there are almost 7000 arguments to a single function call.

And that works if you use the old C style variadic functions?I suppose I see no reason why it wouldn't, but that isn't the same.

Re: Talking to C Programmers about C++ [video]

#118
post #59

Earlier quoted context omitted.

A discussion about "proper functional programming" is not particularly relevant, because the topic is functional programming in the context of C++. The constructs that C++ offers for FP are not complicated.

Sorry, but this is just simply not true. If you've never done functional programming before, then I could see why you think doing it in C++ is not complicated. Here is an example of just how large the can of worms gets when attempting to bring functional programming to C++: https://bartoszmilewski.com/2013/11/13/functional-data-struc... and: https://bartoszmilewski.com/2013/11/25/functional-data-struc... And, I disag…

Fine, what shall we call this programming style in C++ (lambdas, immutability, function composition, etc) so that everyone is happy then?

Functional style C++?

I haven't felt the need to go deeper than that, it's very possible that I've missed many interesting things, but it's not clear that I can use those things and see tangible benefits in my projects today.

Re: Talking to C Programmers about C++ [video]

#119
post #19

Earlier quoted context omitted.

What are the components of C++ that add up to 100%? I can count: * language basics (variables, structural statements, functions, error handling, preprocessor, how compilation works) * OOP * functional programming (which is not that complicated at all in C++) * generic programming * advanced generic programming and metaprogramming * the C standard library * the C++ standard library basics (containers, algorithms, smar…

> * OOP C++ OOP is an endless tire fire. I now have 7 years experience writing C++ "OOP" on the job and I still run into surprises when I try to do things that are easy in other languages but unnecessarily hard in C++. Plenty of examples in the C++ FQA[1]. [1] http://yosefk.com/c++fqa/inheritance-mother.html#fqa-23.5

I'm not an expert at this, but it seems to me that it would be a good idea to take the time to learn it properly in one go instead of independently discovering all the mistakes that can be made in 7 long years and then being upset about it.

Re: Talking to C Programmers about C++ [video]

#120

Earlier quoted context omitted.

I will agree with the point that the other methods of reading/writing from streams aren't taught early enough, and that formatted output is pretty bad with streams. I've actually written a wrapper around snprintf for printing in c++ (I should put that on github sometime) Your project looks good. Two minor observations: 1.) You have 'using' statements in a header file. This is fine for a small project, but is consider…

I wasn't sure how const worked in this language so I decided not to mess with it yet. Coming from Java I have a blanket policy that every variable is final unless needed to be modified. I've run into those pain points. Your first observation is one I have some into as well but I haven't been taught how to do this. For example if my header file needs to define the method: void test(std::string something); Is it bad fo…

I'm not sure I understand the question completely. Do you mean "declare" instead of "define" in "if my header file needs to define the method"? Or are you asking about declaring the parameter to test as "std::string" in the header but then only as "string" in the .cpp definition, because of the presence of a using statement?
Post reply on HN