Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 17 Dec 2009
Online Last Active Today, 12:17 AM

#5269600 Criticism of C++

Posted by on 06 January 2016 - 06:14 AM

Note that i know almost nothing about Jonathans language except for one video i've seen a few years back when he first started working on it.

std::unique_ptr<std::string> uPtrToString = ...;

uPtrToString.reset(); //Is this accessing std::string::reset(), or std::unique_ptr<>::reset()?
auto meow = uPtrToString[27]; //Is this accessing std::unique_ptr<>::operator[], or std::string::operator[]? 
Are you going to allow operator . (dot) overloading? If not, you're saying you're going to ban convenient syntax for things like smart pointers and iterators? If you do allow dot operator overloading, it raises a different set of complications.


This only assumes the language itself doesn't provide you with mechanisms for pointer ownership. I recall from when i watched his first video that he wants to have a mechanism where the language and compiler themselves know that a variable is the owner of a pointer. Imagine it as having the unique_ptr as a built-in type, and not a template as well.
As far as dot operator overloading, that is a valid question, one which is probably answered in one of his videos, maybe.

                    [](const std::string &nya) { return nya; } //Return type auto-detected.
std::string MyFunction(const std::string &nya) { return nya; }
Converting between them is basically a single copy+paste (two, if you're explicitly specifying the lambda's return type), and writing the function's name. tongue.png


How do you easily and cleanly move lambdas that have captures? No idea if his language can do the same, so not sure the question is valid enough.


3) Instead of using templates or macros for preprocessing, he argues why not just run the language code directly at preprocess time. You use a keyword that runs a given function at preprocess time, computes whatever it returns, and sticks it into the line which it is found in. Instead of playing around with ugly template syntax and messing around with a different language like macros, we just run the language we are using directly but during compilation.

But anyway, you are using two different terms. Are you talking about preprocessing, which templates don't do, or compile-time computation?
It sounds like you are talking about compile-time computation.

If so, C++ added that back in 2011, using the 'constexpr' keyword. Initially it was (intentionally) limited in C++11, but they expanded it more in C++14, and intend to keep on expanding it to do exactly what you're talking about: Running arbitrary C++ code at compile-time to compute things, within limitation. Currently it's not fully unleashed, as they are gradually relaxing restrictions with each C++ release, to make sure any problems are ironed out and to give compiler developers a chance to catch up, and so programmers has a consistent featureset until it's fully present.


But the end result is the same, no? You get some automatic code generation done for you.
In C, you have only macros to do things templates can do in C++. Granted, they both have their uses in C++, but it would help if you stopped looking at Johns language as an upgrade over C++, rather as an upgrade over C. As was mentioned in this thread, there's a smaller, simpler an easier language in C++ trying to get out, and that language is C. So why not improve C with some of the stuff C++ does better?
Also, constexpr is very limited right now, and will probably stay limited to some degree. Johns language has no limitation. Sure, you'd have to control yourself and know that if you invoke an expensive function during compilation, it's gonna slow it down. But then again, you're a programmer, you're supposed to know the tradeoffs of doing so.


4) Jonathan argues to remove header files and just have one type of file like in java. The idea here is to remove the busy work of defining a function in one file, then jumping to another file to to write its implementation.
He also wants to get rid of the #pragma once keywords and the order of function definitions and just have the compiler sort out dependencies itself like in many high level languages (again, getting rid of needless busy work).

Again, the jumping to another file is solved by better tools. I can Ctrl+Click in the IDE I use, to jump between declaration and definition. Whereas there are arguable benefits for separating the two. Many C++ programmers argue the opposite extreme of what you are saying, complaining that a C++ class's private member variables are visible in the header. ohmy.png 

Now, headers have other problems (mostly as a result of macroes, which are the reason many seemingly unrelated areas of C++ have taken so long to get fixed), but C++ is migrating towards a module system similar to Python's, which will solve alot of issues.
Last I heard, the modules are supposed to get unofficially added to compilers in late 2017 or earlier 2018, and be officially standardized in 2020.


Sure you can jump easily with your IDE, but you'd have to jump less if we'd all just have the .cpp files instead of .h files, no? This might be the thing modules fix after they roll out, but i believe he was referring to having a java/C# model of just having one file type and the compiler figures out all the function names and symbols without you having to write a separate header file to include all over the place just so you can call a function cross files.
C++ is a general purpose language, and has it's flaws when it comes to certain domains, this much we can agree on, and it's been mentioned throughout this thread. As such it will never be perfect for game development. So why shouldn't we strive to have a language specifically suited for game development? Even if it's just C with some extra blows and whistles, some borrowed from C++, some invented to suit the needs of game development. Dismissing attempts to do so because we have something good enough... Well, the wheel got reinvented from time to time, didn't it?

#5265842 Sailing game: should players consider the wind?

Posted by on 11 December 2015 - 03:09 AM

Is it feasible to make both mechanics, and toggle between them through a menu option?

#5262222 Member function pointers?

Posted by on 16 November 2015 - 03:28 AM

To be fair, casting a member function to a regular function is possible, but is usually not a smart thing to do because it depends on the compiler and if the function is virtual or not etc.

class A
   void Method(int x) { cout << x << endl; }

void (Func*)(A* this, int x);

int main()
   A instanceA;
   Func f = (Func)(A::Method); //or some such evil cast, not sure if i'm missing and address operator, i.e. &A::Method
   f(&instanceA, 5);

However, if you're doing this, note that your code is bad and you should feel bad and change it promptly to a good design so you start feeling good because your code is not bad anymore. :)

#5261994 Member function pointers?

Posted by on 14 November 2015 - 04:39 AM

If you use C++11 onward, you  should use std::function and combine it with std::bind.

class AnotherObject
   std::function<void(void)> callback;

class TestObject
   void MyFunction() {};

int main()
   AnotherObject ao;
   TestObject to;
   ao.callback = std::bind(&TestObject::MyFunction, &to);

Edit: Good catch by CapThunderNutz below.

#5258641 Newbie looking for a high level explination of the systems that make up a mod...

Posted by on 23 October 2015 - 03:56 AM

I recommend you get yourself a copy of Game Engine Architecture by Jason Gregory. It explains a lot of this stuff, overview at first, and dives into specifics later on.

#5253429 Box2D Problem

Posted by on 22 September 2015 - 06:03 AM

It sounds like it might be the ghost vertices. Your OP is not fully clear to me, but i'll assume your body stops moving suddenly and doesn't move at all in that direction anymore? Does it move in the other direction?


What you could do is generate the static bodies a bit differently. Instead of making them one at a time and having a large amount of small boxes, generate as big of a box as you can in the x direction. Modify the algorithm so when you find a tile that is == 1 (aka ground), find all consecutive tiles on the x axis that are == 1, and if you find there are i.e. 5 of them (looking at your map definition above), you would generate a box that is 5 times the width of a single box, with proper position modification so it gets placed in the right location. You could also modify teh algorithm so you look at both x and y directions, so if you have a block of ground that is 3 high and 5 long, you generate just one box with the proper position and size instead of 3 when just looking at the x axis, and opposed to 15 with your current method.

#5251680 Help me find tutorial to make this type of game

Posted by on 11 September 2015 - 01:17 AM

I was looking for a tutorial where they teach you how to do the game and teaches the coding for it. Like how to make a level with proper collision coding tutorial.

Handmade Hero is trying to make a Zelda like game.


It goes from the very fundemental basics, so if you're trying to learn coding from the ground up, try this.

#5250539 C++ engine hosting LUA scripts

Posted by on 04 September 2015 - 02:08 AM

There are two ways to do this on Windows.

One way is to use Win32 API functions ReadDirectoryChanges coupled with WaitForSingleObject in another thread. I personally found this to be a pain in the ass when trying to implement it myself, so i found a project somewhere on the interwebz and just took it for granted it will do what i need. This will give you notifications about any file that changes in a specific directory of your choosing.


The other way is to use GetFileTime coupled with CompareFileTime function. When you read the file the first time, read it's modification time and store it. Each time through the game loop, for each file you're interested in, read the modification time again, compare it with the stored time and if it's newer, read it again, because you know it's been modified from the last time you used it.

#5247736 Matching Parameter Names to Class Fields

Posted by on 19 August 2015 - 02:22 PM


const float& headlightRange = 15.0f
I am sure this isn't allowed to be const or a reference as it has a default value


That is perfectly valid c++ code.

It would be better if it wasn't a const reference but a plain float, but both are valid.

#5247237 DirectX or OpenGL - 2D

Posted by on 17 August 2015 - 02:50 PM

I'm going to quote fastcall22 on this one from the previous topic:


This sounds familiar...

Nope nope nope.

#5242448 Vector cast

Posted by on 24 July 2015 - 12:05 PM

If we're talking about a 2/3/4 dimensional vector class that has a x/y/z/w components, then i'd pass it by value if i'm not modifying it. Works the same as a const reference, and since it's a temporary, you really don't need it to be a reference to anything, const or not.

#5239005 [Win32] No WM_KEYDOWN for screenshot-key

Posted by on 08 July 2015 - 09:45 AM

A quick google for VK_SNAPSHOT nets you this as the first result:



Try catching WM_PRINTCLIENT and see if that helps.

#5234861 Slow down when using OpenMP with stl vector per thread

Posted by on 15 June 2015 - 05:55 AM

You could try using vector.reserve(n)

That should be the solution but is not worth to implement at the moment.

Wait, what? One line of code is not worth implementing?

#5233170 Malloc/Calloc question

Posted by on 06 June 2015 - 11:02 AM

After the line ptr += 50;, ptr points to memory you don't own, and you should not modify it with *ptr = 7;.

#5231925 Defning a namespace class in a header file

Posted by on 31 May 2015 - 01:37 AM

The reason you're getting the error is because in main(), you don't have the full definition of GameManager, you only know it exists by knowing its symbol name.


In order to instantiate anything, you have to know it's exact size, which you accomplish by including the header that has its whole definition, which is your second header.


This has nothing to do with namespaces. Namespaces are used to contain symbols in a named scope, so they don't clash with symbols with the same name from other libraries.


You should probably use namespaces like this:

//GameManagerFwd.h, used when you just need a forward declaration, but rarely actually used
namespace Logic
   class GameManager;

//GameManager.h, used when you need to instantiate the manager of call any of it's methods
namespace Logic
   class GameManager
      void init();
      void run();

//GameManager.cpp, here you can use two forms, where the first is more common
namespace Logic
   void GameManager::init()

void Logic::GameManager::run()