• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Hey gaf, I'm looking for some help with a pong assignment I am working on for school. I'm new to programming, so this code might be a little ugly, and my problem may be a little simple.

I'm using python 3 here, but I'm having trouble with my function for tracking the score for each player. Currently, it only displays 1 point for each player after a player 'scores', but after that it stops adding new points. So it'll say 1-1, but it won't change values after that. Before I started using user defined functions for this program I didn't have this problem. But I can't quite tell why I'm having this issue now.

Code:
def main() :
    
    # Initialize pygame   
    pygame.init()
    
    mainClock = pygame.time.Clock()
    gameOver = False
    
    #Window
    windowWidth = 800
    windowHeight = 600
    window = pygame.display.set_mode((windowWidth,windowHeight),0,32)
    pygame.display.set_caption('Pong')
    
    #Score
    score1 = 0
    score2 = 0
    
    #Paddles
    White = (255,255,255)
    PaddleWidth = 10
    PaddleLength = 50
    Left1 = 50 
    Top1 = 275
    Right1= 740
    Top2 = 275
    p1 = {'rect':pygame.Rect(Left1, Top1, PaddleWidth, PaddleLength), 'color': White}
    p2 = {'rect':pygame.Rect(Right1, Top2, PaddleWidth, PaddleLength), 'color': White}
    
    #Ball
    Black = (0,0,0)
    center = [400, 300]
    radius = 8
    speed = [5,5]
    Ball = pygame.draw.circle(window, White, center, radius, 0)
    
    pygame.display.update()  
    
    while True:
        # Handle events
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
             # Handle additional events
        
        
        ballMove(center,speed,radius,p1,p2,windowHeight,windowWidth,window,White,Black,Left1,Top1,Right1,Top2,PaddleWidth,PaddleLength,mainClock)  
        
        scoreFun(score1,score2,center,radius,White,Black,windowWidth,window) 
        pygame.display.update()          
        mainClock.tick(30)         
    

def scoreFun(score1,score2,center,radius,White,Black,windowWidth,window):
    fontSize = 96
    font = pygame.font.SysFont('', fontSize, True)
    if center[0] - radius <= 0 :
        score1 = score1 + 1
        strscore1 = str(score1)
        textSurface = font.render(strscore1, True, White, Black)
        window.blit(textSurface, (750, 0)) 
        pygame.display.update()                   
    if center[0] + radius >= windowWidth :   
        score2 = score2 + 1 
        strscore2 = str(score2)
        textSurface = font.render(strscore2, True, White, Black)
        window.blit(textSurface, (0, 0)) 
        pygame.display.update()     
     
    pygame.display.update()
       
main()

Hopefully this wall of text isn't too large. If it is I (or a mod) can remove my post. Thanks in advance guys.
 

Somnid

Member
I agree with both of you.

As far as the performance, after the first query there is very little difference between Dapper and EF. 5-25 ms by benchmarks floating around. Which for most of us, probably isn't going to make much of a difference anyways. There are also performance tricks where you can squeeze additional speed out of EF, and if you are concerned about performance you should inspect what EF is generating or profile to make sure that EF is the bottleneck in the first place. It's only black magic if you let it be.

EF will never be as fast as Dapper, but the benefits you gain over using a full ORM over a Micro-ORM probably outweigh the speed that you gain. You can also use both if you have a troublesome query that has to be fast.

Really it always boils down to what you are doing and what performance you need. I wouldn't rule either out.

I'm curious, because I've worked on dozens of projects, using linq-to-sql, EF, nhibernate, ADO, dapper and all sorts of custom ORMs on small to crazy large DBs and yet I've never really seen a need for a big ORM. In fact, I've really only seen complaints because something was hard to tune, had lots of nasty generated code or accidentally loaded the entire DB into memory off a property mapping or something. What do you feel it buys you?
 

leroidys

Member
Hey gaf, I'm looking for some help with a pong assignment I am working on for school. I'm new to programming, so this code might be a little ugly, and my problem may be a little simple.

I'm using python 3 here, but I'm having trouble with my function for tracking the score for each player. Currently, it only displays 1 point for each player after a player 'scores', but after that it stops adding new points. So it'll say 1-1, but it won't change values after that. Before I started using user defined functions for this program I didn't have this problem. But I can't quite tell why I'm having this issue now.

Hopefully this wall of text isn't too large. If it is I (or a mod) can remove my post. Thanks in advance guys.

Look into pass by reference vs. pass by value in python. Hopefully that helps. It's an easy fix but it's an important lesson in programming, so it'll be worthwhile to read through some other people giving better explanations and examples than I will here.
 

MiszMasz

Member
Hey gaf, I'm looking for some help with a pong assignment I am working on for school. I'm new to programming, so this code might be a little ugly, and my problem may be a little simple. ~

Python has a weird way of passing arguments to functions (call by object) and treats numbers as immutable. So when you're passing these into scoreFun(), you're not actually incrementing the score variables in main(). Thus, every time your while-loop goes round, you're always passing in (perpetually unchanged) score values from main that equal 0, incrementing by 1 a copy local to scoreFun() (according to the if conditional), and reflecting it in your display update called in scoreFun()... rinse, lather, repeat.

Example:
Code:
def main():
    score1 = 0
    score2 = 0
    
    for i in range (3):
        scoreFun(score1, score2)
        print (score1)
        print (score2)

def scoreFun(score1, score2):
    if (True):
        score1 += 1
    if (True):
        score2 += 1

main()

Every time i call scoreFun(), as my if conditionals are hard-set to true, my scores are always incremented. Though as in your code, the original score variables in main aren't affected.
So as this loops three times (just for the example as opposed to your game's while-loop), you'd want to see the printed output for each score go up by 1 each round of the loop, but what's actually printed is:
0
0
0
0
0
0

Assuming you're ok with accessing elements in a list (which isn't treated as an immutable object in Python), you could change your initial score initialisation in main() from two numbers to a list of numbers, with the first element at index [0] being the left player's score, and the second element at index [1] being the right player's score. This way, changes to the score within scoreFun() will be reflected in your main function.

Example:
Code:
def main():
    score = [0, 0]
    
    for i in range (3):
        scoreFun(score)
        print (score)

def scoreFun(current_score):
    if (True):
        current_score[0] += 1
    if (True):
        current_score[1] += 1

main()

The output of which is:
[1, 1]
[2, 2]
[3, 3]

Hopefully you can see how to tinker with and integrate such a change, and make use of it in your score display.
This is a more extensive explanation along the lines of what leroidys is getting at, and what i've explained above.

As an aside, you'll notice i changed the argument name in my scoreFun() definition to be different from the name of my score variable too. It's not so important for a small program like this but it's a good habit to get into to help make things clearer for you as your programs get larger. You ought to look up the distinction between formal and actual arguments.
 

Bentles

Member
My biggest beef with F# is there's no forward declarations - you have to declare a function before another function that calls it. Wasn't F# invented in this millennium? :mad:

In C#, I always put my submethods under the method that calls them. In F# I have to reverse that. At least there's no arguments about style.

It was pretty funny the first time I needed mutual recursion in F#. Ok so this goes first and then I need... this to go first -- wait, shit how do I even?
 

Makai

Member
Unity's garbage collector is not fine. The only way to be smooth in a Unity game is to eliminate all continuous memory allocation+deallocation so the garbage collector won't run a cleanup sweep and cause a chug. Even something as simple as running a C# foreach loop on a list will reserve memory and release it when the loop is done, and also be slower than a plain for loop. LINQ is worse, and I'm assuming F# would probably be worse still.
http://www.somasim.com/blog/2015/04/csharp-memory-and-performance-tips-for-unity/
Throughput performance is not the problem.
Oh yeah, I'm familiar with Unity's performance. We never had to push the absolute limits of the hardware we targeted (iPad Air 2) at my last job. Our apps ran smoothly, and when they didn't it was usually a Big O issue rather than the limits of the technologies we used. The memory saved by replacing foreach with for was negligible and LINQ was fine for our purposes. We did run into a lot of build issues because LINQ and even C# generics more broadly had limited support on iOS. The compiler had to convert JIT code to AOT and getting it to build was trial and error. It would always be seemingly harmless stuff like struct collections that would break the compiler.

I don't have a lot going on in my F# app right now, but I don't see any funny business in the profiler. I haven't done any serious tests, but it seems like the performance is roughly equal to C#. If I find that a certain algorithm is too slow in F#, I can always use imperative style with mutable variables as an optimization, or I can even mix and match C#. The biggest annoyance with using F# and Unity is it can't read the script files directly. I have to compile the project as a DLL.
 
Code:
Lots of code

Hopefully this wall of text isn't too large. If it is I (or a mod) can remove my post. Thanks in advance guys.

The simplest way to explain it is

In your 'main' function you have variables 'score1' and 'score2' but then in your 'scoreFun' function you are passing them as paramaters which basically means that the 'score1' and 'score2' variables that you have in your 'scoreFun' function are "copys" of the original values.

So when you say :
score1 += 1

You are taking the original version of 'score1' which exists in the 'main' function and has a value of 0. Then you are inside 'scoreFun' making a copy of that value (0) and adding 1 to it. You are doing this over and over again so the value displayed is always '1'.

You call a display update from pygame inside this function so what is drawn to the screen is what is inside the function at that time and not the value of 'score1' that exists in the 'main' function.

As MiszMasz explained you can use a list to store the values because of the way Python handles lists the contents can be changed anywhere.

Note for the programming gurus: I know that my explanation isn't exactly what is happening but I don't think getting into stuff like call by object, namespaces, object id's in memory, scoping and mutability vs immutability will be helpful to him at the moment as they are all concepts that can take a while to understand properly and I think if we go into too much detail it will make the problem at hand seem much harder.
 

Water

Member
Oh yeah, I'm familiar with Unity's performance. We never had to push the absolute limits of the hardware we targeted (iPad Air 2) at my last job. Our apps ran smoothly, and when they didn't it was usually a Big O issue rather than the limits of the technologies we used. The memory saved by replacing foreach with for was negligible and LINQ was fine for our purposes.
...
I don't have a lot going on in my F# app right now, but I don't see any funny business in the profiler. I haven't done any serious tests, but it seems like the performance is roughly equal to C#. If I find that a certain algorithm is too slow in F#, I can always use imperative style with mutable variables as an optimization, or I can even mix and match C#.
Like I said, it's not about throughput performance, or memory running out. In fact, releasing memory is what will trigger the GC sweeps. Even a high end system will stutter from reserving+releasing only a tiny amount of memory each frame. To clarify, the effect I'm talking about is subtle. People who claim to see no difference between 30 and 60 FPS might not see this stutter either. But for a serious action game project, I think it's very important to get rid of it.

(BTW, this is mostly second-hand info, I haven't had time to experiment with this low level stuff. But I do see the stutter, even in very simple games my students have done, running on fast PCs.)
 

MiszMasz

Member
Note for the programming gurus: I know that my explanation isn't exactly what is happening but I don't think getting into stuff like call by object, namespaces, object id's in memory, scoping and mutability vs immutability will be helpful to him at the moment as they are all concepts that can take a while to understand properly and I think if we go into too much detail it will make the problem at hand seem much harder.

That's a fair point, but i think it's always a case of trying to strike a balance between explaining around things and using the kind of jargon someone could search for on Google and is likely to find on tutorial/reference sites and other technical forums.
I tend to hope that someone asking for help will ask further or be able to search things out at their own pace if given initial direction, should things still remain unclear.
 

Makai

Member
Like I said, it's not about throughput performance, or memory running out. In fact, releasing memory is what will trigger the GC sweeps. Even a high end system will stutter from reserving+releasing only a tiny amount of memory each frame. To clarify, the effect I'm talking about is subtle. People who claim to see no difference between 30 and 60 FPS might not see this stutter either. But for a serious action game project, I think it's very important to get rid of it.

(BTW, this is mostly second-hand info, I haven't had time to experiment with this low level stuff. But I do see the stutter, even in very simple games my students have done, running on fast PCs.)
I have a 144hz monitor, so it's probably safe to call me a framerate stickler. My experience with Unity performance has been much rosier. It was never difficult to get Unity to run at a locked framerate on iPad. I saw a lot of frame dips at work, but it was usually because someone was doing something very wrong. Your students are likely instantiating new GameObjects constantly when they should be swapping out from a pool of GameObjects sitting on the sidelines.

Unity's garbage collector isn't great (it's like 10 years old), but it's competent. There's lots of hacks to get the garbage collector to do what you want. There was a brief window where Unity seriously damaged their GC in the transition to IL2CPP and the official temporary fix was to manually trigger garbage collection every frame with GC.Collect(). Very soon we should get the new .NET garbage collector.
 

Dereck

Member
Makai, is there anyway that you think you could help me with some Java code, one on one somehow?

No worries if you can't, just asking.
 

Makai

Member
Makai, is there anyway that you think you could help me with some Java code, one on one somehow?

No worries if you can't, just asking.
Sure, just PM me your code. I haven't used Java in a while, but if it's intro-level stuff I can probably help.
 
That's a fair point, but i think it's always a case of trying to strike a balance between explaining around things and using the kind of jargon someone could search for on Google and is likely to find on tutorial/reference sites and other technical forums.
I tend to hope that someone asking for help will ask further or be able to search things out at their own pace if given initial direction, should things still remain unclear.

Yeah that makes sense too, I guess trying to find the right balance is always the hardest part, apologies if my reply came across as rude it wasn't my intention.

It's just sometime I see people new to programming ask for help with something in places like stack overflow and then get bombarded with a bunch of complex sounding terminology and jargon which turns them off the field and they never get past that beginner phase.

On a side note programming is filled to the brim with jargon for tons of things that are not even that hard to grasp but people get lost in the complex sounding terms I mean "concatenate" when you first say that to someone they just look at you with a "huh?" look even though it just means adding two strings together which is a really simple concept that almost anyone could understand.

But anyway sorry that's kind of off topic my own little issue with programming academia, forgive the rant.
 

MiszMasz

Member
Yeah that makes sense too, I guess trying to find the right balance is always the hardest part, apologies if my reply came across as rude it wasn't my intention.

It's just sometime I see people new to programming ask for help with something in places like stack overflow and then get bombarded with a bunch of complex sounding terminology and jargon which turns them off the field and they never get past that beginner phase.

On a side note programming is filled to the brim with jargon for tons of things that are not even that hard to grasp but people get lost in the complex sounding terms I mean "concatenate" when you first say that to someone they just look at you with a "huh?" look even though it just means adding two strings together which is a really simple concept that almost anyone could understand.

But anyway sorry that's kind of off topic my own little issue with programming academia, forgive the rant.

No worries mate, i understand completely.
It's a big part of why, even if someone admits it's school/assignment related, i try to provide an example that's not just doing all their work for them, but instead shows the sort of thing that's been explained working in a relevant way. Hopefully then, even if some of what's been said is a bit obtuse and technical, they can try to also follow what's happening or intended.
 

Makai

Member
Yeah that makes sense too, I guess trying to find the right balance is always the hardest part, apologies if my reply came across as rude it wasn't my intention.

It's just sometime I see people new to programming ask for help with something in places like stack overflow and then get bombarded with a bunch of complex sounding terminology and jargon which turns them off the field and they never get past that beginner phase.

On a side note programming is filled to the brim with jargon for tons of things that are not even that hard to grasp but people get lost in the complex sounding terms I mean "concatenate" when you first say that to someone they just look at you with a "huh?" look even though it just means adding two strings together which is a really simple concept that almost anyone could understand.

But anyway sorry that's kind of off topic my own little issue with programming academia, forgive the rant.
https://wiki.haskell.org/Zygohistomorphic_prepromorphisms
 
Hopefully you can see how to tinker with and integrate such a change, and make use of it in your score display.
This is a more extensive explanation along the lines of what leroidys is getting at, and what i've explained above.

The simplest way to explain it is

Look into pass by reference vs. pass by value in python. Hopefully that helps. It's an easy fix but it's an important lesson in programming, so it'll be worthwhile to read through some other people giving better explanations and examples than I will here.

Just wanted to say thanks to all of you guys, as your answers cleared up my problems, and also provided me with some new information/places to go for further learning. I really appreciate it!
 

Slavik81

Member
I'm really looking forward to modules and compile-time reflection. Aside from that, they could do nothing but tweaks and bug fixes, as far as I'm concerned.

Well, and maybe flesh out threading a little. Maybe ranges, too, but that's definitely a tricky one to integrate because it touches so much of the standard library.

Actually, in general a lot of this new stuff seems pretty tricky to get right. I'm glad they're testing things out in the TS (a next-gen tr1) first.
 

Pau

Member
Really can't wrap my head around this one. We're supposed to delete any consecutive duplicates in a vector of strings, but we can't use unique or anything really beyond push_back, pop_back, and size.length. I was getting it to work except for some cases (like the consecutive duplicates being at the end of the vector, or, for some reason, the duplicates being the second to last vector items. There was version working better than this, but I didn't save it. Before all this, the user types in a sentence, I make it so that each word becomes an element of a vector.

Code:
        int repeatCount = 0;

	for(int i=0; i < words.size() - 1; i++)
		{
			if(words[i] == words[i+1])
			{
				repeatCount++;
			}
		}
	//this comes out correctly at least

	for(int i=0; i < words.size();)
	{
		int j = 1; //keep count of how many times the word appears consecutively
		while(((j+i) < words.size()) && (words[i] == words [i+j]))
		{
			j++;
		}

		if(j > 1)
		{
			for(int k=i+1; k < j; k++)
			{
				words[k] = words[i+k];
			}
				
		}
		i++;
	}

	while(repeatCount > 0)
	{
		words.pop_back();
		repeatCount--;
	}

	for(int i=0; i < words.size(); i++)
	{
		cout << words[i] << " ";
	}
Am I over thinking this? Just feeling really dumb. :c
 
Unity's garbage collector is not fine. The only way to be smooth in a Unity game is to eliminate all continuous memory allocation+deallocation so the garbage collector won't run a cleanup sweep and cause a chug. Even something as simple as running a C# foreach loop on a list will reserve memory and release it when the loop is done, and also be slower than a plain for loop. LINQ is worse, and I'm assuming F# would probably be worse still.
http://www.somasim.com/blog/2015/04/csharp-memory-and-performance-tips-for-unity/
Throughput performance is not the problem.

The one commercial Unity game I shipped we actually stripped all of our for each's out after I found out how awful Unity/MonoDevelop is at expanding and handling them.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Am I over thinking this? Just feeling really dumb. :c

If I'm reading the problem right I think you are overcomplicating it.

The trick is using a second vector. Since you're interested in consecutive duplicates, you only need to ever go from back to front, moving words from your input vector (pop_back) to your working vector (push_back).

It should be pretty easy to keep track of which word you've seen "last", so you know whether to move a word or to discard it.
 

Water

Member
I have a 144hz monitor, so it's probably safe to call me a framerate stickler. My experience with Unity performance has been much rosier. It was never difficult to get Unity to run at a locked framerate on iPad. I saw a lot of frame dips at work, but it was usually because someone was doing something very wrong. Your students are likely instantiating new GameObjects constantly when they should be swapping out from a pool of GameObjects sitting on the sidelines.
No, that's elementary stuff. Again, I'm not talking about throughput performance (high framerate, significant dips in framerate) but chugs that may occur once in a few seconds and aren't visible looking at averaged framerate numbers.
Unity's garbage collector isn't great (it's like 10 years old), but it's competent. There's lots of hacks to get the garbage collector to do what you want. There was a brief window where Unity seriously damaged their GC in the transition to IL2CPP and the official temporary fix was to manually trigger garbage collection every frame with GC.Collect(). Very soon we should get the new .NET garbage collector.
I have read quite a bit on the limitations of the Unity GC. Unity's own documentation seems to say the only ways to avoid chugs in continuous realtime games are to either have a tiny heap (impossible for a lot of projects) and constantly manually run the GC, which is an awful hack and also a waste of performance, or if you have anything more than a tiny heap, you have to eliminate basically all memory churn from the realtime portion of the game. Which severely ties your hands and causes ugly code when you can't freely use foreach, LINQ, etc.

I'm all ears if you know of GC hacks that allow bypassing those limitations. As far as I understand, it's not possible without a total GC upgrade, either to reference counting, or being able to reliably split the GC's work over several frames instead of having to do a whole sweep in one go.

http://docs.unity3d.com/Manual/UnderstandingAutomaticMemoryManagement.html
http://www.gamasutra.com/blogs/Wend...nagement_for_Unity_Developers_part_1_of_3.php
 

Makai

Member
No, that's elementary stuff. Again, I'm not talking about throughput performance (high framerate, significant dips in framerate) but chugs that may occur once in a few seconds and aren't visible looking at averaged framerate numbers.
I actually read all of the articles you've linked but I still used plenty of foreach loops, clojures, and LINQ at my last job as a C#/Unity programmer. It's all true, but the magnitude of the leaks never seemed to make a real difference (with foreach and clojures, at least. LINQ had to be used sparingly). We actually had a guy from Unity come down to evaluate my project and he basically said, "looks good to me." The only garbage collection advice he offered was flattening our game object hierarchies. We had a massively nested prefab, which he said was a strain on the garbage collector.

I can see spikes in the CPU profiler for my F# project, but it never dips below 60 fps and the garbage collector is not a major contributor. I'll let you know if I notice any performance issues as I ramp up the spec, but it seems like it'll be smooth sailing.

Oh, I just realized - I am compiling my code with the .NET compiler instead of Mono. That might have something to do with it. I package my project into a DLL and then Unity can see the scripts that derive from MonoBehaviour.
 

Water

Member
I actually read all of the articles you've linked but I still used plenty of foreach loops, clojures, and LINQ at my last job as a C#/Unity programmer. It's all true, but the magnitude of the leaks never seemed to make a real difference (with foreach and clojures, at least. LINQ had to be used sparingly). We actually had a guy from Unity come down to evaluate my project and he basically said, "looks good to me." The only garbage collection advice he offered was flattening our game object hierarchies. We had a massively nested prefab, which he said was a strain on the garbage collector.
Were the projects continuous action games with sizable heaps? And were you also at that time compiling all that logic to a separate DLL with a better compiler, and only compiled a minority of code from Mono?
Oh, I just realized - I am compiling my code with the .NET compiler instead of Mono. That might have something to do with it. I package my project into a DLL and then Unity can see the scripts that derive from MonoBehaviour.
From what I've read, that makes all the difference.

Noob question: when you have a separate DLL (eg. generated from F# or from delegate-LINQ-rich C#) in a Unity game, does all that code still use the poor Unity GC (so all the gains come from the optimizations that cause less memory churn to be generated), or does the DLL have its own modern .Net GC wrapped into it which actually allows a bit of churn to happen without hitches? I'm 95% sure it is the former, but I really want to be sure...
 
2020? And here I thought we could finally get a good module system in the next two years :(

Was talking about networking.

Modules are a different story. Clang and msvc both started working on modules a few years ago with no spec because they were so important. As a result of not having a spec, their implementations diverged to the point of being somewhat incompatible. It sounds like this meeting worked out the high level approach but not the details.


At some point in the future both clang and msvc will need to converge on the spec, but since it still doesn't exist expect them to keep going on their own and we'll see modules by c++17 in both compilers, but it won't be *the* modules.

As an aside, I find it a little ironic that actually implementing modules requires doing all the work that everyone said was impossible for the export keyword. Just goes to show the consequences of getting the language design wrong, as well as how hard it is to get it right
 

Haly

One day I realized that sadness is just another word for not enough coffee.
What are modules in this context?

Is this the kind of packages used in Node and ES6?
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Wow that's totally surreal as someone learning Javascript. JS is getting block level scoped variables and things like default parameters in the next specification, so my programs were becoming more C-like, while C++ got lambdas last year and, apparently, modules in the near future.

Edit: Oh I see the concept of modules is much older than I thought.
 

Makai

Member
Were the projects continuous action games with sizable heaps?
No, but I did a lot of MapReduce style stuff with LINQ and used a lot of events. I don't have access to that project anymore, so I can't be sure if I'm telling you the truth. But I think QA would have said something or I would have noticed when I did profiling.

And were you also at that time compiling all that logic to a separate DLL with a better compiler, and only compiled a minority of code from Mono?
No, I used the Unity compiler for that project. I'm using a DLL now because it's the only way that I know to get Unity to recognize my F# code.

Noob question: when you have a separate DLL (eg. generated from F# or from delegate-LINQ-rich C#) in a Unity game, does all that code still use the poor Unity GC (so all the gains come from the optimizations that cause less memory churn to be generated), or does the DLL have its own modern .Net GC wrapped into it which actually allows a bit of churn to happen without hitches? I'm 95% sure it is the former, but I really want to be sure...
Not sure, but I think you're right. Otherwise, the first recommendation in Unity memory management articles would be to switch to Roslyn. Luckily, we'll probably get better garbage collection soon:

IL2CPP is not tied to any one specific garbage collector, instead interacting with a pluggable API. In its current iteration IL2CPP uses an upgraded version of libgc, even as we look at multiple options. Aside from just the GC itself, we are investigating reducing GC pressure by analysis done in the IL2CPP compiler.

While we don’t have a lot more to share at the moment, research is ongoing. We know this is important to many of you, we’ll continue working on it and keep you informed in future blog posts. Unrelated to IL2CPP, but worth mentioning in the context of garbage collection, Unity 5 will see more and more allocation free APIs.
 

Slavik81

Member
Modules are a different story. Clang and msvc both started working on modules a few years ago with no spec because they were so important. As a result of not having a spec, their implementations diverged to the point of being somewhat incompatible. It sounds like this meeting worked out the high level approach but not the details.
Very cool:
Herb Sutter said:
Modules has reached a milestone: design agreement! This was done by separating &#8220;phase 1&#8221; and &#8220;phase 2&#8221; of modules, and greenlighting phase 1 to proceed to wordsmithing for adoption (hopefully at our next meeting) into a new Modules TS, while in parallel continuing work on an expanded phase 2 which can follow.
Herb Sutter said:
@jmckesson: &#8220;Modules phase 1&#8221; is essentially Gaby&#8217;s approach, and &#8220;phase 2&#8221; is essentially adding support for exporting macros.
"Gaby" seems to be Gabriel Dos Reis, so presumably they're referring to this proposal.
 
Very cool:


"Gaby" seems to be Gabriel Dos Reis, so presumably they're referring to this proposal.

So as far as I can tell, there was actually less agreement than is being let on. My guess is that what will ultimately happen is that it will come down to a vote eventually, and one of the two modules approaches will be adopted into the standard, and the other won't. I have a pretty good idea who will win the vote, but it's not all that important I guess.
 

Pau

Member
If I'm reading the problem right I think you are overcomplicating it.

The trick is using a second vector. Since you're interested in consecutive duplicates, you only need to ever go from back to front, moving words from your input vector (pop_back) to your working vector (push_back).

It should be pretty easy to keep track of which word you've seen "last", so you know whether to move a word or to discard it.
Thanks! For some reason I thought using a second vector would be kind of cheating, since I remember a somewhat similar example in lecture where the professor wanted to just use a single vector. I'm not sure if that's what he wanted for this, but yeah, using a second vector made everything so much easier.
 
guys help me out here, I have no clue whats wrong with this. it says theres something wrong with the iterator.

Code:
template<typename T>
void split(const list<T>& alist, list<T>& list1, list<T>& list2)
{
    int place=1;
    typename list<T>::iterator itr = alist.begin();
    while(itr!=alist.end())
    {
        if((place/2)==0)
            list2.push_back(*itr);
        else
            list1.push_back(*itr);
        itr++;
        place++;
    }
    return;
}

this is the full program if needed. basically odd number objects get added to list1 and even numbered go to list2.

Code:
#include <iostream>
#include <list>
using namespace std;

template<typename T>
void split(const list<T>& alist, list<T>& list1, list<T>& list2)
{
    int place=1;
    typename list<T>::iterator itr = alist.begin();
    while(itr!=alist.end())
    {
        if((place/2)==0)
            list2.push_back(*itr);
        else
            list1.push_back(*itr);
        itr++;
        place++;
    }
    return;
}

int main()
{
    list<int> norm, odd, even;
    norm.push_back(1);
    norm.push_back(2);
    norm.push_back(3);
    norm.push_back(4);
    norm.push_back(5);
    norm.push_back(6);
    split(norm,odd,even);
}
 
guys help me out here, I have no clue whats wrong with this. it says theres something wrong with the iterator.

Code:
template<typename T>
void split(const list<T>& alist, list<T>& list1, list<T>& list2)
{
    int place=1;
    typename list<T>::iterator itr = alist.begin();
    while(itr!=alist.end())
    {
        if((place/2)==0)
            list2.push_back(*itr);
        else
            list1.push_back(*itr);
        itr++;
        place++;
    }
    return;
}

this is the full program if needed. basically odd number objects get added to list1 and even numbered go to list2.

Code:
#include <iostream>
#include <list>
using namespace std;

template<typename T>
void split(const list<T>& alist, list<T>& list1, list<T>& list2)
{
    int place=1;
    typename list<T>::iterator itr = alist.begin();
    while(itr!=alist.end())
    {
        if((place/2)==0)
            list2.push_back(*itr);
        else
            list1.push_back(*itr);
        itr++;
        place++;
    }
    return;
}

int main()
{
    list<int> norm, odd, even;
    norm.push_back(1);
    norm.push_back(2);
    norm.push_back(3);
    norm.push_back(4);
    norm.push_back(5);
    norm.push_back(6);
    split(norm,odd,even);
}

Tl;dr - use `auto` instead of manually specifying the iterator type.

Longer answer: you are getting an iterator, which allows mutation of the underlying data structure, but you have a const reference to the data structure, so getting an iterator violates its constness. You need a const_iterator.

Anyway, this is exactly why auto was invented, so use that instead
 
Tl;dr - use `auto` instead of manually specifying the iterator type.

Longer answer: you are getting an iterator, which allows mutation of the underlying data structure, but you have a const reference to the data structure, so getting an iterator violates its constness. You need a const_iterator.

Anyway, this is exactly why auto was invented, so use that instead

ahhh can't believe I forgot that there are 2 different kind of iterators!! I haven't learned about auto yet so I just put it as a const_iterator :) thank you so much
 

Nelo Ice

Banned
So been looking through the thread for Ruby advice and found some books to get but besides that what else can I do to pick up the language? If anyone remembers me, I've been learning front end stuff for the past few months. But thanks to a potential scholarship opportunity, I'm switching to Ruby.

Thus far my experience with Ruby has been limited to the 1st 7 unite of the Codecademy course here https://www.codecademy.com/learn/ruby. Only did the 1st 7 since that was the only thing that was required as a tech assessment for the scholarship. Have an interview this Friday regarding the scholarship and they're going to give me an in person tech assessment. So hoping to understand all I can before then. They're going to be using aptana studio to give me questions and I've had issues with it and ruby on windows but guessing my linux install via usb will work?. Also guessing I won't have to know as much as I think I do but would rather be hilariously over prepared lol.

Anyway working my ass off to nail the interview since getting the scholarship would drastically change my fortunes. Since with it I'd get a free ride to a coding boot camp, living stipends, and then a guaranteed apprenticeship at one of the organizations partner companies like twitter or pinterest.
 
I got up to speed (not learning, just getting familar) with Ruby through Koans so I could work on some cloud foundry buildpack features. I think that's more for experienced developers though.

If you really want a scholarship you should lock yourself in a room with something like leetcode and grind out interview style questions in ruby until Friday. Do you know the nature of the questions you will be asked? I'm assuming it's standard interview stuff.

Also in terms of development-I've had no problems with Ruby on windows when set up correctly ( I even did my development through Eclipse w/ DLTK ) but one of the most useful tools I have in my set is a cloud hosted Linux VM that I can ssh into if I can't be fussed with how to get something working The Windows Way.
 
Would you guys recommend this book for getting a good handle on graphics if I already have this book ? Or is it redundant?

I have at least three books that are 3D math primers. You can never have too many books on computer graphics.

However, I seem to recall that the second edition of that particular book is better regarded, from being written in a time before GPUs were a mass market item. That said, I remember skimming through an early draft of a chapter on soft shadows in the third edition that looked really good to me. It wouldn't be a bad investment.
 

SOLDIER

Member
Last week, I was surprised to find that over half the people had dropped out. Seems I wasn't alone with my criticisms with the professor.

Still trying to stick it out, though. My latest Python project requires me to create an input validation, and then modify the program so that it uses binary search algorithm instead of sequential search algorithm.

First thing's first, I'm trying to get the code to validate numbers:

Code:
def main():

    numbers = [1, 2, 3, 4, 5]

    found = False

    index = 0

    search_value = input ("Enter a number to search for in the list: ")

    while found == False and index < len(numbers):
        if numbers[index] == search_value:
            found = True
        else:
            index = index + 1

    if found:
        print ("The number was found in element " + str(index + 1))
    else:
        print ("That number was not found in the list.")
    
main()

Current problem is that it will say that the number was not found on the list, even if I type in a number that should validate. Help, as usual, would be appreciated.
 

emb

Member
Current problem is that it will say that the number was not found on the list, even if I type in a number that should validate. Help, as usual, would be appreciated.
What data type are you getting as input? What data type is in the array?
 
Last week, I was surprised to find that over half the people had dropped out. Seems I wasn't alone with my criticisms with the professor.

Welcome to every Introduction to Programming course ever. It's not your professor, it's that it's hard.

To answer your question, input() is going to return a string. The values in your list are integers. Try this:


Code:
# Don't do this
search_value = input ("Enter a number to search for in the list: ")

# Do this, converts the result from a string to an integer.
search_value = int(input ("Enter a number to search for in the list: "))
 

Nelo Ice

Banned
I got up to speed (not learning, just getting familar) with Ruby through Koans so I could work on some cloud foundry buildpack features. I think that's more for experienced developers though.

If you really want a scholarship you should lock yourself in a room with something like leetcode and grind out interview style questions in ruby until Friday. Do you know the nature of the questions you will be asked? I'm assuming it's standard interview stuff.

Also in terms of development-I've had no problems with Ruby on windows when set up correctly ( I even did my development through Eclipse w/ DLTK ) but one of the most useful tools I have in my set is a cloud hosted Linux VM that I can ssh into if I can't be fussed with how to get something working The Windows Way.

Well for the interview it just said this.
Be sure to review the Ruby concepts you learned from Code Academy. You should understand all the functions well enough to structure, call, and use them to program. You should also be able to explain your thinking process as you program.

As for developing on windows, I've never used an ide before and had a helluva time trying to figure out how to get aptana to work properly for ruby. Ruby was installed but aptana wasn't seeing it and I was honestly just lost on how to get it all setup properly. Figured I should at least get it working on one of my computers since that's what I'll have to use for the interview.

edit: Also thanks for the heads up on leet code. Just checked it out and it looks perfect. Also for the interview I'm guessing the questions won't be too insane since the scholarship is for people new to coding but have an interest in it. So figure I won't be asked to be do anything too crazy but I'm gonna prepare as if it will be anyway haha.
 

SOLDIER

Member
Welcome to every Introduction to Programming course ever. It's not your professor, it's that it's hard.

Does it get easier?

I constantly worry if this is just the bare basics, and that further classes/learning will go right over my head. I am improving with Python, but I can't tell if it's normal progression or slow going.

There are people in class who say they've done programming for a living and claiming the professor isn't explaining things well. I do feel he needs to dumb down things more, and he also creates these sudden rule shifts that throw me out of a loop (for instance, he claimed he couldn't open my email with the last assignment because he got a virus warning, so I have to deliver it directly in class).

In any event, I need to take that code and have it search via binary algorithm. I'll start searching/trying it myself, but if anyone immediately knows how to do that it would save me time.
 
Does it get easier?

I constantly worry if this is just the bare basics, and that further classes/learning will go right over my head. I am improving with Python, but I can't tell if it's normal progression or slow going.

There are people in class who say they've done programming for a living and claiming the professor isn't explaining things well. I do feel he needs to dumb down things more, and he also creates these sudden rule shifts that throw me out of a loop (for instance, he claimed he couldn't open my email with the last assignment because he got a virus warning, so I have to deliver it directly in class).

In any event, I need to take that code and have it search via binary algorithm. I'll start searching/trying it myself, but if anyone immediately knows how to do that it would save me time.

Hahahaha.

No. Just wait until you take operating systems or compilers. And if your school doesn't make you take at least one of those then pffffft.
 
Top Bottom