The programming thread. - RPGWatch Forums
|
Your donations keep RPGWatch running!
RPGWatch Forums » General Forums » Off-Topic » The programming thread.

Default The programming thread.

August 28th, 2021, 12:59
TL;DR; Starting with C++.

Don't think we have one (there's Ripper's Godot thread, but that's too narrow), but we should have one; To talk about our experiences, preferences (why Java sucks), asking for (and getting) answers and advice++; So here is my humble fist contribution;

As I've said elsewhere I'm now learning C++; I knew a bit about from years ago, and I have done some programming, but it's a long time a go; And Boy!, the language has certainly developed; I'm now using ver 20, and a lot has changed since back then;

Why C++? Well, it is quite often faster, see https://www.codeproject.com/Articles…es-to-Simulate for a comparison between C++ and c#, showing up to twice the peformance of C++ (but not for every project); Several reasons for that, I won't go into details, but as (most of you?) know, unlike C++, c# doesn't compile into machine code, but into intermediate code, which is then just in time compiled into machine language when needed; In most cases, I think the difference is negligible, unless performance requirements are very hign, as in games;

Other factors:
  • Support for 3D API's, which leaves something to be desired for c#;
  • The possibility (curse) of creating windows applications from the ground up;
  • Linux support;
  • Default;

Of course c# has it's benefits:
  • Developing Windows applications is very fast;
  • Huge libraries;
  • The languge is very elegant (Yes, I think part of C++ is a mess);
  • Lots of errors that might cause run time crashes (allowed in C++) are stopped by the compiler;
  • Default;
One example regarding the libraries. In one of my projects I needed to get a Guid. In c#, just call Guid.NewGuid(); In C++ I first had to consult the net for howto do it, and I ended up creating a 5-10 line routine for the job;

But I love C++, and I suspect that whenever possible I will use that language for my projects; Maybe in combination with c# for the windows;

I'm currently using Visual Studio 2019 and 2022 (preview) for C++, and I notice a few problems, compared to c# programming:

Intellisense is much slower, and often complain about errors in my code, when it compiles just fine (without any warnings); And compiling applications takes significantly more time; Some of it must be due to the linking part, but I doubt that all of it comes from that; I suspect that Visual Studio is first of all adapted to C# (and VB) programming, support for C++ isn't considered that important;

I am considering using other IDE's, maybe somthing that also works in Linux; Any advice?

For (re)learning the language I'm using "Beginning C++20" by Ivor Horton and Peter Van Weert, which I think is a very good book, hereby recommended; Unfortunately books about Windows UI programming using C++ are few; I have of course the Petzold book from '95. But that one is old, and is based on C; Fortunately a previous version of the Horton book ("Beginning Visual C++ 2013") do cover it to some degree;

Today I'm going to start Windows programming, two projects: One using the win32 API, and one using MFC; We'll see where I'm going from there; I will also try GTK and Qt at a later stage;

PibbuR pibbuR{191,94};

PS. As stated in another thread, I'm not a game programmer wannabe; DS.
--
Over the mountain watching the watcher
Last edited by pibbuR; August 28th, 2021 at 13:10.
pibbuR is offline

pibbuR

pibbuR's Avatar
Feeling … lonely?

#1

Join Date: Nov 2019
Posts: 727
Mentioned: 26 Post(s)

Default 

August 28th, 2021, 14:22
C++ is a nice language if you need speed.

Just don't overdo classes and objects - use them only if you really need them.

C and C++ can be used in a classic functional way pretty well.
HiddenX is offline

HiddenX

HiddenX's Avatar
The Elder Spy
RPGWatch Team
RPGWatch Donor
Original Sin 1 & 2 Donor

#2

Join Date: Oct 2006
Location: NRW/Germany
Posts: 14,305
Mentioned: 107 Post(s)

Default 

August 28th, 2021, 15:39
I used to love C++ but I've moved on to C# and Kotlin which eliminate a lot of boilerplate code (Kotlin can also be used for Android development, and benefits from the Java library). But IMO C++ remains a very good choice for speed, and to learn what is really happening / to better control what is happening.

Doc:
I used to check this website for reference, it was excellent but I haven't used it lately: http://www.icce.rug.nl/documents/cplusplus/

IDEs:
Microsoft's Visual Studio and Jetbrains' CLion are the best IDEs, but only Visual Studio has a free Community Edition. CLion is running on Win10, Linux and macOS, and it's probably better than Visual Studio at this point. You could try it if you can't solve those performance problems and can afford it, there's a 30-day trial.

I see that Visual Studio is allegedly working in Linux, but I haven't tried (or I misunderstood).

Qt Creator was promising to be good when I last tried it, even if you don't use the Qt framework. It was slower in Windows, especially the debugger, because it was using gdb.

There are others like Code::Blocks that some seem to appreciate, but honestly I don't know them. When I tried, it looked awkward to use but it was long ago.

Frameworks:
It all depends what you need, of course, but here are some tidbits, others probably have more experience than me with that.

MFC has some components running in Linux, through Mono. Not WPF unfortunately, which is one of the best UI framework around. It also has a good framework for databases (Entity Framework).

Qt was fun, and they have adopted the stylesheet paradigm for UI, like WPF, Android and others, which usually makes it much easier to create interfaces. I don't know how they fare, after all the changes in ownership.
Redglyph is offline

Redglyph

Redglyph's Avatar
SasqWatch
RPGWatch Team

#3

Join Date: Aug 2020
Location: Good old Europe
Posts: 2,653
Mentioned: 58 Post(s)

Default 

August 28th, 2021, 15:53
And if you're meddling with C#:

- C# in a Nutshell by the Albahari brothers is a must-have reference
- don't miss their tool either, LINQPad, it's a tremendous help. Even more if you are using C# to process data.

But as much as I love the language, it's too tied to Windows. Sure, Mono exists, but it's always hard to tell what is available and stable.

For me, Kotlin is one of the most promising languages now, although the performances are not 100% there yet, nor does it have any mature UI framework for workstations.

Python is my friend for scripting and small project, or easy web design with Django.

For both, Jetbrains tools are just a developer's dream become true.
Redglyph is offline

Redglyph

Redglyph's Avatar
SasqWatch
RPGWatch Team

#4

Join Date: Aug 2020
Location: Good old Europe
Posts: 2,653
Mentioned: 58 Post(s)

Default 

August 28th, 2021, 22:29
Isn't there a single call to create a GUID?

Looked it up and yes, it is CoCreateGuid(). It is also the function C# calls to get a GUID.
Do you need something more than just the GUID that you end up with 5-10 lines of code?
--
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. Douglas Adams
There are no facts, only interpretations. Nietzsche
Some cause happiness wherever they go; others whenever they go. Oscar Wilde
Myrthos is offline

Myrthos

Myrthos's Avatar
Cave Canem
Administrator
RPGWatch Team

#5

Join Date: Aug 2006
Location: Netherlands
Posts: 10,321
Mentioned: 160 Post(s)

Default 

August 29th, 2021, 12:53
Ages ago, when I was stuill learning programming, I really really FUCKED UP my Win98 installation by testing a program from that training at home and not setting a pointer right … I had to reinstall my whole system.
In Windows 2000, which we had for training at that "schol", that wouldn't have happend, because of the far better memory system.
But, in the end, that gave me the willies and since then I stay away from C++ as far away as possible. Not 10 horses can bring me back to that.

I must admit, though, that it is indeed very fast - and that garbage collectors can be garbage, because one never knows when they collect (early Java) …

I have never been actively progrtamming in … 15 years or more, but that way of thinking helps a LOT in daily work. A few days ago I just had the idea of doing an IF-THE-ELSE cjeck in a calculation program to check whether one list has had any differences than another list … saved us a LOT of time and eye work !
--
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius and a lot of courage to move in the opposite direction." (E.F.Schumacher, Economist, Source)
Alrik Fassbauer is offline

Alrik Fassbauer

Alrik Fassbauer's Avatar
TL;DR
Original Sin 1 & 2 Donor

#6

Join Date: Nov 2006
Location: Old Europe
Posts: 20,244
Mentioned: 40 Post(s)

Default 

August 29th, 2021, 22:24
I'm not a programer by any means, but I do like to tinker with with some open source programs for Linux if I think I can change something I need. I use Visual Studio Code for that. It's a text editor, not an IDE but it can be customized with extensions which are plenty. I know there are some debugging extensions for C# and Unity but there should also be something similar for C++. I don't know if it is any good or how it compares with Visual Studio, but it was enough for my (again, pretty small) needs. It runs natively on Linux and is free and open source so you can try that very easily.
Ivanwah is offline

Ivanwah

Keeper of the Watch

#7

Join Date: Jun 2014
Posts: 816
Mentioned: 9 Post(s)

Default 

August 30th, 2021, 02:54
I'm actually shocked that C#/VB is so close to C++ speeds now. It doesn't matter to me - I'm working with databases most of the time that take 30+ seconds to get data while my own code only takes a split second to get it organized and displayed, but it's still impressive that a kinda-interpreted language could even get close to a compiled program.
--
The very powerful and the very stupid have one thing in common: instead of altering their views to fit the facts, they alter the facts to fit their views….
-- Doctor Who in "Face of Evil"
Zloth is offline

Zloth

Zloth's Avatar
I smell a… wumpus!?

#8

Join Date: Aug 2008
Location: Kansas City
Posts: 7,463
Mentioned: 32 Post(s)

Default 

August 30th, 2021, 09:22
Originally Posted by Zloth View Post
I'm actually shocked that C#/VB is so close to C++ speeds now. It doesn't matter to me - I'm working with databases most of the time that take 30+ seconds to get data while my own code only takes a split second to get it organized and displayed, but it's still impressive that a kinda-interpreted language could even get close to a compiled program.
Yes, it's surprising at first It really depends what you do, and how you do it. C# automatically handles a part of what is done, whereas it's more obvious in C++ since you have to do it yourself.

There are hidden costs too. When a chunk of C# bytecode needs to be executed for the first time after the program is loaded, it's compiled to native code (I think it's rare the bytecode is actually interpreted). It's not instantaneous, and if you're executing a time-sensitive program, or if you're trying to measure its performance, it's noticeable. But once it's done, it can run almost as fast as native code compiled from source like C++. Maybe the optimization won't be as good, but the impact is usually small.

To my big disappointment, last time I checked Java was faster in general, especially when processing I/Os and big collections of data. Maybe C# caught up since then.
Redglyph is offline

Redglyph

Redglyph's Avatar
SasqWatch
RPGWatch Team

#9

Join Date: Aug 2020
Location: Good old Europe
Posts: 2,653
Mentioned: 58 Post(s)
+1:

Default 

September 1st, 2021, 15:38
@pibbuR You may want to check https://www.hackerrank.com/, it provides many exercises for several languages, including C++. I saw that when I was looking for a little refresher in Python.

There are surely other similar sites. This one is easy, you can directly type and run your code via the browser. It tests the solution with a (hidden) set of data to validate the answer, it's quite fun to practice. What I also like there is that the exercises cover the language and library features, they're not just random little problems.

Nothing like a bit of practice beside the theory
Redglyph is offline

Redglyph

Redglyph's Avatar
SasqWatch
RPGWatch Team

#10

Join Date: Aug 2020
Location: Good old Europe
Posts: 2,653
Mentioned: 58 Post(s)

Default 

September 2nd, 2021, 11:30
TL;DR: the beauty of the WIn32 API.

So I've started windows programming. Below is the mandatory "Hello World" using the Win32 API. Admittedly there are ways to simplifying the code, for instance by using dialogs, but I consider that cheating. Admittedly (again) there's not much C++ here, aside form the nullptr.

Now, why do I post this? Because I think it's beautiful. I am at the moment exploring MFC, and I've downloaded the Qt libnraries and tools. But at the moment I consider staying with Win API. It is of course not an efficient way of developing windows applications these days, but who cares? As a retiree I've got all the time in the world, and I'm doing this for fun. However, in the end I may go for Qt, as I can use that one also under Linux. Or I may stay with c# for the UI, and C++ for the things where performance is essential.

Here we go (MFC and Qt versions upcoming).:

#include <Windows.h>
#include <tchar.h>

LRESULT CALLBACK WinProc(HWND winHandle, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE InstanceHandle, HINSTANCE PrevInstanceHandle, LPSTR CmdLineLp, int CmdShow)
{
WNDCLASSEX WinClass;

static LPCTSTR ClassName{ _T("Pibbur's class") };
static LPCTSTR WindowName{ _T("Pibbur's window") };

WinClass.cbSize = sizeof(WNDCLASSEX);
WinClass.style = CS_HREDRAW | CS_VREDRAW;
WinClass.lpfnWndProc = WinProc;
WinClass.cbClsExtra = 0;
WinClass.cbWndExtra = 0;
WinClass.hInstance = InstanceHandle;
WinClass.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
WinClass.hCursor = LoadCursor(nullptr, IDC_ARROW);
WinClass.hbrBackground = static_cast<HBRUSH>(GetStockObject(GRAY_BRUSH));
WinClass.lpszMenuName = nullptr;
WinClass.lpszClassName = ClassName;
WinClass.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);

if (!RegisterClassEx(&WinClass))
{
MessageBox(nullptr, _T("RegisterClassEx failed"), _T("Error"), MB_OK);
return -1;
}

HWND WinHandle = CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW,
ClassName,
WindowName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
nullptr,
nullptr,
InstanceHandle,
nullptr
);

ShowWindow(WinHandle, CmdShow);
UpdateWindow(WinHandle);

MSG WinMsg;
while (GetMessage(&WinMsg,nullptr,0,0)==TRUE)
{
TranslateMessage(&WinMsg);
DispatchMessage(&WinMsg);
}
return WinMsg.wParam;
}

LRESULT CALLBACK WinProc(HWND winHandle, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC DisplayContext;
PAINTSTRUCT PaintStruct;
RECT Rect;

switch (message)
{
case WM_PAINT:

DisplayContext = BeginPaint(winHandle, &PaintStruct);
GetClientRect(winHandle, &Rect);
SetBkMode(DisplayContext,TRANSPARENT);

DrawText(DisplayContext, _T("Hello, pibbuR"), -1, &Rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(winHandle, &PaintStruct);
return 0;

case WM_DESTROY:

PostQuitMessage(0);
return 0;
}

return DefWindowProc(winHandle, message, wParam, lParam);
}


pibbuR:ostQuitMessage(42);

PS. How can I avoid ":" (: : P -remove whitespace) being interpreted as an emoji? DS.

PPS: The code has indentations, but rpgwatch won't let me us'em. DS
--
Over the mountain watching the watcher
Last edited by pibbuR; September 2nd, 2021 at 12:09.
pibbuR is offline

pibbuR

pibbuR's Avatar
Feeling … lonely?

#11

Join Date: Nov 2019
Posts: 727
Mentioned: 26 Post(s)

Default 

September 2nd, 2021, 11:36
Originally Posted by Redglyph View Post
@pibbuR You may want to check https://www.hackerrank.com/, it provides many exercises for several languages, including C++. I saw that when I was looking for a little refresher in Python.

There are surely other similar sites. This one is easy, you can directly type and run your code via the browser. It tests the solution with a (hidden) set of data to validate the answer, it's quite fun to practice. What I also like there is that the exercises cover the language and library features, they're not just random little problems.

Nothing like a bit of practice beside the theory
Thanks. But the book is very good and I 'm using Visual Studio for programming the examples. (I'm very familiar with OOP after using c# for 15 years, and I have used C++ a looong time ago. Just needed to freshen up a bit, and of course learn the new things in C+ +13/17/20.

pibbuR++;
--
Over the mountain watching the watcher
Last edited by pibbuR; September 2nd, 2021 at 12:44.
pibbuR is offline

pibbuR

pibbuR's Avatar
Feeling … lonely?

#12

Join Date: Nov 2019
Posts: 727
Mentioned: 26 Post(s)
+1:

Default 

September 2nd, 2021, 11:50
Code:
Have you tried the " [ CODE ] " tag ?
Pladio is offline

Pladio

Pladio's Avatar
Guardian of Nonsense
RPGWatch Donor
Original Sin Donor

#13

Join Date: Nov 2006
Location: Manchester, United Kingdom
Posts: 7,423
Mentioned: 65 Post(s)

Default 

September 2nd, 2021, 11:51
Originally Posted by Redglyph View Post
Yes, it's surprising at first It really depends what you do, and how you do it. C# automatically handles a part of what is done, whereas it's more obvious in C++ since you have to do it yourself.

There are hidden costs too. When a chunk of C# bytecode needs to be executed for the first time after the program is loaded, it's compiled to native code (I think it's rare the bytecode is actually interpreted). It's not instantaneous, and if you're executing a time-sensitive program, or if you're trying to measure its performance, it's noticeable. But once it's done, it can run almost as fast as native code compiled from source like C++. Maybe the optimization won't be as good, but the impact is usually small.

To my big disappointment, last time I checked Java was faster in general, especially when processing I/Os and big collections of data. Maybe C# caught up since then.
The article regarding performance is updated. Now, they've including running the parallell array version in usnafe mode for c#, and in this case the difference between C++ and C# is quite smilar. Which shows (I think) that part of the performance hit of c# is due to safety mechanisms such as automatic garbage collection and other things.

pibbuR at somewhat slower than the speed of 299792458 m/s.
--
Over the mountain watching the watcher
Last edited by pibbuR; September 2nd, 2021 at 12:09.
pibbuR is offline

pibbuR

pibbuR's Avatar
Feeling … lonely?

#14

Join Date: Nov 2019
Posts: 727
Mentioned: 26 Post(s)

Default 

September 2nd, 2021, 11:54
Originally Posted by Pladio View Post
Code:
Have you tried the " [ CODE ] " tag ?
No.

Yes. But it doesn't work as I hoped.

pibbuR
Code:
::P
ostQuitMessage(42);

DS. Better perhaps (Still not as I hoped for, but I guess it will do:
Code:
pibbuR::PostQuitMessage(42);
DS.
--
Over the mountain watching the watcher
Last edited by pibbuR; September 2nd, 2021 at 12:08.
pibbuR is offline

pibbuR

pibbuR's Avatar
Feeling … lonely?

#15

Join Date: Nov 2019
Posts: 727
Mentioned: 26 Post(s)

Default 

September 2nd, 2021, 12:00
Originally Posted by Myrthos View Post
Isn't there a single call to create a GUID?

Looked it up and yes, it is CoCreateGuid(). It is also the function C# calls to get a GUID.
Do you need something more than just the GUID that you end up with 5-10 lines of code?
Yes. But CoCreateGuid returns a struct which has to be formatted before returning a string. Unlike the C# call.

pibbuR who 1) may be exaggerating and 2) has learned to spell "exaggerating" and 3) desperately tries to find the function he wrote and 4) who sadly is a bit unstructered.
--
Over the mountain watching the watcher
Last edited by pibbuR; September 2nd, 2021 at 12:20.
pibbuR is offline

pibbuR

pibbuR's Avatar
Feeling … lonely?

#16

Join Date: Nov 2019
Posts: 727
Mentioned: 26 Post(s)

Default 

September 2nd, 2021, 12:07
As I've said, the book I'm reading is very good. Here are a couple of things I've learned:
  1. The terms "little endian" and "big endian" derives from Gulliver's Travels by Jopnathan Swift and how eggs were supposed to be cracked in the state of Lilliput.
  2. “Rodolfo Alfonso Raffaello Pierre Filibert Guglielmi di Valentina d’Antonguolla” is the the real name of an iconic star of the silent movie era [aka "Rudolph Valentino"].

pibbuR who aknowledges the benefits of std::string;
--
Over the mountain watching the watcher
pibbuR is offline

pibbuR

pibbuR's Avatar
Feeling … lonely?

#17

Join Date: Nov 2019
Posts: 727
Mentioned: 26 Post(s)
+1:

Default 

September 2nd, 2021, 20:42
Wow a programming thread, we need more threads like this.

C# is not only quite fast now, if you want to do new things you should use .NET core, which means everything will run on linux and/or windows.

But for certain tasks C++ remains much faster and better this page is very interesting for speed comparasions, speed is of course very interesting….

https://benchmarksgame-team.pages.de…pcore-gpp.html

People always talk about speeds, but let us talk about memory usage, RAM manufacturers love java and C#…… take a look at this example. for certain memory heavy applications java and C# is just not in the game at all:

https://benchmarksgame-team.pages.de…narytrees.html
GothicGothicness is offline

GothicGothicness

GothicGothicness's Avatar
SasqWatch

#18

Join Date: Oct 2006
Posts: 6,197
Mentioned: 11 Post(s)

Default 

September 3rd, 2021, 02:24
Pthtthth, memory is cheap.

Though the 32-bit barrier has been bothering me of late. One of my big programs has to be 32-bit because it needs to use (I kid you not) JET drivers to read old Access .mdb files. However, it also has to deal with large pictures. I'm hoping we can get a more recent Access engine distributed to everyone but, right now, JET is the only thing that I know is on everyone's PC. People working with pictures that are too large get memory errors all the time.

Even with JET replaced and switching to 64-bit, .Net Framework still has lots of memory limits. I'll find out those details if I ever get to switch.

P.S. If you "go Advanced" on your post, there's a checkbox to disable emojis.
--
The very powerful and the very stupid have one thing in common: instead of altering their views to fit the facts, they alter the facts to fit their views….
-- Doctor Who in "Face of Evil"
Zloth is offline

Zloth

Zloth's Avatar
I smell a… wumpus!?

#19

Join Date: Aug 2008
Location: Kansas City
Posts: 7,463
Mentioned: 32 Post(s)

Default 

September 3rd, 2021, 09:32
Memory is cheap but it's the #1 power consumer and its access is slow. It's usually the first item one is trying to reduce when optimizing
Redglyph is offline

Redglyph

Redglyph's Avatar
SasqWatch
RPGWatch Team

#20

Join Date: Aug 2020
Location: Good old Europe
Posts: 2,653
Mentioned: 58 Post(s)
RPGWatch Forums » General Forums » Off-Topic » The programming thread.
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 02:26.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
vBulletin Security provided by DragonByte Security (Pro) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
Copyright by RPGWatch