Jump to content

  • Log In with Google      Sign In   
  • Create Account

Strewya

Member Since 17 Dec 2009
Offline Last Active Today, 05:51 AM

Posts I've Made

In Topic: Criticism of C++

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?
 
images%2B%25283%2529.jpg


In Topic: Sailing game: should players consider the wind?

11 December 2015 - 03:09 AM

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


In Topic: Member function pointers?

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
{
public:
   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. :)


In Topic: Member function pointers?

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
{
public:
   std::function<void(void)> callback;
};

class TestObject
{
public:
   void MyFunction() {};
};

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

Edit: Good catch by CapThunderNutz below.


In Topic: Newbie looking for a high level explination of the systems that make up a mod...

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.


PARTNERS