Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

Lube up.

Or, go to a website like cplusplus.com and at least learn the basic data types, including pointers, so when you hear keywords like “int” your don’t explode your head in class and get it on the good students’ notes. Get acquainted with as much as possible.

Do you know what compiler and possibly IDE they’ll make you use? Find out how to use it as soon as you can.

I don’t hear many bad things about it. Then again the only person I’ve ever asked was myself. And the only time I say bad things is when I have no idea why I’m getting the error I do, and either figure it out eventually or just say fuck it and re-write that portion. Especially with templates. Those seem to be the bane of my programming life more than anything else.

Closest annoyance is constantly forgetting the std namespace when I’m using std objects. That shit should just be implied.

I had originally intended to learn C++ for game development but changed my mind since I wasn’t planning to work on anything that would require that level of control. My brother used to work in C++ in his last job (drones) but now works in C# said he doesn’t miss having to worry so much about memory management anymore but its a great skill to have. Do you know any other languages besides C++, where does it rank for you amongst those?

For me it depends entirely of what i am trying to do.
C++ gives you a lot of liberties, but that is also a double edge sword.

When i started to study on my university, the 1st language that you learned was Ada 95, the next one was C++. Later it was expected that you learned other languages by yourself.
From what i heard from a friend that is the current head of the career there, they now learn Java and .Net.

As for what languages i know, i think that there is a post with them around this thread.

The only other programming-style language I use heavily is PHP. Outside of those I dabbled in BASIC at the age of 7, when I was just copying shit from a book without knowing what any of it meant, and Visual Basic, which I stopped using when I got to C, and then C++. I’ve thought about Python and Perl but I have yet to fully develop an interest in either.

I don’t mind dealing with memory management directly. Automated memory management is nice but it’s not a necessity for me. I just try to make sure that anything I allocate gets deleted. Probably easier when I’m doing my work myself and not having to make sure someone else cleaned up their mess.

Hm : / have a bit of a conundrum. I already accepted an internship for the summer but Google has requested an interview for a job that needs me to start in September. If I don’t take classes over the summer for my internship I wouldn’t graduate until December. Told them if they really are interested I’d need to know ASAP, since to enroll in summer classes I have to do that within 2 weeks. Have a Skype interview Friday with them. I doubt they will be able to get back to me before my internship starts in 2 weeks, so not sure if I should try to do full time summer classes concurrently or not.

Honestly, most people in school write C++ like C. Modern C++ is a pretty good language. It just needs the libraries to catch up. C++17 will fix about 90% of the issues it has with catching up to modern languages with the implementation of modules, sockets, better filesystem support, and a few other things. C and C++ aren’t for every application, but if you need to write something that crunches a lot of numbers ASAP there really isn’t another language without going into assembly, C, or something laughable like FORTRAN. Vectorized code is a major boon to a lot of applications. Heck most really fast C#, Node. js, python, etc. libraries are just really optimized C or C++ libraries with wrappers for things like machine learning, numpy, opencv, etc:

C++ has a purpose but it generally is a small niche set of people that write it then everyone else gets to use the wrappers that get created by it. Also if you are calling delete or malloc a lot you likely aren’t writing ‘good’ c++ code. RAII let’s you automate away most memory issues. Only time you will have issues is if you go trying to do something pretty as low to the metal as you can which is rarely necessary unless implementing a super optimized library as mentioned. It will never be great for front-end stuff just because it lacks Reflection and there really isn’t a way to implement the necessary support without major memory bloat which would destroy its usefulness in embedded applications.

I always hear C++ is on the outs, but it’s still used for almost everything…

I wonder if Java will have the same thing happen to it? Maybe not because memory management is nowhere near as hands on.

I think Java is, every other week you hear about a new exploit, most browsers block it by default. Oracle sueing Google over it’s use in Android, Google may decide to create their own language (or use C# since Windows mobile is pretty much dead now).

Java as a language doesn’t have to be on the out, just the shitty implementation of it. Just like how Adobe’s implementation of Flash is garbage, bug-ridden, exploitable, etc. People are working on free alternatives to that. Same with C/C++. The language by itself doesn’t do anything, the compilers have to do their job of converting it to the proper machine code. If GCC / MinGW were terrible at it (are they? idunno), we’d just look for other programs to compile with.

No one’s used Java in browsers for 15 years, but I think there is a lot of server side Java that’s still alive and well. There’s also Java [Dalvik] for Android, but I don’t do mobile development so I don’t know how big that is versus native code. I could see Xamarin making big inroads there though now that it’s free.

C++ is a perfectly good language, and you can certainly wring a lot of performance out of it. A lot of the code people write though is written as if it were C, until you come across someone obsessed with templates.

You can write bad code in C# too of course, but the .NET runtime will do a lot to keep you from completely blowing shit up.

C# is really nice, but I am a little worried seeing what’s going into .NET 7. Syntactic sugar is nice and all but at some point you’re throwing out so much context that the code doesn’t “read” any more.

My college is switching from Java to C# next semester.

Unreal 4 still uses C++, so maybe that will help extending its fanbase.

Holy shit, I just read C+= for the 1st time, that shit is genius.

C++ teaches you the fundamentals, and puts a lot of power in your hands – for better or for worse. Java, C#, etc comes with a lot of overhead. To think one language is straight better than another is silly. We might as well be arguing whats better, screws or nails.

Heres my personal belief. If you can code in C++, you can code in anything.

Screws > nails. Only a Java lover would think otherwise.

Any one knows objective-C? I know C++, but I trying to learn objective-C because I need it to build something.

I am reading through tutorials and I don’t get this code.


[super viewDidLoad];
 
    // Set up context
    EAGLContext* context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
    [EAGLContext setCurrentContext:context];
 
    // Set up view
    GLKView* glkview = (GLKView *)self.view;
    glkview.context = context;


Would this code look like this in C++?

EAGLContext-> alloc -> initWithAPI(kEAGLRenderingAPIOpenGLES2)

Why do a lot of classes have alloc? It seems objective C have some sort of root object class stuff going on like Java does.

And I still don’t quite understand how super and self works

Also, does objective C have static and dynamic allocation separately? so [EAGLContext alloc], but glkview.context is regular allocation?

If I recall you have to do all memory allocation and garbage collection manually. It’s useful to learn and know.

Its been a minute since I did my IOS programming, but lets see if I remember right. Alloc is basically like new, typically you call alloc and init, which is like the default constructor. But in this cast, you’re callng alloc and initwithAPI, which is like a non default constructor used for NSObjects I believe. From the quick googlefu I did, using [[EAGLContext alloc] init] is the same as doing [EAGLContext new] only in this case, you’re calling new with a non default constructor and passing in the API string/variable.

In c++, I imagine it would be like



 EAGLContext *context = new EAGLContext(kEAGLRenderingAPIOpenGLES2);
EAGLContext->setCurrentContext(context);


As for Super and Self, imagine you have a class, and that class inherits from another class, and you override a function from that class. If you needed to call that parent function, you would use “Super” to still access that version of the function.

Say, for instance, we had a class that did simple math, like a running total.



//class RunningTotal
function add(int value){
  total += value;
}


Now, lets say we inherit from running total, and we want to add something that actually counts how many transactions were made as well. We could use Super to override the add method, and still have the parent code called



//class TransactionRunningTotal inherits from RunningTotal
function override add(int value){
   numTransactions++;
   super.add(value);
}


In this case, when we did



TransactionRunningTotal total;
total.add(5);


It will call my overidden function add in TransactionRunningTotal, which then calls Super.add, which then calls the parent classes add function, which actually does the adding.

this is the most common usage of super; I use it a lot when doing initializing.

Self is basically like This in C++, the difference being self is a variable that is free to be modified in objective C, while in C++ self is literally a pointer to yourself. So doing



// Set up view
    GLKView* glkview = (GLKView *)self.view;
    glkview.context = context;


You’re saying, get the pointer to my view variable, and assign it to the pointer object glkview. Then you’r assinging the context variable of that view to the context variable you created.

You could probably do the same thing like this



 self.view.context = context;


and never actually declare a pointer variable.

It depends if the view is always a GLKView, maybe thats a specific subtype and not all of them share the .context variable, in which case you’d probably need to change it up a bit and do casting.

In this case, you may be able to get away without even using “Self” and just say view? Like in C++ you can reference your variables without having to say this.view, but sometimes you want to in case it is ambigious and things share the same name? My Objective C is not that strong.

Heres an example of how I used this concept in C#, when I was making a unity game. I would make a base object, called Enemy, that handles all the basic logic shared amongst all enemies in the game (health, setting animations, creating UI elements like sprites, etc) and have all of that in one place. Every enemy type would inherit from this type, set the enemy specific things (like health, xp, etc) and then call the Base version of the function to handle the heavy lifting (base is the same idea as Super in objective C/Java).

So heres how the skeleton class looked:

And heres how the base Enemy class looked:

This keeps me from having to replicate that code amongst all the enemy types, and allows me to kee pall that logic in one place for debugging/fixing things.

When you do OOP, should all the parameters be set to private and only allow getter and setter to retrieve them?

I need to process an array from inside of 1 class, just a regular array. I stored the size of the array as an integer in the class. The array should obviously be private, but should the size also be a private member?

I am using a library to draw this array of positions, and it needs to read the entire array in 1 go, so I need to pass the array pointer of floating numbers and the size of the array to the function.

But this feels wrong somehow because I don’t feel like my class is abstracted properly.

Generally yes.

Absolutely. If someone changes the size without the array changing (because they can’t) then the size will be wrong and Bad Things can happen.
To point 1 though you could have a setter.


class ArrayWithSize
{
private:
  float mArray;
  int mArraySize;
public:
  ArrayWithSize() : mArray(NULL), mArraySize(0) { }
  ~ArrayWithSize() { delete[] mArray; }
  void SetSize(int newSize)
  {
    delete[] mArray;
    mArray = new float[newSize];
    mArraySize = newSize;
  }
};


You may want to get a little fancier and copy data from the old array to the new one or such, possibly having different setters that deal with existing values differently.

But this feels like you may not want the size to be set directly at all, only have methods such as AddPosition(), InsiertPosition(), RemovePosition(), and so on. You can set the size directly if you allow direct access to the elements though… Something general purpose like std::vector does indeed let you, but something specialized like this I think I would try to avoid it.

Has anyone by any chance come across any decent tutorials/books for making a Pokemon Go clone? We were discussing at work today making a easter egg hunt game for our exhibition so something similar to pokemon go would be perfect.

From e3 Pokemon Go developer QandA