Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 05:52:09 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)What C codestyle/features are you using? C++98, C++11, C++17 or plain C?
Poll
Question: What C codestyle/features are you using? C++98, C++11, C++17 or plain C?
C++98 - 1 (4.5%)
C++11 - 5 (22.7%)
C++17 - 6 (27.3%)
C - 10 (45.5%)
Total Voters: 22

Pages: [1] 2
Print
Author Topic: What C codestyle/features are you using? C++98, C++11, C++17 or plain C?  (Read 3588 times)
Ordnas
Level 10
*****



View Profile WWW
« on: September 24, 2019, 08:57:19 AM »

At work I am focusing on using C++11 features (unique_or, lambdas, ranged for loop etc.), but I was interested in learning the new features of C++17. Is it worth? Or should I stick with C++11? What C language are you using at the moment both at work and/or for hobby?
Logged

Games:

TomHunt
Level 3
***



View Profile WWW
« Reply #1 on: September 24, 2019, 09:23:51 AM »

C++11 multithreading is super interesting to me at the moment. was able to get a modest performance increase out of some code by parallelizing the execution.

nice to have that baked into the standard library.
Logged

~tom | □³ | kRYSTLR
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #2 on: September 24, 2019, 05:18:11 PM »

More often than not what I use is dictated by the project I'm working on and I have little to no choice.

In the rare cases I don't have that restriction I tend to use c++ features but I avoid the stl. The style I guess is pretty close to orthodox c++. If there's any anticipated interop then I do my best to stick to ANSI C because exporting c++ functions is not very fun.

Whenever I want the control flow features of modern c++ stl (for example map,filter,reduce etc) I tend to use a different language with better support for expressing that kind of intent like F#/ML/C#+LINQ.
Logged

fluffrabbit
Guest
« Reply #3 on: September 24, 2019, 05:23:34 PM »

C++11, though I'm not taking full advantage of the STL and my tastes are closer to C99. I get more enjoyment out of C99, but C++11 has backwards compatibility with that and some other nice features, plus a lot of libraries are unfortunately tied to C++, so I mainly use that for games, at least until I can replace my C++ dependencies.
Logged
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #4 on: September 24, 2019, 10:57:15 PM »

As recent as possible. I like quite some bits of every C++ iteration so far, not bothering with a whole other list of news.

C++11: major turn, the dawn of the ages. Range-based loops, variadic templates, auto for complicated types, although I still like to *see* what type it is at a glance, so I only use it for iterators and such, or in template fuckery. Threads, Mutexes and the like are nice. Lambdas are indispensable, my code got way better since I got into the habit of coding in small local helper functions as lambdas. With lambdas, all of <algorithm> got finally usable. Smart Pointers are nice here and there, although I rarely use the heap at all since I got all that move fluff and guaranteed copy elision.

C++14: feels like an addendum. Still the whole constexpr stuff got usable, lambdas with auto are comfortable, all type_traits and stuff finally got the templated using treatment. Was possible in C++11 already, but they forgot. Some goes for user defined literals - was invented with C++11, but in C++14 they finally used it for chrono and so on. Only size_t still has no UDL, so I still put one in a central place in any project I work.

C++17: Grrrreat. if-constexpr() changed the way I write template stuff. Template Magic is very backwards and clumsy by its very nature, so I'm not a friend of large "helper" constructs, but it has its uses here and there, and with if-constexpr it all got a bit shorter and more comfortable. <filesystem> is nice and comfortable, and it has this DownToEarth vibe I was sorely missing from most Boost-spawned projects. Structured bindings are nice, too, even though most indexers and syntax highlighters seem to not be able to cope with them, yet.

C++20: well, let's see. I like the spaceship operator, it's small and simple and saves me some lines of boilerplate. Coroutines? Hm. Quite some people get joyful over it, but I haven't wrapped my mind around it, yet. And for reasons they fell back to enforce boilerplate stuff to use it. Meh. Was hoping for stateful coroutines, but that's a whole different can of worms. Ranges? No, thanks. The few key strokes I'd save by this utter madness is not worth my brain, IMO. std::jthread looks nice, although I wonder why std::thread hasn't been that way right from the beginning. Modules? I'm skeptical, might be great.

So let's see. I still really look out for static reflection.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
powly
Level 4
****



View Profile WWW
« Reply #5 on: September 24, 2019, 10:59:53 PM »

I’m relatively free to use what I like both for hobby and work projects, so C++17. Not that I’d even know about every new feature, but there are already some I really like.
Logged
Daid
Level 3
***



View Profile
« Reply #6 on: September 24, 2019, 11:38:10 PM »

C++11 adds so many useful things, even if you use 10% of those it's worth it. While C++14 and later just refine it more. I'm finding that doing C++ without C++11 is a pain in the ass (one of the compilers at work has C++11 support, but only partially, much of the STL is missing)

Note that I do a lot of higher end microcontroller work, where C++ is a good fit, but higher level languages are not an option. Which is why I do a lot of C++ on desktop as well. It's my poison of choice, but in all honesty, in general, it's not the best for game development. A higher level language is much more suited for 90% of the work.

@Schrompf: What do you mean with "stateful coroutines"? I've only used lua coroutines so far, but I like those a lot.
Logged

Software engineer by trade. Game development by hobby.
The Tribute Of Legends Devlog Co-op zelda.
EmptyEpsilon Free Co-op multiplayer spaceship simulator
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #7 on: September 25, 2019, 02:29:42 AM »

I meant fibers. Stackful coroutines. Like boost.context. Which the author now hid internally and tries to enforce one of his various awful APIs which all make use of it.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
oahda
Level 10
*****



View Profile
« Reply #8 on: September 25, 2019, 06:42:42 AM »

I'm "stuck" on 14 for my main game and engine for now because I'm scared about touching stuff now that it's working on so many platforms, and 14 is comfortable enough.

But I am definitely keeping up with the revisions and ogling some 17 additions (constexpr if, structured bindings, std::optional, std::byte… where possible I've just rolled my own for now) and beyond. I might upgrade the toolkit codebase since that only needs to compile for PC unlike the games themselves. I'm already using boost::filesystem there, which I like a lot, so I'm glad that it's been ported almost verbatim to 17's STL.

I guess I'm with Schrompf in feeling that every new version seems to add at least something nice even if bad or disappointing stuff might also come along, but I see no reason not to use the latest where possible for me personally. c:
Logged

qMopey
Level 6
*


View Profile WWW
« Reply #9 on: September 25, 2019, 01:47:13 PM »

C with a little C++; operator overloading, function overloading, default parameters, a few member functions for ADTs (abstract data types), a little bit of templates for containers (dictionary and array/vector).

The rest of the features in C++ are unused for a variety of reasons.

Keeping up with new C++ features is only necessary for me to talk with people at work who like that stuff. Otherwise I personally consider everything after C++98 pretty terrible, and I heartily disagree (but encourage discussion with) everyone else in this thread  Smiley
Logged
nikodil
Level 0
*



View Profile
« Reply #10 on: September 26, 2019, 03:15:15 AM »

pardon the pun, but the coroutine stuff looks really promising
Logged

fluffrabbit
Guest
« Reply #11 on: September 26, 2019, 03:42:33 AM »

I don't really get the need for coroutines that are any more complex than setInterval, which can be trivially implemented as an event loop.
Logged
nikodil
Level 0
*



View Profile
« Reply #12 on: September 26, 2019, 04:47:05 AM »

If you have a lot of asynchronous code, like requesting stuff from the network etc, then the async/await style will make the code look much more readable. You can do the same thing with promises/thenables or even callbacks, but the code flow will be muddled and not as clear.

https://en.wikipedia.org/wiki/Async/await
Logged

Daid
Level 3
***



View Profile
« Reply #13 on: September 26, 2019, 04:55:36 AM »

I don't really get the need for coroutines that are any more complex than setInterval, which can be trivially implemented as an event loop.
Scripted sequences are really much nicer in co-routines:
Code:
Do X
Wait 10 sec
Do Y
Wait 5 second
Do Z
It just removes the need for a lot of complexity. Especially if you need to remember some kind of state.
Example of enemy AI code:
https://github.com/daid/LostWoodsLegend/blob/master/resources/script/basic_enemy.lua#L13

In steps:
  • Pick a direction
  • Walk a set amount of time in that direction
  • Possibly fire a projectile in that direction, and then wait a bit
  • Start from 1
Logged

Software engineer by trade. Game development by hobby.
The Tribute Of Legends Devlog Co-op zelda.
EmptyEpsilon Free Co-op multiplayer spaceship simulator
fluffrabbit
Guest
« Reply #14 on: September 26, 2019, 06:05:06 AM »

I'm seeing yield() but in JS I'm used to automatically yielding at the end of the callback function, so you setTimeout and return to get that effect, which can be done in C/C++ with nanosleep and a wrapper. Better yet, make a cyclic executive (like setInterval with adjustable timeouts) so your code will execute at specific times and account for the time it takes to execute, which is important if you expect major lag.
Logged
Ordnas
Level 10
*****



View Profile WWW
« Reply #15 on: September 26, 2019, 08:57:13 AM »

I think it is more complicated than implementing a nanosleep, for a cross-project it is a hack that works platform-specific, probably it can be done with a bit of asm, but I would probably use boost::coroutine as a second solution.
Logged

Games:

nikodil
Level 0
*



View Profile
« Reply #16 on: September 26, 2019, 10:19:01 AM »

Speaking of coroutines, anyone tried the  -std=c++2a support for it in clang? It says partial support but I did't find any details what that mean
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #17 on: September 27, 2019, 03:37:03 PM »

I happened upon this article today, which seemed relevant to the thread: https://floooh.github.io/2019/09/27/modern-c-for-cpp-peeps.html
Logged

fluffrabbit
Guest
« Reply #18 on: September 27, 2019, 05:14:08 PM »

What that blog post seems to miss are all the people writing "C/C++" for a certain minimum compatible standard supported by non-Microsoft compilers, usually either C89/C++03 or C99/C++11. Think STB etc. I fall into that category, and write C because it compiles faster and has less syntax ugliness than C++, but I like to recycle code where C++ is more convenient.
Logged
nikodil
Level 0
*



View Profile
« Reply #19 on: September 29, 2019, 11:57:03 PM »

found this: https://github.com/roger-dv/cpp20-coro-generator

seems it's time to start the transition to c++20
Logged

Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic