View Full Version : C++20 anyone?
feisty2
6th January 2020, 22:31
I cant be the only one on this forum who's currently using C++20 to write filters.
To me, C++20 is finally one step closer to "python with pointers" because of abbreviated templates.
also with the power of "constexpr if", functions and other entities can have "fake dynamic" (indefinite) types, as long as the types can be determined later on at compile time.
you can thus use the same mindset as how you would code in a dynamically typed language to write c++20 programs.
FranceBB
7th January 2020, 00:32
I studied C++ but I never really used it in real life applications as I'm lazy. As a matter of fact, when they ask me to make programmes all they want is a kinda nice GUI and the programme ready in as little time as possible. They couldn't care less about memory usage, RAM allocation, CPU instructions etc. As long as it works on their beloved Windows 10 with both mouse and touch, they're happy, that's why I became lazy and I started using C# long time ago. C# itself has had a long run and nowadays we don't have the old Windows Form implementation but we have a universal Windows Platform environment instead in which you can build your app which is literally just an app that works in both desktop and tablet PC. Coding in C# is far easier and more intuitive than in C++:
1) I don't have to think about where I'm gonna allocate things and to dynamically allocate memory as the garbage collector is gonna do it for me.
2) If I try to use some function that is within a certain Library but I forgot to include it, Visual Studio says "you're trying to use this, but there's nothing called that way. Perhaps you wanted to include this library. Do you want me to include it for you? (Yes, no)" which is amazing.
3) If I make a typo Visual Studio is gonna warn me and correct me.
4) If I have redundant code, intellisense will tell me and it will take care of that automatically and (most of the time) in the right way.
5) Everything is optimised and handled by the .NET Framework and I don't have to get headaches trying to write intrinsics in assembly like in C++ (I can't code in assembly).
6) making UI in C# through the old Windows Form is very easy as well as using the new XAML designer with blender. When you're designing in XAML it looks and feels like when you're making a website. xD
So... yep I'm a C# fan. It would be great if I were proficient in C++ as well but as I became lazier and lazier, my C++ skills became worse and worse.
feisty2
7th January 2020, 00:53
but both avisynth and vaporsynth don’t come with c# APIs so you can’t write filters in c#, right?
If I have to rank the programming languages purely based on my personal preference and regardless of their applications, I would prefer dynamically typed languages over any statically typed language because OOP in statically typed languages is wrong, class, inheritance, interface and polymorphism are bullshit, only duck typing and classless objects that can dynamically change its own structure and behaviors are the TRUE OOP.
and what true OOP should look like in a dynamically typed language (python): https://github.com/IFeelBloated/true_oop/blob/master/example.py
screw class, screw all them statically typed half-ass crippled OOP languages.
videoh
7th January 2020, 03:05
OOP is so 90's.
https://medium.com/@cscalfani/goodbye-object-oriented-programming-a59cda4c0e53
I remember UML too. One project I worked on was required to use UML. After 6 months everyone was still arguing about how to do UML correctly, so the bosses said screw it, do what you have to do to get the job done. We did functional programming in C and hit our deadlines. :)
feisty2
7th January 2020, 03:44
We did functional programming in C
then you must check out my (very functional) hello world program in C++20 and see how things have changed over time: https://github.com/IFeelBloated/Hello-world/blob/master/hello.cxx
videoh
7th January 2020, 04:42
I must?
feisty2
7th January 2020, 04:55
I must?
Well, "must" as in "I just made this amazing stuff, you must check it out!! (with an excited expression)", not "must" as in "you must get the shit done or I’ll kill you (with an angry face)" :D
videoh
7th January 2020, 04:58
Ah, thank you. Is there an executive summary? Or just post it right here? I probably already agree with you, though, right?
May not be the sharpest knife in the drawer, but I try hard.
FranceBB
7th January 2020, 07:56
but both avisynth and vaporsynth don’t come with c# APIs so you can’t write filters in c#, right?.
Exactly, I can't write plugins. My contributions to the community are mostly from testing and writing scripts and BATs to help others out. I remember that there was a project to allow developers to write plugins in C# called AVS Filter NET but I don't think anyone has ever used it for a real world application especially 'cause it was translating things from C# so plugins would have had an additional overhead.
OOP is so 90's.
And they're still taught at university in the exact same way as they were taught in the 90s in pretty much every University which has a computer science engineering course.
Jamaika
7th January 2020, 08:44
Interesting topic C⁺⁺???
The desktop computer has ceased to be popular for the smartphone. We have a new cyber man on whom the internet world earns.
Money and time are important, not quality.
Since everyone uses Visual Studio XXXX and there is a hint, why are there so many mistakes in projects?
C⁺⁺20 oops. They don't have a problem on github. Basic programs are in C⁺⁺11 and will be there for a long time because no one will develop them for free and will not want to change them because C⁺⁺11 will not be compatible with the rest.
Currently GCC 10.0 is under C⁺⁺14 and there is already a problem. Is the conversion of C⁺⁺11 to C⁺⁺14 conflict-free.
stax76
7th January 2020, 13:58
making UI in C# through the old Windows Form is very easy as well as using the new XAML designer with blender. When you're designing in XAML it looks and feels like when you're making a website. xD
Forget about WinForms, it's broken, high DPI is a nightmare, because it uses device dependent pixel measurements and scaling simply don't work, layout controls must be used and much custom drawing and building custom controls, all that is very cumbersome and small changes need testing on different DPI setups, there are countless issues, it's terrible. It was a shock to find out that even the ancient C++ Win32/MFC form designer uses device independent measurements and scaling works perfect.
videoh
13th January 2020, 20:20
No time to refute all the nonsense, but regarding #1, there are 'for' loops. Are you upset that they are not called 'foreach' loops?
And I never found coding in C to be bad or hard. It's a low-level language. If you need hand-holding, try something else, like BASIC. ;)
EDIT: The post to which I replied was deleted. Gotta remember to quote. ;)
shekh
13th January 2020, 20:21
...and Visual Studio can't tell you if it is still compiling or what, because it doesn't understand wtf it is doing after you press 'build' :)
videoh
13th January 2020, 20:29
...and Visual Studio can't tell you if it is still compiling or what, because it doesn't understand wtf it is doing after you press 'build' :) Nonsense. Rather surprising from a sharp guy like you.
osgZach
13th January 2020, 21:01
No time to refute all the nonsense, but regarding #1, there are 'for' loops. Are you upset that they are not called 'foreach' loops?
And I never found coding in C to be bad or hard. It's a low-level language. If you need hand-holding, try something else, like BASIC. ;)
hey now, PureBasic is a very respectable, procedural, compiled language and never did anything to anyone. :cool:
shekh
13th January 2020, 21:05
Nonsense. Rather surprising from a sharp guy like you.
Came back to delete it but too late. I'm referring to this (offtopic) behavior in vs2008: sometimes status bar shows "Ready" all the time, when it should be "Build started.. Build succeeded."
Groucho2004
13th January 2020, 21:20
And I never found coding in C to be bad or hard. It's a low-level language.I agree that coding in C is not that hard and certainly not "bad".
However, it's not a low level language. Assembler is low level. I suppose it depends on one's point of view. For the kids nowadays who are spoiled rotten with .NET and what not libraries, it may seem C/C++ is ancient and difficult. It's not. It's just like any other language you have to learn in order to use it.
All the conveniences that come with new versions C++ and C# are well suited for rapid development in a professional environment. For most of us (mostly) hobby coders, this is of little relevance. Avisynth plugins for example should be written in C or C++ and, if necessary, ASM/Intrinsics. Plugins depending on the latest bloody .NET version are just ridiculous.
Groucho2004
13th January 2020, 21:25
hey now, PureBasic is a very respectable, procedural, compiled language and never did anything to anyone. :cool:So what? Does it produce fast code? I bet not.
Are you aware that the entire Win32 API is based on C? Using it with any other language means jumping through all kinds of hoops in order to make it work.
osgZach
13th January 2020, 21:38
So what? Does it produce fast code? I bet not.
Are you aware that the entire Win32 API is based on C? Using it with any other language means jumping through all kinds of hoops in order to make it work.
Sorry you appear to be misinformed, my shirt doesn't say "X product salesman", I was just responding to a playful jab with a playful rebuttal :rolleyes: I'd be happy to sell you some oat bran, though...
I'm sure its plenty fast for plenty of folks. Go play with its demo compiler if you think you have to prove something
videoh
13th January 2020, 21:43
Came back to delete it but too late. I'm referring to this (offtopic) behavior in vs2008: sometimes status bar shows "Ready" all the time, when it should be "Build started.. Build succeeded." Ah, OK, I see. You are a sharp guy and I love your VirtualDub2. Couldn't live without it!
videoh
13th January 2020, 21:47
However, it's not a low level language. Assembler is low level. I suppose it depends on one's point of view. One's point of view, yes. C compilers spit out code that is easily correlated to paradigmatic assembler constructs by inspection. I debated saying 'lower-level'.
Groucho2004
13th January 2020, 22:22
Go play with its demo compiler if you think you have to prove somethingNo, nothing to prove any more at this stage.
StainlessS
13th January 2020, 23:57
This will unconfuse the confused:- https://www.webopedia.com/TERM/H/high_level_language.html
(First link that came up in google search "High level Language", guess which is mentioned first)
Though not as high as some of course.
nevcairiel
14th January 2020, 00:13
The original definitions are from the time where C was arcane magic and everyone rather worked directly in assembler. But regardless of what you call it, C is definitely on a lower level then even C++, and much lower then C# and all the other "managed" languages.
That certainly doesn't make it bad, or even worse. Harder to work in, sure, especially for casual visitors. But having full control over memory and much of the execution is valuable. There is a reason key software is still written in C, much of that is performance.
Although many of the ludicrous complaints about C on the previous page seem to have been edited out now, many of those are just building blocks that those fancy managed languages just hide from you but still do all the same, and others can be turned around into advantages if you want full control over your code (ie. memory allocations) to get all the performance you can.
But since this thread was about C++ specifically, a modern codebase making use of all tools that C++17/20 have to offer can offer quite a similar experience to eg. C#. The standard library has grown quite a lot to include much of the helpful utility functions, and if thats not enough there is always Boost.
And if I look at the post from FranceBB at the beginning of the thread - much of his "pro C#" points are just Visual Studio features, which incidentally also work with C++ to a very large degree.
PS:
"Optimized .NET Framework" vs. writing assembler yourself, be it intrinsics or ASM directly is worlds apart in performance. If you want to write any DSP functionality, its either ASM or slow. There is nothing the .NET framework can offer that I would bother to write assembly for in the first place, instead the parts you do write assembly for are not things any framework can handle.
videoh
14th January 2020, 03:29
+1/2 (mooses only count half)
Words of wisdom from Nev!
FranceBB
14th January 2020, 07:38
But regardless of what you call it, C is definitely on a lower level then even C++, and much lower then C# and all the other "managed" languages.
It is, at least for people who are not really familiar with it like me.
many of those are just building blocks that those fancy managed languages just hide from you but still do all the same
I know, but not having to think about them makes it easier for me. Sure they can be turned into advantages but only if you really understand what you are doing in C and you have experience with such a language which is definitely not my case.
And if I look at the post from FranceBB at the beginning of the thread - much of his "pro C#" points are just Visual Studio features
Microsoft "ruined" me and "saved" me at the same time, in the sense that I had to write code with pen and paper in C++ at university (no IDE, nothing) and I never really used it for anything other than passing exams that were like asking us to do mathematical operations without using the math library which is way different from writing a real useful programme. When I finished my bachelor, I didn't really continue to study C++, so I had a pretty basic understanding of mathematical operations and that's it. At the time I remember that Microsoft just started something called "Microsoft Virtual Academy" and I quickly registered out of curiosity. As a matter of fact I was one of the very first people to register and the idea behind that portal was to publish online courses that people were able to attend (watch) for free made by Microsoft developers. For instance the Powershell course was done by Jeffrey Snover, the creator of powershell himself. Anyway, they were really well done and they were kinda satisfying my desire to know more ('cause I was an idiot at the time and I thought that a bachelor was going to get me a permanent position in a full time job to get myself settled for the rest of my life. Little I know that EVERYBODY in my field nowadays has a bachelor and a master at least and many of them have a lot of experience as well so it was really hard for me to get into the broadcasting world as an encoder. I've gone through some companies, 'till I finally managed to get to the company I'm working for, and although it's a very big one and I'm flattened to work here, my position is not stable even though I've been working here since January 2016. This is the main reason why last year - a few years after I finished my bachelor - I decided to go back to university to get my master degree while I'm working).
Anyway I'm digressing.
As I said, back in the days I was an idiot and I was looking for a place to learn a few more things for free and I found the Microsoft Virtual Academy. Courses were great but of course they were all focused on Microsoft products: C# and UWP, ASP.NET, IIS etc. They were trying to get people into their ecosystem which kinda became more like an eco chamber for me. A few times later I got my job in a big TV as an encoder and I began to learn from QC at the very beginning and then I started to encode files myself to get them on air, however one day one of my bosses came to me and said:
"Oh, so you studied engineering, uh?"
- Y-Yes...
"So you definitely know how to code."
- B-But I've only done the very basis when I was at university, I'm actually an encoder.
"Yes, but I'm sure you can do it. Look we need this programme to work with touch screens on W10 but also normal computers running Windows 10, the UI has to be like this this and this and so on..."
"You have one month".
So I had a problem: I was out from university and I had a good understanding of things like viscosity, fluid dynamics, cinematic, mechanics, optics, linear algebra, calculus, quaternions, topology and so on, but I wasn't able to code! The only things I was able to do were matrices operations and mathematical operations on the command line in C++ which wasn't really useful for a real world scenario...
"I never made a UI in my whole life" I thought, "what do I do now?". So I remembered that during one of the videos I watched at the MVA, they did make a UI, so I decided to fire up visual studio and try to make the programme and the UI myself with what I learned. "How hard can it be?" I thought. Well, I spent several hours trying to do things and getting everything to work. Within that month, the code was ugly but it was working, I sent the compiled programme to my boss and people liked it. They're still using it nowadays. From that day I decided that I was going to stick with C# 'cause Microsoft literally saved me. If someone like me who didn't know how to code managed to make a (rather simple but still functional) programme with a UI, it means that libraries, documentation, examples of how to do everything in places like Stack Overflow/MSDN and an IDE that literally takes your hand and (almost) "teaches" you how to code really make your life easier.
many of the ludicrous complaints about C on the previous page seem to have been edited out now
Well yes because I realised that it wasn't right.
What I was trying to say is that I wasn't really complaining about C. I mean, C has been one of the first languages, so we wouldn't be here without it. Anyway my point was that to someone like me who is not used to it it just feels like complicated because I take for granted things that aren't.
Let's be real: if I had to do the same thing in C in the same time, I would have probably failed because I find it more difficult and I'm not really familiar with it at all.
"Optimized .NET Framework" vs. writing assembler yourself, be it intrinsics or ASM directly is worlds apart in performance. If you want to write any DSP functionality, its either ASM or slow. There is nothing the .NET framework can offer that I would bother to write assembly for in the first place, instead the parts you do write assembly for are not things any framework can handle.
I understand that. One of the things it left me stunned was how much gain intrinsics can give to a programme. I remember making tests with encoders with and without assembly optimisations and the difference was remarkable. And although in my heart I know that a real programme should be made in C++ with intrinsics in assembly, I'm not able to do it. Another thing I noticed is that back when they asked me to make that programme, it was using a few more Megabytes of RAM than I thought (and I don't like RAM to be wasted), so I was really sorry about that but my boss and other people were only concerned about how "nice" the UI had to look like and they couldn't care less about RAM usage.
This is all to say that I would love to learn how to code properly in C and Assembly, but this is the story of how I ended up the way I am: I didn't know how to do things, I had a deadline and I picked up what I thought was the easiest option.
As a side note: I love this community, it feels like a family from which I took so much and I try to contribute whenever I can so that it's a sort of "do ut des". The fact that I can't really make plugins or contribute to the code but only help people write a script has always made me feel "bad". Believe me, there are so many things I'd like to do and so many projects I'd like to help, but I can't... :(
nevcairiel
14th January 2020, 09:03
I had to write code with pen and paper in C++ at university (no IDE, nothing)
We had to do that in exams, and it was so weird. On a computer, even with a barebones editor, you get used to writing stuff in a certain fashion - and its usually not linear from top to bottom. But if you need to insert something higher up on a paper ... you got a problem. :D
Nevermind all the IDE assistance one gets used to. Not that its necessarily a bad thing to know you can get by without it if needed.
feisty2
14th January 2020, 09:29
to me the problem with C is not manual memory manipulation, I do it all the time in C++ and I'm good as long as there is RAII. I also rarely use OOP features in c++ because I dislike the crippled OOP experience in statically typed languages (to be fair C++ is not that crippled (or, nominal, to be more precise) like Java because there is a compile-time structural typing system in c++ called templates and I absolutely love it, nevertheless, it is still far less expressive than dynamic typing).
so, what I dislike about C are:
a) lack of type deduction
b) lack of structural typing (aka templates in C++)
c) with a) and b) combined, it means I cannot code in a "python with pointers" style, everything has to be f**kin nominal like stupid Java and it's extremely verbose, of little flexibility, and the mindset is completely different from coding in dynamically typed languages.
d) lack of function literals (aka lambda expressions in C++)
e) lack of string views (string constants) and strings (mutable strings)
f) lack of tuples, I don't want to write a f**kin verbose one-time only struct every time I need to wrap things in a "package".
g) lack of structral bindings and combined with f), lack of functions with multiple return values.
g) lack of various syntactic sugar that makes life easier (range-for, etc...)
and yes, all aforementioned features are zero cost abstractions in C++, they do not have any impact on the runtime performance of the compiled program, so you should be able to take the advantage of all these features while still producing fast code.
kromak
6th February 2020, 01:07
I am using only classical c++, and I wonder if the newer c++ from 11 to 20 have considerable advantages ?
Anyway, regarding the last post, I really do not see a big disadvantage, actually any, in not having type deduction. Not too time ago, I started to mess with Python and do not think it helps me to write fast code compared to c++ or c. How long it takes to specify the variable type? It's negligible for me that spends more time in fixing errors than in anything else.
The lack of function with multiple return values was something that bothered me when I started to code, however after some time, whenever I needed to change more than one thing, I started to return one and change the other through references. After some time, I started to use void functions and change both through references. Nowadays when I need to change just one I use a non void function (which is minority of time I guess).
The lack of strings is something would really bother me in using pure C.
I don't think I ever used range for (assuming my compiler supports it) Just do not see any advantage.
By the way, I do not see much use for pointers in c++, except when one really needs dynamic memory and vectors are too slow or unsuitable by whatever reason.
feisty2
6th February 2020, 16:07
Anyway, regarding the last post, I really do not see a big disadvantage, actually any, in not having type deduction. Not too time ago, I started to mess with Python and do not think it helps me to write fast code compared to c++ or c. How long it takes to specify the variable type? It's negligible for me that spends more time in fixing errors than in anything else.
auto f = [](){};
specify the type of f.
auto f(auto val) {
if constexpr (std::is_same_v<std::string, decltype(val)>)
return "hello "s + val;
else
return 2.71 + val;
}
auto x = f("world"s);
auto y = f(3.14);
specify the return type of f()
auto aggregate(auto op, auto unit, auto ...args) {
if constexpr (sizeof...(args) == 0)
return unit;
else
return op(unit, aggregate(op, args...));
}
auto a = aggregate([](auto x, auto y){ return x + y; }, 0, 1, 2, 3);
auto b = aggregate([](auto x, auto y){ return x * y; }, 1, 2, 3, 4);
auto c = aggregate([](auto x, auto y){ return x + y; }, ""s, "hello"s, " "s, "world"s);
specify the parameter types and the return type of aggregate()
feisty2
6th February 2020, 16:20
The lack of function with multiple return values was something that bothered me when I started to code, however after some time, whenever I needed to change more than one thing, I started to return one and change the other through references. After some time, I started to use void functions and change both through references. Nowadays when I need to change just one I use a non void function (which is minority of time I guess).
you have serious problems if you think
void div(int x, int y, int "ient, int &remainder) {
quotient = x / y;
remainder = x % y;
}
int quotient;
int remainder;
div(x, y, quotient, remainder);
looks better than
auto div(auto x, auto y) {
return std::tuple{ x / y, x % y };
}
auto [quotient, remainder] = div(x, y);
feisty2
6th February 2020, 16:31
By the way, I do not see much use for pointers in c++, except when one really needs dynamic memory and vectors are too slow or unsuitable by whatever reason.
do you know there's something called viewing pointers (aka iterators)?
kromak
7th February 2020, 20:53
you have serious problems if you think
Are you always so aggressive, especially with someone that 1) Never spoke to you before. 2)Was not aggressive with you in first place?
void div(int x, int y, int "ient, int &remainder) {
quotient = x / y;
remainder = x % y;
}
int quotient;
int remainder;
div(x, y, quotient, remainder);
looks better than
auto div(auto x, auto y) {
return std::tuple{ x / y, x % y };
}
auto [quotient, remainder] = div(x, y);
Anyway I do not see a meaningful difference in clarity between both, neither in the time takes to write either.
do you know there's something called viewing pointers (aka iterators)?
Do you mean something like ?
vector<string> v = {"abc","def"};
vector<string>::pointer ptr = v.data();
cout << *ptr;
If that is the case, I am not sure if there are many cases where it has an advantage over all the other methods.
feisty2
7th February 2020, 23:03
I get aggressive when someone questions my taste and I strongly disagree with his opinion.
Jamaika
13th October 2020, 09:34
How different is the std::thread from std::jthread in c++20?
Does it make sense to change definitions for c++20?
Is std::jthread only under c++20?
I was able to compile std::jthread under c++17. Is it compatible with mingw.thread?
Katie Boundary
14th October 2020, 21:49
I reattempted learning C++ a few months ago. I got a lot further than my first few attempts but still had to give up because the documentation was so goddamn terrible and the people that I asked for help were incapable of explaining anything in a way that made any sense. I commented at the time "anyone autistic enough to understand the documentation is too autistic to write better documentation". And when something is too autistic for even me to understand, that's pretty bad.
I might pick up "C++ for Dummies" later and see how that goes.
StainlessS
14th October 2020, 22:05
I might pick up "C++ for Dummies" later and see how that goes.
I always feel the Dummies books have way too much 'fluff', ie humour and such, I prefer something a little more concise.
This site is quite good as a rapid "get a feel for it" type whotsit [many programming langs, and also spoken langs].
Learn X in Y minutes:- https://learnxinyminutes.com
C
https://learnxinyminutes.com/docs/c/
C++
https://learnxinyminutes.com/docs/c++/
Also, for those C proggers wanting a quick intro to CPP, see "AQuckIntroductionToCPP.PDF"
@ Mediafire in my sig below this post, in the DEVELOPER folder.
[235KB, 29 Pages PDF]
Introduction
This note introduces some simple C++ concepts and outlines a subset of C++ that is easier
to learn and use than the full language. Although we originally wrote this note for explaining
the C++ used in the Nachos project, I believe it is useful to anyone learning C++. I assume
that you are already somewhat familiar with C concepts like procedures, for loops, and
pointers; these are pretty easy to pick up from reading Kernighan and Ritchie's "The C
Programming Language."
I should admit up front that I am quite opinionated about C++, if that isn't obvious
already. I know several C++ purists (an oxymoron perhaps?) who violently disagree with
some of the prescriptions contained here; most of the objections are of the form, "How could
you have possibly left out feature X?" However, I've found from teaching C++ to nearly
1000 undergrads over the past several years that the subset of C++ described here is pretty
easy to learn, taking only a day or so for most students to get started.
The basic premise of this note is that while object-oriented programming is a useful way
to simplify programs, C++ is a wildly over-complicated language, with a host of features
that only very, very rarely find a legitimate use. It's not too far off the mark to say that
C++ includes every programming language feature ever imagined, and more. The natural
tendency when faced with a new language feature is to try to use it, but in C++ this
approach leads to disaster.
feisty2
14th October 2020, 23:14
C++ is simple as long as one particular feature (and anything related to it) is not involved, subtyping.
Subtyping is the root of all evil.
Without subtyping, the remainder of C++ is simply (compile time) duck typed, that’s as easy as learning any scripting language.
Katie Boundary
14th October 2020, 23:45
C
https://learnxinyminutes.com/docs/c/
C++
https://learnxinyminutes.com/docs/c++/
Those are excellent examples of what I meant when I said "anyone autistic enough to understand the documentation is too autistic to write better documentation".
stax76
15th October 2020, 06:45
www.learncpp.com
wswartzendruber
8th November 2020, 03:15
Arrogant Rust master race, checking in!
feisty2
8th November 2020, 05:44
no, rust doesn't have templates and this is unacceptable for a statically typed language, rust macros are nowhere near as powerful as C++ templates
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.