Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411283 Posts in 69325 Topics- by 58380 Members - Latest Member: bob1029

March 29, 2024, 12:16:12 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)The grumpy old programmer room
Pages: 1 ... 284 285 [286] 287 288 ... 295
Print
Author Topic: The grumpy old programmer room  (Read 733401 times)
Crimsontide
Level 5
*****


View Profile
« Reply #5700 on: February 02, 2019, 01:06:01 PM »

Also, I want to know what kind of whack C++ programmer refuses to use enums for flags.
Unless you need some kind of ABI stability, bitfields in structs are in certain cases a much better solution:
https://en.cppreference.com/w/cpp/language/bit_field

Oh most definitely not.  If you just want flags, nothing is better than enum class for C++.  Its as safe, as fast, and as easy as you can get.  There are many implementation specific details that are non-standard with bitfields, enum class's are fully standard compliant and fully portable.
Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #5701 on: February 02, 2019, 01:17:26 PM »

I'm sure there's a library for that, but it would be nice if there was a built-in language construct for flags considering how widespread their use is. I'm kind of surprised there hasn't been a standardization for them yet.
Logged

Crimsontide
Level 5
*****


View Profile
« Reply #5702 on: February 02, 2019, 01:25:39 PM »

Enum classes were added to support bit flags, its completely standardized, that was one of the primary reason for their introduction.

The old style:
Code:
enum Color { red, blue, green };

Has implementation specific issues, and doing mathematical operations can be unsafe (though it was almost always an int under the hood.  The enum class style:
Code:
enum class Color : uint8_t { red = 0b00000001, blue = 0b00000010, green = 0b00000100, };
constexpr Color operator|(Color a, Color b) noexcept { return static_cast<Color>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b)); }
Color red_blue = Color::red | Color::blue;

Is as fast as you're going to get, safe, serializable, and you can even perform bit operations/arithmetic operations on it with portable results.
« Last Edit: February 02, 2019, 01:32:32 PM by Crimsontide » Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #5703 on: February 02, 2019, 01:29:50 PM »

I thought enum classes forbade you from using bitwise operators on its instances? Also, you can specify a type for old style enums, so I'm not sure what you mean about implementation specific issues for those.
Logged

Crimsontide
Level 5
*****


View Profile
« Reply #5704 on: February 02, 2019, 01:39:06 PM »

I thought enum classes forbade you from using bitwise operators on its instances?

They're not automatically created for you, but you can create your own.  The ability to cast from an enum to its underlying type, do some math, then cast back, was what was added to the spec when they added enum classes.  This isn't a bad thing as you can add as many or few operators as you like.  In most situations 'and', 'or' and 'not' are all you need.  Some you might only want 'or'.

Also, you can specify a type for old style enums, so I'm not sure what you mean about implementation specific issues for those.

From my understanding that was added with the enum class addition, though I'm not entirely certain.  Technically, before C++11 (I think it was the C++11 standard... not entirely certain, maybe before hand, its been a while since I looked into this so memory is a bit fuzzy on some of the specific dates/standards) casting from an enum to an int or back was implementation specific.  Even the size of an enum was implementation specific (though every compiler used int).
Logged
Raptor85
Level 5
*****



View Profile WWW
« Reply #5705 on: February 17, 2019, 12:31:39 PM »

Welp...what started as a grumpy experiment has turned to a full fledged huge project with thousands of lines of code.  I don't know why I didn't do this before, this is the most fun I've had in years!

Also I'm a little surprised so many people don't know about bitwize operators on enums, just be careful, VC++ defaults to always using signed integers while gcc only uses signed if there's a negative  value in the enum, the specification does NOT say which way is correct so if using bitwise operators ALWAYS define your enum type.  There were ways to do it before C++11 but it wasn't very clean.
Logged

-Fuzzy Spider
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #5706 on: March 11, 2019, 09:13:00 PM »

For the last couple of weeks, I've been trying to figure out what I'll need to do to get my game (and the framework it uses) running on Android. It's been an excruciating process of reverse engineering Android Studio and gradle so that I can figure out how to do things with a build system that's actually sane. I just got to the point today where I can build some example code and deploy it to my phone without involving anything other than make, javac, and a few of the more friendly command-line tools in the Android SDK.

The reason I'm grumpy is that up until now, all of my googling hadn't turned up this article that literally spells out everything I've been painstakingly trying to discover on my own: https://www.hanshq.net/command-line-android.html

So, I'm happy this article exists and tells me the precise thing I'm looking for, but mostly feeling grumpiness at the amount of time I just spent not knowing about it and doing everything the hard way.
Logged

oahda
Level 10
*****



View Profile
« Reply #5707 on: March 11, 2019, 11:40:07 PM »

I have similar memories about getting Android working with my own engine and build system. Screamy It's working now, but through a somewhat more convoluted process with cmake with all sorts of custom stuff. Never found this article either. Looks like a good read!
Logged

Daid
Level 3
***



View Profile
« Reply #5708 on: March 13, 2019, 04:19:43 AM »

Enum classes were added to support bit flags, its completely standardized, that was one of the primary reason for their introduction.
All the casts in your code pretty much scream the opposite to me. And more looks like you can make the shoe fit the hoof of the horse, but it wasn't intended for it at all.


Bit fields are part of the C++98 standard. So nothing "undefined" and "implementation specific" about that. Other then that the exact storage of structures is implementation specific. But that's the case with any structure.


Also, the whole rant about doing math with them kinda misses the point. If you want bit flags, you are not going to do math with them if you put them in a struct. Only sad part is that "Designated initializers" are not part of the standard yet, which makes bit flags a bit harder to use as nice inline function parameters.
Logged

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


View Profile
« Reply #5709 on: March 14, 2019, 09:04:53 AM »

All the casts in your code pretty much scream the opposite to me. And more looks like you can make the shoe fit the hoof of the horse, but it wasn't intended for it at all.

Static casts aren't bad.  I could see if they were reinterpret or otherwise, but static's are the 'safe' ones Smiley

Quote
Only sad part is that "Designated initializers" are not part of the standard yet, which makes bit flags a bit harder to use as nice inline function parameters.

Completely agree.  That and I REALLY want to be able to overload on constexpr, but I don't think that's ever happening.  I just need to finish my own language but I just don't have the time...
Logged
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #5710 on: March 14, 2019, 11:17:48 PM »

Build systems :-( Huge CMake project, dozens of libs and executables, some used to generate code for others. And I want to build them with -flto (Link Time Optimizations). Fails at the beginning - some C files are compiled and linked into a static library. That "ar" call seems to fuck up the object files. Then the first executable tries to link this library and bails out with a misleading error message. Every single compiler invocation correctly specifies -flto, so it should work. But it doesn't.

And the usual: googling didn't turn up anything, so I tried to write to the Clang dev mailing list. And all mails to them bounce :-( Frigging professionals.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
Daid
Level 3
***



View Profile
« Reply #5711 on: March 15, 2019, 03:31:36 AM »

The way CMake calls the compiler makes it quite difficult to add LTO. I've tried it on a project, but removed it in the end because of issues.

You could try this flag:
https://cmake.org/cmake/help/latest/variable/CMAKE_INTERPROCEDURAL_OPTIMIZATION.html#variable:CMAKE_INTERPROCEDURAL_OPTIMIZATION
Which is intended for the LTO flag, however, when I tried, it wasn't implemented on the CMake GCC backend yet.
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 #5712 on: March 20, 2019, 05:42:20 AM »

Sorry for the late reply, and thanks for the hint towards CMAKE_INTERPROCEDURAL_OPTIMIZATION. I already tried that approach, and it turned out to do exactly nothing. Build went through and resulted in bytewise identical executables.
Logged

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



View Profile WWW
« Reply #5713 on: March 28, 2019, 06:43:30 PM »

Building my framework for Android has been coming along pretty OK. I have an application building with a simple makefile (no Android Studio, gradle, or Cmake involved in any part of the process) and deploying to my phone, drawing with GLES3, and receiving touch events. There's still a bunch more to do with bringing up the onscreen keyboard, file I/O, adapting my shaders to work with the ES version of GLSL, and other stuff like that.

This time, the reason I'm grumpy is the amount of Java code I'm having to write. There are so many things about this language that seem ridiculous. If a module I've imported has functions that return an object type I haven't imported, I can call methods on them just fine, but in order to assign an instance of one to a variable, I have to add an explicit import statement for it. Why? Also, the compiler insists on enforcing a directory structure on my filesystem that matches the package identifier used in my code, and it didn't want to let me do everything in the top-level package for some reason. javac doesn't have an equivalent of gcc/clang's -D flag, so I can't do compile-time substitution of string constants. JNI also keeps getting snippy with me for accessing objects in a different thread than the one they were created in, even though I haven't opted into any kind of multithreading - it just happens anyway.

Why does anyone actually use this language?
Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #5714 on: March 28, 2019, 06:45:01 PM »

Mostly because they teach it in universities ;P
Logged

Crimsontide
Level 5
*****


View Profile
« Reply #5715 on: March 29, 2019, 03:22:53 AM »

Yeah, they forced Java on me in university.  I hate the thing with a passion.
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #5716 on: April 02, 2019, 07:27:29 PM »

My impression is that the technical marvel of Java isn't the language but the JVM.

but I digress

I sat down tonight and wanted to get all the youtube videos for a particular channel. I figured this would be pretty easy but apparently I need an api key to issue commands to their rest api? Even though what I'm doing is just reads? I don't have a lot of web experience so I have no idea if this is standard or I'm reading the documentation wrong..


any insights would be appreciated
Logged

Daid
Level 3
***



View Profile
« Reply #5717 on: April 05, 2019, 09:42:04 AM »

My impression is that the technical marvel of Java isn't the language but the JVM.
Well, in my memory, the language basics are quite fine, it's the standard library and the way of working that I found toxic. AKA, "you can never have too many layers of abstraction and factories"

I sat down tonight and wanted to get all the youtube videos for a particular channel. I figured this would be pretty easy but apparently I need an api key to issue commands to their rest api? Even though what I'm doing is just reads? I don't have a lot of web experience so I have no idea if this is standard or I'm reading the documentation wrong..


any insights would be appreciated
Generally, with web APIs (from google) your API key is linked to quotas (limited amount of request per time until you need to pay) even for just getting data. I've only worked with the google drive API, so youtube might be different.
Logged

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



View Profile
« Reply #5718 on: April 05, 2019, 05:13:42 PM »

My impression is that the technical marvel of Java isn't the language but the JVM.
Well, in my memory, the language basics are quite fine, it's the standard library and the way of working that I found toxic. AKA, "you can never have too many layers of abstraction and factories"

I sat down tonight and wanted to get all the youtube videos for a particular channel. I figured this would be pretty easy but apparently I need an api key to issue commands to their rest api? Even though what I'm doing is just reads? I don't have a lot of web experience so I have no idea if this is standard or I'm reading the documentation wrong..


any insights would be appreciated
Generally, with web APIs (from google) your API key is linked to quotas (limited amount of request per time until you need to pay) even for just getting data. I've only worked with the google drive API, so youtube might be different.

RE : Youtube

I guess I can see that but if I really wanted I could write a scraper to do it anonymously which I'm guessing would be a much greater strain since now I'm downloading images etc. Bah!

RE : Java

That's my memory of using Java too. Last time I used it heavily lambda's didn't exist so I seem to recall having to make an entire class to handle a button callback :X

The crazy pattern stuff I've had to deal with a tiny bit, usually when trying to fix or modify software we had a source license too. I remember having to google terms like "Java bean" because the docs and code assumed I knew what that meant. Very tedious.


Logged

Crimsontide
Level 5
*****


View Profile
« Reply #5719 on: April 15, 2019, 10:20:40 PM »

Download vs2019 is hopes of trying out modules and unless I'm completely mistaken... they suck.

At this point I'm certain the C++ committee's sole purpose is to ensure the language dies a slow and painful death.
Logged
Pages: 1 ... 284 285 [286] 287 288 ... 295
Print
Jump to:  

Theme orange-lt created by panic