• 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

Minamu

Member
Any good ways to change sprites in real time in xna? I have some space ships that load their textures (ship, bullet, explosion) into their separate objects. But my game crashes when I try to switch out the ship texture for the explosion.

Edit: Still haven't fixed it but I'm more concerned with my memory usage. It seems I have leaks somewhere as the ram usage is getting bigger. Apart from Content.Unload() in the default UnloadContent(), I only use RemoveAt(i) to remove objects from lists (which I gather is not the same thing as actually deleting them?).
 

Jokab

Member
Hey guys, new to this thread. :)

I was wondering if anyone knew any good online resources to use to learn Javascript, a couple of friends and I are working on some projects and they're vastly better at this programming thing than I am, I'm the donut bitch for the group right now. Any help would be appreciated. :)

www.codeacademy.com is the best resource I've found.
 

usea

Member
Any good ways to change sprites in real time in xna? I have some space ships that load their textures (ship, bullet, explosion) into their separate objects. But my game crashes when I try to switch out the ship texture for the explosion.

Edit: Still haven't fixed it but I'm more concerned with my memory usage. It seems I have leaks somewhere as the ram usage is getting bigger. Apart from Content.Unload() in the default UnloadContent(), I only use RemoveAt(i) to remove objects from lists (which I gather is not the same thing as actually deleting them?).
In general in C#, you don't explicitly delete things. Once you stop using them they will get deleted automatically. This only happens when you don't have anything left referencing them. So if you have them in a list somewhere and that list is a class-level variable in an object you are still using, they'll still be in memory.

XNA might have some special rules regarding loading and unloading content, and I don't really remember what the best practices there are. I'm guessing that you have to explicitly unload textures and such when you want them out of memory, as that would definitely make the most sense. If your memory usage is going up and up, are you repeatedly loading the textures into memory? It might be a general problem and not something to do with xna.

How are you trying to replace your ship sprite? You should be changing the sprite that gets drawn, not trying to overwrite the ship with the explosion in memory. In other words, you probably have some spot in your code where every frame you tell xna to draw your ship sprite. During the explosion, draw the explosion instead of the sprite.
 

TheExodu5

Banned
Alright, so I have a question regarding OOP.

Say you're working with a type of object, let's call it Object A. Later down the road, you're working with a similar object, Object B. It's about 80% the same, but it works differently in some ways. How should you proceed at that point?

I'm guessing expanding Object A with some if/else where it differs is a no-no? Should you attempt to factor out the common components into a third object, let's call it Object Parent AB, and make these two extend that? It seems feasible at first, but if you add a third Object C that has only some stuff in common with Object A and B then refactoring becomes a nightmare.

Any thoughts?
 
Alright, so I have a question regarding OOP.

Say you're working with a type of object, let's call it Object A. Later down the road, you're working with a similar object, Object B. It's about 80% the same, but it works differently in some ways. How should you proceed at that point?

I'm guessing expanding Object A with some if/else where it differs is a no-no? Should you attempt to factor out the common components into a third object, let's call it Object Parent AB, and make these two extend that? It seems feasible at first, but if you add a third Object C that has only some stuff in common with Object A and B then refactoring becomes a nightmare.

Any thoughts?

It's more of a question of do A and B have the same overall purpose rather than do they have the same code. If they do, then you make that parent class AB, with most, if not all, of the common code. When C comes along then you can just extend that AB class and add/override what you need.

Personally, it's less of a headache to do that rather than just adding if/else blocks into the existing A code to the point it becomes an unmanageable monster.
 

2MF

Member
Alright, so I have a question regarding OOP.

Say you're working with a type of object, let's call it Object A. Later down the road, you're working with a similar object, Object B. It's about 80% the same, but it works differently in some ways. How should you proceed at that point?

I'm guessing expanding Object A with some if/else where it differs is a no-no? Should you attempt to factor out the common components into a third object, let's call it Object Parent AB, and make these two extend that? It seems feasible at first, but if you add a third Object C that has only some stuff in common with Object A and B then refactoring becomes a nightmare.

Any thoughts?

If "Object Parent AB" is actually a concept that makes sense then yes, that's a good idea (and it's likely that some later classes will be able to inherit from it). If it's a contrived class which has no chance of being a useful general concept then no, it probably doesn't make sense.
 

Slavik81

Member
Alright, so I have a question regarding OOP.

Say you're working with a type of object, let's call it Object A. Later down the road, you're working with a similar object, Object B. It's about 80% the same, but it works differently in some ways. How should you proceed at that point?

I'm guessing expanding Object A with some if/else where it differs is a no-no? Should you attempt to factor out the common components into a third object, let's call it Object Parent AB, and make these two extend that? It seems feasible at first, but if you add a third Object C that has only some stuff in common with Object A and B then refactoring becomes a nightmare.

Any thoughts?
If you just want to reuse code, create a common component that they both use.

If there's a common purpose they both share, and a coherent base class can be extracted (that is itself usable without knowing the underlying concrete type) then consider inheritance.
 

usea

Member
Alright, so I have a question regarding OOP.

Say you're working with a type of object, let's call it Object A. Later down the road, you're working with a similar object, Object B. It's about 80% the same, but it works differently in some ways. How should you proceed at that point?

I'm guessing expanding Object A with some if/else where it differs is a no-no? Should you attempt to factor out the common components into a third object, let's call it Object Parent AB, and make these two extend that? It seems feasible at first, but if you add a third Object C that has only some stuff in common with Object A and B then refactoring becomes a nightmare.

Any thoughts?
I agree with Slavik. When you say the classes are the same, do you mean their data or behavior? If they have a lot of the same code in their methods, make a third class with that functionality and have both A and B use it. If they share a lot of the same fields, then it's possible a base class would make sense. But only if it really does make sense. We can't tell without more context.

Usually prefer composition to inheritance. Never use inheritance only to reuse code. That's my personal philosophy, and not everyone will agree.
 
Alright, so I have a question regarding OOP.

Say you're working with a type of object, let's call it Object A. Later down the road, you're working with a similar object, Object B. It's about 80% the same, but it works differently in some ways. How should you proceed at that point?

I'm guessing expanding Object A with some if/else where it differs is a no-no? Should you attempt to factor out the common components into a third object, let's call it Object Parent AB, and make these two extend that? It seems feasible at first, but if you add a third Object C that has only some stuff in common with Object A and B then refactoring becomes a nightmare.

Any thoughts?

use a interface or abstract class for the same stuff.
But it has been a while using OOP for me so i could have it wrong.
 

Minamu

Member
In general in C#, you don't explicitly delete things. Once you stop using them they will get deleted automatically. This only happens when you don't have anything left referencing them. So if you have them in a list somewhere and that list is a class-level variable in an object you are still using, they'll still be in memory.

XNA might have some special rules regarding loading and unloading content, and I don't really remember what the best practices there are. I'm guessing that you have to explicitly unload textures and such when you want them out of memory, as that would definitely make the most sense. If your memory usage is going up and up, are you repeatedly loading the textures into memory? It might be a general problem and not something to do with xna.

How are you trying to replace your ship sprite? You should be changing the sprite that gets drawn, not trying to overwrite the ship with the explosion in memory. In other words, you probably have some spot in your code where every frame you tell xna to draw your ship sprite. During the explosion, draw the explosion instead of the sprite.
I got some help with the framerate. I was loading in a new texture set for each new object instead of only one per class. The memory "leak" isn't that great, only a few kilobytes every few seconds and it peaks out at around 29mb usually. Some googling suggests it's because of extensive use of Lists<T>, foreach loops and Draw methods for strings that's the cause of it. I'll look into the explosion solution tomorrow if there's time, thanks :)

Edit: I think it's kinda interesting that a 1-2kB texture being loaded less than ten times a second can cause my framerate to drop to single digits almost. And it's not like other textures are that much bigger, I think I use 12kB maximum, apart from a way too oversized background image.
 

Onemic

Member
Anyone here use code academy? I just recently got back into it. Really great site, I just wish you could add friends so that your achievements and trophies you receive can give you a more competitive incentive to keep learning.
 
Anyone here use code academy? I just recently got back into it. Really great site, I just wish you could add friends so that your achievements and trophies you receive can give you a more competitive incentive to keep learning.

I just started using it today, it's pretty awesome so far.
 
Can anyone explain if this is working correctly?

So I'm trying to pull a substring from a string, and codecademy is showing me that this is the correct code to pull "Jan" from "January".

alert("January".substring(0,3));

Wouldn't (0,3) pull "Janu"? If not could some explain to me why it wouldn't?

edit: sorry, forgot to include that this is in javascript.
 
Can anyone explain if this is working correctly?

So I'm trying to pull a substring from a string, and codecademy is showing me that this is the correct code to pull "Jan" from "January".

alert("January".substring(0,3));

Wouldn't (0,3) pull "Janu"? If not could some explain to me why it wouldn't?

edit: sorry, forgot to include that this is in javascript.

It pulls a string from [0, 3) starting from offset 0 so characters at offsets 0(J),1(a), and 2(n) are extracted.
 

Godslay

Banned
Anyone here use code academy? I just recently got back into it. Really great site, I just wish you could add friends so that your achievements and trophies you receive can give you a more competitive incentive to keep learning.

Anybody higher than this?

ixqt1yK6SAkDC.png
 

usea

Member
It's saying pull 3 characters starting at 0.
This is what I thought at first due to other languages. But I just tried it in a console and the 2nd argument is indeed an exclusive end index.

"alphabet".substring(2,3) evaluates to p
 

injurai

Banned
Starting C for the first time. I've been spoiled by modern languages and standard libraries, but I'm excited to learn the daddy of these languages. We will be learning it alongside assembly as well.
 

Kalnos

Banned
Starting C for the first time. I've been spoiled by modern languages and standard libraries, but I'm excited to learn the daddy of these languages. We will be learning it alongside assembly as well.

some sort of microprocessor class? Assembly isn't too bad, just time consuming.
 

leroidys

Member
Starting C for the first time. I've been spoiled by modern languages and standard libraries, but I'm excited to learn the daddy of these languages. We will be learning it alongside assembly as well.

After hearing hate piled on C for a solid couple years before I actually had to learn it for class, I found it to be an amazing language.

It's unintuitive as anything you'll ever come across, piecemeal, and janky, but I really feel that it lets you be much more creative than most other languages.

I found assembly to be all about pattern recognition. Be able to focus in on what is actually pertinent to your problem. Don't worry about analyzing every single disassembled line, generally.
 

Victarion

Member
Hey gaf, just wanted to ask what are the most useful programming languages to learn these days? I already have good skills in C++ and C# and average Java knowledge.
I'm also gonna start learning HTML5 soon. Should I bother with Ruby?
 

Zoe

Member
Hey gaf, just wanted to ask what are the most useful programming languages to learn these days? I already have good skills in C++ and C# and average Java knowledge.
I'm also gonna start learning HTML5 soon. Should I bother with Ruby?

Got any DB knowledge in there?
 

usea

Member
Hey gaf, just wanted to ask what are the most useful programming languages to learn these days? I already have good skills in C++ and C# and average Java knowledge.
I'm also gonna start learning HTML5 soon. Should I bother with Ruby?
I really like programming languages; I enjoy learning about the cool things each of them does. But at the end of the day, they're tools you use to accomplish something. Should you learn Ruby? Sure, if you need it for a project. Or if you need to fill some gaps in your knowledge.

How good are you with functional programming concepts? Do you ever use lambdas, Action and Func in C#? Are you comfortable with declarative style programming? These are things you'd pick up really quickly with Ruby, but are significantly less common in the other languages you named.
 

Victarion

Member
By useful I mean most used languages in the industry. I'm gonna graduate in a couple of days and really like to broaden my knowledge for finding a job as soon as possible. Nobody wants to hire a junior.
 

usea

Member
By useful I mean most used languages in the industry. I'm gonna graduate in a couple of days and really like to broaden my knowledge for finding a job as soon as possible. Nobody wants to hire a junior.
Competent developers are in high demand. Many companies will leap at the chance to hire a fresh graduate who can actually program.

Regarding useful, it depends on where you live and what kind of job you want. A lot of the times, jobs in certain regions will use the same kind of technologies. If you want to work at microsoft, then you probably don't need to learn ruby right away. If you want to work at Yelp, then you need to know ruby. It varies a lot.

If you get a job at a less prestigious place, they'll be a lot more forgiving about what languages you know. 3 of the 4 developers at my current job didn't know the main language we use when they joined. Doesn't really matter.
 

leroidys

Member
Does anyone have tips for finding public projects to work on? I need to start building a portfolio but really have no clue where to start.
 

injurai

Banned
After hearing hate piled on C for a solid couple years before I actually had to learn it for class, I found it to be an amazing language.

It's unintuitive as anything you'll ever come across, piecemeal, and janky, but I really feel that it lets you be much more creative than most other languages.

I found assembly to be all about pattern recognition. Be able to focus in on what is actually pertinent to your problem. Don't worry about analyzing every single disassembled line, generally.

Yeah, It seems like it would work great when coupled with something like python. Work in a high level language then break into C whenever you need extra power or handing specific sorts of hardware or signal calls.

Excited to learn more.
 
By useful I mean most used languages in the industry. I'm gonna graduate in a couple of days and really like to broaden my knowledge for finding a job as soon as possible. Nobody wants to hire a junior.

Hard to say because i probably need to know what education CS(?) and what branch(web,app,system or embedded) you want to enter. As far as i know highly technical personal is in big shortage so jobs enough.
At least that is the situation here in the Netherlands.

System and embedded programming(C,C++)
Web don't know i'm not interested in that field.
Apps C# and java

But language shouldn't be that important know your algorithms and data structures.
 

missile

Member
I recently came about this article;

Interview with Herb Sutter, By Andrew Binstock, October 12, 2011
The lead architect of the Visual C++ design team discusses implementation of
C++11 features, why C99 will never be fully implemented, and the emerging
"C++ Renaissance".


Herb Sutter | Mircosoft said:
...

C++ Renaissance

AB: One of the terms frequently heard at the Build conference was "C++ Renaissance." I'd like to know what it means to you. And what is Microsoft doing differently in how it values C++?

HS: The C++ renaissance has two aspects. One is commenting on C++ resurgence across the industry. And, second, particularly at Microsoft, if you look at the short history of C++, it was really only in the decade that started in the mid-90s that people started getting interested in managed languages. Java came along. Then C# came along. And it was completely appropriate. Those languages are good and useful. They optimize for programmer productivity. And that's exactly the right thing to optimize for, if that's your primary cost. And during that decade we didn't do all that much exciting stuff, especially with user interfaces. We deployed across the industry a bunch of computers with nice windows that had WIMP — windows, icons, menus, and pointers. And we called it good for a decade. And it was only in the last few years that we're starting to see with the iPhone, the touch interface, and augmented reality — Kinect, especially — that we're seeing a whole new kind of user interface. And, of course, all those features now require processing power. We're demanding that the computer do more for us. At the same time, because of the increasing issue of power consumption in mobile devices and in data centers, we're being asked to do more work with less hardware. That's where efficient languages get to be important again, just like they always have been in the history of our industry — except for those 10 years.

AB: Managed languages still have their place, no?

HS: Managed languages are perfectly appropriate where your goal is to optimize programmer productivity above all else, even at the cost of performance…by having always available garbage collection that you can't turn off, always available metadata, always available JIT execution, and a virtual machine…whether you're actually using it or not, you bear the cost. But, you make the programmer so much more productive. Great. That's what you should optimize for if your biggest cost and constraint is programmer productivity. But more and more, at least part or all of your of your application needs to optimize for performance per dollar, or performance per watt, performance per transistor — because you can only put so many of them in a device. And that's why C++ is the preeminent language, because it's the king of performance per dollar. That's why it's making a comeback.

AB: And what does that translate to at Microsoft?

HS: At Microsoft, the same kinds of forces have been at work. As you've seen with Windows 8, it's been public knowledge for the last few weeks, that Windows 8 is built around this nice, OO, class, and exception, interface-based API-based system in WinRT and it's all native code. And the reason for that is performance and efficiency. So we've really seen a resurgence of in C++ at Microsoft. And I think in this particular release — I haven't counted, but I'll bet we shipped twice as many features in this release for native C++ developers, most of whose code can and should be written in standard C++, than in any two previous releases that I can think of. And that's reflective of the investment in C++-based technology.

...
2013:
Starting C for the first time. I've been spoiled by modern languages and standard libraries, but I'm excited to learn the daddy of these languages. We will be learning it alongside assembly as well.
After hearing hate piled on C for a solid couple years before I actually had to learn it for class, I found it to be an amazing language.

It's unintuitive as anything you'll ever come across, piecemeal, and janky, but I really feel that it lets you be much more creative than most other languages.

I found assembly to be all about pattern recognition. Be able to focus in on what is actually pertinent to your problem. Don't worry about analyzing every single disassembled line, generally.
Eh? I see a pattern!


... will be learning it alongside assembly as well.
At a given time you may recognize that all languages are an artificial
complication of

:<label> <mnemonic> <operand1>, <operand2> ;<comment>

Want to see an example? Avoiding FORs – Anti-If Campaign
That's where we are today. xD
 

hateradio

The Most Dangerous Yes Man
For anyone trying any JavaScript stuff, here's a (not really) ProTip: Use your browser's console! Stop using alert, and start using console.log (along with other console methods).

If you're using the latest version of Chrome, Firefox, Opera, and even IE, you have a console, which can evaluate JS. Open it, and start typing.

As for substring, I usually prefer substr.
 

JeTmAn81

Member
I have done C, C++, Assembly, and a bunch of higher-level languages, but Assembly is probably the only one I have no desire to revisit, though I did enjoy what I was able to do with it (interfacing with physical hardware for lab experiments) in college.
 

Minamu

Member
I just turned in my 58 page report for my C# class and while XNA has been fantastic to work with as a beginner, I really enjoy having C++ forcing me to deal with everything on my own.
 
anyone ever program in C and then go back to a higher level language and then be all like fuuuuu why i can't i just struct this godforsaken thing
 
anyone ever program in C and then go back to a higher level language and then be all like fuuuuu why i can't i just struct this godforsaken thing

My bet is that you are not going high enough. If you don't see the advantages of a higher level language, either:

1.- It's the wrong tool/language for what you are trying to do
2.- You are doing it wrong and writing your code like it's C/C++ instead of embracing the language own paradigms
 

Bear

Member
Anyone here use code academy? I just recently got back into it. Really great site, I just wish you could add friends so that your achievements and trophies you receive can give you a more competitive incentive to keep learning.

Yeah, it's excellent. The Python track has a few issues and is a little short on content (not as bad as a few months ago), but it taught me well enough that I can use it effectively in my school work now (in computational physics projects) .

Coming from a C and JavaScript background, Python is a joy to work with.
 

Onemic

Member
Yeah, it's excellent. The Python track has a few issues and is a little short on content (not as bad as a few months ago), but it taught me well enough that I can use it effectively in my school work now (in computational physics projects) .

Coming from a C and JavaScript background, Python is a joy to work with.

Have you worked on the Javascript track? I'm not sure if I should continue with the Javascript (original) track (currently on objects II) or if I should switch to the new javascript track. What's the difference between them? I noticed that the new one has less exercises than the original one.
 

Bear

Member
I went through the first JS track and I'd definitely recommend it, especially since you're so far along. I haven't tried the new one so I can't compare them.
 
Top Bottom