Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Dec 2011
Offline Last Active Private

Posts I've Made

In Topic: Random Spawn Optimisation

06 January 2016 - 01:56 PM

Create an array of something like 1000 locations around the circle. Put spawns in a random location and eventually mark as occupied also nearby locations to avoid duplicate spawns. If density of enemies is not too much you are done by generating in loop new random locations until you find a free spot, otherwise you just have to move at the end of the array occupied places (swap 2 numbers) and generate a random number between 0 and the last free location.

In Topic: Criticism of C++

05 January 2016 - 06:14 PM


I seriously think someone should re-think C++ from scratch instead of driving away into another language.

A 'rethink from scratch' would just give you another language.

Anything which breaks backwards compatibility is a new language.

End of story.

And people have tried, D which was brought up earlier is this indeed incarnate, yet it has failed to catch on.

A 'rethink of C++' is no longer C++.



I think you should take my words with much more immagination. D is substantially different, C++ has different goals and try to keep them by forcing backward compability, what if C++ had to be designed nowdays from scratch? It will result in much more clean, simple and performant language with less maintenance burden both on client and compiler side.

In Topic: Criticism of C++

05 January 2016 - 03:53 AM

People easily complaint about C++, but barely are able to propose and argue solutions about them (especially without smashing the purpose of the language).


Especially when the solutions are not well-received or even hard to maintain tongue.png. I seriously think someone should re-think C++ from scratch instead of driving away into another language.


There should be no more attemp anymore to keep backward compability (in example "template" vs "typename"), most times keeping compability introduces ugly syntax and complexity both on compiler and client side.
The resource management should be always explicit with nice syntax to give away ownership (without resorting necessarily to smart pointers or move semantices

int *a = new int[15];

function_call( give a);

function_call( int * a ){

  // do something.

  IF( MINE(a)) //link time directive => act as a different overload of function_call when
               // "a" ownership is gave away. (when no "MINE" overload present, warn about "a" not disposed.
     delete [] a;

and get compiler warnings if a owned resource is not disposed (including allocated memory) with no GC at all, templates can be made much simpler and we could get syntax for certain features provided by SFINAE and a decend module system.

Also the language should be thinked for supporting better debuggin, exceptions (I mean no issues like DWARF vs SJLJ that force users to target 2 different binaries at least with GCC), and in general better integration with code-assist tools so that syntax completion becomes easier and faster.

Link time conditional statements could be used to avoid writing a lot of duplicated code, the optimizer will just decide if resolving into 2 different functions or just generate hidden boolean parameters (also that would allow iteratin FOR_EACH over pointers without having to passing manually the size and enable native guards to prevent buffer overflows if wanted).


Instead of writing 2 constructors it could be nice if "moved stuff" has a more usefull behaviour (moving is just copying of all values and poitners and automatic ownership transer, the object from wich we moved should just fallback do a "deafault constructed" object that allow in many cases to avoid writing a 2nd copy constructor and a 2nd copy operator).


I also want better module system even for templates. If I include "std::Vector" (I would not call it "vector" but Array or DynamicArray) I do not want to pollute my namspace with all side included headers of std::vector. The header of "std::vector" should just be a interface, not the whole implementation

Here's a possible example of missing ownership.

int main(){
  int *a = new int[15];

  function_call( a); //thanks to link-time flags compiler know "function_call" will use "a" un-initialized and is able to dispose it. 
                    //seriously no introspection needed at all, just look at dependencies flag when linking and with ability to set a 
                    //compiler flag to stop re-linking when behaviours of subroutines changes 
                   //(in example a subroutine of function_call may initialize "a" after a code change
                    // "a" but we don't want that to go unnoticed so we could examine better the situation)

  return 0;  

/*COMPILER WARNING:: "a" is not disposed (file:line), "function_call" is able to dispose it if ownership given
 or instead you must delete "a" before exiting the "main" scope. 
  COMPILER WARNING:: "a" is not initialized  when first used inside "function_call".
  Linker will now assume "main" want "a" to no be initialized inside "function_call"*/

//after a code change:

/*ERROR:: code previously compiled with the assumption that "a" is not initialized inside "function_call" may now be broken because of
    "subroutine_1" now initializing "a". You can recompile "main" or just suppress this error with "-AllowsUpwardLinkFlagPropagation" */

Example to enforce ownership transfer and no initialization

function_call ( noInit give a);

In Topic: Criticism of C++

04 January 2016 - 03:57 AM

I always used C++ for years, it can be used in right way, but seems "the right way" is not for most common and used libraries wich just have awful issues (that could be avoided easily), one point still holds, you can setup a cross-platform toolchain in a really easy way (just unzip something somewhere) with C++, even if having such toolchain do not avoid you to write ad-hoc source code for each target you can at least start more quickly than other tools (I had pain times setting up libGDX in example). Another bad point is standard library, it just gets even more complicated at each language version and it is not to be expected to have something like .NET framework (even in part) for C++. Still .NET framework is missing lot of funcionality and sometimes I had to write my C# piece of code anyway. No language is perfect and is hard to predict if a choice will reward or harm you on the long run. Standard library has its use but its the only one I have to continuosly check against some reference for examples (while in C# there are fewer concepts so once you get grasp of basics you are done with autocompletion, in C++ you still have to check carefully all side effects for exception safety, iterators etc.).

What I think is that C++ could be a much better language if there's much more good code around to learn from, instead people tends to stick with junky code and write junk again by copying it.

In Topic: Integrating a scripting language

16 November 2015 - 03:39 PM

Base it on your preferences. I tried already lua and prefer it. Angel script may be a bit easier to debug while lua has real coroutines and I think is faster (especially last lua release).
There are out there lua editors for sure, don't know about angel script.)

also consider dependencies, if you want to use lua, you want for sure to use also an additional C++ framework to automate most binding tasks, while angelscript have that feature natively


also note that based on my experience Angel script is not a full fledged OO language so if you are used to stress limits of the languages you use (in example you go heavily with templates and reflection in C# and metaprogramming in C++) then probably you will find better with lua because thanks to its "dynamicity" allow to overcome the limits of the language. Said that, you have to try both.

I think I'll try Angelscript now, I just saw it has Cmake script => easy compilation rolleyes.gif