• 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

usea

Member
I use visual studio with mostly default settings. And Linqpad. Sometimes Notepad++. They all look default and not special at all.
 

Sqorgar

Banned
I think we're technically on Java 7 now, but Java 6 would be a minimum. If you learn from a Java 5 book, you're likely going to be taught a few things that are deprecated in later versions.
Should be fine. Java 6 didn't add any new language features, and most of the new library classes are not important to first time programmers. Java 7 did add some useful stuff (I think collections have been changed), but Java 7 isn't widely used at the moment. It's not even available on OS X.
 

Complex Shadow

Cudi Lame™
Looks like usea has it covered for the most part, but I'm curious about an aspect of your program. How large is the binary string you're getting? Will it always be "small" values like 1010? Or are we talking binary strings that might get into the hundreds. Remember, integers can only hold so many bits...

For example, the decimal bit representation of the relatively small string :"I need help Gaf!" far eclipses the maximum size an Integer or even a Long can hold.

If you want to handle potentially large inputs, you can utilize the BigInteger class. This can handle - let's just say - very large number values.
So this will work not only for the small values, but also the large ones if your program is allowing the possibility of that. Downside is that of course BigIntegers are a bit more memory hungry than your normal primitive value. Of course, you can institute size checks on your input before you do any converting to see if you'll need an Integer, Long, or BigInteger, and then program accordingly.
no its not that big, i ve limited the values to <31. all my program does is takes a string of binary numbers and converts it. its just a small little program with a gui, that only accepts 0's and 1's
Please don't take this the wrong way, I'm genuinely trying to help
Have you tried googling your problem?
When you're asking for help with some code, you have to post the code. Nobody can see it otherwise.
I want to help you, but you have made it very difficult.
Spelling is important when you're programming. Details are important.
If you don't want to figure out anything, you just want to "get it working" without caring, why should other people care to help when you don't? Care about what you're doing. Pay attention. Read error messages. Read the code. Read examples online. Google your problem. Make an effort.
Again, not trying to be rude or offend you. I am just trying to help.
its not as if i don't care, its just that i can take care of spelling and spacing at the end. yes i know i have spelling errors. i know that because i can't spell. that doesn't make me lazy. and yes i have googled and the most common response i get is use a NumberFormatException try and catch handler , google is a mixed bag of advise at times. i am sorry i made it so difficult, i didn't mean for it to be.
if you still wanna see the code, here it is.
Code:
                 String old = tField.getText();  	           	
             	 Integer val = Integer.valueOf(old, 2);
                 String temp = new String();
                                          if(oct.isSelected()){
						temp = Integer.toString(val,8); //oct
						flag = 1;
					   }             
...etc (same if statement different radix values)
 tField.setText(temp);
 

usea

Member
no its not that big, i ve limited the values to <31. all my program does is takes a string of binary numbers and converts it. its just a small little program with a gui, that only accepts 0's and 1's

its not as if i don't care, its just that i can take care of spelling and spacing at the end. yes i know i have spelling errors. i know that because i can't spell. that doesn't make me lazy. and yes i have googled and the most common response i get is use a NumberFormatException try and catch handler , google is a mixed bag of advise at times. i am sorry i made it so difficult, i didn't mean for it to be.
if you still wanna see the code, here it is.
Code:
                 String old = tField.getText();  	           	
             	 Integer val = Integer.valueOf(old, 2);
                 String temp = new String();
                                          if(oct.isSelected()){
						temp = Integer.toString(val,8); //oct
						flag = 1;
					   }             
...etc
 tField.setText(temp);
Sorry. I didn't mean to sound harsh.

Did you get it working? The code looks reasonable to me.
 

Aeris130

Member
What are the exact values of old, val and temp when the exception is thrown?

If nothing else, use toOctalString(val) instead.
 

Aeris130

Member
So Integer.toString(21, 8) (exactly this) throws an exception? Because it doesn't for me. Does the exception printout say anything useful?

The following code runs ok for me. Try pasting it and see if you still get an error.

Code:
String bin = "10101";
Integer i = Integer.valueOf(bin, 2);
System.out.println(i);
System.out.println(Integer.toString(i, 8));
System.out.println(Integer.toString(i, 16));

/* Output: 21
25
15 */
 

usea

Member
what ever the last converted value was. so lets say 10101 -> (dec) 21 ->(hex) error
This is almost certainly incorrect. Have you actually looked at the values, or are you just guessing? Print them out after each line to be sure. Or step through with a debugger.

Which line does the NumberFormatException happen on? The one with Integer.toString()? This is all vital information to help you. You didn't even say what the error was until a minute ago. How can somebody help you if you don't say what the problem is??

If you really want this problem solved. Paste your code (all of it) in a pastebin. Also post the error message in its entirety. Why you would withhold this information is mind boggling.

I just ran this code:
Code:
String old = "10101";  	           	
Integer val = Integer.valueOf(old, 2);
String temp = Integer.toString(val,16);
System.out.println(old + ", " + val + ", " + temp);
And it prints "10101, 21, 15"


If you put a newline character at the end of the string (or anything else that isnt a number), the "Integer val = Integer.valueOf(old, 2)" line will throw a NumberFormatException. Are you CERTAIN that the conversion to decimal is working correctly? Are you SURE the error is when converting to hex? Have you actually checked?

edit: to be more clear: replace this line
String old = tField.getText();
with this line:
String old = "10101";

And your program will probably work (except ignore what's in the text field). I'm betting the field is giving you some extra character(s) such as new lines or something. Either that or you're typing something other than 0s and 1s.
 

Complex Shadow

Cudi Lame™
edit: to be more clear: replace this line
String old = tField.getText();
with this line:
String old = "10101";

And your program will probably work (except ignore what's in the text field). I'm betting the field is giving you some extra character(s) such as new lines or something. Either that or you're typing something other than 0s and 1s.
it's fine. I hav no problem showig you my code. If you wanna see it, I'll paste bin it when I get home. Don't worry about it though. I'll just take care of this in class tomrrow.

Also I think you toke my example too literally. I ment to say that the user inputs a binary string which gets converted to w/e, let's say hex. The problem is that the hex value is sent to the text field and when I press enter, to convert from one value to another (not binary) , again it takes the converted value from the text field and gives an error.
 

usea

Member
it's fine. I hav no problem showig you my code. If you wanna see it, I'll paste bin it when I get home. Don't worry about it though. I'll just take care of this in class tomrrow.

Also I think you toke my example too literally. I ment to say that the user inputs a binary string which gets converted to w/e, let's say hex. The problem is that the hex value is sent to the text field and when I press enter, to convert from one value to another (not binary) , again it takes the converted value from the text field and gives an error.
Ah I see. Well if you get stuck let us know. Don't mind helping at all. It's a nice break from work, and I haven't done java in ~2 years.
 

Complex Shadow

Cudi Lame™
Ah I see. Well if you get stuck let us know. Don't mind helping at all. It's a nice break from work, and I haven't done java in ~2 years.
Will do. Worst comes to worst, I'll store the binary string in a pravite var which stored in the main. untill the user clears it.
 

usea

Member
Same here.

Anyone here thinking of writing anything for the Windows 8 Store ? Had this pop up on my Facebook wall today (Windows 8: Applications for the UK Windows Store)and thought about giving it a shot. Still got no idea what to go for but I'm sure I can think of something.
No. Fuck the windows 8 store.

edit: unless I need to for work. But that's not likely.


Oh, and because I mentioned it above Linqpad is one of the best pieces of software I've ever bought (well, company bought it for me). It's great not just for database queries but also as a little C# environment when you want to test something really quickly. Like "will a task continuation get called if it's added to the task after it runs to completion?"
Code:
var t = Task.Factory.StartNew(() => "inside task".Dump());
Thread.Sleep(1000);
t.Status.Dump("status after sleep");
t.ContinueWith((x) => "new continuation".Dump());
Boom. Answer: yes

I've also written larger programs with it, probably when I shouldn't have. Anyway, I highly recommend it for anybody who does C# for work. The free version is a lot less valuable though (no intellisense).
 

GaimeGuy

Volunteer Deputy Campaign Director, Obama for America '16
So, gaf, I'm a software engineer that regularly works with C++. a friend of mine (Electrical Engineer) asked me to help debug this C++ code his little brother (Also a friend of mine, and he's currently studying Computer Science) wrote... I'm a little embarrassed to say that I don't see the issue, but I think this is one of those gotchas involving initialization lists. The code compiles properly but, when executed, it cores when attempting to execute the highlighted line (Illegal Instruction) and I can't for the life of me explain why, or how to fix the issue.

I've only included the relevant portions of his code (First a shortened class outline of the Table and Entry classes, and the constructors and relevant fields).

Code:
class Table {
  public:
    Table(Model& X, Converter& Y);
    Model& getModel();
    Converter& getConverter();
  private:
    vector<Entry*> entries;
    Model& m_Model;
    Converter& m_Converter;
};



class Entry {
  public:
    Entry(value_t entryValue, Table& table);
  private:
    Value m_Value;
    Table& m_Table;
    Model& m_Model;
    Converter& m_Converter;
};


Table::Table(Model& X, Converter& Y)
 : m_Model(X),
   m_Converter(Y)
{
  entries.push_back(new Entry(FIRST_VALUE, *this));
  entries.push_back(new Entry(SECOND_VALUE, *this));
  entries.push_back(new Entry(THIRD_VALUE, *this));
  .
  .
  .
}

Entry::Entry(value_t entryValue, Table& table)
  : m_Value(entryValue),
    m_Table(table),
    m_Model(m_Table.getModel()),
    m_Converter(m_Table.getConverter())
{
  // empty constructor
}

Anyone spot the problem? I've forgotten quite a bit about initialization lists, and the fact that the issue pops up on the second entry rather than the first seems REALLY odd.
 
Same here.

Anyone here thinking of writing anything for the Windows 8 Store ? Had this pop up on my Facebook wall today (Windows 8: Applications for the UK Windows Store)and thought about giving it a shot. Still got no idea what to go for but I'm sure I can think of something.

Dont know a class mate scored a lumia 800 with writing 3 shitty apps.
2 where homework assignment he ported and on was a game(Gamer.nl)site news feed app.

So i said when the next microsoft developers convention is back in town im scoring some new hardware.
 
Laying out HTML/CSS for printing in IE8 is the most infuriating web development thing I've ever done. It's just broken, period.

Speaking of printing, why the hell doesn't CSS let you use @media inside CSS selectors?

e.g:
Code:
#Header {
 position: fixed; height: 32px;
 @media print { 
   display: none; 
 }
}

99% of the time your print styles are going to augment your main styles, so there really should be a good way to keep the styles together. CSS sucks so god damn much.
 

Lathentar

Looking for Pants
So, gaf, I'm a software engineer that regularly works with C++. a friend of mine (Electrical Engineer) asked me to help debug this C++ code his little brother (Also a friend of mine, and he's currently studying Computer Science) wrote... I'm a little embarrassed to say that I don't see the issue, but I think this is one of those gotchas involving initialization lists. The code compiles properly but, when executed, it cores when attempting to execute the highlighted line (Illegal Instruction) and I can't for the life of me explain why, or how to fix the issue.

I've only included the relevant portions of his code (First a shortened class outline of the Table and Entry classes, and the constructors and relevant fields).

Code:
class Table {
  public:
    Table(Model& X, Converter& Y);
    Model& getModel();
    Converter& getConverter();
  private:
    vector<Entry*> entries;
    Model& m_Model;
    Converter& m_Converter;
};



class Entry {
  public:
    Entry(value_t entryValue, Table& table);
  private:
    Value m_Value;
    Table& m_Table;
    Model& m_Model;
    Converter& m_Converter;
};


Table::Table(Model& X, Converter& Y)
 : m_Model(X),
   m_Converter(Y)
{
  entries.push_back(new Entry(FIRST_VALUE, *this));
  entries.push_back(new Entry(SECOND_VALUE, *this));
  entries.push_back(new Entry(THIRD_VALUE, *this));
  .
  .
  .
}

Entry::Entry(value_t entryValue, Table& table)
  : m_Value(entryValue),
    m_Table(table),
    m_Model(m_Table.getModel()),
    m_Converter(m_Table.getConverter())
{
  // empty constructor
}

Anyone spot the problem? I've forgotten quite a bit about initialization lists, and the fact that the issue pops up on the second entry rather than the first seems REALLY odd.

Is getModel returning a non-const reference to model? (Note: Yes it is). Whatever he's doing this is a really odd way to do it. So many references.

In the constructor for Entry, it's wise to not use member variables in the initializer list. While the standard says members are initialized in the order they are defined in the class definition it is not something I would rely on. Use table.getModel() and table.getConverter() or just hold onto the table and use the functions when needed in the future.
 

MJLord

Member
Well the other night I decided I was going to make a proper attempt at nailing down OO techniques for C++. So I tried to do some Polymorphism and I can't seem to get my method to Override in my "child" class. It's probably just a small syntactical problem but any help is great !

Main :
Code:
#include"Boss.h"

void main()
{
	int stop = 0;
	Enemy enemy[10];

	cout << "Chapter one : Inheritance and Polymorphism\n\n";

	//initialise the enemy array with both Enemy AND Boss
	for(int i = 0; i < 3; i++)
	{
		enemy[i] = Enemy();
	}

	for(int i = 4; i < 7; i++)
	{
		enemy[i] = Boss();
	}

	for(int i = 8; i < 10; i++)
	{
		enemy[i] = Enemy();
	}


	//call the Array and print out its entityAI method

	for(int i = 0; i < 10; i++)
	{
		enemy[i].entityAI();
	}


	cin >> stop;



}

Enemy:
Code:
#include <Windows.h>
#include <iostream>
#include <sstream>
#include <fstream>

using namespace std;

class Enemy
{
private:

protected:
	int health;

public:
	Enemy();
	virtual void entityAI();

};
Code:
#include "Enemy.h"

Enemy::Enemy()
{
	health = 0;
}

void Enemy::entityAI()
{
	cout << "I am an enemy, ";
}

Boss:
Code:
#include "Enemy.h"

class Boss : public Enemy
{
private:

protected:

public:
	Boss();
	void entityAI();

};
Code:
#include "Boss.h"

Boss::Boss()
{
	health = 0;
}
void Boss::entityAI()
{
	Enemy::entityAI();

	cout << "but I am a boss !\n";
}
 

Lathentar

Looking for Pants
Well the other night I decided I was going to make a proper attempt at nailing down OO techniques for C++. So I tried to do some Polymorphism and I can't seem to get my method to Override in my "child" class. It's probably just a small syntactical problem but any help is great !

Main :
Code:
CODE

You need an array of pointers or references. There is no vtable look up with a value type.
 

Slavik81

Member
So, gaf, I'm a software engineer that regularly works with C++. a friend of mine (Electrical Engineer) asked me to help debug this C++ code his little brother (Also a friend of mine, and he's currently studying Computer Science) wrote... I'm a little embarrassed to say that I don't see the issue, but I think this is one of those gotchas involving initialization lists. The code compiles properly but, when executed, it cores when attempting to execute the highlighted line (Illegal Instruction) and I can't for the life of me explain why, or how to fix the issue.

I've only included the relevant portions of his code (First a shortened class outline of the Table and Entry classes, and the constructors and relevant fields).

// code

Anyone spot the problem? I've forgotten quite a bit about initialization lists, and the fact that the issue pops up on the second entry rather than the first seems REALLY odd.

I'm pretty sure you removed the problem when you simplified it. Were there any virtual calls? Also, if he isn't doing it already, he should be compiling with -wAll and -Werror (or equivalent). Lathentar's worries about initialization list order can be caught by the compiler, so there's no reason to avoid depending on it.
 

GaimeGuy

Volunteer Deputy Campaign Director, Obama for America '16
It seems he was not recompiling all libraries that included the Entry and Table headers (Entry used to take in the entry value and model/converter references as parameters for the constructor), no table reference. the table used to just pass in the references directly but I guess he decided ot limit the # of parameters or something.

I think that the table was dynamically allocated by a parent object.
The modified size of the Entry class (its size was increased by the size of the Table reference) became a problem during dynamic memory allocation of the entries because the vector.push_back(new Entry) was allocating space for the new Entry on the vector, but the parent class of the table thought that the second Entry was infringing on the tail-end of the first Entry's memory space.

Or something like that.

It was an illegal operation so you'd have to analyze the assembly code to figure out exactly what was going wrong, and I don't think either of us feel like doing that.


TLDR version: Code worked fine, idiot didn't recompile everything, which resulted in runtime dynamic memory conflicts between linked objects expecting different sizes.
 

Lathentar

Looking for Pants
I'm pretty sure you removed the problem when you simplified it. Were there any virtual calls? Also, if he isn't doing it already, he should be compiling with -wAll and -Werror (or equivalent). Lathentar's worries about initialization list order can be caught by the compiler, so there's no reason to avoid depending on it.
I'm pretty sure a lot of compilers won't warn about the initialization list order. I just like to be cautious when coding.
 

XiaNaphryz

LATIN, MATRIPEDICABUS, DO YOU SPEAK IT
For those who care, we released the first public beta of OpenEXR 2.0 recently:

http://www.openexr.com/

June 18, 2012 - We're pleased to announce the first public Beta release of OpenEXR v2.

Development of OpenEXR v2 has been undertaken in a collaborative environment (cf. previous github announcement) comprised of Industrial Light and Magic, Weta Digital as well as a number of other contributors.

Some of the new features included in the Beta.1 release of OpenEXR v2 are:

* Deep Data. Pixels can now store a variable length list of samples. The main rationale behind deep-images is to have multiple values at different depths for each pixel. OpenEXR v2 supports both hard surface and volumetric representation requirements for deep compositing workflows.

* Multi-part image files. With OpenEXR v2, files can now contain a number of separate, but related, images in one file. Access to any part is independent of the others; in particular, no access of data need take place for unrequested parts.

In addition, OpenEXR v2 also contains platform independent mechanisms for handling co-existing library version conflicts in the same process space. (Currently implemented in IlmImf)

Finally, a reminder that this is a Beta release and potentially incompatible changes may be introduced in future releases prior to the v2.0.0 production version.

OpenEXR v2Beta.1 can be found at: https://github.com/openexr/openexr/tree/v2_beta.1
 

RustyO

Member
I'm working on a little personal project that requires some C++ coding, and getting through it, but I think where I am up to now is beyond my current capabilites, so thought I'd ask for some help as I'm trying to figure out the maths, and how to apply this in C++

Scenario:

- I have two parameters stored as integers, 'CX' and 'CY'
- I have an incoming value, 'CZ', that can be between 0 and 127

Requirement:

If I have CX = 0, CY = 127 (or ignore them) then CZ affects the whole range, which is perfect.

What I want is to be able to set CX and CY to some other arbitary values and then interpolate (?) the value of CZ between them, to calculate an output value, for example:

If CX = 5, CY = 7 and CZ = 0 then result = 5
If CX = 5, CY = 7 and CZ = 20 then result = 5
If CX = 5, CY = 7 and CZ = 40 then result = 5
If CX = 5, CY = 7 and CZ = 60 then result = 6
If CX = 5, CY = 7 and CZ = 80 then result = 6
If CX = 5, CY = 7 and CZ = 100 then result = 7
If CX = 5, CY = 7 and CZ = 127 then result = 7

If CX = 40, CY = 60 and CZ = 0 then result = 40
If CX = 40, CY = 60 and CZ = 20 then result = 43
If CX = 40, CY = 60 and CZ = 40 then result = 46
If CX = 40, CY = 60 and CZ = 60 then result = 50
If CX = 40, CY = 60 and CZ = 80 then result = 53
If CX = 40, CY = 60 and CZ = 100 then result = 56
If CX = 40, CY = 60 and CZ = 127 then result = 60

However I want to be able to do this on the fly, rather then having an array, and the result needs to be rounded to 0 decimal places.

Yeah, I'm struggling a bit... any help would be appreciated.
 

usea

Member
first make a double or float that is CZ / 128.
float percentage = (float)CZ / 128.0;

Then get the range of CX to CY (I'm assuming CX will always be less than CY. otherwise figure out which is smaller first).
int range = CY - CX;

Then multiply difference times percentage, and add that to CX (or CY if it's smaller).
float interpolation = CX + (difference * percentage);

Code:
int interpolate(int cx, int cy, int cz)
{
  float percent = (float)cz / 128.0f;
  int range = cy - cx;
  float interpolation = cx + (range * percent);
  return floor(interpolation + 0.5f); //this rounds. is the 'f' necessary? I don't really know c++
}

The reason for all this is because your CZ is the amount you want to interpolate by right? So if it's 64 you want 50% between CX and CY. How do you make 64 = 50%, 128 = 100%, 0 = 0% ? You just divide CZ by 128.

Now that you have the percent, how do you apply it? 50% should be half-way between CX and CY. How do you get 15 from 10, 20 and 0.5? It's half of the distance between the two, or in other words half the difference. So you need the difference (CY - CX). Now just apply the 0.5 to the difference and add it back in.
 

RustyO

Member
@usea Wow, thats awesome. Thank you very much. Will try it tomorrow and let you know how I go.

I'll drop this into my code, and hopefully it will solve that riddle, the output (CZ) just needs to be rounded to zero decimal places.

Thanks again.
 

Slavik81

Member
first make a double or float that is CZ / 128.
float percentage = (float)CZ / 128.0;

Then get the range of CX to CY (I'm assuming CX will always be less than CY. otherwise figure out which is smaller first).
int range = CY - CX;

Then multiply difference times percentage, and add that to CX (or CY if it's smaller).
float interpolation = CX + (difference * percentage);

Code:
int interpolate(int cx, int cy, int cz)
{
  float percent = (float)cz / 128.0f;
  int range = cy - cx;
  float interpolation = cx + (range * percent);
  return floor(interpolation + 0.5f); //this rounds. is the 'f' necessary? I don't really know c++
}

The reason for all this is because your CZ is the amount you want to interpolate by right? So if it's 64 you want 50% between CX and CY. How do you make 64 = 50%, 128 = 100%, 0 = 0% ? You just divide CZ by 128.

Now that you have the percent, how do you apply it? 50% should be half-way between CX and CY. How do you get 15 from 10, 20 and 0.5? It's half of the distance between the two, or in other words half the difference. So you need the difference (CY - CX). Now just apply the 0.5 to the difference and add it back in.

The f is not necessary, but it ensures the multiplication is done with single-precision floating point values, rather than double precision floating point values. Though in general I'd use double precision for everything unless you have a specific reason not to. Also, depending on your compiler and settings, the implicit conversion from float to int in 'return floor' may cause a warning for loss of precision.

It's also worth mentioning that your rounding method, floor(value + 0.5f), will round -0.5f to 0.0. This means that interpolate(10,20,96)=18 and interpolate(-10,-20,96)=-17. It's not immediately clear to me from the original question if or how negative numbers should be handled.

EDIT: Actually, there's another thing. The Rusty0 specified cz should be 0-127. The first line should be float percent = cz / 127.0f; Otherwise interpolate(0,300,127)=298. This is why we write tests.
 

amrihua

Member
Many unsettling things have popped up when coding for the Intel MIC (now named Xeon Phi). One of them is my code runs 50x slower (compared to quad core Xeon)!! Not too bad, actually gives me a chance to optimize and parallelize my code. A 3x speed up would be huge, not as fast as Xeon but I'm working on a prototype board, the production Xeon Phi should be faster. It is just that Intel wasn't being completely honest when it came to how much effort is required to get performance out of the many integrated cores architecture.
The other unsettling thing was ICC, compared to GCC, is very strict. Gives me errors where GCC would consider the code to be valid. So at home I compile with GCC then at the lab I compile again and modify it to make it legal for ICC. Apparently defining pi as
Code:
double pi = 4.0*atan(1);
Makes ICC very very sad.

Also in the end I might end up learning my (most?) hated language, because things I might need are only implemented in it. My goal for the moment is to avoid that as much as possible, stick to C and focus on Cilk, MPI and OpenMP.
 

RustyO

Member
It's also worth mentioning that your rounding method, floor(value + 0.5f), will round -0.5f to 0.0. This means that interpolate(10,20,96)=18 and interpolate(-10,-20,96)=-17. It's not immediately clear to me from the original question if or how negative numbers should be handled.

EDIT: Actually, there's another thing. The Rusty0 specified cz should be 0-127. The first line should be float percent = cz / 127.0f; Otherwise interpolate(0,300,127)=298. This is why we write tests.

Sorry, I should have clarified that. It should always be absolute numbers, whether floor or ceil is ok. The standard utilised does not cater for precision at all, hence the whole number.

CX may be greater then CY, or CY greater then CX, but can easily have an if statement to factor that in, but they will always be absolutes.
 
I think this is the best thread to ask: I am nearing my graduation here in Germany. One year to go. Now I am trying to figure out what I should study. I am between three subjects: Math, Physic or computer science. I prefer computer science because it looks interesting and contains math. But the problem is, I never programmed. I do not know a computer language. That's the reason why I want to start learning one. But at the end, there are tons of books, websites etc. and the reviews of the books do say some confusing things (like this book is perfect for starters, next review: This book is definitely not for starters etc.)

So with which language should I start? Which websites or books can you guys recommend?
 

Gaspode_T

Member
I think this is the best thread to ask: I am nearing my graduation here in Germany. One year to go. Now I am trying to figure out what I should study. I am between three subjects: Math, Physic or computer science. I prefer computer science because it looks interesting and contains math. But the problem is, I never programmed. I do not know a computer language. That's the reason why I want to start learning one. But at the end, there are tons of books, websites etc. and the reviews of the books do say some confusing things (like this book is perfect for starters, next review: This book is definitely not for starters etc.)

So with which language should I start? Which websites or books can you guys recommend?

I am assuming you mean you are graduating from equivalent of high school and want to decide what to study in college?

Most people are not sure about this even to the moment they graudate university, my advice is:

  • Try writing a game, if you cannot finish it, you might not be good for software engineering (there are a bunch of tutorials online like this one http://create.msdn.com/en-US/education/tutorial/2dgame/getting_started )
  • If you like the application of math and science to real world problem solving, there are so many possible job paths it is insane, so you should find mentors and find out what you are passionate about
  • Computer science is not all about math - well, if you stay in academics it might be...but you need some amount of langauge writing and creation ability to be good at doing stuff with your computer science knowledge...do you like to write? does staring at words for hundreds of hours sound boring to you?
 

raphier

Banned
Is there any way use variable as type?

I have this calculation which depends on the variable type and I want to make it simpler than using IF-statements.

example:

int Type = Green;

int Green = Green_Rating(3);
int Blue = Blue_Rating(1)
int Red = Red_Rating(1);

The calculation is 1+8*Type; // Here it uses Green's integer value for the result.

But the problem is that I also want it to behave differently in an IF-statement,

if (Type == Blue), should not compare the integers, but compare whether Type variable is Blue or not.
 

Aeris130

Member
Is there any way use variable as type?

I have this calculation which depends on the variable type and I want to make it simpler than using IF-statements.

example:

int Type = Green;

int Green = Green_Rating(3);
int Blue = Blue_Rating(1)
int Red = Red_Rating(1);

The calculation is 1+8*Type; // Here it uses Green's integer value for the result.

But the problem is that I also want it to behave differently in an IF-statement,

if (Type == Blue), should not compare the integers, but compare whether Type variable is Blue or not.

What language is this?

"Type" is an int, so it shouldn't matter what type of variable gave it its int value. As long as Type=Green is a valid assignment, Type "forgets" where it got its value from once the assignment is complete. Also, "Blue" is not a variable of type "Blue", but a variable of type "int". The fact that it's called "Blue" shouldn't matter, what if you change the name later on?
 

Slavik81

Member
But the problem is, I never programmed. I do not know a computer language.
That's not neccessarily a problem. It helps to have a bit of foreknowledge, but they will teach you everything even if you don't.

So with which language should I start? Which websites or books can you guys recommend?
I've been seeing python being recommended more and more as a first language. Learn Python the Hard Way is supposedly a good guide and is free.
 
I am assuming you mean you are graduating from equivalent of high school and want to decide what to study in college?

Most people are not sure about this even to the moment they graudate university, my advice is:

  • Try writing a game, if you cannot finish it, you might not be good for software engineering (there are a bunch of tutorials online like this one http://create.msdn.com/en-US/education/tutorial/2dgame/getting_started )
  • If you like the application of math and science to real world problem solving, there are so many possible job paths it is insane, so you should find mentors and find out what you are passionate about
  • Computer science is not all about math - well, if you stay in academics it might be...but you need some amount of langauge writing and creation ability to be good at doing stuff with your computer science knowledge...do you like to write? does staring at words for hundreds of hours sound boring to you?
The question I tried to ask was: How to start learning a computer language. I know that it is not going to be all about math. I like love Math. But I cannot imagine to get into the whole academic level. I want to do something creative combined with Math. That's the reason Computer Science sounds interesting for me and why I want to try it out. But at the end, there are so many ways to start. Too many for me that I got confused. I do not know where I should. Should I buy this book? Should I try out this webpage? Personally the best thing is I should make a short trip to the University and ask about the program.

On the other hand I have the interest to program an App for a year already. I always wanted to start. So I am thanking for your link because it looks like I will learn some small bits of CL and can continue afterwards.(If I succeed)
 

xptoxyz

Member
Anyone familiar with SQL (working with Oracle), any easy way to drop all tables in a DB/user, regardless of constraints. It would help testing some scripts...
 

usea

Member
EDIT: Actually, there's another thing. The Rusty0 specified cz should be 0-127. The first line should be float percent = cz / 127.0f; Otherwise interpolate(0,300,127)=298. This is why we write tests.
Ah you're right, totally missed that. Thanks.
 

Kalnos

Banned
Anyone familiar with SQL (working with Oracle), any easy way to drop all tables in a DB/user, regardless of constraints. It would help testing some scripts...

Why can't you just drop the database?

I don't have time to try it right now but I'm guessing you're going to use a cursor to loop through and drop all the constraints and then use another cursor and drop all the tables.
 

raphier

Banned
What language is this?

"Type" is an int, so it shouldn't matter what type of variable gave it its int value. As long as Type=Green is a valid assignment, Type "forgets" where it got its value from once the assignment is complete. Also, "Blue" is not a variable of type "Blue", but a variable of type "int". The fact that it's called "Blue" shouldn't matter, what if you change the name later on?

C. Type is a name of the variable. The idea is that Blue is constant. I guess the better example of what I am trying to do is, yeah it's actually really similar to that.

Think I have a pokemon of grass type against a pokemon of water type. I want to compare their types AND use the same variable to calculate bonus damage(int).

I can come up with a large chunk of code to get the result, but I'm challenging myself to find most simplest possible solution to this and now I can't get it out of my head.
 

Slavik81

Member
C. Type is a name of the variable. The idea is that Blue is constant. I guess the better example of what I am trying to do is, yeah it's actually really similar to that.

Think I have a pokemon of grass type against a pokemon of water type. I want to compare their types AND use the same variable to calculate bonus damage(int).

I can come up with a large chunk of code to get the result, but I'm challenging myself to find most simplest possible solution to this and now I can't get it out of my head.

That's not the simplest solution. That's a confusing solution. Don't make your variables mean two things.

It would be much simpler to have a bonus damage lookup table that could take a pair of types and give you back the bonus damage.
 
Top Bottom