• 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
Oh wow, dat massive post :) Thanks! That should help a lot I think, yeah. I'm actually studying game design at the university but this is the first course in two years (and it's voluntary, sort of) where I'm completely on my own with doing a whole game and not small prototypes. I'm using intersect and globalbounds in sfml to detect collision between bullets and enemies and that works fine (just need to insert the explosion for a few frames somehow but that's a minor detail). No reason why the same shouldn't work between enemy bullets and the player. I should be able to use something similar to that I suppose for moving the ship outside the screen? :) My resolution is 800*600 and the ship's origin is at the sprite center of a 32*32 (I think) sprite so I suppose I gotta remove half of that to compensate. Wouldn't want half the ship sticking out :D
 

Kinitari

Black Canada Mafia
Fuck you random. Fuck you SO hard. Spent an hour of my time not understanding why the class I was instantiating a bunch of times in a single loop wasn't acting right - at one point I eventually realized that was because the random values (within a range) that it was supposed to be assigning to a lot of variables just repeated for every single object.

Then I found out that random seeds off the clock, so if all 30 of my loops happened at the exact same time (is it the same millisecond?) they all get the same 'random' variables.

FUCK YOUR SHIT RANDOM, HOW IS THAT RANDOM!?

Fixed it by making random static, but still.
 

SRG01

Member
Fuck you random. Fuck you SO hard. Spent an hour of my time not understanding why the class I was instantiating a bunch of times in a single loop wasn't acting right - at one point I eventually realized that was because the random values (within a range) that it was supposed to be assigning to a lot of variables just repeated for every single object.

Then I found out that random seeds off the clock, so if all 30 of my loops happened at the exact same time (is it the same millisecond?) they all get the same 'random' variables.

FUCK YOUR SHIT RANDOM, HOW IS THAT RANDOM!?

Fixed it by making random static, but still.

The best way you can fix this is to seed the random number generator each time you use it.

There are also different RNGs out there, outside of the one that's readily available.
 

DTKT

Member
So, newbie batch question. I'm trying to automate some simple tasks and I'm looking into some pointers.

It's pretty basic, I need to start the Microsoft SDK console, change the active directory to C:\ and type xbmovie/something:something [name of the video].wmv

Here is what I have so far:

@echo off
rem videoName would just be holding the name of the video. I would add the .wmv within the command itself.
set /P videoName="Name for the video?"
rem That would start the
start "SDKCONSOLE.bat"

Now, can I directly pass a parameter when I start the XDK console? Can I also change the directory to C:\ at the same time.
 

wolfmat

Confirmed Asshole
at one point I eventually realized that was because the random values (within a range) that it was supposed to be assigning to a lot of variables just repeated for every single object.

Then I found out that random seeds off the clock, so if all 30 of my loops happened at the exact same time (is it the same millisecond?) they all get the same 'random' variables.
Write 30 random ints into an array at the start. Get one random every top iteration. XOR the random individually with an int in the array for each loop.
 

Slavik81

Member
Fuck you random. Fuck you SO hard. Spent an hour of my time not understanding why the class I was instantiating a bunch of times in a single loop wasn't acting right - at one point I eventually realized that was because the random values (within a range) that it was supposed to be assigning to a lot of variables just repeated for every single object.

Then I found out that random seeds off the clock, so if all 30 of my loops happened at the exact same time (is it the same millisecond?) they all get the same 'random' variables.

FUCK YOUR SHIT RANDOM, HOW IS THAT RANDOM!?

Fixed it by making random static, but still.

Could you tell me what language you're using, so I can be sure never to use it? Seeding an RNG automatically (let alone repeatedly) would be a fundamental design flaw in my books.
 

Kinitari

Black Canada Mafia
Could you tell me what language you're using, so I can be sure never to use it? Seeding an RNG automatically (let alone repeatedly) would be a fundamental design flaw in my books.

It's C#. It was pretty simple to work around. I just made the RNG static. I think the main problem is that I had the RNG inside the class that I was instantiating on a loop.
 

usea

Member
It's C#. It was pretty simple to work around. I just made the RNG static. I think the main problem is that I had the RNG inside the class that I was instantiating on a loop.
Yeah you should instantiate Random only once. Making it static will work, but it'd be even better if your class took an instance of Random as a parameter in its constructor.
 

methane47

Member
Ok i have a question.

I want to write a simple application.
The job of this application will be to create a document tracking of a list of items.

But I'm wondering what language i should write the application in.
The software should be able to talk to an mssql or equivalent database.
The application should handle multiple concurrent users and should be able to handle an item database of 100,000 unique entries.

And the mostt important thing. I want to build in a dynamic lookup system.
Where you can have a list of database items and as you type into a text box immediately the list of entries gets filtered to match the string.

So in a list containing
wood
jacket
tire
golf
game

if I typed "re"
it should automatically filter the list instantly to just
tire

Any advice on a language that could do this?
 

Kalnos

Banned
@methan47... what are the platform requirements? Just Windows, or do you need Linux and OSX as well?

It would be pretty easy to do in C# or VB.NET using this for MySql. You can follow this really basic article to set it up. Then you can follow any .NET sqlconnection tutorial and replace anything that says 'sqlconnection' or 'sqlcommand' and make it 'mysqlconnection' or 'mysqlcommand' and etc.

WinForms would supply your textbox and there are tons of ways you could choose to display the data.

If you use C# it's possible all of your code could run easily on Linux/OSX using Mono.
 

wolfmat

Confirmed Asshole
Ok i have a question.

I want to write a simple application.
The job of this application will be to create a document tracking of a list of items.

But I'm wondering what language i should write the application in.
The software should be able to talk to an mssql or equivalent database.
The application should handle multiple concurrent users and should be able to handle an item database of 100,000 unique entries.

And the mostt important thing. I want to build in a dynamic lookup system.
Where you can have a list of database items and as you type into a text box immediately the list of entries gets filtered to match the string.

So in a list containing
wood
jacket
tire
golf
game

if I typed "re"
it should automatically filter the list instantly to just
tire

Any advice on a language that could do this?
Usually, deciding which language should be used needs more details to be absolutely sure the choice can be made properly.

But from what you're saying, my hunch is that the application should be webbased, and it should be programmed in Ruby on Rails.

The search feature you're describing is a bit uncomfortable. In pseudocode, it's basically this (provided you have the list of all items ready):
Code:
List search(String query){
   matches = new List
   foreach item in item_list {
      if item.name.substring(query) {
         matches.append(item)
      }
   return matches
}

So you can immediately see the problem. Since the algorithm has to go through all items linearly, you cannot take any smart shortcuts, like hash-based lookups and the like. That may or may not be an issue down the line, both in terms of processing time required for this, and in terms of RAM used.
You could cut down on the demands by only starting to search if there are more than 3 characters, and using other tricks. Whatever reduces lookup time.
One thing you could do is carrying a table (or view, for that matter) in which it is denoted which names do NOT have which letter. So you have a column for not_A, and not_A holds wood, tire and golf in your example.
Maybe there's a module out there that does tricks like that well; you might want to try and find one instead of cooking that mess up on your own.
 

Kalnos

Banned
Usually, deciding which language should be used needs more details to be absolutely sure the choice can be made properly.

But from what you're saying, my hunch is that the application should be webbased, and it should be programmed in Ruby on Rails.

This is true, I just saw 'application' and assumed he meant non-web but it very well could be.
 

MJLord

Member
hey guys I've been trying to use templates in C++ but I'm not having much luck.
Code:
#include <iostream>

template <class T>
class List {

private:
	struct treeNode{
		T data;
		treeNode *left;
		treeNode *right;
	};

	treeNode root;

public:

	List(T rootData);
	treeNode* Traverse();
	treeNode* makeNode(T data);
};

This is it, but when I include it into an empty .cpp it tells me that there is no definition for List.
 

injurai

Banned
I am currently learning C++ on an Ubuntu partition, but say I wanted to use that code in windows what sorts of things would I have to do? Recompile it with a windows compiler and make a windows executable? Or is it more intensive to port basic code. I'm not talking about code that implements any sort of os specific APIs, just what the language itself provides capabilities for.
 
I am currently learning C++ on an Ubuntu partition, but say I wanted to use that code in windows what sorts of things would I have to do? Recompile it with a windows compiler and make a windows executable? Or is it more intensive to port basic code. I'm not talking about code that implements any sort of os specific APIs, just what the language itself provides capabilities for.

Avoid any posix and gui stuff, and it's extremely easy to port.
 

Randdalf

Member
Are you defining all of its member functions inline? It's pretty much required for templates.

Yeah, I found that out as well, ran into the same problem. You have to define the member functions in the header file, I assume the way I've been doing it is good enough, for example...

Code:
template <class T>
class Rocket
{
public:
    Rocket();
    void launch(int fuel);
}

template <class T>
Rocket<T>::Rocket()
{
    //...
}

template <class T>
void Rocket<T>::launch(int fuel)
{
    //...
}
 

injurai

Banned
Fuck you random. Fuck you SO hard. Spent an hour of my time not understanding why the class I was instantiating a bunch of times in a single loop wasn't acting right - at one point I eventually realized that was because the random values (within a range) that it was supposed to be assigning to a lot of variables just repeated for every single object.

Then I found out that random seeds off the clock, so if all 30 of my loops happened at the exact same time (is it the same millisecond?) they all get the same 'random' variables.

FUCK YOUR SHIT RANDOM, HOW IS THAT RANDOM!?

Fixed it by making random static, but still.

lol, I believe new intel processors now seed off of some unpredictable entropy source located on the cpu. yeah random is a bitch.
 

BHZ Mayor

Member
My current real experience with development is mainly with data and reporting. Just mostly simple forms with simple code (if/case statements, loops, connection strings, code to save/edit/delete data, basic exception handling, etc.). But because of the relative simplicity of these applications, I feel like I've been pretty much frauding it up, so I'd like to know, besides gaming, what type of development is out there that gets into the more complex aspects of programming?
 

Lathentar

Looking for Pants
My current real experience with development is mainly with data and reporting. Just mostly simple forms with simple code (if/case statements, loops, connection strings, code to save/edit/delete data, basic exception handling, etc.). But because of the relative simplicity of these applications, I feel like I've been pretty much frauding it up, so I'd like to know, besides gaming, what type of development is out there that gets into the more complex aspects of programming?

Depends what you consider complex. Simulation/Data crunching gets complex very quickly. Most things can get very complex with the appropriate constraints.
 
My current real experience with development is mainly with data and reporting. Just mostly simple forms with simple code (if/case statements, loops, connection strings, code to save/edit/delete data, basic exception handling, etc.). But because of the relative simplicity of these applications, I feel like I've been pretty much frauding it up, so I'd like to know, besides gaming, what type of development is out there that gets into the more complex aspects of programming?

Security, scientific modeling, o/s dev. That's about it. Most jobs are pretty simplistic and even the more complex stuff gets real easy real fast after some years of experience.

My previous position at my current employer routinely required me to recreate the data layout of raw binary storage files as wekk as routinely break encryption on credit cards to migrate client data. Before that, I worked at another company where I occasionally had to reverse engineer programs that had their source code lost.
 

BHZ Mayor

Member
It also probably doesn't help that with Windows Forms applications, Visual Studio and the .NET Framework does a good chunk of the legwork for you, increasing the fraudulence. :(
 

Mondriaan

Member
You could cut down on the demands by only starting to search if there are more than 3 characters, and using other tricks. Whatever reduces lookup time.
One thing you could do is carrying a table (or view, for that matter) in which it is denoted which names do NOT have which letter. So you have a column for not_A, and not_A holds wood, tire and golf in your example.
Maybe there's a module out there that does tricks like that well; you might want to try and find one instead of cooking that mess up on your own.
I think the general way that this would be handled would be to create an index/mapping of character sequences to a list of words (This will probably be implemented as two tables in a database). Once you've returned that list to the browser (probably via AJAX), the client can handle the filtering of the list as the number of possibilities is pared down.

Each word would end up adding n-1 index entries (in your first table) where n is the number of characters in that word.

The size of the list might reach a point where it becomes unwieldy so you might want to stick some sort of usage counter on that second table and return a set number of the most popular words and re-executing the query to return new suggestions instead of doing the filtering within the client.
 
Working on learning hashing, and found a link to using std::map, as what I'm working on deals with strings (and appears to be an efficient way of handling them). I want to use a string, then attach a name and number to the initial string, as well as having the ability to expand as needed. and I'm having trouble wrapping my head around doing so.

Code:
string1| -> name1(->number) -> name2(->number)...->nameN(->number)
string2| -> name1(->number) -> name2(->number)...->nameN(->number)
.
.
.
stringN| -> name1(->number) -> name2(->number)...->nameN(->number)

I've worked with using:

Code:
std::map <string> List

and then using a for loop to enter each key into it. I just want to be able to attach a name and number to each like in the above example, and I know I need to set it as a linked list, but I am real lost on how to implement this.

Suggestions?
 
So I'm going to be learning C++ in September, but I have no idea what it is. And the results from Google are confusing me.

Can someone please enlighten me?
 

tmdorsey

Member
Subscribed.

In my job I do web development(basic HTML, JavaScript), a little VB/.net stuff for custom module development for some of our applications, and recently have been getting into Powershell(which I love). I also do some report writing so I have fair knowledge of SQL. I've recently been tasked with learning Ruby on Rails and I'm in the process of going through the RubyonRails tutorial book. I'm liking what I've seen so far including going for using an IDE(VS) to a text based editor in Sublime Text 2. I'm going to check out some the links in the OP to help me really get accumulated to this new framework.

What are the general thoughts here on Ruby on Rails?
 

jvalioli

Member
So I'm going to be learning C++ in September, but I have no idea what it is. And the results from Google are confusing me.

Can someone please enlighten me?

Are you learning it in class? Don't worry about it; your teacher will teach it to you. You won't be the only one in class that doesn't know C++.
 

Godslay

Banned
So I'm going to be learning C++ in September, but I have no idea what it is. And the results from Google are confusing me.

Can someone please enlighten me?

Intermediate level programming language.

Intermediate means basically that it isn't as low level as something like assembly language, but not as high level as something like C# or Java.

Basically the idea that is mostly used is that the computer hardware is referred to as the "metal". The lower the level programming language, the closer you are to the "metal". While this gives a person plenty of control and performance, it comes with the cost of complexity and tedious programming, in order to do simple things.

The higher the level programming language, the easier it is to do tasks. Languages such as C++ for instance are considerably more readable to humans than say assembly. The downfall for this ease of readability and use is that a programmer does not have absolute control and loses some performance. Certain functions might be automated (such as garbage collection in C# or Java), and can cause performance set backs.

C++ for instance strikes a nice balance, hence the intermediate name. You still have plenty of control (such as memory allocation and deallocation), which allows for better performance than higher level languages typically. At the same time it is high level enough to be readable and introduce constructs such as objects, inheritance, polymorphism, as well as others.

I hope I wasn't too off base with this answer. I wrote it assuming that you don't have any programming background.
 

Kalnos

Banned
Are you learning it in class? Don't worry about it; your teacher will teach it to you. You won't be the only one in class that doesn't know C++.

Eh, I'd still recommend learning on your own. It's a field where you learn by being proactive and doing projects. I found that the intro classes at my school weren't very helpful to people who didn't have previous knowledge of basic concepts.

Curious, why are you taking a C++ class jonny? Is it a part of your major or was it something you were simply interested in? You might have more luck looking up what a programming language is before looking up C++ in particular.
 

partime

Member
This thread is great, I'm starting mobile development from Full Sail University this month. With no prior knowledge of programming, I'll be in over my head without preparation.
 

jvalioli

Member
Eh, I'd still recommend learning on your own. It's a field where you learn by being proactive and doing projects. I found that the intro classes at my school weren't very helpful to people who didn't have previous knowledge of basic concepts.

Curious, why are you taking a C++ class jonny? Is it a part of your major or was it something you were simply interested in? You might have more luck looking up what a programming language is before looking up C++ in particular.

If it is an intro class, it is his professors job to teach the material (well). I think if googling C++ is causing him trouble then he probably doesn't learn very well by reading and probably learns better verbally and by example which is what his class is for. I think he should wait for class to begin before completely stressing out about it.
 

dabig2

Member
Working on learning hashing, and found a link to using std::map, as what I'm working on deals with strings (and appears to be an efficient way of handling them). I want to use a string, then attach a name and number to the initial string, as well as having the ability to expand as needed. and I'm having trouble wrapping my head around doing so.

Code:
string1| -> name1(->number) -> name2(->number)...->nameN(->number)
string2| -> name1(->number) -> name2(->number)...->nameN(->number)
.
.
.
stringN| -> name1(->number) -> name2(->number)...->nameN(->number)

I've worked with using:

Code:
std::map <string> List

and then using a for loop to enter each key into it. I just want to be able to attach a name and number to each like in the above example, and I know I need to set it as a linked list, but I am real lost on how to implement this.

Suggestions?

Like you said, sounds like you'll be using a linked list as your value. Try something like this:

Code:
//define linked list
struct Node {
  string name;
  string number;
  Node *next;
};

//define your map
map<string, Node*> List;

//and here's an example of populating your map (with a starting entry)
Node* root = new Node;
root->name = "John Q.";
root->number = "555-5555";
root->next = and so on and so on....

//now place the key,value pair into the map 
List["yourKey"] = root;

//and you loop and access data of the map like so...
for( map<string, Node*>::iterator ii=List.begin(); ii!=List.end(); ++ii)
   {
       cout << ii->first << ": " << ii->second->name << ii->second->number <<endl;
   }

That's basically how it will work. So every string key of your map will possess a struct containing the name, number, and the next struct of data in memory (a.k.a linked list).

But be careful. This isn't the most elegant solution, so if you have a large amount of data to put into this map, this will eat up memory like a mofo.
 
Like you said, sounds like you'll be using a linked list as your value. Try something like this:

Code:
//define linked list
struct Node {
  string name;
  string number;
  Node *next;
};

//define your map
map<string, Node*> List;

//and here's an example of populating your map (with a starting entry)
Node* root = new Node;
root->name = "John Q.";
root->number = "555-5555";
root->next = and so on and so on....

//now place the key,value pair into the map 
List["yourKey"] = root;

//and you loop and access data of the map like so...
for( map<string, Node*>::iterator ii=List.begin(); ii!=List.end(); ++ii)
   {
       cout << ii->first << ": " << ii->second->name << ii->second->number <<endl;
   }

That's basically how it will work. So every string key of your map will possess a struct containing the name, number, and the next struct of data in memory (a.k.a linked list).

But be careful. This isn't the most elegant solution, so if you have a large amount of data to put into this map, this will eat up memory like a mofo.

Shit dude. You rock.

And I don't think it'll get too much data. It's for my mom's business, so we're not talking about thousands upon thousands of names and numbers. I'm really using this as A) a way to help her, and B) a way for me to expand some knowledge before the fall semester begins.
 
Eh, I'd still recommend learning on your own. It's a field where you learn by being proactive and doing projects. I found that the intro classes at my school weren't very helpful to people who didn't have previous knowledge of basic concepts.

Curious, why are you taking a C++ class jonny? Is it a part of your major or was it something you were simply interested in? You might have more luck looking up what a programming language is before looking up C++ in particular.

It's a required course for Engineering. I have no choice over what I take.

What type of program should I buy/download to let me program with C++?
 
Always get the highest version possible!

Express is the true free version though.

Of these, which is the highest version?
Microsoft Visual Studio 2010 Premium
Microsoft Visual Studio 2010 Ultimate
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Visualization & Modeling Feature Pack
Microsoft Visual Studio 2010 Express
Microsoft Visual Studio 2010 Remote Debugger
Microsoft Visual Studio Team Foundation Server 2010
Microsoft Visual Studio 2010 Feature Pack 2
Microsoft Visual Studio Team Explorer Everywhere 2010
Microsoft Visual Studio 2010 Professional Caption Language Interface Pack
 
Top Bottom