PDA

View Full Version : ProgrammersitP



Pages : [1] 2

Miscast_Mage
2012-09-05, 08:21 AM
So, I was wondering if there was anyone involved or wanting to get into programming in the playground, and just had a few questions:


Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?



For myself:

Doing a 8-ish month course on java at the moment, and I've done a year of computer applications before.

Java is pretty much my bread and butter at the moment, but I have some skill with html(yes I know it's not a programming language. Hush.:smallredface:) and I've been peeking into in C and C++ lately.

Hoping to get a full time job as a fully certified programmer, though methinks that's a while off.

Apart from the odd random idea such a coin counter or dice game in java, I've been seeing about doing something in Danmakufu, like this, (http://www.youtube.com/watch?v=Q-7Xe-nQehA) though I'm still quite a novice that regard. I'm also hoping to eventually develop a small roguelike game, though the notion of it rather terrifies me.:smalleek:

I started with compiling and running on the command line on linux, and I'll die with the command line, though I'm trying to get used to Netbeans at the moment.

I'm having a rather annoying problem with Java; for most of my old code from college, I had used the console commands to read in strings/ints/etc from the user on the command line. I've only recently started coding again, but for the life of me I can't find out how to set up or import the console util, or the graphics util for some of my other code for that matter; this is regardless of whether I use command line, Eclipse or Netbeans. Any help would be much appreciated.



So yeah, any programmers in the playground? If so, speak up.:smallbiggrin:

Oh, and I may randomly post interesting bits of code, if people need them, or if there's something about them bugging me; things like this:



//Works as planned when tested, values come out
//correctly. Originally thought a while loop was
//needed, but realised that wouldn't be the case when
//using the / and % arithmetic operators. Works for
//values above 99, just giving out more 50's. Unsure
//if a restriction is needed on the money entered,
//but an if statement could be used.

public class Change //
{
public static void main(String[] a) //main class
{
System.out.println("Enter amount of cents: "); //gets user to input amount of money in cents
int centsx = Console.readInt(); //code to translate 1 euro = 100 cent could also be used

int cents50 = (centsx / 50);
//First line finds the value to print out. Eg, if 99 cent, this will print 1.
int cents50Remain = (centsx % 50);
//Second line finds the remainder to send to the next line. Eg if 99 cent, this will divide by 50,
//and send remainder(49) to next line of code.

int cents20 = (cents50Remain / 20);
//Uses the remainder from the above line to repeat the First line for the 20cent value.
int cents20Remain = (cents50Remain % 20);

int cents10 = (cents20Remain / 10);
int cents10Remain = (cents20Remain % 10);

int cents5 = (cents10Remain / 5);
int cents5Remain = (cents10Remain % 5);

int cents2 = (cents5Remain / 2);
int cents2Remain = (cents5Remain % 2);

int cents1 = (cents2Remain / 1);
int cents1Remain = (cents2Remain % 1);

System.out.println("50: " + cents50); //These print out of the number of each coin that was calculate
System.out.println("20: " + cents20);
System.out.println("10: " + cents10);
System.out.println("5: " + cents5);
System.out.println("2: " + cents2);
System.out.println("1: " + cents1);
//More organised when grouped together, as opposed to
//int cents50 = (centsx / 50);
//int cents50Remain = (centsx % 50);
//System.out.println("50: " + cents50);

//A while or for loop may be possible to use here with a break; command. Will have to try out.
}

}

Tyndmyr
2012-09-05, 09:19 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time? It's my job, has been for, oh, eight years or so now. Went to college a bit for it, could use some more certifications and stuff.

What language or languages are you using primarily at the moment? What's your favourite, and why? For work? Java. At home, I use C#. Don't really have a favorite per se, just different things I prefer in different situations.

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along? Getting back into java webapp/web service coding...probably going to pick up one of these attribution based frameworks.

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on? I have roughly a million unfinished projects at the moment, but right now, my focus is on 3d modeling/printing, so coding projects are being mostly ignored.

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor? Eclipse/Visual Studio. Nothing terribly creative, I'm afraid, but it makes it super easy to swap workstations. That said, I am terribly fond of TortoiseSVN.

Razanir
2012-09-05, 09:23 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
Odd tasks in my free time

What language or languages are you using primarily at the moment? What's your favourite, and why?
I primarily use Java, but also know some C++ and Python

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
Nothing in particular yet

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?
I was programming a Chrome extension, but they won't accept Java applets. Anyone want to help convert it to JavaScript?

What environment do you work/prefer to work in? BlueJ or a command line

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?
Like I said before- Chrome doesn't allow Java applets in extensions

Knight13
2012-09-05, 09:27 AM
•Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
Got my BS in Comp Sci and I've been working for a company as a programmer for 3 years now.


•What language or languages are you using primarily at the moment? What's your favourite, and why?
In high school and college I mostly used Java, along with a sprinkling of other languages. At my current job, my primary language is C#, along with some ASP.Net (I primarily work with web pages) and I've recently been getting into javascript. I also work with SQL databases. My favorite language right now is C#, it's like Java except it's even easier to get it to do what you want.


•Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
I've been looking for a new job lately, since this one doesn't pay enough. I'm also looking to move away from web-based stuff. I would like to work for a game company eventually, but that's kind of a vague goal at this point.


•What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?
I use Visual Studio at this job, though I used to use Eclipse back in high school and college.

Whoracle
2012-09-05, 09:32 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?




Mostly spare time, a little bit due to employment.


Primarily I use python and bash, and I know my way around the following, at least a little bit:
PHP, HTML, CSS (yeah, I know. Shush.), C, C++, JS, Java, D, perl, lua, C#, LotusScript and BASIC.
Python's my favourite, since it's great for rapid prototyping and easily readable. Granted, its performance isn't too great, but for quick demonstrations it's great. Also, the various toolkit bindings are good.


I'm quite content with where I am, to be honest. With the current trend of "everything must run in a browser" and such, I'm not too sure if I like where programming is going. Oh, the days where you at least tried to code clean and elegant, and didn't just steamroll code problems with MOAR CYCLES and MOAR RAM!


I've got two projects:
A procedural 3D-Landscape engine (I blame Shamus Young (http://www.shamusyoung.com/twentysidedtale) for that.
And a 2D action adventure engine/editor/framework a la Secret Of Mana.
Both get the occasional big push, when I manage to get some consecutive free time, but nothing I follow with any determination.


Under Windows: Notepad++.
Under Linux: vim/urxvt and sometimes geany. Simple, clean and powerful. Just as I like it.


Trying to understand computing surface normals. I've seen many implementations of it, and shoved some of them right into my codebase. I think I managed to understand the underlying principle. But I just can't get it right.
Threading in Python. Most of the times it works, but time and again I've run into snags that _should_ have worked...

Teddy
2012-09-05, 11:24 AM
So, since I seriously don't feel like doing a list...

I'm currently working toward a master in Information Technology (I've just begun my second year out of five), and so far, I've learned programming in SML and MIPS assembly, and we've just recently begun with C. Later this school year, we'll be getting into Java as well, but I already know a fairly decent amount of that since earlier, and I use it whenever I've got a hobby project to work on.

My goals for the future are mostly learning as much as possible (going strong so far), and then getting a job somewhere. I don't really care much about where I end up for as long as the tasks provide me a suitable challenge, but I suppose a good salary would be nice as well. I'm currently working on a computer game as well, and I aim to finish that one in a few years. I'm not sure about making my career in the gaming industry, but I can kind of see myself as a part-time indie game developer if things work out well in that direction. Then again, my primary goal on that front is to get anything done at all, so any eventual delusion of grandeur can wait until then. :smallwink:

When it comes to programming, I've used all manners of environments, mostly depending on what language I'm working in at the moment. During school, I mostly use Emacs, which I find just as infuriating as it's helpful. At home, I'm using DrJava, which is what I started learning Java in, and I haven't bothered with an upgrade.

My biggest problem with programming isn't anything code-related per se, but rather my inability to figure out how to go about making my game. I do have achieved some progress, and I still am, but it's going terribly slow, just because I can't figure out from which direction I should attack it.

Miklus
2012-09-05, 05:58 PM
[QUOTE=Miscast_Mage;13845328]

Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?

[QUOTE]

I'm a pro, in that they pay me to do it.

C/C++ because that that the codebase is in.

Plans for the future...oh gods, my career...I'm gonna be a programmer forever, ain't I? :smallfrown:

We work in Visual studio.

My fellow programmers drive me nuts. They have egos the size of zeppeliners. But I don't think they are all that. For example, they just recently discovered that their home-made memory management system is f-ed up and have been since day one. It is actually possible for two parts of the program to get their data mixed up! Even worse, they can't fix it because the entire concept don't work. They just did some work-around so that the program deliberately crashes itself if the memory gets screwed up. That way, they avoid a potentially catastrophic data-mix up!

Today the head zeppeliner waddles over to me and accuses me of making dup code (two parts of the program is exactly identical). That is not too bad, it is just redundant. But the part that I had supposedly dupped from somewhere else in the program was actually in a file that I had stolen off the internet and used unchanged. How curious. The only explanation is that the guys I stole from in turn stole their code from the same place that the head zeppelin stole HIS code from.

And so the world goes around.

olelia
2012-09-05, 07:36 PM
So, I was wondering if there was anyone involved or wanting to get into programming in the playground, and just had a few questions:


Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?



For myself:

BS in comp science. Been working at a company for two years now.

My primary programming language is SQL Server and VB.net. I know enough about C# to read it proficiently but wouldn't trust myself to code in it.

I'm currently happy with my company and they are extremely happy with me. If I got some time of once in a life time opportunity, like a job at a gaming company, I'd grab it...otherwise I don't current have plans to leave.

My current big project is designing a report that heavily utilizes dynamic components in its variables...but the trick is it isn't using dynamic sql...just overly complicated filters and selections.

Visual Studio is my favorite but thats mostly because I'm lazy :smallbiggrin:

Currently my main problem includes our IT department. My job requires nearly unlimited access to work efficiently...but...they like to hedge me out as much as possible since i'm not One of them

RunicLGB
2012-09-05, 07:48 PM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?





I'm in Las Vegas, and currently going to CSN to learn programming.

Taking classes in both C and Visual basic right now.

The Dream is to somehow become involved with Video Game Development, thats what I've wanted to do since I was like 9 years old. If that (in all likleyhood) doesn't pan out, its a good thing I just enjoy programming for its own sake.

Not really.

Couldn't say, I don't really have enough experience to know what you're talking about. :smallbiggrin:

Not at this time, but I hope this thread could become a new and valuable resource for expert advice and communal learning.

Emmerask
2012-09-05, 08:29 PM
So, I was wondering if there was anyone involved or wanting to get into programming in the playground, and just had a few questions:


Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?



Mostly freelancing for various companies, the biggest organization I´ve worked for so far would be the who.

Primarily Java, Ruby, php.

What I really would like to do would be e-sport related stuff or game design (not the coding part^^), but having a job that pays pretty well is enough atm.

I started and semi completed a d&d java tool that functions both for editing a map and playing on it, atm though I have not enough time to do anything with it.

For java I have tried pretty much anything from netbeans to eclipse but the single most awesome ide is IntelliJ, I cannot recommend it enough for any java projects!

Miscast_Mage
2012-09-06, 05:21 AM
My, quite a bunch of programmers we've got.:smallbiggrin:

So, platform-wise for java, there does seem to be quite a lot. So far we've got:

Eclipse
Netbeans
Intellij
BlueJ
Visual studio, possibly?(Not sure if you can compile/run java with it.:smallconfused:)
And obviously the command line and a text editor. =3


Do anything of them have any particular features that the others lack? Anything that says "Use me! Use me!" over the other options?

And just a personal question here; do any of them handle console commands or importing the console class? All of my old code uses the console class for inputting data from the command line in linux, but trying to recompile or rerun them now, I constantly get a "class cannot be found" error. It's probably a case of not importing or setting up the class right, but it's still causing me a bit of grief. In class at the mo, so I'll see about getting the specific error when I get home tonight if anyone thinks they can help.

I've been meaning to look into getting started with databases(with java), and I've seen a few different choices; HSQLDB, Java DB, JDBC... What would be best suited for someone who hasn't touched databases before? Any good tutorials or information about them? The only thing I've found(and have yet to look at) is Manga Guide to Databases. (http://nostarch.com/mg_databases.htm)

shawnhcorey
2012-09-06, 08:28 AM
Yeah, I program computers. I don't do Windows¹. I usually do web development on Linux servers.

¹ Programming in Windows is like trying to run a marathon while pulling a bus in an ice storm.

Dusk Eclipse
2012-09-06, 09:01 AM
I might as well ask here, I am having trouble with a loop for my programming course at University.

The program is supposed to help teachers capture Students data for the course, the data that is needed to capture is:
Name, carreer, term and register number.

Right now I only have to make the pseudocode and a flow chart diagram.
Now my problem is that the number of students per course is variable and I have to make an input for the number of students. I thought a while loop (While X <=number of students per course, capture data); but I don't see how I can make it so the program automatically declare different variables based on the number of students input.

Am I making sense?

Miscast_Mage
2012-09-06, 09:28 AM
Wel'p, I'm an idiot. I figured out what I was doing wrong with trying to get the console class to work in Netbeans;
I had the console.java file in the project that I wanted to use it in, but it turns out I didn't have the package name in the console file, and it wasn't recognising it.
It works perfectly with the package name added in, but I didn't realise this; the progress bar just said "running", so I assumed it was looking for the class and it couldn't be found. Turns out, it was waiting for input, and now I feel silly.:smallredface:



I might as well ask here, I am having trouble with a loop for my programming course at University.

The program is supposed to help teachers capture Students data for the course, the data that is needed to capture is:
Name, carreer, term and register number.

Right now I only have to make the pseudocode and a flow chart diagram.
Now my problem is that the number of students per course is variable and I have to make an input for the number of students. I thought a while loop (While X <=number of students per course, capture data); but I don't see how I can make it so the program automatically declare different variables based on the number of students input.

Am I making sense?

First off, what language are you using? I only really know about java, so my suggestions are coming from there, primarily.

Also, I'm not quite sure what you mean by
declare different variables based on the number of students input. I'm assuming you mean take in different variables for each "student", right?

My first guess would be using a constructor called getStudent



class Student
{
String forename;
String surname;
String career;
int term;
int registerNumber;



void getStudent() //class constructor. Takes in these parameters.
{
forename = Console.readToken();
surname = Console.readToken();
career = Console.readString();
term = Console.readInt();
registerNumber = Console.readInt();
}
}


Here's a sample code of something I did, that sounds a bit similar to what you want:




class Person2
{
String forename;
String surname;
char gender;
int age;

void getPerson()
{
forename = Console.readToken();
surname = Console.readToken();
gender = Console.readChar();
age = Console.readInt();
}

void putPerson()
{
System.out.println(forename + ", " + surname + " " + gender + " " + age);
}

boolean isYoungMale()
{
if(gender == 'm' && age >= 20 && age <= 30)
return true;
else
return false;
}

boolean isYoungFemale()
{
if(gender == 'f' && age >= 18 && age <= 28)
return true;
else
return false;
}

boolean isEligible()
{
if(isYoungMale() || isYoungFemale())
return true;
else
return false;
}

public static void main (String [] args)
{
int num = 0;
while(!Console.endOfFile())
{
Person test = new Person();
test.getPerson();
test.putPerson();
if(test.isEligible())
num++;

}
System.out.println("number of eligibles: " + num);
}
};

Basically, what it is does is, is read in from a file(using the command line), constructs a constructor/pseudo-method(is object also correct terminology for this?:smallconfused:) called getStudent from the information taken in, tests these objects against a few boolean methods, and if they're eligible, a number is added to a counter, which is printed at the end.


Hope that any of that was of help, Dusk Eclipse.:smallwink:

Edit: Ah, sorry, I missed something in what you said. How are you inputting the actual student information? If it's from a file, you could use while(!Console.endOfFile) like I did in my example, if you have the console class. There should be something similar if you don't, though I wouldn't know what it is, sadly.:smallfrown:

Dusk Eclipse
2012-09-06, 09:38 AM
First of all thanks.

Right now I am not using a set language, just pseudo-code and Raptor (which from what I understand is an Flow Chart Interpreter), though I think we will start with Java or C++ after we finish this project.

What I need, is say the user declares that there are 5 students in the course, now my loop should well loop 5 times. In each loop it should ask for Name, Register number and career. My problem is that I don't know how to make that within that loop, the name, career and register number is set to a different variable each time (so on the first loop name, career and register number would be n1, c1, rn1 and on the second would be n2, c2, rn2, and so on) without me having to write and arbitrary number.

Does that makes more sense?

shawnhcorey
2012-09-06, 09:59 AM
I might as well ask here, I am having trouble with a loop for my programming course at University.

The program is supposed to help teachers capture Students data for the course, the data that is needed to capture is:
Name, carreer, term and register number.

Right now I only have to make the pseudocode and a flow chart diagram.
Now my problem is that the number of students per course is variable and I have to make an input for the number of students. I thought a while loop (While X <=number of students per course, capture data); but I don't see how I can make it so the program automatically declare different variables based on the number of students input.

Am I making sense?

Kind of.

If you're using a modern scripting language like Perl or Python, they have built-in auto-expanding arrays that can be easily used for this type of operation.

However, just loading the data into memory seldom serves any useful purpose. What do you intend to do with this data?

Miklus
2012-09-06, 10:57 AM
First of all thanks.

Right now I am not using a set language, just pseudo-code and Raptor (which from what I understand is an Flow Chart Interpreter), though I think we will start with Java or C++ after we finish this project.

What I need, is say the user declares that there are 5 students in the course, now my loop should well loop 5 times. In each loop it should ask for Name, Register number and career. My problem is that I don't know how to make that within that loop, the name, career and register number is set to a different variable each time (so on the first loop name, career and register number would be n1, c1, rn1 and on the second would be n2, c2, rn2, and so on) without me having to write and arbitrary number.

Does that makes more sense?

Looks like you need to build a list? You make a struct with one students data (like that class miscast mage did) and inside the loop you allocate one of these structs per student. A list seems to be the way to go when the number of students is variable. Or you could use an array if you make sure it is long enough. But with variable amount of data, the array is either too big or not big enough. The beauty of a list is that you need not keep a variable for how many students there are, you can just count the number of elements in the list.

1) Promt user for student data
2) Put data into student data struct
3) Hitch data struct to end of list
4) Repeat until user gets bored with this

So you don't need to promt the user for how many students there are beforehand.

Anyway, we had this big audit yesterday. One customer, how is, like, the world fifth largest medico company decide to audit your software quality insurance systems. So they send these two external consultents. Much hilarity ensued.

Consultant: "Where are the program files stored?"
Boss: "Here, on the development server."
Consultant: "...uhm, why is the servers electronics showing?"
Boss: "It's just the cover that has been taken off. So it gets more air."

Dusk Eclipse
2012-09-06, 11:36 AM
Kind of.

If you're using a modern scripting language like Perl or Python, they have built-in auto-expanding arrays that can be easily used for this type of operation.

However, just loading the data into memory seldom serves any useful purpose. What do you intend to do with this data?

With the data I have gathered in the first part of the project I have to run some calculation (average grade, highest grade, lowest grade and the like); but right now I only need to be able to run this loop.


Looks like you need to build a list? You make a struct with one students data (like that class miscast mage did) and inside the loop you allocate one of these structs per student. A list seems to be the way to go when the number of students is variable. Or you could use an array if you make sure it is long enough. But with variable amount of data, the array is either too big or not big enough. The beauty of a list is that you need not keep a variable for how many students there are, you can just count the number of elements in the list.

1) Promt user for student data
2) Put data into student data struct
3) Hitch data struct to end of list
4) Repeat until user gets bored with this

So you don't need to promt the user for how many students there are beforehand.

Anyway, we had this big audit yesterday. One customer, how is, like, the world fifth largest medico company decide to audit your software quality insurance systems. So they send these two external consultents. Much hilarity ensued.

Consultant: "Where are the program files stored?"
Boss: "Here, on the development server."
Consultant: "...uhm, why is the servers electronics showing?"
Boss: "It's just the cover that has been taken off. So it gets more air."

I really love all the help I am getting; but this is for an Introductory course and I am really rusty on programing, so while I kinda recognize some of the things you are talking me about I don't know how to implement it.

shawnhcorey
2012-09-06, 12:23 PM
With the data I have gathered in the first part of the project I have to run some calculation (average grade, highest grade, lowest grade and the like); but right now I only need to be able to run this loop.

I thought so. You can do this in the input loop. Just store the highest, lowest, running total, count, etc. for each statistic you're interested in. You don't need to store every record. After the loop, calculate and print out the statistics.

Maxios
2012-09-06, 12:25 PM
Do any of you know how to code in the Free!Unreal Engine?

Knight13
2012-09-06, 12:52 PM
Couple question, Dusk Eclipse

First, does the user actually input the number of students that they're requesting data for or do they just go "get me all the students in this class"? If it's the former, you know ahead of time how many rows of student data you're going to be retrieving, so you can just put that input value in an int variable to determine the size of your array (or whatever data structure you're going to be putting this in).

Second, where is this student data you need to retrieve going to be coming from? Are you requesting it from a database or is it just stored in a spreadsheet file or something?


What I need, is say the user declares that there are 5 students in the course, now my loop should well loop 5 times. In each loop it should ask for Name, Register number and career. My problem is that I don't know how to make that within that loop, the name, career and register number is set to a different variable each time (so on the first loop name, career and register number would be n1, c1, rn1 and on the second would be n2, c2, rn2, and so on) without me having to write and arbitrary number.

You don't need to make separate variables for all of this data. From the looks of it, I would say that a 2-dimensional array should work fine. If you're going to be using something like C#, I would even recommend a Datatable.

Dusk Eclipse
2012-09-06, 01:02 PM
Couple question, Dusk Eclipse

First, does the user actually input the number of students that they're requesting data for or do they just go "get me all the students in this class"? If it's the former, you know ahead of time how many rows of student data you're going to be retrieving, so you can just put that input value in an int variable to determine the size of your array (or whatever data structure you're going to be putting this in).

The user has to input everything (that is my main problem)

Second, where is this student data you need to retrieve going to be coming from? Are you requesting it from a database or is it just stored in a spreadsheet file or something?

For the purpose of this project, the data is arbitrary, entirely made up by the user and it won't be stored once the Program ends running..

You don't need to make separate variables for all of this data. From the looks of it, I would say that a 2-dimensional array should work fine. If you're going to be using something like C#, I would even recommend a Datatable.
I can't use arrays, because well I don't know how to program this


Answers in bold.

And it seems I didn't explain my problem properly, first this is not the entire program, just a start and I only need the pseudocode and a flow chart to give in tomorrow to my teacher

Here is what I have already in pseudocode (some parts are in Spanish as I am mexican and the class is in spanish; but it shouldnt affect the read-ability of the "code") and based on this, I have to draw a flow chart.
1 Start
2 Print “Numero de alumnos en el curso”
3 Input nac
4 Print “Nombre del Alumno”
5 Input NombreAlu
6 Print “Introduce Matricula”
7Input Matricula
8 Print “ Introduce Carrera”
8 Input Carrera
9 Print “Semestre Enero-Mayo 2012 (EM) o Semestre Agosto-Diciembre 2012 (AD)”
10 Input sem
11 If Semestre= EM then sem=PrimerSemestre
Else sem=Segundosemestre.
12 Print “Introduce Nombre de Materia 1”
13 Input nm1
14 Print “Introduce Calificación”
15 Input cal1
16 Print “Introduce Nombre de Materia 2”
17 Input nm2
18 Print “Introduce Calificación”
19 Input cal2
20 Print “Introduce Nombre de Materia 3”
21 Input nm3
22 Print “Introduce Calificación”
23 Input cal3
24 Print “Introduce Nombre de Materia 4”
25 Input nm4
26 Print “Introduce Calificación”
27 Input cal4
28 Print “Introduce Nombre de Materia5”
29 Input nm5
30 Print “Introduce Calificación”
31 Input cal5
32 Print “Introduce Nombre de Materia 6”
34 Input nm6
35 Print “Introduce Calificación”
36 Input cal6
37 end

pendell
2012-09-06, 01:06 PM
So, I was wondering if there was anyone involved or wanting to get into programming in the playground, and just had a few questions:


Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

Full time senior software engineer at my company. I report directly to the CTO. While there are other people at my level, none of them have the time in grade I do and they didn't write the fundamental system architecture.



What language or languages are you using primarily at the moment? What's your favourite, and why?


Primarily use Java with a secondary focus on C#. Use Java for J2EE and web application work. It's open source and that is a load off my mind having to keep up with ever changing windows COM/NET/METRO architectures.

C# used for realtime programming of windows phones.

My favorite language is the one that gets the job done. At the moment I would say Java, because it is more object oriented than the C family, but has a ton of useable third party libraries and support. Also , Open Source rules all .



Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?


I've gone pretty much as far as I can go. I'm the senior developer who designs, architects, codes, and tests pretty much everything for a major company. I work independently and command a reasonable salary. There is literally nowhere else for me to go unless I branch out of it to go up the management chain, or start my own business and go into programming for myself. That second is very likely if I need to change jobs and run into age discrimination. At age 41, I should've shot myself years ago from a career perspective.



Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?


Unfortunately, that is company proprietary. Once we publish, I'll be able to talk more about it :).

ETA: I guess I can talk about products and not mention the giant fighting robots super-secret additional projects coming down the pike. I write the software for these systems (http://www.minibar.ch/standard.cfm?ID_n=204&haupt=137&unter=204&language=1). The bars use sensors to detect product sales and communicate these to a database. I write everything on the software end save the firmware in the bars themselves.




What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?


Unix command shell using grep for text search, notepad++ for text editing, and command line compiling/integrating. I started out that way in 1989, and for my purposes Netbeans and Eclipse give me little additional functionality and I get tired of looking at hourglasses while waiting for them to load. I prefer to keep my environment as simple as possible.



Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?


The most serious problem I have is giving the customers on the management side what they *want* , as opposed to what they *asked for*. Non-programmers are quite imprecise in their use of language and make a lot of assumptions which to them are "just common sense". But since I don't know their business I HAVE no common sense. So the biggest challenge for me is the people -- getting everyone to agree on a set goal of what the system should look like. And do so with a minimum of high school drama.

I must emphasize that this is NOT because the non-programmers are stupid or incompetent; they are neither. But we're both rubbing on the edges of those areas we're expert in (they don't know computers, I don't know hotels) and the end result is the sum of our weaknesses. "None of us is as dumb as all of us".

I've seen my share of projects fail. And *every last one* to my memory was because the customer didn't get what they wanted. We may have written the best FPS in the history of gaming, but if what the customer wanted was accounting software, it's a waste of their money. At least until we rebrand and remarket it.

So if you want to succeed as a programmer, the first and most critical skill is people skills. This can be worked around if you have a really good boss (I do) who speaks both customer-talk and geekspeak, but you can't always count on such people being around. In larger companies, more often than not the boss is someone from a non-IT background entirely who's warming the seat because they needed a manager and s/he had the appropriate management credentials. They are out of their depth and muddle along as best they can. If you're smart, you'll help them succeed and make them look good so they can help you, as opposed to griping about them behind their back.

Respectfully,

Brian P.

shawnhcorey
2012-09-06, 01:12 PM
Here is what I have already in pseudocode (some parts are in Spanish as I am mexican and the class is in spanish; but it shouldnt affect the read-ability of the "code") and based on this, I have to draw a flow chart.


Try this:


# Loop to input student records

loop:

print "Enter another record [yN] ? "
input answer
exit loop if answer equal 'y' or 'yes'

create record for student

print "enter the student name "
input name
add name to student record

print "How many grades? "
input grades
add number_of_grades to student record

for 1 to grades
create record for grade

print "Enter subject "
input subject
add subject to grade

print "Enter grade "
input score
add score to grade

add grade to student record

next for

next loop

Dusk Eclipse
2012-09-06, 01:15 PM
Try this:


# Loop to input student records

loop:

print "Enter another record [yN] ? "
input answer
exit loop if answer equal 'y' or 'yes'

create record for student

print "enter the student name "
input name
add name to student record

print "How many grades? "
input grades
add number_of_grades to student record

for 1 to grades
create record for grade

print "Enter subject "
input subject
add subject to grade

print "Enter grade "
input score
add score to grade

add grade to student record

next for

next loop


Wow that is perfect, thanks:smallbiggrin:

Whoracle
2012-09-06, 01:46 PM
So, Dusk, without knowing in which language you're gonna have to code that exercise, it's kinda hard to help you out there. Also, you don't know what an array is or how to use one? In that case, though highly unlikely, have you heard of classes? (Don't laugh, my first programming course at university taught us classes WAY before arrays. Yes, it was a Java course. No, it didn't really teach me anything.)

Either way, in pseudocode, it'd look roughly like this (including commments, code might be a bit pythonesque):

Uncommented blob:


int studentCount
int traitCount

traitCount = readline("Enter amount of different data sets you want to capture: ")
studentCount = readline("Enter student count: ")

string traits[traitCount]
array students[studentCount]

int i
int j

for (i in range(0,studentCount)) {
for (j i range(0,traitCount)) {
traits[j] = readline("Enter value of trait #" + j + ":");
}
students[i] = traits;
}

print(student[1][2])


And now, with comments:


# we need one integer to store our amount of students
int studentCount
# we need one integer to store our amount of traits, so we don't have to
# type a line for each trait later. Might be redundant, but I like to think
# it's more elegant. Correct me, I dare you :)
int traitCount

# here we get user input (the readline part) and store it into the vars
traitCount = readline("Enter amount of different data sets you want to capture: ")
studentCount = readline("Enter student count: ")

# here we declare 2 arrays (denoted by the [] after the var name)
# usually, arrays are declared in the following way:
# data varname[size_of_array]
#
# think of one such array as a key->value pair
#
# we need two since we want to iterate over both the traits and the amount
# of students

# traits is an array of strings, since we'll most likely store strings in them.
# note that this is really broken down to basics, since you'd either use a
# struct in strict type languages, or won't bother declaring datatypes in less
# strict ones.
# So now we have a nice array the size of our traits that we can store data in.
string traits[traitCount]

# next up is something interesting. We want to store our data in distinct
# blobs, so we know each student has exactly n traits. What I do here
# could be seen as a crude implementation of _some_ base traits of classes,
# which is something I won't go into detail here, since you either already
# know this, or won't have a clue, in which case explaining this'd take too
# long
# What we do is create an array that stores arrays and is as big as our
# amount of students.
array students[studentCount]

# Whew. With all that magic done, all that's left is the surprisingly
# straigthforward implementation of the loop:

# we need two counter vars for the loops
int i
int j

# run from 0 to stundentCount, incrementing i with each iteration.
# this means we go through exactly studentCount iterations.
for (i in range(0,studentCount)) {
# run from 0 to traitCount, incrementing j with each iteration
# this means we go through exactly traitCount iterations
for (j i range(0,traitCount)) {
# during each run through the inner loop, which means once per trait,
# ask for user input and store it in traits[j].
# e.g. traits[0] = Anne // trait 1 would be the given name
# traits[1] = Smith // trait 2 would be the surname etc.
traits[j] = readline("Enter value of trait #" + j + ":");
}

# at this point in our loop we have a completely filled traits-array for one
# student, since we went through the whole inner loop before going on
# with that said, all that's left is storing our fresh array in our students array
# for proper usage later.
students[i] = traits;
}

# example code for printing out student1 and his trait 2:
print(student[1][2])

Note that this IS pseudocode and it's viability and simplicity is wildly dependent on the language used.


I can hammer out a python implementation if you like somewhen tomorrow.
Also, bask in the glory that is commented code. You won't be seeing much of that in the wild, unless you manage to get hired by a GOOD company.

Also: It was hard to write, it should be hard to read :smallbiggrin:

Edit: curse you, shawnhcorey! Also, bump so the board acknowledges my post :)

Neftren
2012-09-06, 02:01 PM
So, I was wondering if there was anyone involved or wanting to get into programming in the playground, and just had a few questions:


Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?



Squeee! This looks fun!

I'm moving towards a dual degree in Computer Science and Game Design (and I might add a third in Cognitive Science, just for fun, but we'll see). I primarily program in C/C++, and I do web and game development in Python. I actually hate programming with a burning, fiery passion, but it's a means to where I want to end up, so I'm living with it.

Projects! I'm currently working on a blog platform built on Google App Engine (https://developers.google.com/appengine/). It's basically a WSGI environment with a Google High-Replication Datastore atttached to it instead of using MySQL.

Hmm... favorite development environment... Sublime Text (http://www.sublimetext.com/) reigns supreme methinks, for a Text/Code editor. For more advanced programs, I typically turn to XCode for an IDE, though you'll probably have to A) buy an Apple computer, and B) fiddle with the settings if you want to do any language other than C/C++/Obj. C.


As for things driving me nuts... well, I put together a basic WSGI application on Google's App Engine SDK; it runs excellently on the local (emulated/virtual) development server, but totally flops over when deployed on a live server. The datastores don't seem to interface in exactly the same way... :smallfurious:

Knight13
2012-09-06, 02:11 PM
Oh, okay. So you're just using user-generated input to calculate output. Heh, I'm flashing back to high school. Well, if shawnhcorey's pseudocode is what you need, then great. Let us know if you need help with the actual coding. I still think an array is your best bet, they really aren't complicated to set up and use.

Lensman
2012-09-07, 11:30 AM
So, I was wondering if there was anyone involved or wanting to get into programming in the playground, and just had a few questions:


Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?





Gulp. I feel old.

I started programming on a BBC Microcomputer, in Basic. I wrote programs for fun and as aids for roleplaying. No "environment" - just direct program writing, with line numbers and "RUN" at the command prompt.

Then Windows came along. I got Visual Basic 4 - it was amazing! I could write really sophisticated, impressive-looking programs. I really, really liked VB4. It was simple, the dialect was close enough to my old BBC basic that I could handle it with ease, and it had so much additional material and opportunities.

I never bothered to pay to upgrade to VB6 - my programs worked, and were really quite sophisticated, tying into Access databases for all the material I used for character and creature generators. If it works, why change it?

And then I upgraded my computer. The new machine had 1gb RAM. VB4 said "Hunh? This machine has 0 memory" - and died. It couldn't cope with that much RAM.

I looked to upgrade to a Basic language that worked with modern machines - the only option was VB Studio.

And I really loathe it. No Control Arrays any more. I loved Control Arrays. Why did they scrap them?

And so much extra verbiage and (to me) unnecessary complications. "Namespaces." "(ByVal sender As System.Object, ByVal e As System.EventArgs)". "Imports System.Web.UI". What is all this verbiage FOR? This is no longer Visual Basic - it's Visual Hideously Complicated. It is no longer a language for the amateur programmer doing odd sequences and bits and pieces in his spare time. The error messages alone need a PhD in computer science to understand.

But the three core programs I wrote in VB4 have been, after much heart-ache and effort, updated to work in VBS-2010. I'm too old and have too little spare time to start learning a completely different language. And I need something that will work with databases. So I guess I'm stuck struggling with VBS.

Sorry - reads like I was ranting. Actually, I was. Anyone got an alternative to Visual Studio that a dumb amateur programmer can cope with?

shawnhcorey
2012-09-07, 12:13 PM
Sorry - reads like I was ranting. Actually, I was. Anyone got an alternative to Visual Studio that a dumb amateur programmer can cope with?

Try a modern scripting language: Perl, Python, Ruby, PHP.

Recaiden
2012-09-08, 02:40 PM
Part time work programming for a small company, and studying Computer Science in college.

This has me working with C#, Javascript, and C at school, and C++ at work. But previously there was actionscript and Python to deal with too. Python is easily my favorite. I never have to fight with the language to get things done.

Mainly waiting. I like programming, but not as much as other things. It's just at an intersection of being good, getting me a job and not being disliked.

I had a project to do with music composition, but since going back to school
I haven't been able to work on it. Programming actually depresses me a bit.

I prefer QtCreator, but it's only good for a few types of project. Mainly it's Emacs and the command line.

Reinboom
2012-09-08, 07:06 PM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

I'm a software engineer at a video game company. I'm a college dropout (I went for Animation, anyways :P ), and my spare time programming tends to be focused on game utilities of some sort. I don't do much anymore in terms of self interest programming however.

What language or languages are you using primarily at the moment? What's your favourite, and why?

Primarily I use ActionScript 3 (note: Scaleform, not for Flash games) as of late, and C++ secondarily. Other languages in use: JavaScript (Node.js), Ruby (mostly build scripts), C# (Tools), PHP (Symfony2 small end apps), and quite a few others crop up at times (Erlang, Python, Java, and more).

My favorite language, as a language in of itself, is ActionScript 3. Being able to pass loose Objects around while still having hard types. A syntax that partially self documents. Annotations as a language feature. Interfaces as a language feature. Regular expressions having an in language syntax. External code interface that's simple and to the point. A strong standard library that can keep out of the way when you don't want it. Graphics as an assumption instead of an afterthought.

However, I hate the "standard compiler". Flash as a dependency is annoying. Especially for my work flow (we don't use AS3 for Flash purposes).


Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

My programming work is my living, and my fun. I've already settled on my career, though I might transition slightly away from it in time, depending.


Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

At work: Many. At home: I'm building a JavaScript CAS, but otherwise... nothing.


What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Depends.
ActionScript 3: FlashDevelop (+... Flash Professional for creating timelines / a graphics bucket. :/ )
C++: visual studio + a bunch of other things to make it less visual studio
Everything else: Notepad++ or vim


Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?

Uh... legacy code that's written to be unreadable and not well commented is about all that angers me in coding anymore. That's where the most expensive and annoying tech dept arises.


Edit:
Oh, and floating point errors. Floating point errors are annoying.

Miscast_Mage
2012-09-16, 03:59 AM
So, I've been working on understanding 2D arrays, and in particular higher dimensional arrays, but is there any practical application to higher dimensional arrays(that go beyond 2D/3D)?

Say, with 2D arrays, I could have a list of classrooms that contains students. If I make it a 3D array, I could have a list of schools, which each have a list of classrooms, which each have a list of students. The only problem with that is, is that the classroom/school is only a list, not an object in of itself, so I can't see how you'd apply any data to anything other than the student class.

Would arraylists or collections be better suited for something like this, or something else all together?

Teddy
2012-09-16, 04:29 AM
Depending on your programming language, objects, structs or tuples all provides means of storing information in the intermediate layers of an array.

And yes, multiple dimension arrays quickly lose any rational applicability after the first 2 or 3 dimensions. You can certainly find some use for them, but the 100-dimensional array is probably just built for laughs anyway (and on top of that, it's a terrible memory hog, filling up 4MB worth of memory just with memory adresses (assuming a 32 bit system))

shawnhcorey
2012-09-16, 07:15 AM
Would arraylists or collections be better suited for something like this, or something else all together?

Yes, definitely. The language you're using influences what would be the best solution. Some languages come with an associated list, which makes problems like this easy. What language are you using?

Neftren
2012-09-16, 09:52 AM
So, I've been working on understanding 2D arrays, and in particular higher dimensional arrays, but is there any practical application to higher dimensional arrays(that go beyond 2D/3D)?

Say, with 2D arrays, I could have a list of classrooms that contains students. If I make it a 3D array, I could have a list of schools, which each have a list of classrooms, which each have a list of students. The only problem with that is, is that the classroom/school is only a list, not an object in of itself, so I can't see how you'd apply any data to anything other than the student class.

Would arraylists or collections be better suited for something like this, or something else all together?

As Teddy pointed out, the choice of language heavily influences your data structure. In the case of C/C++, it might make more sense to have a map with key/pair combinations of classrooms and student listings (as opposed to nesting arrays). Also, data doesn't necessarily need to be kept in your own instantiated "objects" or such. You can freely put lists inside vectors, and so on... I'm not quite sure what the Java equivalent is though. I haven't touched it in a few years.

As for answering your question, computation bounds are typically no more than four dimensions (x, y, z, t), at least in a physics or scientific computation sense. For the most part, it might even be just three dimensions (x, y, z) and you iteratively solve the problem by computing the solution at each time step, using the solution from the previous time step (see: difference equations).

pendell
2012-09-16, 10:13 AM
So, I've been working on understanding 2D arrays, and in particular higher dimensional arrays, but is there any practical application to higher dimensional arrays(that go beyond 2D/3D)?

Say, with 2D arrays, I could have a list of classrooms that contains students. If I make it a 3D array, I could have a list of schools, which each have a list of classrooms, which each have a list of students. The only problem with that is, is that the classroom/school is only a list, not an object in of itself, so I can't see how you'd apply any data to anything other than the student class.

Would arraylists or collections be better suited for something like this, or something else all together?

In my experience (18 years of it), I have never needed an array bigger than 2D.

When you're storing a list of schools with classrooms, it's better to delve into object-oriented programming and define a class of schools thus:

Class Student {
Integer id;
String name;
Date dateOfBirth;
// etc.
}

Class Classroom {
Integer roomNumber;
Student[] studentsInClass;
}

Class School {

String schoolName;
Classroom[] classes;
}

Of course, this is a very simple way to do it. If you're working with a data table you might do something like this:

School {
Integer id;
String schoolName;
}

ClassRoom {
Integer id;
Integer schoolId ; // Foreign Key to School-> ID;
}

Student {
Integer id;
Integer[] classIds; // foreign keys to classrooms
Integer schoolId; // foreign key to school.
}


The advantage of an approach like this is you can use it in conjunction with software such as hibernate (http://www.hibernate.org/) to quickly drop it into a mysql database.

SO: Fundamentally I have no need for 3D or 4D arrays. It is almost always better to have a 1D array or list or collection of a data structure such as a pascal record (http://pascal-programming.info/lesson11.php) or a c struct (http://en.wikipedia.org/wiki/Struct_%28C_programming_language%29)

But better than either of those are object-oriented classes such as those defined in python (http://docs.python.org/tutorial/classes.html). Partly because they're more common, but also because they mask a lot of complexity. The ability to attach methods doesn't hurt either.

IME, higher-dimensional arrays are only really necessary if you're running a very high performance application (global climate modeling, say) and you can't afford the overhead of object-oriented programming. But that is quite uncommon.

Respectfully,

Brian P.

nedz
2012-09-16, 10:35 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
I have a BSc in Computer Science and Mathematics.
I'm a free lance software engineer with 26 years of commercial experience, currently between contracts.

What language or languages are you using primarily at the moment? What's your favourite, and why?
I normally write Windows C++, but have done all sorts of things. I managed to pick up some Java and C# experience on my last contract, using Netbeans and Eclipse. I tend to be systems orientated, usually working at the framework level; I'm a pretty experienced assembler programmer for instance.

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
My last two contracts were as a performance analyst/trouble-shooter, which generally seems to imply that the architect screwed up. I might want to do something else next.

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?
I have recently downloaded the Android SDK, but haven't done anything with it yet. I did have an image processing idea, which I ought to do some work on.

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?
I don't like CVS or command line interfaces, but I can use anything.

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?
Resolving this issues is what I get paid for, and thankfully enjoy.:smallcool:

Capt Spanner
2012-09-16, 04:14 PM
I guess I should tip my hand.

Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

I had some modules in computational modelling while doing my physics degree. I then did an MSc. in Game Software Development and now work for Sony Computer Entertainment Europe in the R&D department.

What language or languages are you using primarily at the moment? What's your favourite, and why?

We use C++, with the odd bit of Lua. I've never touched the Lua side. I'm also adept in Python.

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

I'm happy where I am. Working for Sony has a lot of benefits. I may look into getting into an actual game studio later in my career.

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

I recently finished a procedural racetrack creator for TORCS. I'll next be looking to create a racing team manager game, where procedurally generating tracks will be very handy.

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Microsoft Visual Studio is a pretty tight environment. I want to upgrade to VS1012 soon, as it has loads of the C++11 features.

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?

Linker errors. They are always really obscure. I also hate naked pointers.

Balain
2012-09-16, 10:11 PM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?


I have taken some programming courses in the past. Used some of it in my last job. Now that I am unemployed I have decided to go back to university and get a Computer Science degree.


What language or languages are you using primarily at the moment? What's your favourite, and why?

At work I had written some programms in Awk, C, and C++. The courses in the past we studied c, I studied some C++ on my own. My current cpsc course we are using python, my next cpsc course we will use java (created at my University no less :) ) Don't have vast experience with many languages yet. So far I guiess c/c++ is my favorite since I know it the best so far. Python does have some cool features though.



Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?


Graduate with a Bsc in Computer science in 3 to 4 years. Then either get back out there looking for work or think about getting a masters.



Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?


Nothing except school assignments right now.



What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?


Well I use to own the old Borland c++ 4.5, I have tried both eclipse ond code blocks. Currently I just type in pico.



Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?


Not right now years ago in one of my first programming courses there was this one assignment I just couldn't get to run. I tried and tried but nada. I asked the instructor just to give me a zero (lowest mark on assignments was dropped) he said he couldn't do that till I handed in a working copy of the program. I got fed up and just asked another student if I could look at his code (this is like 3 months past it's deadline)

Thajocoth
2012-09-19, 04:33 PM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
-I'm a full time employee in the video game industry.
What language or languages are you using primarily at the moment? What's your favourite, and why?
-I'm using C. My favorite is C++ with a C leaning.
Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
-I've fulfilled all my goals... I need to come up with new ones.
Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?
-Yes. I'm in the middle of several professional projects.
What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?
-Microsoft Visual Studio
Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?
-The code base I'm in is kinda old, so there's code here & there that's not written well, or is confusing, but nothing seems to be in my way. The most annoying thing for me, honestly, is that I had gotten used to '}' causing automatic indentation of the block I'm closing, and Microsoft Visual Studio only has this option for C#, not for C.

Capt Spanner
2012-09-19, 04:40 PM
Sorry - reads like I was ranting. Actually, I was. Anyone got an alternative to Visual Studio that a dumb amateur programmer can cope with?

Visual Studio can really help you programming. It's actually quite easy to use - just write the code and press the green button.

It can ever create boilerplate code for you.

Neftren
2012-09-19, 04:47 PM
Visual Studio can really help you programming. It's actually quite easy to use - just write the code and press the green button.

It can ever create boilerplate code for you.

Visual Studio does have its share of frustrations though. I spent two hours trying to figure out why my Rabin-Karp hash was failing in Visual Studio, when it compiled just fine under gcc 4.2 in OSX. :smallfurious:

That, and I actually need to go get a copy now that I think about it. Just so I can compile in Windows when people ask me...

(or maybe I'll just install MinGW or something)

Capt Spanner
2012-09-19, 04:55 PM
Visual Studio does have its share of frustrations though. I spent two hours trying to figure out why my Rabin-Karp hash was failing in Visual Studio, when it compiled just fine under gcc 4.2 in OSX. :smallfurious:

Getting stuff to compile cross platform is a programming frustration - not a problem with any particular environment.

shawnhcorey
2012-09-19, 05:29 PM
Getting stuff to compile cross platform is a programming frustration - not a problem with any particular environment.

Getting stuff to compile cross platform should only be a problem for the I/O portions. Everything else should compile and work.

Drumbum42
2012-09-20, 10:34 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time? Got a BS in CompSci but currently I'm working as a network admin. Not exactly what I pictured doing, but I enjoy it so.... close enough.

What language or languages are you using primarily at the moment? What's your favourite, and why? Well primarily I'm using Java and SQL (yes I know it's a query language) for network tools and database management.

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along? Planning on moving to programming in the future, but I enjoy my current job, so no rush.

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on? I programmed a 1e AD&D combat simulator to find out how powerful characters ACTUALLY are. Then I ran into the problem of having more then 8v1 at a time. In a box grid the 9th person would have to wait for his friend to die, then move into his spot. I stopped when I realized it would be weeks of work to add agency to my software. I called it a victory and moved on.

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor? Eclipse and command line. Often both at the same time for networking applications.

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code? Nope, currently just slowly plodding along with my multi-server C&C application. Only code in my spare time at the moment.

Also I have used munti-dimentional arrays (more then 3). Though very rarely. Mostly it was to keep big programs from getting really slow or holding multiple spreadsheets of data. (For access speed arrays are the way to go. Seek time? 1. But for sorting, terrible.) And I would assume that older languages need these too as objects/linked lists/array lists don't exist.

Miscast_Mage
2012-10-09, 03:29 AM
So, I've been having a bit of a problem with arraylists here(working in Java):

I've been working on a program to generate a deck of cards, each unique, e.g. [spades][5], [clubs][A], etc. I wanted to use an arraylist, because I can then use the collections shuffle to easily randomise the positions of the card in the deck.


Here's a slightly barebones version of the code:




import java.util.ArrayList;

public class Card
{
static String suit;
static String number;

void printCard() //print outs card.
{
System.out.println("Suit is: [" + suit + "] and number is: [" + number + "]");
}

static void deckGenerator()
{
ArrayList<Card> deck = new ArrayList<>();
Card test = new Card(); //only one object created; I think this is the problem.

for(int i = 0; i < 4; i++) //outer for loop, gets the suit of the card.
{

switch(i)
{
case 0:
suit = "Spades";
break;
case 1:
suit = "Hearts";
break;
case 2:
suit = "Clubs";
break;
case 3:
suit = "Diamonds";
break;
}


for(int x = 1; x < 14; x++) //inner for loop, gets the number of the card.
{

switch(x)
{
case 1:
number = "A";
break;
case 11:
number = "Q";
break;
case 12:
number = "J";
break;
case 13:
number = "K";
break;
default:
number = (Integer.toString(x));
break;
}
deck.add(test);//adds the card to the deck.
//if I put the test.printCard() here, it prints each card with their own value.
}//end of inner for loop
}//end of outer for loop

for(Card meow : deck) //test for-each loop. Prints the same value each time.
{
test.printCard();
}
}


}


The output when I have the for-each loop where it is is:


Suit is: [Diamonds] and number is: [K]
Suit is: [Diamonds] and number is: [K]
Suit is: [Diamonds] and number is: [K]
...
etc, for 52(4 x 13) loops.


The output when I have the print method inside the inner for-loop:


Suit is: [Spades] and number is: [A]
Suit is: [Spades] and number is: [2]
...
Suit is: [Hearts] and number is: [5]
Suit is: [Hearts] and number is: [6]
...
Suit is: [Clubs] and number is: [Q]
Suit is: [Clubs] and number is: [K]
...
etc, for 52(4 x 13) loops, but each card value is correct.



Now, the problem I'm having is that having the for-each loop to print each card where it is(outside of the for loops) just prints back [diamonds][K] for as many cards in the array.
But if I put the print statement in the inner for loop, it gives back each card as it's own value, e.g. [spades][5], [clubs][A], etc.

I think the cause of the problem is that I'm only creating the one object, and using that for each card in the arraylist. So I'm writing new values to the card each time, and putting it in the arraylist, but this just changes all the previous cards values as well, which isn't what I want.

I don't know how to create a unique card object for each time a suit and number is applied. Is there a way to do this, that I can later reference/use specific cards that I want? Maybe have an ID variable for each card? Thanks and appreciation for any help that can be offered.:smallbiggrin:

Teddy
2012-10-09, 04:32 AM
You're right in your analysis that you create just one card and then modify the value of it. The reason for why it prints out correctly inside the inner loop is because you only print out the last card each time. If you were to print them all out each time, you'd see that they all have the same colour and value in any given iteration of the loop(s).

The solution is simply to declare 52 different Card objects, which is easiest done inside the loop. I suggest the following changes: (variable names in green)

First, add this constructor to the Card class above printCard:

public Card(String suit, String number) {
this.suit = suit;
this.number = number;
}
This allows you to create a card with the values suit and number set from the start.

Then, replace the declaration of the Card object test with these two variable declarations:

String suit;
String number;
Giving these the same name as the values of the card mostly serve to reduce the number of changes needed in the code, as the lines that previously would affect the cards values now only change these two variables. You may change them in order to reduce any confusion, but then you'll have to change any reference to suit and number later in the code to the new variable names as well.

Finally, when you add the card to the ArrayList, replace the current line with this:

deck.add(new Card(suit, number));
This creates an unique Card object and sets its values at the same time, whereafter it's immediately added to the deck. Since this line of code is repeated 52 times thanks to the outer and inner loops, you'll end up with 52 unique cards in your deck.

Finally, there's a bug in your printing loop at the end. You take each card out of the deck, name it meow and then call printCard with test, which has the value of the last card inserted, no matter what (although it would generate a compiler error if the above changes were made, since that would remove test entirely). Swap test for meow inside the method call and you should be set.

Emmerask
2012-10-09, 04:46 AM
You're right in your analysis that you create just one card and then modify the value of it. The reason for why it prints out correctly inside the inner loop is because you only print out the last card each time. If you were to print them all out each time, you'd see that they all have the same colour and value in any given iteration of the loop(s).

The solution is simply to declare 52 different Card objects, which is easiest done inside the loop. I suggest the following changes: (variable names in green)

First, add this constructor to the Card class above printCard:

public Card(String suit, String number) {
this.suit = suit;
this.number = number;
}
This allows you to create a card with the values suit and number set from the start.

Then, replace the declaration of the Card object test with these two variable declarations:

String suit;
String number;
Giving these the same name as the values of the card mostly serve to reduce the number of changes needed in the code, as the lines that previously would affect the cards values now only change these two variables. You may change them in order to reduce any confusion, but then you'll have to change any reference to suit and number later in the code to the new variable names as well.

Finally, when you add the card to the ArrayList, replace the current line with this:

deck.add(new Card(suit, number));
This creates an unique Card object and sets its values at the same time, whereafter it's immediately added to the deck. Since this line of code is repeated 52 times thanks to the outer and inner loops, you'll end up with 52 unique cards in your deck.

Finally, there's a bug in your printing loop at the end. You take each card out of the deck, name it meow and then call printCard with test, which has the value of the last card inserted, no matter what (although it would generate a compiler error if the above changes were made, since that would remove test entirely). Swap test for meow inside the method call and you should be set.

Yep thats correct, though the create deck functionality should not be in the card class.
The card class really should only have the new card(suit,number) and the getter (don´t think you need a setter) and a pint functionality maybe.
The deck class then should create a deck, shuffle the deck etc.

Teddy
2012-10-09, 05:46 AM
Yep thats correct, though the create deck functionality should not be in the card class.
The card class really should only have the new card(suit,number) and the getter (don´t think you need a setter) and a pint functionality maybe.
The deck class then should create a deck, shuffle the deck etc.

Agreed, but I opted for as few changes to the original code as possible. Also, the printing method could perhaps be exchanged for a toString method, or at least utilise one...

Ashtar
2012-10-09, 08:33 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
I work in a company developing energy optimisation software, I do the main development of the application and part of the calculation kernel (optimization and parallelization). I have a master in computer science.

What language or languages are you using primarily at the moment? What's your favourite, and why?
I use C# with .Net 3.5 primarily for the user interface and server programming side of the application. For the calculation kernel, I use FORTRAN with OpenMP as a parallelization library.

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
At this point, I really have no idea, I don't know if the future is in programming at all for me or to transition more to a manager / project leader type of role.

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?
Currently, I'm the main developer of the tool my company sells. That takes all my focus.

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?
I work with visual studio, both for the C# and for the Fortran (since intel visual fortran integrates with visual studio).

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?
My largest problem now is I have a piece of code in fortran for the calculation kernel that parallelizes well on a single motherboard computer (SMP) up to 64 cores, but I now have access to a ccNUMA computer made of 16 blades of 16 cores each (total 256 cores - 2 TB memory) and I have to modify the code to obtain a better speedup. On the ccNUMA system, I'm only getting a max of 16x speedup, when the program is local to one of the blades. I'm really having to dig into the memory and usage of the OpemMP commands. It's driving me mad.
I need this because the largest problems we run take about 12 hours on a 64 core machine using about 32 GB of ram and I need to bring it down.


About larger than 3D or more dimensions:
In our code, when we deal with n-dimensional spaces (we are solving a bellman equation for a multiple state system), we basically covert these n-dimensions into a 1-dimensional array of memory by enumerating (dim1 * dim2 * dim3 * dim4 = maxdim) it to flatten it out.

Miscast_Mage
2012-10-10, 04:31 AM
Edit: *Spoiler'd for length and size*


Ah, thank you! I tinkered around with it, and it works perfectly now!



I had constructors at first as well, but I was looking into getters and setters(something I hadn't specifically looked into yet), and I think I just ended up confusing myself more than anything else. I just took them out for the moment, to make things simpler for a bit.




This is what was driving me mad; I knew I had to do this, but I simply didn't know how. Many thanks to you, good sir!:smallbiggrin:



Yeah, I had changed it just to make it easier to post, and I guess I must have missed/messed up with that.:smallconfused: It was odd, though; trying to use test (Great idea about using different colour, by the way; I can see it making things a lot clearer.)




Yeah, I had originally planned to have seperate Card and Deck classes, the Deck handling things like DeckGenerator, or Shuffle; I was just doing everything in the Card class for the moment to test to see if it worked. Probably not the smartest decision in the world though, I admit. :smallredface:



Personally, I prefer using a print method as all I need from it here is to check to see if it's what it should be, and I like having my own format for that. You wouldn't use a toString method for manipulating something in the object, would you, or is it too just for printing/checking? :smallconfused:

Many thanks, again; you've been a great help.:smallbiggrin:

Teddy
2012-10-10, 07:24 AM
I had constructors at first as well, but I was looking into getters and setters(something I hadn't specifically looked into yet), and I think I just ended up confusing myself more than anything else. I just took them out for the moment, to make things simpler for a bit.

Why not do both? Although setters are only relevant if the value in the object should be possible to modify after declaration (which isn't really the case for cards).


This is what was driving me mad; I knew I had to do this, but I simply didn't know how. Many thanks to you, good sir!:smallbiggrin:

I'm always happy to help. :smallsmile:


(Great idea about using different colour, by the way; I can see it making things a lot clearer.)

Yeah, when writing the post, I realised that things were pretty quickly going to become confusing if I kept writing variable names like any other word, so I borrowed the idea of colouring variables from the way many IDEs tend to do it.


Yeah, I had originally planned to have seperate Card and Deck classes, the Deck handling things like DeckGenerator, or Shuffle; I was just doing everything in the Card class for the moment to test to see if it worked. Probably not the smartest decision in the world though, I admit. :smallredface:

In a program this small, it doesn't matter especially much, but when you're working with larger projects, it generally saves you a lot of time to do them as separate parts to start with.


Personally, I prefer using a print method as all I need from it here is to check to see if it's what it should be, and I like having my own format for that. You wouldn't use a toString method for manipulating something in the object, would you, or is it too just for printing/checking? :smallconfused:

The method toString() prints information about an object as a string. It already exists in the Object class (which all classes automatically extend). If you tried...

Card noir = newCard("Spades", "J");
String s = noir.toString();
System.out.println(s);
...you'd get some cryptic numbers which I think are an ID-number of some sort. By defining your own toString() method, you can decide what to print, for example...

public String toString() {
return(number + " of " + suit);
}
...would make the output of the previous code block "J of Spades".

What also is worth pointing out is that toString() is automatically called on an object when you call println() with it, so...

Card noir = newCard("Spades", "J");
System.out.println(noir);
...is equivalent in output to the first code block.

Neftren
2012-10-10, 12:04 PM
I'm no expert in Java, but my hunch would be that calling toString() on an object without an overloaded toString() method would print the memory address or something similar to that degree.




Also, that silly moment when you realize sys.maxint returns a 64-bit number locally, but a 32-bit number on the deployment server. :smallredface:

Yeah. That just happened to me.

Teddy
2012-10-10, 12:44 PM
I'm no expert in Java, but my hunch would be that calling toString() on an object without an overloaded toString() method would print the memory address or something similar to that degree.

Possibly, but since Java goes through great lengths to conceil the actual working mechanisms of the memory management, and since the numbers are seemingly arbitrary, I'm open for other possibilities as well...


Also, that silly moment when you realize sys.maxint returns a 64-bit number locally, but a 32-bit number on the deployment server. :smallredface:

Yeah. That just happened to me.

Let me guess, you're running a 64-bit machine. :smallwink:

Neftren
2012-10-10, 01:53 PM
Let me guess, you're running a 64-bit machine. :smallwink:

Yeah, this is for Google App Engine using the Python SDK. I'm running this locally in OSX 10.8.2 (x86_64) whereas Google's server is running some flavor of 32-bit ... I want to say Linux.

Anyways, I got my datastore query working now. Yay!

akma
2012-10-12, 08:38 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
I taught myself (slowly and inconsistently) from the internet. I do it in my spare time.

What language or languages are you using primarily at the moment? What's your favourite, and why?
I only know java. It doesn`t look like I`ll have to deal with other OS other then windows anytime soon, but I like the idea of it working the same on any OS.

I read a bit about other leanguages, but I won`t be able to do much with any of them (maybe a bit with SQL).

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
My abstract goal is to know how to program anything I`ll want to, and be able to do it (not including things like artifical inteligence). I might work in programming in the future.

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?
I have too many project ideas. I decided that my main focus would be on utility classes and methods, and other then that I work on things at random. Right now I`m a bit focused on mathamatical stuff - I wrote a class that represents a simple fracture (3/4, 1+2/5, etc), which works well. It used 3 int values, and I decided they should be longer. So I`m working on an arbitary length integer class to replace the int values with (yes, I know one exists with java - one of my projects is making my own versions to some of the classes in java).

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?
The unsynchronized console in NetBeans irked me (that and a few other features), so I passed to Eclipse, and I might get sick of it too eventully.

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?
I hate it when I make obvious mistakes. Those are the easiest type to detect and fix, but it`s still annoying that I accidently used about half of java reserved keywords while writing a class.



*card stuff*


A note about the card class:
I think it would be better if you used Enums instead of String values for Suit and Number. That way if you accidently insert incorrect values to the constructor, the program would fail instantly with obvious reasons instead of messing up things later.

The way the toString method is implemented by default is by returning the class name and it`s address in hexdecimal format.

DeusMortuusEst
2012-10-12, 08:51 AM
Hi!

I just started looking at Executable UML, does anyone have any experience with it, or any tips regarding learning it?

Krazzman
2012-10-12, 08:54 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

Working, but not really as Programmer. Was employed after my apprenticeship as "Fachinformatiker im Fachbereich Anwendungsentwicklung".
Passed that with a 4+ (D+ in American grading system) due to the Commission (IHK) not getting what my Project was about and having a blackout at the exam...


What language or languages are you using primarily at the moment? What's your favourite, and why?

ATM I work with COBOL but I would like to do more with Java which I might come to in the future... but then more in terms of hobby not for cash as it seems.


Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Staying at my job as it is not really programming more maintenance of the systems for Insurance Companies but it is quite fun. And pretty damn well payed :smallbiggrin:


Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

Nothing really at the moment. Messed some Tables up today but got to fix that again...


What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

For COBOL we use the RDz (Rational Developer for System z) a sort of Homemade version of an Eclipse environment similar to the RSA (Rational Software Architect from IBM). It is quite well made and once configured works really well. At home I used IntelliJ for school stuff


Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?
[/LIST]

COBOL Global Variables... seriously... confusing stuff when encountered the first time

Kallisti
2012-10-12, 11:28 PM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

What language or languages are you using primarily at the moment? What's your favourite, and why?

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?




I've been studying Python using the free courses on the internet--particularly Udacity--in my spare time. I've played with Python, Ruby, JavaScript and C++, but Python's the only language I both found a robust set of tutorials for and made time to stick with. Mostly I've been enjoying it, although I started with Ruby and will occasionally be annoyed by something Ruby had and Python lacks.

I have a few projects I'd like to complete eventually, mostly for personal use, but my main motive to study programming is that it seems interesting. I really enjoy the problem-solving, although it irritates me that my toolset (read: my knowledge of the language) is incomplete; it feels akin to wrestling for a logic puzzle for hours on end before the guy who posed it goes "Oh! I just remembered, there's a clue I was supposed to give you, you won't be able to solve without it..."

My most immediate project is a program that will take parameters for a given RPG's die system and output some statistical calculations--so you could ask how likely you are to succeed in a given opposed roll in nWoD or how many hobgoblins your ranger can kill before getting nat-20'd to death. Eventually I'd like to release it as a series of free apps--one for each system I end up supporting.

I generally use the built-in interpreter in Udacity simply because it's what I'm provided, but if a piece of code is giving me serious trouble I'll move it into PyScripter to take advantage of some of its IDE features; I have Eclipse on the Linux the friend-who-is-actually-good-at-computers insisted I should be able to dual-boot, but I almost never use it--I found the sizable feature set a bit overwhelming and I like PyScripter better visually, which matters if I'm going to be staring at a screen for hours on end. I know I can customize the appearance of my Eclipse install, but that's a lot more work than I want to do to turn Eclipse into PyScripter when I already have PyScripter.

Currently there aren't any problems driving me too crazy, although several of the challenges of Udacity give extra kudos for more parsimonious code and I'm utterly stumped as to how some of those could be solved in just a few lines of code.

akma
2012-10-13, 04:39 AM
My most immediate project is a program that will take parameters for a given RPG's die system and output some statistical calculations--so you could ask how likely you are to succeed in a given opposed roll in nWoD or how many hobgoblins your ranger can kill before getting nat-20'd to death. Eventually I'd like to release it as a series of free apps--one for each system I end up supporting.

I made a dice rolling program, and I plan to expand it to include probabilities and more systems, although my general goals for that are much smaller then yours (I don`t plan to include calculations for opposed roles, I don`t want to make it user friendly, etc).

There is a formula which I think is correct for calculating the probability of a certain sum in a roll of a few dice, but I don`t remmember it exectly.

PairO'Dice Lost
2012-10-13, 09:55 PM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
I have a MS and BS in computer science and am working as a software engineer at a Big Data company.
What language or languages are you using primarily at the moment? What's your favourite, and why?
Languages I'm using at work: C, C++, Python, and MySQL.
Languages I'm using for fun: Perl, PHP, and Java.
I love Perl's quirky syntax and built-in hashes and regular expressions, so I'd say that's my favorite right now.
Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
No plans, really, I just like coding.
Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?
I'm working on a D&D database for my group's use, basically a comprehensive SRD of all 3e material out there like dndtools or realmshelp, but that isn't missing anything and that has more powerful searching and sorting. It's all OCRing PDFs, parsing, formatting, scanning, stuff like that. I've also recently made a tower defense game with an AI that reacts to the player's choice of tower types, paths defended, etc.
What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?
Linux terminal and vim for me, please. My work laptop is a Macbook, but the dev team works in a RHEL 6 VM.

My most immediate project is a program that will take parameters for a given RPG's die system and output some statistical calculations--so you could ask how likely you are to succeed in a given opposed roll in nWoD or how many hobgoblins your ranger can kill before getting nat-20'd to death. Eventually I'd like to release it as a series of free apps--one for each system I end up supporting.

Writing dicerollers and other gaming apps is a hobby of mine as well. I wrote a diceroller that handles conditional logic, exploding dice, rerolls, multiple rolls, and more. Some examples:


~$ diceroller.pl "7d10b5e10" --verbose
7d10b5e10 Result: 29
Rolled 8d10: 2, 4, 6, 3, 4, 10 (die 6 exploded), 5, 1
Chose best 5: 10 6 5 4 4

~$ diceroller.pl "1d20+X" --repeat 4 --var "X={20/15/10/5}"
1d20+20 Result: 39
1d20+15 Result: 17
1d20+10 Result: 28
1d20+5 Result: 21

~$ diceroller.pl "1d20+5" --repeat 100 --atleast 23 --index
1) 1d20+5 Result: 25 Critical Hit!
4) 1d20+5 Result: 24
5) 1d20+5 Result: 25 Critical Hit!
8) 1d20+5 Result: 25 Critical Hit!
15) 1d20+5 Result: 24
24) 1d20+5 Result: 24
28) 1d20+5 Result: 25 Critical Hit!
37) 1d20+5 Result: 24
65) 1d20+5 Result: 24
69) 1d20+5 Result: 25 Critical Hit!
70) 1d20+5 Result: 23
83) 1d20+5 Result: 23
86) 1d20+5 Result: 24
87) 1d20+5 Result: 25 Critical Hit!
90) 1d20+5 Result: 24
92) 1d20+5 Result: 23
97) 1d20+5 Result: 23
I also wrote a dice statistics program for arbitrary dice expressions:


~$ statistics.pl
Enter a dice expression:
4d6b3
Result Times Probability
3 1 0.0008
4 4 0.0031
5 10 0.0077
6 21 0.0162
7 38 0.0293
8 62 0.0478
9 91 0.0702
10 122 0.0941
11 148 0.1142
12 167 0.1289
13 172 0.1327
14 160 0.1235
15 131 0.1011
16 94 0.0725
17 54 0.0417
18 21 0.0162

Mean: 12.2445987654321 Standard Deviation: 2.8468

...as well as a simulator for Star Wars Saga vehicle combat to handle massed attacks, condition track steps, shield reduction, and such. It made combats in my Rogue Squadron campaign ("72 TIE Interceptors and 2 Dreadnoughts? There's 12 of us, we can take 'em!") a lot easier to handle.

TSGames
2012-10-14, 12:35 PM
For people into Python: I thought this (http://www.codeskulptor.org/) was pretty neat.

Miklus
2012-10-14, 05:13 PM
For people into Python: I thought this (http://www.codeskulptor.org/) was pretty neat.

I don't get it... What does it do? Other than write "good job" in big red letters, obviously.


EDIT: On second look, it compiles the code you type in? that is neat in a redundant sort of way.

Might as well add a question of my own: Is everything classes and automatic garbage collection these days? I ask because we don't use that much where I work. The programs we make has to run real time, so I guess we have a wierd programming style.

I'm sitting here with a little hobby project and the garbage collected classes from microsoft and my own code does NOT want to play nice together. It does not really want to mix managed classes and my code. Should I just give in and make everything managed? Proformance is not too important in this little application.

Miscast_Mage
2012-10-16, 05:44 AM
Writing dicerollers and other gaming apps is a hobby of mine as well. I wrote a diceroller that handles conditional logic, exploding dice, rerolls, multiple rolls, and more. Some examples:

*kersnip'd*


Ah, very nice; I've got a little dice program myself from ages ago that I've really been meaning to expand on. It asks you how many sides the dice you want to roll has, how many times you want to roll it, and returns the results of each roll, and the total value of all rolls combined:




Enter the amount of sides the dice has:
6
Enter number of times to roll the dice:
100
The total result is 381
1: 11
2: 17
3: 18
4: 15
5: 12
6: 27



Some things I want to add to it is having conditonal rolls(such as critical hits, nat 20s, nat 1s,), and automatically adding in modifiers, and possibly tying it to a database of weapons that would have damage, crit ranges, etc.

Once I get the dice program to a level I'm happy with, I'll try and use it for some other projects; I've been meaning to get a D&D character generator up and running, and I'm planning on doing it in netbeans forms, or possible some other form of GUI.


Also, that silly moment when you realize sys.maxint returns a 64-bit number locally, but a 32-bit number on the deployment server. :smallredface:

Yeah. That just happened to me.

It could be worse; try having an Arraylist(in java) of objects, and a method to take objects from it and give it to another Arraylist; I had:




static ArrayList<Card> dealToHand(ArrayList<Card> deck, ArrayList<Card> hand, int cards)
{
for(int i = 0; i < cards; i++)
{

Card test = deck.get(0);

test.setHasBeenDealt(true);
hand.add(deck.get(i));
deck.remove(i);
}


return hand;
}



And I was driving myself mad trying to find out why it taking the first card, then the third, then the fifth, when I wanted it take just the first each time; turns out I just needed to have the is as 0s, and it took longer than I'd like to admit for this piece of logic to click. :smallredface:


I'm no expert in Java, but my hunch would be that calling toString() on an object without an overloaded toString() method would print the memory address or something similar to that degree.

Yeah, you would have to have an overridden toString(), and personally I find it just the same to have a printDetails() method, especially as I can have printCard(), printHand(), and printDeck() for different formats of printing.



A note about the card class:
I think it would be better if you used Enums instead of String values for Suit and Number. That way if you accidently insert incorrect values to the constructor, the program would fail instantly with obvious reasons instead of messing up things later.

The way the toString method is implemented by default is by returning the class name and it`s address in hexdecimal format.

Ah, but I've designed it in a way that an incorrect value can't be put in for Suit or Number, so I don't have to worry about using an enum. :smallbiggrin: Also, haven't covered enums yet, and I'm starting to get worried about the amount of stuff on my plate at the moment.:smalleek:

Also, something of note: I found a free online Introduction to Computer Science course (https://www.edx.org/courses/HarvardX/CS50x/2012/about) from Harvard, if anyone is interested in signing up for it; it started yesterday, and goes on until the 15th of April.

TSGames
2012-10-16, 06:36 PM
I only looked at the code in the second spoiler, but it looks like a good time to try out a for:each statement (http://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html). I'm not sure if it's possible with the way your program is written, but if you can do it, it is usually a nice way to perform a set amount of operations to a list of objects.

Neftren
2012-10-16, 08:46 PM
Ugh. x86 Assembler. :smallfurious:

Miscast_Mage
2012-10-17, 02:43 AM
I only looked at the code in the second spoiler, but it looks like a good time to try out a for:each statement (http://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html). I'm not sure if it's possible with the way your program is written, but if you can do it, it is usually a nice way to perform a set amount of operations to a list of objects.

Hmm, the thing is, I don't think a for-each loop would work out here(I have used for-each loops a bit, at this point); the method takes in the number of cards to take from the deck and to give to the hand. I can't see how you would do this in a non-messy way using a for-each loop. A for-each loop would go through every card in the deck, whereas I only want a specific number of cards from it(e.g. deal five cards to a hand).

Miklus
2012-10-17, 01:40 PM
So our head programmer at work...just dropped dead last weekend! :smallfrown: I'm not making this crap up. The funeral is next tuesday.

I wonder what part of his 1 million unfinished but highly business critial projects will land on my head? Well, now the power of careful documentation will come to it's fullest! Oh wait! We don't do paper! Our mantra is "The documentation is in the code", because documentation is for amaturs!

I'm not asking for detailed documentation for every little bit of code, but it would be nice if I knew, like, what the program was *supposed* to do.

*Sigh* I will miss his completely unmotivated outbursts of "WHAT?!" whenever his code did something unexpected, his constant clicking of ball point pens and violent sneeze attacks, all heard from two cubicles over.

pendell
2012-10-17, 02:38 PM
My sympathies :(. It's sad to lose a co-worker.

At any rate, this is why our project has several dozen, possibly several hundred, articles by me in the project wiki discussing every aspect of what I've done and why I did it.

Respectfully,

Brian P.

Miklus
2012-10-17, 04:19 PM
My sympathies :(. It's sad to lose a co-worker.

At any rate, this is why our project has several dozen, possibly several hundred, articles by me in the project wiki discussing every aspect of what I've done and why I did it.

Respectfully,

Brian P.

"Project wiki"?! You got to be kidding me. That sounds cool.

BTW, my coworker died from a heartattack of some kind. He had previously had a quardruble bypass. So at least he went quick. Man, what if he had dropped dead at work?! :smalleek:

Neftren
2012-10-17, 04:37 PM
"Project wiki"?! You got to be kidding me. That sounds cool.

BTW, my coworker died from a heartattack of some kind. He had previously had a quardruble bypass. So at least he went quick. Man, what if he had dropped dead at work?! :smalleek:

For large code bases, it's not uncommon to have a Wiki or other established comment system (e.g. GitHub commit histories).

pendell
2012-10-18, 08:34 AM
Allow me to direct you to Assembla (https://www.assembla.com/home) . They provide a repository, trouble ticket management system, a wiki, and a bunch of other stuff. There's a free version for students which provides something like :mumble mumble: storage space in 1 workspace. I've had occasion to use the paid versions, but for which companies and which projects I cannot say.

Respectfully,

Brian P.

akma
2012-10-19, 01:09 AM
Ugh. x86 Assembler. :smallfurious:

I`m thinking of trying to learn Assembly after I`ll be more satisfied with my skill in java (I want to try something not object oriented).
How bad is it? I know there are no classes, are there even method declerations?

factotum
2012-10-19, 01:35 AM
How bad is it? I know there are no classes, are there even method declerations?

Assembly is raw machine code instructions...it doesn't really have *any* language constructs you might be familiar with. As an example, this is a small piece of in-line assembly code I put into a C function to speed it up many years ago:



mov ecx, 0
mov ebx, width
mov esi, tempsrc
mov edi, tempdest

asm_loop:
cmp ecx, ebx
jnc end_asm

test ecx, 31
jnz no_load

mov eax, DWORD PTR [esi]
add esi, 4
bswap eax
no_load:
shl eax, 1
jnc no_inc
inc BYTE PTR [edi]
no_inc:
inc ecx

test ecx, tbit
jnz asm_loop

inc edi
jmp asm_loop
end_asm:


To give you a clue, the things at the beginning of lines ending colons are labels, anything starting with a J is a jump command that will jump to one of those labels depending on conditions (e.g. jnz = jump if non-zero). This might look like the most horrible spaghetti code you've ever seen, but this is the *only* way to code in raw assembler.

TSGames
2012-10-19, 04:23 AM
If all you know is Java, I would not waste my time trying to learn assembly: it will be next to impossible. To jump from one of the highest level languages in existence to assembly (the lowest level practical language) would take inordinate amounts of time, practice, and dedication.

It would legitimately be quicker to learn another language at a lower level and then try to learn assembly, than it would be to just jump to it from Java. At the very least you should know a language that is no higher level than C++ before you start assembly ( C would be even better). Then it may be easier to mess around with something like an Arduino (http://www.arduino.cc/), which can be programmed basically in C or in assembler, allowing you progress down into the assembly code as you are comfortable with (and you can actually see it do stuff which makes code verification easy).

If you want to go straight from Java to assmbly code, go for it; I'm just saying that there are much better ways to go about it that will take a lot less time and be a whole lot less frustrating.

Teddy
2012-10-19, 04:32 AM
It might also be prudent to start with another assembly language than x86. We had assembly programming as a part of a computer architecture course last spring, where we were taught MIPS assembly, which wasn't all too hard to grasp, at least not in my opinion.

I should also point out that the only languages I knew prior to that course were Java and SML (which is a functional language, and thus even further removed from assembly, which is imperative), and the same applied to most of my coursemates, so it's not impossible to learn assembly just because you know nothing like it. Actually, since we just had left SML, I found MIPS assembly to be sort of a relief, seeing how it let me put skills in imperative programming I'd learned in Java to use again.

Miscast_Mage
2012-10-19, 04:34 AM
@Miklus:

Oh dear, I'm sorry to hear of your loss. My sympathies to his friends, family, and coworkers. :smallfrown:



Allow me to direct you to Assembla (https://www.assembla.com/home) . They provide a repository, trouble ticket management system, a wiki, and a bunch of other stuff. There's a free version for students which provides something like :mumble mumble: storage space in 1 workspace. I've had occasion to use the paid versions, but for which companies and which projects I cannot say.

Respectfully,

Brian P.

Ah, I've actually been looking into setting up a wiki or database that would contain classes and methods I've that I thought were particularly useful; this looks like it could be just what I need. It seems a lot more complex than what I need, but still, learning something new never hurts. :smalltongue:

Just to get a bit of a head start though, if all I want is essentially a database of small programs, and brief descriptions of what they do, all I would need for the moment is the git repository, right? And I would essentially be able to set it up like a wiki for myself and others(assuming I set it to public) to access? Or would I just be better off setting up something on wikispaces? (http://www.wikispaces.com/)

akma
2012-10-19, 11:53 AM
To give you a clue, the things at the beginning of lines ending colons are labels, anything starting with a J is a jump command that will jump to one of those labels depending on conditions (e.g. jnz = jump if non-zero). This might look like the most horrible spaghetti code you've ever seen, but this is the *only* way to code in raw assembler.

Seems scary. What was it supposed to do? What the bigger program is supposed to do?



It would legitimately be quicker to learn another language at a lower level and then try to learn assembly, than it would be to just jump to it from Java. At the very least you should know a language that is no higher level than C++ before you start assembly ( C would be even better).


From what I know of C++ syntax, it`s very similiar to that of Java. I don`t see how that could help significantly in learning assembly (anyways I`ll pick something easier then assembly after Java).


It might also be prudent to start with another assembly language than x86. We had assembly programming as a part of a computer architecture course last spring, where we were taught MIPS assembly, which wasn't all too hard to grasp, at least not in my opinion.


When I`ll work on learning Assembly, I will work on learning the Assembly leanguage of the computer I`ll have at the time.



Ah, I've actually been looking into setting up a wiki or database that would contain classes and methods I've that I thought were particularly useful; this looks like it could be just what I need. It seems a lot more complex than what I need, but still, learning something new never hurts. :smalltongue:


I didn`t look at the website pendell posted, but Java has a built in documentation system - Javadoc.
Also, if your packages are organized well, it saves you a lot of bother. You could create a package named utility and put everything usefull there.

Neftren
2012-10-19, 01:31 PM
From what I know of C++ syntax, it`s very similiar to that of Java. I don`t see how that could help significantly in learning assembly (anyways I`ll pick something easier then assembly after Java).

Sure, the syntax is pretty similar. It's a type-cased brackets-based language. Java does a lot of hand holding for you though. C/C++ really requires you to have a good working knowledge of memory layout, pointer usage, and so on. There are also a lot of different data structures in the standard library, and knowing which one to use when can be tricky.


When I`ll work on learning Assembly, I will work on learning the Assembly leanguage of the computer I`ll have at the time.

I'd strongly suggest you start with a simpler Assembly language (e.g. MIPS, as Teddy suggested). x86 makes me want to smash my head against the wall every night just trying to keep track of all the opcodes, jumps, conditional and unconditional branching, etc.

1

Miscast, at work, a lot of people had their own established (personal) codebases saved locally. For instance, my mentor didn't like the STL Vector class (think ArrayList in Java), so he wrote his own. It's not uncommon to keep small utility programs around. I do it for Python and C/C++, mostly for image processing. Centroiding and filtering are pretty common operations.

If you find yourself using a lot of the same initialization code, consider just putting together a template program. I have one for OpenCL runtimes, as 90% of the time it's the same cl::getPlatform(), cl::getDevices(&Platform) or something along those lines.

What you don't want to do is make a wiki and just post raw code snippets. Avoid writing a chunk of code and copy/pasting it every time you use it. Consider encapsulating it into an (inline) function if you use it frequently, then import the file.

factotum
2012-10-20, 05:19 AM
Seems scary. What was it supposed to do? What the bigger program is supposed to do?

The code snippet there scans a line of input pixels and converts it to an array several times smaller with a count of pixels...so, if you wanted it to be 4 times smaller, you'd get back an array with values from 0-4 in it saying how many "set" pixels were in each 4-pixel block. It was part of a font rendering engine that created anti-aliased text by rendering it several times larger than it needed to be and then scaling it down. Those were the days before proper anti-aliased font handling was built into Windows, of course!

DeusMortuusEst
2012-10-20, 06:14 AM
For large code bases, it's not uncommon to have a Wiki or other established comment system (e.g. GitHub commit histories).


Allow me to direct you to Assembla (https://www.assembla.com/home) . They provide a repository, trouble ticket management system, a wiki, and a bunch of other stuff. There's a free version for students which provides something like :mumble mumble: storage space in 1 workspace. I've had occasion to use the paid versions, but for which companies and which projects I cannot say.

Respectfully,

Brian P.

Any thought on how Assembla compares to Trac? Me and a co-worker are planning a new project and we were thinking of using Trac and Git to sync everything.

pendell
2012-10-21, 09:51 AM
@Miklus:




Ah, I've actually been looking into setting up a wiki or database that would contain classes and methods I've that I thought were particularly useful; this looks like it could be just what I need. It seems a lot more complex than what I need, but still, learning something new never hurts. :smalltongue:



Just to get a bit of a head start though, if all I want is essentially a database of small programs, and brief descriptions of what they do, all I would need for the moment is the git repository, right?


Correct. Git can store your code, and I supposed you could add documentation in the form of .rtf or text files to the repository as well. I prefer wiki articles for that, but if it's simpler to just use the repository that will work.



And I would essentially be able to set it up like a wiki for myself and others(assuming I set it to public) to access?


I believe so, yes. Certainly that's the way I've used it.

Or would I just be better off setting up something on wikispaces? (http://www.wikispaces.com/)

I can't say I've used Trac or wikispaces. Sounds like a homework assignment for me at some point.

Respectfully,

Brian P.

Wookieetank
2012-10-22, 09:11 AM
•Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
I'm currently a Hospital Secretary (with a degree in geology no less) so no real programming work there. Taken a couple of classes in C++ and I've been teaching myself Python the past couple of years. Just started the cs50x class posted here so here's hoping something new sticks.

•What language or languages are you using primarily at the moment? What's your favourite, and why?

I'm currently using python as my main language (and favorite so far), although with the class I'm taking I'll be getting to use C, PHP, and Java. I also have experience with C++ but haven't used it in long enough that I'm on the farther side of rusty with it.

•Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

I'd like to one day be a freelance programmer and/or indie game programmer, both of which are sometime in the nebulous future.

•Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

I've got a rougelike that I dable with from time to time, need to get back to working on that at some point. Other than that just working on learning as much about programming as I can.

•What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

I generally just use IDLE for a programming enviornment. As for a text editor, I greatly enjoy the look and feel of Notepad++.

•Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?

Biggest problem I have right now is making sure I don't have any typos or syntatic errors. I have a tendency to type obnoxiously fast, which causes case errors, and spelling errors more frequently than I would care for.

Miklus
2012-10-22, 06:55 PM
@Miklus:

Oh dear, I'm sorry to hear of your loss. My sympathies to his friends, family, and coworkers. :smallfrown:

Thanks. Speaking of assembler, I just remembered that he was the only one who knew how to program in that. There are functions programmed by him in assembler for speed. Let's hope they never need to be debugged or we are so screwed. :smallsigh:

Now for my little hobby project: Managed code and my code fit like foot in glove. Seriously, help! I want to use the build-in components like treeview and such. They are all managed and will only work with other managed object. It is borderline harrasment. For example, the treeview has a "tag" property per node which is just a pointer. But it can only point to managed objects. you can't even cast it to the type you want.

It's the same for this list class I'm making. The head class (the form) is managed, so the list must be managed. The elements in the list must thus also be managed. And all the part of the element must also be managed, right down to a 2D vector. Really?

Is this really how it is supposed to be? Everything is on the garbage collected heap now and nothing on the stack?

I guess if you want to use a Microsoft product, you have to program the Microsoft way.

Neftren
2012-10-22, 07:07 PM
Thanks. Speaking of assembler, I just remembered that he was the only one who knew how to program in that. There are functions programmed by him in assembler for speed. Let's hope they never need to be debugged or we are so screwed. :smallsigh:

Now for my little hobby project: Managed code and my code fit like foot in glove. Seriously, help! I want to use the build-in components like treeview and such. They are all managed and will only work with other managed object. It is borderline harrasment. For example, the treeview has a "tag" property per node which is just a pointer. But it can only point to managed objects. you can't even cast it to the type you want.

It's the same for this list class I'm making. The head class (the form) is managed, so the list must be managed. The elements in the list must thus also be managed. And all the part of the element must also be managed, right down to a 2D vector. Really?

Is this really how it is supposed to be? Everything is on the garbage collected heap now and nothing on the stack?

I guess if you want to use a Microsoft product, you have to program the Microsoft way.

What exactly is this for? I'm guessing .NET Framework?

Also, why are you using a vector in a list? That seems to defeat the purpose of putting together a list...

There's quite a lot that goes onto the heap now, and rightly so. For large data sets, you probably won't be able to fit it into the stack frame...

Miscast_Mage
2012-10-23, 08:30 AM
Miscast, at work, a lot of people had their own established (personal) codebases saved locally. For instance, my mentor didn't like the STL Vector class (think ArrayList in Java), so he wrote his own. It's not uncommon to keep small utility programs around. I do it for Python and C/C++, mostly for image processing. Centroiding and filtering are pretty common operations.

If you find yourself using a lot of the same initialization code, consider just putting together a template program. I have one for OpenCL runtimes, as 90% of the time it's the same cl::getPlatform(), cl::getDevices(&Platform) or something along those lines.

Hmm, I suppose a template program would be handiest for what I want to do. At the moment I just copy and paste previous classes/methods from previous work that I think would be handy for whatever I'm working on at the moment. I'll have to see about looking into that, thanks. :smallwink:



What you don't want to do is make a wiki and just post raw code snippets. Avoid writing a chunk of code and copy/pasting it every time you use it. Consider encapsulating it into an (inline) function if you use it frequently, then import the file.

Ah, I think I've spotted an issue with what I want to do, actually; I've been meaning to do two things, and I've been muddling them together:

Having a database of my own useful methods/classes/etc for my personal use
Having something to show other people in my course if they're having a problem


I was thinking of a wiki to have more an index of useful methods/classes, descriptions of what they do and how, what they take in/return, and what project I have them located in. The advantage to this would be it would useful for me, and for anyone if they wanted to see how snippets of my code worked.

However, now I'm just thinking of having a seperate way of managing my stuff for me, and having a wiki of useful snippets completely separate for other people to look at that would be more the tricky things that we'll have to be aware of in the exam like:




int
number = 5;
if(++number == 6)
{
System.out.println("Hello.");
}

if(number-- == 5)
{
System.out.println("Goodbye");
}


Or



int []y[];



Or just plain useful methods like this for sorting arrays


public static void swap(int [] num, int i, int j)
{
int tmp = num[i];
num[i] = num[j];
num[j] = tmp;
}
public static void sort(int [] num)
{
for(int i = 0; i < num.length - 1; i++)
{
int minIndex = i;
for(int j = i + 1; j < num.length; j++)
{
if(num[j] < num[minIndex])
minIndex = j;
}

swap(num, i, minIndex);
}
}




I didn`t look at the website pendell posted, but Java has a built in documentation system - Javadoc.
Also, if your packages are organized well, it saves you a lot of bother. You could create a package named utility and put everything usefull there.

Amen for organised packages; I organise mine by date(Y/M/D)-subject, e.g. 20121023Sample2DArrays or 20121014CharacterGenerator. It's annoying that there doesn't seem to be a tagging system or even a "ascending/descending according to date made/last edited" option; it makes it a pain to have a coherent yet expansive way of cataloging projects. :smallmad:

Lumping everything useful in one package does sound like a pretty convenient solution, even just for the moment where I don't really have anything huge yet.


Correct. Git can store your code, and I supposed you could add documentation in the form of .rtf or text files to the repository as well. I prefer wiki articles for that, but if it's simpler to just use the repository that will work.


Hmm, I think I'd prefer if it had some way of keeping the different sections of code inherently with documentation, as opposed to having it is as a separate file, which I can imagine getting messy or being a pain to keep updated.

Leona
2012-10-23, 09:02 AM
I'm in a C++ freshman course for my computer engineering degree, and basically for a scholarship I'm working with my professor on stuff outside the normal class things, including going into Python, cgi, and sqlite. It's pretty interesting! I'm working on one big program for the end of the semester that runs an HTML page where students can select a topic to practice coding on, where it'll pull a problem from an sqlite db and then take a form from the user. Then I guess I need to work on saving it as a .cpp file and compiling it through the command prompt (returning errors if there are any). So I may update you guys/ask for help :P

Neftren
2012-10-23, 12:16 PM
Hmm, I suppose a template program would be handiest for what I want to do. At the moment I just copy and paste previous classes/methods from previous work that I think would be handy for whatever I'm working on at the moment. I'll have to see about looking into that, thanks. :smallwink:

What I'm saying is that you shouldn't copy/paste at all. If it's a code snippet, it's short enough to retype, or regex/text-expand it. Typing it out will help you avoid mistakes (enter the logical fallacy of code found on the internet). If it's some sort of utility method (e.g. templated matrix multiply) that you use on a frequent basis, it should be documented and then compiled into a package.

Code that you use personally and code that you show other people shouldn't be any different. If you maintain a rigorous and neat programming style, your code should be easily understandable to anyone reading it. At that point, it's just a matter of "oh, here's my file, look at it and understand!"

As for some comments on your code... I know a lot of instructors provide cheat sheets on exams. I don't know if yours does the same though. Anyways ...

You should probably avoid performing mathematical operations within conditional statements. Your first code sample will fail if the given number isn't 5. Granted you probably already knew that part. :smalltongue:

I'm surprised you (or other people you're helping) found int []y[]; tricky. Well, maybe it's the format you wrote it in. This is more of a pet peeve of mine more than anything else (going back to the Star (Pointer) Wars. It makes much more sense to rewrite that fragment as int[] y[]; (note the spacing). That way, you keep the data type with the container. An integer[array] (of) y[array_size]. Similarly, in C/C++, int* i makes much more sense than int *i, as you would read it as an integer pointer. If in doubt, refer to your style guide (most companies or managed code bases typically have one somewhere).

Also, for the last code example, Bubble Sort (and similar O(n2) algorithms)...? Why do you consider this useful?



Amen for organised packages; I organise mine by date(Y/M/D)-subject, e.g. 20121023Sample2DArrays or 20121014CharacterGenerator. It's annoying that there doesn't seem to be a tagging system or even a "ascending/descending according to date made/last edited" option; it makes it a pain to have a coherent yet expansive way of cataloging projects. :smallmad:

A tagging system in what? All modern operating systems can sort by file name and date. Or are you using some IDE?


I'm in a C++ freshman course for my computer engineering degree, and basically for a scholarship I'm working with my professor on stuff outside the normal class things, including going into Python, cgi, and sqlite. It's pretty interesting! I'm working on one big program for the end of the semester that runs an HTML page where students can select a topic to practice coding on, where it'll pull a problem from an sqlite db and then take a form from the user. Then I guess I need to work on saving it as a .cpp file and compiling it through the command prompt (returning errors if there are any). So I may update you guys/ask for help :P

Compiling via command line is pretty easy. You'll probably learn to use the GNU Compiler (gcc/g++). In Terminal (or shell of choice), you'll enter something along the lines of...

Welp. Forbidden post error. I had something written up here, but the forum won't let me post it (and no, I didn't use the word involving a cat (yes, that word) or a colon followed by two spaces anywhere).

akma
2012-10-23, 12:17 PM
Amen for organised packages; I organise mine by date(Y/M/D)-subject, e.g. 20121023Sample2DArrays or 20121014CharacterGenerator. It's annoying that there doesn't seem to be a tagging system or even a "ascending/descending according to date made/last edited" option; it makes it a pain to have a coherent yet expansive way of cataloging projects. :smallmad:

There is another option - static variables, or maybe even a class with details about a package (if you are going to include one in every package, I recommend naming it $).



Hmm, I think I'd prefer if it had some way of keeping the different sections of code inherently with documentation, as opposed to having it is as a separate file, which I can imagine getting messy or being a pain to keep updated.

Again, javadoc.
A class written with javadoc documentation: http://docs.oracle.com/javase/7/docs/api/java/lang/Package.html
A package written with javadoc documentation: http://docs.oracle.com/javase/7/docs/api/java/lang/ref/package-summary.html
The entire API supplied with java, with much javadoc documentation (bookmark this one): http://docs.oracle.com/javase/7/docs/api/

Teddy
2012-10-23, 01:03 PM
Similarly, in C/C++, int* i makes much more sense than int *i, as you would read it as an integer pointer. If in doubt, refer to your style guide (most companies or managed code bases typically have one somewhere).

Ahh, that one. On our first lecture on pointers in our C class, our lecturer completely failed to grasp how putting the pointer in front of the name could be confusing, even when I pointed out to him that...

int *x = y;
...and...

int *x;
*x = y;
...do two completely different things.

Myself, I used to write as you do before I (privately) found out how...

int* x, y;
...will declare y as an int, and not a pointer to an int. Now I just refuse to write the star together with anything in variable declarations. After all, I wouldn't do it with const, so why do it with *?


Also, for the last code example, Bubble Sort (and similar O(n2) algorithms)...? Why do you consider this useful?

Yeah, and especially when a better sorting algorithm (QuickSort) already can be found in the Arrays library. I mean, you could just write Arrays.sort(array), where array is the array you wish to sort, and you'd be done.

Alaris
2012-10-23, 01:32 PM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

Early on in learning my programming. Looking for employment, but when I'm not, I'm trying to learn programming. At the end of the day, I might be able to make some money out of it, so why not learn it, right?


What language or languages are you using primarily at the moment? What's your favourite, and why?

Well, only learning one right now. That's Python. Technically fiddling with the sub-module of Pygame (as a crutch). Overall, the language is pretty straightforward... I've looked at C++ (or C+) and it gave me a headache really quick.



Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?

Ideally? Full-time career as a programmer. My dad did it before me, so did my brother. And while some forms give me a headache, it's pretty cool what you can do with programming.


Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?

Umm... mostly just learning the language. Within the pygame module, I'm trying to learn to make a physics engine of some kind, but boy is that getting me stuck.


What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?

Standard IDLE for Python (if I'm right in what you mean). Debated trying others, but I don't want to get into complicated things honestly.


Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?

Just that I have absolutely no clue where to start with a Physics engine. I've grasped basic python, and basic Pygame, but there are like... 0 Tutorials for Python 3.2 on it. So I'm stumbling blindly, and it's VERY time consuming.

Neftren
2012-10-23, 01:42 PM
Myself, I used to write as you do before I (privately) found out how...

int* x, y;
...will declare y as an int, and not a pointer to an int. Now I just refuse to write the star together with anything in variable declarations. After all, I wouldn't do it with const, so why use it with *?

Ahh, yes, the precedence bit. I typically avoid declaring multiple variables on one line, so I don't really have that problem. To each their own I suppose.

Const is just one of those annoying keywords where I don't think anyone can really agree on what to do. I think most people prefer placing const before the type declaration, though off the top of my head, const should always be placed in such a way so as to modify the type to its immediate left (int const). I think this breaks on older compilers though. I haven't really tested it rigorously.


Umm... mostly just learning the language. Within the pygame module, I'm trying to learn to make a physics engine of some kind, but boy is that getting me stuck.

Pygame isn't really designed to handle complex physics. The most I've ever gotten it to do is simple mechanics (e.g. handling kinematic equations, force application, etc.). You're not going to be able to get it to do anything in 3D or handle shadows/shaders/cloth simulation, at least, not with any sort of reasonable execution speed. Maybe if you hooked it into PyOpenCL or something to handle computations, but...


Just that I have absolutely no clue where to start with a Physics engine. I've grasped basic python, and basic Pygame, but there are like... 0 Tutorials for Python 3.2 on it. So I'm stumbling blindly, and it's VERY time consuming.

I don't think the Pygame implementation for Python 3 is finished yet. At least, it wasn't last I checked. Most of the syntax between Pygame on 2.7 vs. 3.2 should be the same. If you're dead set on starting with a physics engine... you'll probably want to put together a calculations package containing the basic kinematic equations. As an aside, you'll have to tweak the numbers a bit to get the right feel (e.g. increasing gravity while falling, decreasing while jumping, to get that Mario feel).

Do you have some sort of goal, other than "I want to build a physics engine"?

Teddy
2012-10-23, 04:12 PM
Ahh, yes, the precedence bit. I typically avoid declaring multiple variables on one line, so I don't really have that problem. To each their own I suppose.

Yeah, when it comes to pointers, I usually do as well, but I felt like being prepared for when I want to do it one line.


Const is just one of those annoying keywords where I don't think anyone can really agree on what to do. I think most people prefer placing const before the type declaration, though off the top of my head, const should always be placed in such a way so as to modify the type to its immediate left (int const). I think this breaks on older compilers though. I haven't really tested it rigorously.

Yes, that seems about right, even though const int works as well. The unholy combination of const and pointers really messed up one of our lectures for a while. Our lecturer (a replacement that day, so it's kind of understandable) wrote the pointer stars together with the variable name rather than with the type (or stand-alone, for that matter), which meant that he couldn't figure out where to put the const keyword when trying to declare a constant pointer to a variable value. Since I by then had learned about how pointer stars acted in multiple declarations on a single line, I could figure out how to do it (by placing the const after the star) and make the example work.

It also annoys me slightly how both const and (especially) * are read from right to left. the utterly brilliant declaration char * * const * const x (auto-generated example taken from this (http://cdecl.org/?q=char+**+const+*+const+x) site) gives you a constant pointer to a constant pointer to a pointer to a char. When I first saw it myself earlier today, I failed to grasp why the const keywords affected the pointers in that order, before I realised how it reads them right to left. Simple when you know it, but hard to realise on your own...

Miscast_Mage
2012-10-24, 07:47 AM
Spoiler'd for length. :smallsmile:

Okay, I wasn't mixing up two things at once, I was mixing up three.:smallredface:


Having a database of my own useful methods/classes/etc for my personal use.
Having something to show other people(that have started the course we're doing from a complete beginners viewpoint and thus have difficulty understanding a lot of the logic and syntax, whereas I have a year of experience in computer applications) in my course if they're having a problem.
A collection of slippery/tricky little aspects of coding in java that would be on the OCJA exam, such as what happens when you use ++ in an if statement, or a if(boolean = true)(this is assigning) as opposed to if(boolean == true)(this is checking), or a comment with \\(wrong) as opposed to //(right)



Again, javadoc.
A class written with javadoc documentation: http://docs.oracle.com/javase/7/docs/api/java/lang/Package.html
A package written with javadoc documentation: http://docs.oracle.com/javase/7/docs/api/java/lang/ref/package-summary.html
The entire API supplied with java, with much javadoc documentation (bookmark this one): http://docs.oracle.com/javase/7/docs/api/

Unfortunately, while that may be what I'm asking for, it's completely beyond my level of comprehension at the moment; I'm barely understand any of it or how to utilize it.:smallfrown:



What I'm saying is that you shouldn't copy/paste at all. If it's a code snippet, it's short enough to retype, or regex/text-expand it. Typing it out will help you avoid mistakes (enter the logical fallacy of code found on the internet). If it's some sort of utility method (e.g. templated matrix multiply) that you use on a frequent basis, it should be documented and then compiled into a package.


Well, the thing is, I have found that there occasionally methods that I would want to re-use, that I know they would fit perfectly in this new situation. It could be quite a large method, or several methods, but I would know that what I expect to put in and get out is the exact same as the previous code. Not frequent enough to warrant making a package(though that is quite a good idea; that shall be a task for another day), but large enough that re-typing it out when I know what it does and that it works in the circumstance is just redundant work.


Code that you use personally and code that you show other people shouldn't be any different. If you maintain a rigorous and neat programming style, your code should be easily understandable to anyone reading it. At that point, it's just a matter of "oh, here's my file, look at it and understand!"

I clarified this up at the top a bit; this isn't code for people at my skill level or above, but rather to help explain the code, how it works, why it does what it does and such for other people learning java for the first time in the course who might be struggling to grasp it.

I'd like to think of my code as quite neat and readable, and I already threaten apocalypse via armoured attack-weasels on people who don't indent/comment/do general neaty-ness things. :smallwink:


As for some comments on your code... I know a lot of instructors provide cheat sheets on exams. I don't know if yours does the same though. Anyways ...

Well, our exams so far are snippets of code that are designed to be as sneaky, evil, and underhanded as possible, i.e. no-where near what good practical coding should ever look like. :smallannoyed:


You should probably avoid performing mathematical operations within conditional statements. Your first code sample will fail if the given number isn't 5. Granted you probably already knew that part. :smalltongue:

This is more to prove the kind of questions we get, i.e. what will this snippet of code output? In this case, just "Hello.", because of pre and post incrementing, and the fact that using ++ or -- in the if parameter still increments/decrements for outside the if statement, regardless of whether or not the if statement proves true or not. Unless I'm mistaking something here, and am just ending up with egg on my face. :smallredface:


I'm surprised you (or other people you're helping) found int []y[]; tricky. Well, maybe it's the format you wrote it in. This is more of a pet peeve of mine more than anything else (going back to the Star (Pointer) Wars. It makes much more sense to rewrite that fragment as int[] y[]; (note the spacing). That way, you keep the data type with the container. An integer[array] (of) y[array_size]. Similarly, in C/C++, int* i makes much more sense than int *i, as you would read it as an integer pointer. If in doubt, refer to your style guide (most companies or managed code bases typically have one somewhere).

It's more that I (and as far as I know, everyone else in the course) have always used int x[][];, and we would be asked questions like "Will int []x[]; compile?" in exams, when we've never seen an array intialised like that before.


Also, for the last code example, Bubble Sort (and similar O(n2) algorithms)...? Why do you consider this useful?

In of itself, it's not that useful, apart from the fact that I worked out the logic of the code myself(and I am damn proud of that! Stupid thing wrecked my brain for a while.:smallmad:). However, I can show this to other people to explain how sorting an array works.

Another benefit is that I can alter this. For example, say I have a Card object that has a int value(is it a 5, 6, Ace, King, etc). I can copy this code, and change it to take in an Array of Cards, and use getValue to compare the values. In fairness, I could also have a method to take the values from an Array of Cards, and write that to an Array of ints called values, but either way is valid from what I can see, and having an extra alternative is never a a bad thing.:smallwink:


A tagging system in what? All modern operating systems can sort by file name and date. Or are you using some IDE?

Netbeans. :smallannoyed: I have my projects named YYYY/MM/DD/NAME so I can at least search by date. Also, is it possible to add search tags(similar to those for images) to folders/files, for things like, say Has2DArrays, ExampleOnMethods, Assignment, etc? I know what you mean by searching by date created/size/name/etc, but I mean to search for programs that come back with the following tags, and such.


Compiling via command line is pretty easy. You'll probably learn to use the GNU Compiler (gcc/g++). In Terminal (or shell of choice), you'll enter something along the lines of...

Funny enough, I started learning using java, so I'm quite happy with that environment. The only issue I have is that I don't know how to access methods from another class in one class, and I used a class that handled all input from the user that a lecturer from college gave us. I'm happy enough using netbeans for the moment though, and our next teacher is going to go through compiling via command line further down the line, so I'll be happy to deal with that issue then.

Gryffon
2012-10-24, 08:38 AM
So, coming a little late to the party, but here is a little about me:

I work in the Engineering group at my job, but my duties are mostly related to release management, so as my direct duties I deal mainly with things like Ant and Ivy. For my background I have a BS in Computer Science, and I did a little bit of graduate work(of which I'd like to do more). Most of programming is currently of the hobby variety, though I'd love to do more of it as my actual job. I've been employed for the same company for 10 years, but only worked in the engineering group for 6 of them. Did a little QA, then a little bit of bug fixing, then moved into more of a support role, leading to my being part of release management during a merger.

I've used a lot of languages for different purposes. C/C++ was the language my school used for teaching, and it's in place in a fair amount of our projects at work. I've done Java and JSP. I've scripted in Perl, PHP, awk, and Python. For school, I've done Prolog and Lisp(Lisp is fun). I mucked around in C# a little as well for an opensource project. My current favorite and what I use for home projects is Python. It's just kind of fun. It's fairly straight forward, but has a lot of power and versatility.

I have a couple of goals. I'd either like to focus on programming more as a profession than I currently do, or I'd like to become a professor and teach. I'd also like to continue my graduate studies. My interest lay in the realm of AI and specifically Natural Language Processing. Given the opportunity, I'd probably do some studies in Linguistics as well.

I have a couple of projects that I work on from time to time, but nothing serious.

I usually use eclipse when I'm working with Python, at work, I'll either use vi or jedit for quick changes/merge conflict resolution.

akma
2012-10-24, 11:54 AM
Unfortunately, while that may be what I'm asking for, it's completely beyond my level of comprehension at the moment; I'm barely understand any of it or how to utilize it.:smallfrown:

It`s not easy to learn from it, but it`s a very good refrence tool if you already know about the things you want to use, just not remmember how exactly ("This class has a method to preform that thing I want to be done... but how is it called?").



Well, the thing is, I have found that there occasionally methods that I would want to re-use, that I know they would fit perfectly in this new situation. It could be quite a large method, or several methods, but I would know that what I expect to put in and get out is the exact same as the previous code. Not frequent enough to warrant making a package(though that is quite a good idea; that shall be a task for another day), but large enough that re-typing it out when I know what it does and that it works in the circumstance is just redundant work.

A package is just a bunch of classes bundled togather. One of the core packages comes with two classes and one enum (java.lang.math), it doesn`t have to be big to be part of a package.



This is more to prove the kind of questions we get, i.e. what will this snippet of code output? In this case, just "Hello.", because of pre and post incrementing, and the fact that using ++ or -- in the if parameter still increments/decrements for outside the if statement, regardless of whether or not the if statement proves true or not. Unless I'm mistaking something here, and am just ending up with egg on my face. :smallredface:

I have a confession: I don`t know the diffrence between using ++ before a number and after it.
I looked at it, I got confused, I decided to never use it. I could get the same results without dealing with this.



Netbeans. :smallannoyed: I have my projects named YYYY/MM/DD/NAME so I can at least search by date. Also, is it possible to add search tags(similar to those for images) to folders/files, for things like, say Has2DArrays, ExampleOnMethods, Assignment, etc? I know what you mean by searching by date created/size/name/etc, but I mean to search for programs that come back with the following tags, and such.

You can have a file with a realy long name, that in it`s title it would contain all this date, inside the folder.
Or another, single file that contains data on all the projects, but you would have to update it frequently.



Funny enough, I started learning using java, so I'm quite happy with that environment. The only issue I have is that I don't know how to access methods from another class in one class

Short answer:
import somePackage.*; (before the first { )
Then, write ClassName.MethodName(arguments)
And here is the long answer: http://docs.oracle.com/javase/tutorial/java/package/index.html

Gryffon
2012-10-24, 12:04 PM
I have a confession: I don`t know the diffrence between using ++ before a number and after it.
I looked at it, I got confused, I decided to never use it. I could get the same results without dealing with this.


++<num> increments it before it evaluates the value, <num>++ increments after.



val = 2
print ++val // 3
print val++ // 3
print val // 4

Balain
2012-10-24, 04:57 PM
I need some help reading a text file in python3.

We are given a text file that looks like this

ID , LAST, FIRST, Lecture, Tutorial, A1, A2, A3, A4, A5
######, NAME, NAME, L##, T##, 9.0,5.0,2.5,7.0,10
######,NAME, NAME, L##, T##,0.0, 1.0,10,0.0,3.5


with hundreds of entries

I have a function to read the file a line at a time and split each line into a list.



def main_list(fname="grades.txt"):
import locale

fin = open(fname,mode='rt' buffering=1, newline='\n', encoding=locale.getpreferrencoding())

lst=[]

for line in fin:
lst.append(fin.readline().split(','))

fin.close()

return lst


Earlier attempts didn't have the buffering and newline character and encoding for the open call.

it appears to be creating the list I want, a list with each entry is a list of strings. However it seems to only be reading every other line of the file.

PairO'Dice Lost
2012-10-24, 05:30 PM
it appears to be creating the list I want, a list with each entry is a list of strings. However it seems to only be reading every other line of the file.

The problem here is the for loop syntax. When you say "for line in fin," you're iterating through fin's file and returning the lines one at a time as line...and then in the body of the loop you're telling it to readline() to get a line again, so you're throwing away every other line.

Just change the body of the loop to "lst.append(line.split(','))" and that should fix it.

Balain
2012-10-24, 05:45 PM
.....Just change the body of the loop to "lst.append(line.split(','))" and that should fix it.

I can't believe I didn't see that. Thank you very much!

Neftren
2012-10-26, 09:12 PM
So I started on a re-code of my previous attempt of a blogging platform on Google App Engine. So far so good. I've managed to get adding/editing posts working properly, and I've integrated Twitter Bootstrap, the Bootstrap-WYSIHTML5 plugin, and the Google-Code-Prettify plugin. Everything is saved/retrieved dynamically from the datastore and rendered using the Jinja2 templating engine.

I think my next step is to add RSS/Atom support, but I'm finding it rather difficult to actually put that together. Does anyone here have experience with writing xml feeds?

Miscast_Mage
2012-11-01, 08:09 AM
So, working in Java, and trying to figure out combining inner/outer classes with using an abstract class.

Say I've got an abstract class, Person, which extends to two classes, Teacher and Student.

I want each to have an inner class, Stats, but stats is slightly different for either of them(say their difference is Student has marks, Teacher has wages);

Would having Stats as an abstract class, and then having a Stats for Teacher and a Stats for Student work here? Would I have the abstract class Stats inside the abstract class Person as well?

Would it be a case of Teacher extends Person, then inside Teacher, TeachStats extends Stats?

Edit: I should probably clarify, when I say "Stats for Student", I mean "Stats for StudentStats extends Stats". Sorry if that caused any confusion.:smallredface:


http://i.imgur.com/wkMDh.png
Note that variables could mean methods as well; I was just lazy drawing up this diagram.:smalltongue:

akma
2012-11-01, 11:30 AM
I don`t see why you want to use an inner class at all. You could create a regular class/interface named Stats, and just have a reference to it. In Student and Teacher it`s use is completly diffrent.

Anyways, you could have the Stats object contain an int value.
You could have a getMarks() method in Student, and getWage() method in Teacher, both returning that int value.

Is it completly neccesery for you to use inner classes for some reason? (if so, remmember not to make the inner class private)

Miscast_Mage
2012-11-01, 12:33 PM
Well okay, if I don't have to have it as an inner class, how would I implement it? Would I just have Stats, StudentStats and TeacherStats as seperate classes, and just have in, say, Student:




public class Student extends Person
{
private String whatever;
private StudentStats studentStats;
}


where StudentStats is a completely seperate class? This is what I was thinking originally, but then figured that if I want to add a few more classes(which is what I'm planning on doing; this is just testing for another project that have a lot more classes extending Person), it might be more organised if I had the Stats(which also changes depending on what class it's going with) inside the Student/Teacher classes.


Having the stats object just as it is, and having the getMarks/getWages be the only difference might work; I'll have to look into that. The only problem is I'm only going through this project so I can understand the logic of it and apply it to a larger project. I'll see about about getting precise details on what I want this project to do later; I've been studying the last two and half hours and my brain is starting to melt, so apologies if I'm mixing things up or being incomprehensible. :smalltongue:

akma
2012-11-01, 02:26 PM
I`m thinking more of:
public class Person {
protected Stats stats; // so it would be inherited
}

public class Student {
stats = new StudentStats();
}
or otherwise make sure it would be StudentStats.

The field that will be returned by getWage()/getMarks() doesn`t have to be inherited, but I do strongly suggest that all values would be returned from a method inherited from the class Person.

factotum
2012-11-01, 04:07 PM
I'm not sure why you need a separate class for those stats at all. I thought the whole point of abstract classes were that you put the basic details of the type in there, and then got more detailed with the derived classes? So, Wages is a particular way in which the Teacher class extends the basic Person one. I might be thinking of this too much from a C++ viewpoint, mind you, since I'm not overly familiar with Java...

Miscast_Mage
2012-11-02, 04:19 AM
I'm not sure why you need a separate class for those stats at all. I thought the whole point of abstract classes were that you put the basic details of the type in there, and then got more detailed with the derived classes? So, Wages is a particular way in which the Teacher class extends the basic Person one. I might be thinking of this too much from a C++ viewpoint, mind you, since I'm not overly familiar with Java...

It probably isn't needed for this example, but I just want to see the logic of how they work and how to use them properly; I'm trying to learn this for another project where the Person class, if I didn't use an inner class, would have quite a lot of variables. I can imagine it would work the same, the problem would be that I would have is that it would be quite messy.

However, I think there's been a bit of a misunderstanding here, to my fault.:smallredface: I don't think inner classes are what I was planning to do, but I got muddled up with terminology there. My code probably makes more sense like this:



abstract public Person()
{
private String whateverString;
private int whateverInt;
private Stats stats;

abstract void greetings();
}




abstract public Stats()
{
private String something;
private String somethingElse;
}




public TeachStats extends Stats
{
private String somethingForTeacher;
}




public StudentStats extends Stats
{
private int somethingForStudent;
}




public Student extends Person
{
private StudentStats studentStats;

public void greetings()
{
System.out.println("Hi, I'm a student.");
}
}




public Teacher extends Person
{
private TeachStats teachStats;

public void greetings()
{
System.out.println("Hello, I am a teacher.");
}

}



That is, of course, assuming that this even works; I'm starting to think I may be out of my depth here(Yet another project that'll have to go on the backburner untill I get the proper skills and experience for it. Sigh.:smallfrown:), but I do still want to try and understand the logic of this.

Also, just as an aside; does anyone have any handy UML tutorials/notation pages that they'd recommend? Just googling for some now, but it's always nice to have one that's recommended.

Edit:


*snip*

Just out of curiousity, why would I use protected as opposed to private? Would using private cause issues with inheritance? I've only ever used private/public before, but then, I've never worked with classes like this before, so c'est la vie.:smalltongue:

TSGames
2012-11-02, 04:36 AM
Just out of curiousity, why would I use protected as opposed to private? Would using private cause issues with inheritance? I've only ever used private/public before, but then, I've never worked with classes like this before, so c'est la vie.:smalltongue:

Yes, private causes issues with inheritance. Check here (http://www.tutorialspoint.com/java/java_access_modifiers.htm) for a decent explanation of the difference between private, protected, and public. A protected method gives subclasses an opportunity to take advantage of the method, or to allow its children to overwrite the method, which cannot be done with a private method. Public/private only coding is OK as long as you A)don't have a lot of inheritance, and B)follow good coding style and have get/set methods for your variables.

Miscast_Mage
2012-11-02, 05:13 AM
Yes, private causes issues with inheritance. Check here (http://www.tutorialspoint.com/java/java_access_modifiers.htm) for a decent explanation of the difference between private, protected, and public. A protected method gives subclasses an opportunity to take advantage of the method, or to allow its children to overwrite the method, which cannot be done with a private method. Public/private only coding is OK as long as you A)don't have a lot of inheritance, and B)follow good coding style and have get/set methods for your variables.

Ah, I see now. I would have the variables marked as private and use getters/setters to access them. That can get quite fiddly though; having the variables as protected seems like it'll make things much easier in that regards, thanks for that. :smallbiggrin:

akma
2012-11-02, 05:34 AM
Just out of curiousity, why would I use protected as opposed to private? Would using private cause issues with inheritance? I've only ever used private/public before, but then, I've never worked with classes like this before, so c'est la vie.:smalltongue:

private variables, private methods and private inner classes cannot be accsessed by subclasses.
You could have a protected/public method named get, which returns a Stats object, which could then be used to get the wanted data.

My philosephy on accsess modifiers
(Note: This is the opposite of the approach encouraged by the tutorials I have read)
Generally speaking, I believe variables should be as public as possible. If the variable can contain any value, limiting the access to it only make you write unnessecery get and set methods. If you have a reason to limit the access to a variable (if it must not contain certain values, for exemple), then limit it as neccessery (probably making it private).

With methods, I write all of them as public or private. The private ones are utility methods used by the public methods, and are not usefull outside of the class.

Miscast_Mage
2012-11-02, 06:32 AM
private variables, private methods and private inner classes cannot be accsessed by subclasses.
You could have a protected/public method named get, which returns a Stats object, which could then be used to get the wanted data.

Yeah, that's what I was doing before; using getters/setters to access private variables and methods(haven't really gotten into private inner methods yet, which I've realised aren't even what I want to do here.:smalltongue:). Having things as protected though just seems like a lot less hassle and headaches than having to use getters to access them.


My philosephy on accsess modifiers
(Note: This is the opposite of the approach encouraged by the tutorials I have read)
Generally speaking, I believe variables should be as public as possible. If the variable can contain any value, limiting the access to it only make you write unnessecery get and set methods. If you have a reason to limit the access to a variable (if it must not contain certain values, for exemple), then limit it as neccessery (probably making it private).

With methods, I write all of them as public or private. The private ones are utility methods used by the public methods, and are not usefull outside of the class.

The only problem with having access modifiers as public as possible, is that does it not get inefficient the larger the code gets due to local/global scope? I got the impression that having a variable on a scope larger that it has to be inefficient and bad practice; does it actually cost more processing power to run that code, or is it just a case of different practices? :smallconfused:

Also, I've encountered this problem three times in the last three days and I keep forgetting it:




public Person()
{
protected Stats stat;
protected String whatever;

public Person(String whatever)
{
this.whatever = whatever;
stat.setStats(); //a method in the Stats to class to assign data to the variables
}
}


And I was getting a nullPointerException. What I need to do was intiliaze the stat object first:



public Person()
{
protected Stats stat = new Stats();
protected String whatever;

public Person(String whatever)
{
this.whatever = whatever;
stat.setStats(); //a method in the Stats to class to assign data to the variables
}
}

I feel silly now.:smallredface:

akma
2012-11-02, 07:44 AM
The only problem with having access modifiers as public as possible, is that does it not get inefficient the larger the code gets due to local/global scope? I got the impression that having a variable on a scope larger that it has to be inefficient and bad practice; does it actually cost more processing power to run that code, or is it just a case of different practices? :smallconfused:

I have never seen that claim.
I don`t think this is true. The variable would exist anyways, even if you couldn`t access it - int would "cost" 32 bits even if you could access it anywhere.
I also think you are mixing concepts, and static variables are like global variables in other leanguages, and instance variables are like local variables in other leanguages.
Maybe I`m wrong.

The arguments I remmember to make things as private as possible is to make it less clear how operations are preformed and to make it less error prone by wrong values being inserted (which is not always relevent).

I guess it`s more of a matter of personal taste - the thing that matters the most is if the code you write does the things it`s supposed to do.

factotum
2012-11-02, 10:57 AM
I guess it`s more of a matter of personal taste - the thing that matters the most is if the code you write does the things it`s supposed to do.

Readability and maintainability are at least as important as that, IMHO. It would be perfectly possible to write code that does what it's supposed to, but is so tangled and labyrinthine that *you* can't even remember what it does when you look at it a few months later, much less someone who's been hired to maintain the program after you've left!

Wookieetank
2012-11-02, 12:39 PM
Readability and maintainability are at least as important as that, IMHO. It would be perfectly possible to write code that does what it's supposed to, but is so tangled and labyrinthine that *you* can't even remember what it does when you look at it a few months later, much less someone who's been hired to maintain the program after you've left!

Unless of course you're participating in: http://en.wikipedia.org/wiki/Obfuscated_C :smallwink:

Teddy
2012-11-02, 04:28 PM
Unless of course you're participating in: http://en.wikipedia.org/wiki/Obfuscated_C :smallwink:

Heh, I actually thought about that contest a week or so ago, but couldn't come up with a good way of posting it without it seem all too much out of context. It's a neat concept, isn't?

Also, on the topic of writing good code, as one of our lecturers use to say: "It's ten times as hard to debug code than it is to write it, so if you write the most complicated code you could ever make, it consequently will be impossible for you to debug".

Miscast_Mage
2012-11-05, 10:08 AM
I have never seen that claim.
I don`t think this is true. The variable would exist anyways, even if you couldn`t access it - int would "cost" 32 bits even if you could access it anywhere.
I also think you are mixing concepts, and static variables are like global variables in other leanguages, and instance variables are like local variables in other leanguages.
Maybe I`m wrong.

The arguments I remmember to make things as private as possible is to make it less clear how operations are preformed and to make it less error prone by wrong values being inserted (which is not always relevent).

I guess it`s more of a matter of personal taste - the thing that matters the most is if the code you write does the things it`s supposed to do.

Ah, I must have been mistaken then; I thought I remembered my lecturer saying that it was inefficient before, but I must have been mis-remembering. My apologies.:smallredface:


Readability and maintainability are at least as important as that, IMHO. It would be perfectly possible to write code that does what it's supposed to, but is so tangled and labyrinthine that *you* can't even remember what it does when you look at it a few months later, much less someone who's been hired to maintain the program after you've left!

Funny thing, a friend of mine in college created a simple OS, and when he went back to it a few months later, he went "I can't remember what any of this does. :smalleek:" "Well that's because you don't have any comments.:smalltongue:". So it just goes to show, comments are definitely something you want to keep in mind. :smallbiggrin:

Also, I think I've got the diagram I had above sorted out now; hopefully this makes sense as a graphical representation:

http://i.imgur.com/LwBM8.png

akma
2012-11-05, 11:31 AM
Readability and maintainability are at least as important as that, IMHO.

I personally disaggree, but can`t seem to be able to detail any further (I`m usually better at debating).
But don`t worry, I don`t neglect this things while proggramming.



So it just goes to show, comments are definitely something you want to keep in mind. :smallbiggrin:


Generally my comments tend to be in the style of "Not debugged" and lists of methods to do (which I tend to neglect after I do the hardest, most intresting and most important methods of a class).

Balain
2012-11-05, 12:52 PM
Reading on posts about comments, in my opinion style(comments,readable, etc) is very important. This should be taken with a grain of salt cause most of my programming is personal, although I did write a little code here and there at work to make some of my jobs easier when I was working.

When I was younger the order was more than likely 1. Program works, 2. Program is efficient, 3. style

Then I started working and the order was more like. 1.program works, 2. program is done on time, 3. program is efficient, 4. style

as I worked more in oil and gas industry and now that I'm back in school it's more like 1. program is finished on time, 2. program works and style, 4. program is efficient. It seems to work for me cause I get 100% on my assignments....Except one I got 98%

PairO'Dice Lost
2012-11-05, 01:57 PM
If you ever intend to work in the software industry, get in the habit of commenting well, commenting thoroughly, and commenting often.

I'm currently working on a project involving an unholy synthesis of Java, C++, and third party C libraries comprised of over 200,000 lines of code all written by one person, who probably shouldn't have been allowed near our codebase in the first place. The code is so unintuitive and over-complicated that he was the only one who understood it all, he retired two weeks ago, and he didn't leave a single comment in any of the files. And now the new guy (yours truly) gets to try to rewrite that cluster**** to make it usable when we have a new release in less than a month. :smallfurious:

Even if you're just coding for fun, you will run into a situation where you see code without comments and hate the person who wrote the code, whether it's someone who wrote libraries or code samples on the internet or yourself-of-two-months-ago who thought yourself-right-now wouldn't need comments to remember how that one kludge worked. Comment, comment, comment.

Teddy
2012-11-05, 04:13 PM
My first university-level programming course (where we did functional programming), we had to be insanely meticulous with documentation, writing function specifications that usually were 2-3 times longer than the functions themselves for each and every function, no matter how insignificant or obvious nature. In the beginning I hated it, but toward the end, my views changed and I started to like the strict format. Except for writing the mandatory examples. Those were always a pain.

In my current course, however, we get specifications supposed to mimic those you get in the working life, i.e. ambiguous, missleading and possibly erroneous. I can't say that I like it, but hey, I suppose I'd better get used to it. And imperative/object-oriented programs aren't quite as easy to specify as functional ones...

Should still do some proper documentation of my own hobby projects. Especially since I have a tendency to drop them for several months before picking them up again...

Capt Spanner
2012-11-07, 12:58 PM
My first university-level programming course (where we did functional programming), we had to be insanely meticulous with documentation, writing function specifications that usually were 2-3 times longer than the functions themselves for each and every function, no matter how insignificant or obvious nature. In the beginning I hated it, but toward the end, my views changed and I started to like the strict format.

I'm of the school of thought that says by reading through a list of functions that make up a thing it should be obvious what it's doing without comments. The rationale for this is that the code may get changed, but leave the comments, which become out of date. (I know I've confused myself on my own projects with this...)

As an example:


float getCylinderVolume(Cylinder cylinder) {
return cylinder.height * getCircleArea(cylinder.circle);
}

float getCircleArea(Circle circle) {
return pi * circle.radius * circle.radius;
}

I suggest that the above is clearly understandable without comments, and furthermore, if you were to see "getCylinderVolume( pump[3] );" somewhere in the code you would have no problem figuring out what it does.

So why take up valuable screenspace and brain-cycles with comments that don't add anything?

This is how I got good marks with very few comments in my projects.

factotum
2012-11-07, 04:18 PM
That's self-documenting code, and it works to a degree. I still like to leave comments in my code so I remember myself what it's doing without having to figure it out from first principles, though!

Teddy
2012-11-07, 04:57 PM
I'm of the school of thought that says by reading through a list of functions that make up a thing it should be obvious what it's doing without comments. The rationale for this is that the code may get changed, but leave the comments, which become out of date. (I know I've confused myself on my own projects with this...)

[...]

I suggest that the above is clearly understandable without comments, and furthermore, if you were to see "getCylinderVolume( pump[3] );" somewhere in the code you would have no problem figuring out what it does.

So why take up valuable screenspace and brain-cycles with comments that don't add anything?

This is how I got good marks with very few comments in my projects.

The problem is that the more complicated the function, the longer the name will have to be to explain what it actually does. Especially in functional programming where not only do you write new functions at an alarming rate, but where the standard method for repetition is recursion as well.

For example, take the function that takes a list and returns the list (or rather, an identical copy of the list) in reversed order. Naming it is a trivial task, anyone can figure out what reverseList does. But recursive functions are terrible to the stack if you can't make them tail recursive. The arguments for reverseList doesn't allow for tail recursion (or recursion at all, for that matter), however, so you have to write a helper function that takes two lists and prepend the first in reversed order to the second, but what would you name that one? reverseListAndPrependToList? It's too long! reversePrependList? Decidedly unclear name, I wouldn't want to guess what this function does!

And that was only a simple example. What would you call the function that takes a function, a value and a list and calls the argument function with the element at the front of the list and the argument function called with the next element in the list and so on until you reach the function call with the last element in the list, where you instead use the argument value as an argument instead of calling the argument function yet another time? It took me six lines to describe, and I'm pretty sure it's completely illegible anyway. :smallwink:

Capt Spanner
2012-11-07, 07:14 PM
The problem is that the more complicated the function, the longer the name will have to be to explain what it actually does. Especially in functional programming where not only do you write new functions at an alarming rate, but where the standard method for repetition is recursion as well.

If a function is getting complicated, break it down into multiple, simple functions.


For example, take the function that takes a list and returns the list (or rather, an identical copy of the list) in reversed order. Naming it is a trivial task, anyone can figure out what reverseList does. But recursive functions are terrible to the stack if you can't make them tail recursive. The arguments for reverseList doesn't allow for tail recursion (or recursion at all, for that matter), however, so you have to write a helper function that takes two lists and prepend the first in reversed order to the second, but what would you name that one? reverseListAndPrependToList? It's too long! reversePrependList? Decidedly unclear name, I wouldn't want to guess what this function does!



LIST reverseList(LIST list) {
if( list.size() == 0 )
return list;
LIST returnedList;
addToBackOfList( returnedList, getItem( list, 0 ) );
removeItem( list, 0 );
return concatenate( returnedList, reverseList( list ) );
}


No confusingly named functions there.


And that was only a simple example. What would you call the function that takes a function, a value and a list and calls the argument function with the element at the front of the list and the argument function called with the next element in the list and so on until you reach the function call with the last element in the list, where you instead use the argument value as an argument instead of calling the argument function yet another time? It took me six lines to describe, and I'm pretty sure it's completely illegible anyway. :smallwink:

I'd use something based on "for_each" and describe the exact thing in problem space rather than solution space.

CreganTur
2012-11-08, 09:52 AM
Where are you and what are you doing in terms of programming? Employment, education or in your spare time?

I'm web master and lead (read: only) programmer/applications designer for an internal website for a major financial institution.
I'm completely self taught and have been programming for about 5 years now.

What language or languages are you using primarily at the moment? What's your favourite, and why?
ASP.NET is primary with C# and JQuery taking care of logic and scripting.
C# is my favorite by far.
I LOATHE pure Java. Can't stand how it handles objects.

Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
No real plans except hoping to one day quit my job and be a full time novelist.

Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?
My only personal project is an on-again-off-again project I'vee been working on for a while: a DM's toolbox that helps me track different things when I'm running a campaign.
The first version was an initiative and damage tracker for the Dragon Age RPG. I really need to rewrite it for the Pathfinder game I'm starting tonight...

What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?
Visual Studio 2010 is my preferred environment- the ability to drag a tab out of the shell and onto a different monitor is inspired. Too bad most of what I work on is still stuck in VS 2008.

Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?
The finer points of wbsite and server development escape me. Since I'm self taught, I know my code really well, but I don't have a broader view of things that most people who went to college for this have.

Teddy
2012-11-08, 06:07 PM
If a function is getting complicated, break it down into multiple, simple functions.
[...]
No confusingly named functions there.

The problem is that your code is imperative, not functional. Or at least not optimised functional. To give the code for the helper function in SML code:


fun reverse' ([], aList) = aList
| reverse' (rElem :: rList, aList) = reverse' (rList, rElem :: aList);

Extremely simple code (apart from the syntax, which might look a bit perplexing to those who don't know the language), but not self-documenting, and I've got the distinct feeling that self-documentation comes at the expense of optimisation...


I'd use something based on "for_each" and describe the exact thing in problem space rather than solution space.

Once again, to write the optimised function in SML:


fun foldr aFun aVal [aElem] = aFun(aElem, aVal)
| foldr aFun aVal aElem :: aList = aFun(aElem, foldr aFun aVal aList)

This is one of those functions that entire lectures are devoted to explain (because it's riddiculously useful), and it's still but a library function. You can make it work, but the time you'd devote to make it obvious is probably no less than the time it'd take to write a standardised function specification in the first place.

Also, two final issues with only relying on self-documenting code: 1. everyone else is completely at mercy of your own idea of self-documentation (either is everything obvious at the moment of writing, or you haven't got any idea of what you're doing in the first place), and 2. it doesn't work with encapsulation.

Wookieetank
2012-11-09, 10:47 AM
Maybe its just me, but python has me spoiled on reversing lists:


list = [thing1, thing2, thing3, etc]
list.reverse()

:smallbiggrin:

Teddy
2012-11-09, 11:28 AM
Maybe its just me, but python has me spoiled on reversing lists:

[...]

:smallbiggrin:

Nah, it's one of the most common library functions for one of the most common data structures. Name any programming language with a mediocre standard library or better, and I'd bet you that there exists a function for reversing lists in it. I just needed an example to work with.

Wookieetank
2012-11-09, 11:33 AM
Nah, it's one of the most common library functions for one of the most common data structures. Name any programming language with a mediocre standard library or better, and I'd bet you that there exists a function for reversing lists in it. I just needed an example to work with.

Fair enough.

pendell
2012-11-13, 01:01 PM
I'm of the school of thought that says by reading through a list of functions that make up a thing it should be obvious what it's doing without comments. The rationale for this is that the code may get changed, but leave the comments, which become out of date. (I know I've confused myself on my own projects with this...)

As an example:


float getCylinderVolume(Cylinder cylinder) {
return cylinder.height * getCircleArea(cylinder.circle);
}

float getCircleArea(Circle circle) {
return pi * circle.radius * circle.radius;
}


First question: What units are we using? To what precision?

That's frequently the issue I run into when reusing other people's homebuilt functions. I may know that, say, I want the time of sale. I see there's a function that returns DateOfSale. So: Is that a Java Date? Or is it an integer representing milliseconds? seconds? Something else?

I've reverse-engineered a LOT of legacy code written by people who thought "the code should be clear by itself without the need for comments and documentation" and the experience can be compared to being stabbed repeatedly in the eyes with white-hot needles. It's been my experience that "self-documenting" code works well on short lab projects, but when you're dealing with tens of thousands or hundreds of thousands of lines of code which has mutated over the course of several years, the code quickly becomes illegible. Say hello to the big ball of mud (http://en.wikipedia.org/wiki/Big_ball_of_mud).


This is doubly so because , in my experience, what is "clear and obvious" to one person is not at all to someone else.



I suggest that the above is clearly understandable without comments, and furthermore, if you were to see "getCylinderVolume( pump[3] );" somewhere in the code you would have no problem figuring out what it does.


In theory, that sounds good. In practice, what if getCylinderVolume() is overridden by multiple other subclasses? And what if getCylinderVolume() is obsolete code and the programmers have been using getCylVol() for the past year? Seen it happen.



So why take up valuable screenspace and brain-cycles with comments that don't add anything?


I'm not going to argue that most early CS courses take things to the opposite extreme of tacking on layer upon layer of wedding cake comments which are a burden to maintain and usually unhelpful. But I've also been on the receiving end of programmers (most) who don't believe in documentation at all.

I believe there is a happy medium, and that medium is best encompassed with the agile (http://en.wikipedia.org/wiki/Agile_software_development) approach. You don't want fifty lines of comments for even three-line functions. I typically write up a one-paragraph doc describing the module or class and 2 or 3 sentences describing individual methods if necessary. I can do this because I've got a lot of experience with reading other people's code and know what a maintainer needs to know.

So I think it best to strive for "just enough" documentation. Too much of it simply means people copy-paste doc templates without concern for any actual information, with the result that the code is full of decorative comment blocks of no use to anyone. Too little of it means that the code is incomprehensible. So I recommend one paragraph per class with an optional one or two sentences per method -- so long as the method is trivial.

For a non-trivial method, such as the one I currently write to calculate sales tax, the algorithm should be written out. It is a complicated algorithm and not easily readable, since different states have different sales taxes, different products are taxed at different rates, and some states have multiple sales taxes while others do not. Europe includes sales tax in the selling price but the US does not.

I could go on, but the code is extremely hard to read, even for me, the person who wrote it. So the algorithm must be written out with mathematical equations and English comments. But there's no need to keep this algorithm description in-line : An article on the project wiki will do just as well.

I hope you see what I'm getting at: No comments is bad, but comments as taught in intro CS are even worse because they typically result in useless copy-pasted comment blocks of no utility. So the trick is to put away only as much information as you absolutely need to make life easier on the maintainers. It's something agile does well, and it gets easier with experience.

Respectfully,

Brian P.

Balain
2012-11-18, 03:08 AM
I am totally stuck on the current assignment in computer science. Normally I can get it 80% working in the first day but not this time. Using python3 our program is to read a text file to make a dictionary(at least a dictionary is highly recommended so we can us keys like 'sun' instead of an index ), then use recursive functions to create output to be piped to a second program. the second program will draw a representation of the solar system.

the input file looks like:


Root Object: Sun

Object: Sun
satellites: Mercury,Venus,Earth,Mars,.....
Radius: 208937878
Orbital Radius: 0

Object: Moon
Orbital Radius: 25235235
Radius: 343442
period: 27.33532

Object: Earth
Orbital Radius: 32353523
period: 365.67
Radius: 532523
Satellites: Moon


There is no order to the listing of planets and moons.

I was thinking of creating a nested dictionary like



s={'sun':{'earth':{'moon':{'radius':3242,'orbit':3 72384,'period':35235},{'radius':343234..........}} }


the idea was I could call s['sun']['earth']['moon'] I haven't been able to get the input into a dictionary like that yet though.

Then I thought of using named tuples but that wasn't getting me anywhere either.

Anyone have any ideas on where to start better than I have had?

factotum
2012-11-18, 03:33 AM
I'm not at all familiar with python, but what you need is some sort of hierarchical data structure--I doubt a standard array would fit that bill, you might have to hand-roll something.

Teddy
2012-11-18, 06:39 AM
I don't know enough Python to give you any code, but I suggest you create an object to represent a celestial body, and then let it hold the body's satellites as a list of celestial bodies together with any other information you have of the body (radius, orbital radius, period, a string for easy searching...).

This way, you'll create a tree of celestial bodies with the sun as the root, the planets as intermediate branches and the moons as leaves (you can even give the moons satellites if you feel like it). Trees are easy to merge, so you can create a new tree for each body which you don't know where it goes (take the Moon, for example), and insert at the correct place later. On top of that, trees work very well with recursive functions, which is an added bonus for you.

shawnhcorey
2012-11-18, 08:38 AM
I don't know enough about Python to get the nomenclature correct but in my favourite language, Perl, this is how I'd do it:

#!/usr/bin/env perl

use 5.010;
use strict;
use warnings;

# --------------------------------------
use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
local $Data::Dumper::Maxdepth = 0;

# --------------------------------------


my %solar = ();

my $object = '';
while( <DATA> ){
chomp;
next unless /:/;

my ( $tag, $value ) = split /\s*:\s*/, $_, 2;
$tag = lc( $tag );

if( $tag eq 'object' ){
$object = $value;
}

if( $tag eq 'satellites' ){
$value = [ split /\s*,\s*/, $value ];
for my $sat ( @$value ){
$solar{$sat}{orbits} = $object;
}
}

$solar{$object}{$tag} = $value;
}

print Dumper \%solar;

__DATA__

Object: Sun
satellites: Mercury,Venus,Earth,Mars,.....
Radius: 208937878
Orbital Radius: 0

Object: Moon
Orbital Radius: 25235235
Radius: 343442
period: 27.33532

Object: Earth
Orbital Radius: 32353523
period: 365.67
Radius: 532523
Satellites: Moon


It gives the result:

$VAR1 = {
'.....' => {
'orbits' => 'Sun'
},
'Earth' => {
'object' => 'Earth',
'orbital radius' => '32353523',
'orbits' => 'Sun',
'period' => '365.67',
'radius' => '532523',
'satellites' => [
'Moon'
]
},
'Mars' => {
'orbits' => 'Sun'
},
'Mercury' => {
'orbits' => 'Sun'
},
'Moon' => {
'object' => 'Moon',
'orbital radius' => '25235235',
'orbits' => 'Earth',
'period' => '27.33532',
'radius' => '343442'
},
'Sun' => {
'object' => 'Sun',
'orbital radius' => '0',
'radius' => '208937878',
'satellites' => [
'Mercury',
'Venus',
'Earth',
'Mars',
'.....'
]
},
'Venus' => {
'orbits' => 'Sun'
}
};


I use an associative list to store each object and its data. Its satellites as stored as an anonymous array. I also added code to include the object each one orbits. :smallsmile:

Neftren
2012-11-18, 04:47 PM
Here's a quickie Python (2.7) solution. Depending on your assignment, there's probably a more clever way of handling this, but I'll leave that for you to figure out (small hint: regular expressions and string splitting). I'm not sure where the recursion bit fits in though.


# Planet Class
class Planet():
name = ''
satellites = {}
radius = 0
orbit = 0
period = 0

# Program Data Structures
solar = Planet()
system = []

# Open and Parse the Input File
input = open('input.txt')
for data in input:

# Linebreak Triggers New Stellar Object
if data[0:] == '\n' and solar.name != '':
system.append(solar)
solar = Planet()

# Parse Search Queries by Substring for Object Data
elif data[:6].lower() == "object": solar.name = data[8:-1]
elif data[:14].lower() == "orbital radius": solar.orbit = data[16:-1]
elif data[:10].lower() == "satellites": solar.satellites = data[12:-1]
elif data[:6].lower() == "radius": solar.radius = data[8:-1]
elif data[:6].lower() == "period": solar.period = data[8:-1]

system.append(solar) # Append the Last Stellar Body
input.close() # Close the Input File

# Iterate and Print Object Data
for i in system:
print "Object: " + str(i.name)
print "Satellites: " + str(i.satellites)
print "Radius: " + str(i.radius)
print "Orbit: " + str(i.orbit)
print "Period: " + str(i.period)
print "\n"


http://i.imgur.com/yl5J5.png

You'll have to make modifications depending on how your input/output needs to be structured.

Balain
2012-11-18, 05:21 PM
Cool, Thanks for all the help guys :smile:

TSGames
2012-11-18, 06:30 PM
Speaking of Python, I just got it up and running on my Android device. I can now program in python and compile into an APK ob the device. I'm pretty stoked about it. =D

It also has the bonus feature (unwanted side effect) of allowing me to do the same with Java programs.

Lord Loss
2012-11-20, 10:01 PM
Me and my friend were thinking of creating a self-improving program. We were wondering just how insanely difficult this would be. I have little knowledge of computer programming, and he's studied it for a year in school + some more out of school (we're in our last year of highschool). The idea would be to create a program that completes a simple task, then have it create a slightly modified version of its own code, then running most versions of the program. Whichever achieves the correct result the fastest would be kept, whilst the other would be discarded.

Thoughts? Advice?

shawnhcorey
2012-11-20, 10:07 PM
See genetic programming (http://en.wikipedia.org/wiki/Genetic_programming).

Ashtar
2012-11-21, 06:23 AM
You could say that the current javascript engines in browsers fit that criteria for "self-improving", since as they execute javascript code, they optimize it and use the result immediately. For example, V8 in Google chrome (http://en.wikipedia.org/wiki/V8_(JavaScript_engine)).

So it is possible to do it, mostly the self-improvement comes from compilation techniques: code branch prediction, dead variable elimination, ...

In certain cases, a compiler (Emscripten (https://github.com/kripken/emscripten/wiki)) can self-improve by compiling itself again (http://mozakai.blogspot.ch/2012/11/emscripten-compiler-upgrades.html), a recent example was highlighted on slashdot (http://developers.slashdot.org/story/12/11/12/2327224/emscripten-compiler-gets-optimizations-now-self-hosting) the other day.

Gryffon
2012-11-21, 08:26 AM
Speaking of Python, I just got it up and running on my Android device. I can now program in python and compile into an APK ob the device. I'm pretty stoked about it. =D

It also has the bonus feature (unwanted side effect) of allowing me to do the same with Java programs.

Do you have a link to a good resource for this? I'd be interesting in doing some Python for Android.

akma
2012-11-21, 02:50 PM
Speaking of Python, I just got it up and running on my Android device. I can now program in python and compile into an APK ob the device. I'm pretty stoked about it. =D

It also has the bonus feature (unwanted side effect) of allowing me to do the same with Java programs.

What program did you use? Is it any good?
(I don`t know Python, but I know java)



*self improving software*

I don`t know anything about the topic, but I think that you would have to be extremly carefull not to create a very buggy program, as the consequences would be very hard to predict.

Balain
2012-11-22, 03:04 AM
solar system assignment again in python3. I started going with a the planet class , but talking with the TA that marks it, I would lose marks because the assignment says I should use a dictionary. So I got it creating my dictionary okay, which ends up looking like:



solar=
{
'root': Sun

'Sun': {'Satellites': ['Mercury', 'Venus', 'Earth'......], 'r':# , 'or': 0.0}

'Earth': {'Satellites': ['Moon'], 'r':# , 'or':#, 'p':#}

'Moon': {'r':#, 'or':#, 'p':#}

}



The radius('r') and orbital radius('or') are scaled to fit the screen resolution we have.

We pipe the output of our program to another program that will draw the solar system. We should use a recursive function to draw the sun,planets, moons, commits, etc. Some objects maybe listed as a satellite, but not exists as a dictionary entry.

I think I'm missing a logic step somewhere. My small sample with just the sun, earth moon prints the sun the earth orbit and earth but no moon. My large sample seems to print all the objects around the sun with their orbits and some of the moons (Jupiter's moons for sure). I'm super tired so I'm sorry if I'm missing something real stupid.

Here is the function:



#x,y are centre of screen
#solar is the dictionary
def draw_system(x,y,solar):

#draw the sun/planet/moon

print('fillcircle', x,y,solar[solar['root']]['r'])
print('text', solar['root'],x+solar[solar['root']]['r'],y+solar[solar['root']]['r'])

#if the root object has satellites draw orbits

if 'Satellites' in solar[solar['root']]:

for s in solar[solar['root']]['Satellites']:

#some objects in satellite list may not exists in dictionary
#if it does print the orbit around root object

if s in solar:
print('circle', x,y,solar[s]['or'])

for s in solar[solar['root']]['Satellites']:

#if the satellite exists in the dictionary change
#the root in dictionary to new root

if s in solar:
solar['root']=s

#call function with new x,y and dictionary with new root

draw_system(x,y+solar[s]['or'],solar)


and yes for now the x co-ordinate isn't changing I don't have the loops set up to draw the rotations I just want to make sure everything is drawing to the correct starting spot first.

Teddy
2012-11-22, 09:48 AM
Something looks amiss with the for loop toward the end. The if statement, which I assume is supposed to be inside the loop, isn't indented, and if I remember what little I know of Python correctly, won't that mean that it's executed outside the loop?

Even if this is the case, I fail to see how this would cause the bugs you're experiencing (given, an undefined behaviour can do the wierdest things). Do you have access to a debugger with which you can step through the code and find out hwere the bugs appear?

Balain
2012-11-22, 04:29 PM
Sorry the indenting wasn't like that in my code, it's how I copy and pasted it into here. I edited my last post so it looks better.

So far I have been doing this old school and just using vi. Although I have been thinking of downloading eclipse.


Well it's a new day and classes are done and the due date has been extended by 32 hours so hopefully I get it solved this afternoon.

OKay the problem wasn't with that function as far as I can tell. The problem is some of the moon have an extra space in the key so they get missed. back to creating the dictionary correctly.

akma
2012-11-23, 12:08 AM
I have a problam with regular expressions in Java.
The program gets a string representing a mathmatical formula (a+b-3, for exemple), then you put values for the variables (possible 2 for a and 4 for b), and a method in the class returns the result (in this exemple, 3). I had a version that crashed in certain conditions due to bad design, so I commented out everything and started again.

After doing some modifications to the formula (converting from ab to a*b), I try to isolate the oparaters using String.split("[a-zA-Z0-9]"). This returns a String array, which always contains empty strings. I can bypass that, but I rather know why I get empty strings, and how to avoid it in the future.

Balain
2012-11-24, 02:31 PM
Never mind I figured out my problem walking to the store lol

Incase any one actually cared what my problem was I spoiled it

one more question about my assignment.
I have it working but would like to change the labels to be printed along
the side with a line pointing to each object as it moves.
This is in python3

so I have the following functions:



def draw_label(x,y,name,i):
#print commands to draw labels in quickdraw window

#print name along the left side of the quickdraw window
# and i*50 pixels from the top of the quickdraw window
print('text' name, 700,i*50)

#print line from the name to the centre of the object
print('line' , 700,i*50, x,y)


(the next is very similar to the on in my previous post but I will shorten it
to some pseudo code here)



def draw_system(x,y,solar,t,i=0): #if i has no value set it to 0

#do a bunch of calculations to x and y
x = x*trig functions
y = y* trig functions

i = i +1
#print the object to quick draw
print('fillcircle', x,y, radius)

#call the draw label function
draw_label(x,y,object name,i)

#some loops to draw orbits
for loop
do stuff

for loop #loop to get next object to be printed
print(stuff)
solar[rootobject]=[next root object]
#recursive function call
draw_system(x,y,solar,t,i) #should be i+=1



When I use my small sample (Sun, earth, moon)it prints the solar
system okay and the labels seem to be okay

when I use my large sample it prints the solar system okay the sun label is
okay but further down there is a bunch of labels printed on top of each
other and further down another mess of labels.


Example:

Sun


jumbled mess1


jumbled mess2

I can't make anything out in each jumbled mess but my guess is
the first is planet names and second is moon names.
What am I missing to get each name printed 50pixels from each other?

Balain
2012-12-03, 08:45 PM
I'm working on my last assignment in python3. and running into an index out of range error, and I'm not seeing why.

factotum
2012-12-04, 03:02 AM
Sounds like a common or garden off-by-one error. In C, for example, array bounds start at 0, so it's a very common mistake for someone to declare an array with 8 elements and then try to access an element numbered 8, whereas the elements are actually 0 to 7. (Worse still, in C the compiler will usually let you get away with it, so you'll be reading or writing whatever happens to be in memory just beyond the end of your array!). Is Python similar?

Teddy
2012-12-04, 06:02 AM
It seems like you allow i and j to increment above the greatest indices of the arrays, which could be a cause of your out of range error. What confuses me is that it doesn't crash for any other moves than those at the last row/column...

Balain
2012-12-05, 04:46 PM
My understanding of for loops in python is, when I do


for i in range(8)
, it should start at 0 and go to 7 the 8 is not included.

I tried changing my loop to 7 instead of 8, it doesn't get the error but I can't pick the last row or column.

Our TA gave us a website that may help going to go over it right now.

Teddy
2012-12-05, 06:19 PM
Playing around with Python a bit, I now think I know what your problem is caused by. The error lies just where I thought it was, but it turns out that negative indices let you index from the end of a list in Python, which is why it isn't triggered when you click any other square, which is what confused me in the first case.

To clarify, I've marked the flawed parts of your code in red:



delta = [[0,-1],[1,-1],[1,0],[1,1],[0,1],\
[-1,1],[-1,0],[-1,-1]]



def play_move(self, move):
m,n=move[0],move[1]
for d in range(8):
i, j = m, n
if self.check_move(move,d):
i, j = i+self.delta[d][0], j+self.delta[d][1]
while self.board[i][j] == 1-self.turn:
self.board[i][j] = self.turn
i, j = i+self.delta[d][0], j+self.delta[d][1]
self.board[m][n]=self.turn


When m or n is 7, i or j will for some d become 8, causing a list index out of range error to be thrown. This normally never occurs, because due to the above mentioned list oddity, you'll already have reversed (or whatever you call it. I don't know reversi) any tile to the right or below the clicked one, causing the loop to terminate before any offense has happened (I'm not sure what will happen if you keep playing, however), but when you click somewhere in the last row or column, the red line will increase the index before any tests can be made to break the bad habit.

I suggest you change the blue line to this:



while i != -1 and i != 8 and j != -1 and j != 8 and self.board[i][j] == 1-self.turn:


This will cause the loop to break before testing a too large or negative index (as I suspect you don't want it to crawl over the edge to the left and reappear to the right, which is what it should be doing right now).

Balain
2012-12-05, 07:30 PM
Yeah I added some print statements and was watching that. The problem is, the instructions are I can't change any of functions or methods except get_moves, check_moves and select_move. I will make those changes for now for the simple test.

Once I get the basic(no rules) working I'll work on check_move to return false and true with real reversi rules.

Thank you very much for taking time to look over my code :smallsmile:

Balain
2012-12-06, 07:50 PM
Ughh...I hate trying to work on assignments while I'm sick, my concentration sucks and so does my logic it seems.

I think I have fixed my problems except one and I don't see the problem...Python is saying I have an indentation error at the blue line and I don't see it...


Edit: okay found that problem too I think I'm done...

Miscast_Mage
2012-12-12, 08:32 AM
Just something I'm wondering with Java; is there a way of getting the name of a variable to a String? e.g., say I have


public int number = 5;


Is there some way of accessing the variable number by using a String called number?

Here's a bit of pseudo-code as to what I'm looking for:



public class Test
{
public int number = 5;
public int anotherNumber = 2;

public int getVariable(String input) //input in this case is "number"
{
//take in String, "number"
//find variable with the name number
//returns the int variable number
}
}


Though something I just realised was the return type, though you could around this by just having different methods, e.g. getStringVariable, getIntVariable, getBooleanVariable, etc.

I've done this before with a switch statement, like this:



protected Stat str = new Stat("str"); //stats
protected Stat dex = new Stat("dex");
protected Stat con = new Stat("con");
protected Stat ine = new Stat("int");
protected Stat wis = new Stat("wis");
protected Stat cha = new Stat("cha");

public Stat getStat(String choice)//takes in choice, returns specific stat
{
switch(choice.toLowerCase())
{
case "str":
return str;
case "dex":
return dex;
case "con":
return con;
case "int":
return ine;
case "wis":
return wis;
case "cha":
return cha;
default:
return null; //only returns if invalid string is entered
}
}


But I'm wondering is there some automated way of doing this so that I don't have create a switch statement that encompasses all the variables I want?

AlterForm
2012-12-12, 11:38 AM
According to a couple (http://stackoverflow.com/questions/1063543/how-to-get-variable-names-at-runtime) questions (http://stackoverflow.com/questions/744226/java-reflection-how-to-get-the-name-of-a-variable) on StackOverflow, no, it's not possible to get a variable name at runtime. (In Java)

I would suggest looking at using a HashMap<String, int>, or possibly HashMap<enum, int>. You may need to use Integer instead of int; I'm a little fuzzy on whether Java stores primitives as references or as values.

Thus your code would become:



public class Test
{
private int number = 5;
private int anotherNumber = 2;
private HashMap<String, int> attribs;

public Test(){
// Little rusty on the syntax here; you get the idea
attribs.put("number", number);
attribs.put("anotherNumber", anotherNumber);

public int getVariable(String input) //input in this case is "number"
{
return attribs.get(input);
}
}


All this is predicated on there not being a better data structure for your code than a String -> int mapping. (Which I suspect there is, since if you have a string that unambiguously refers to a particular variable at compile time, you may as well just write a getter/setter pair)

[EDIT]: Reviewing what the SO threads and what Akma posted below, it seems you can get at a variable's name at runtime. It's just a Very Bad IdeaTM.

akma
2012-12-12, 12:13 PM
There is a way to get the variable name from a String, but it`s not recommended*
Relevent link: http://docs.oracle.com/javase/tutorial/reflect/index.html

Basically, this is how you would do this:
Class clazz = instance.getClass(); //method inherited from Object
Field field = clazz.getField("field name");
(you can also get a Class instance for primitive types and void, but that`s more complicated)

There are also similiar methods to get methods and constructors, including private methods, changing final variables, etc.

*Reflective code is slower to execute then regular code, and there are more exceptions you would have to manage. It`s better to avoid it whenever possible (for exemple case: "method3" this.method3();)

Teddy
2012-12-12, 12:56 PM
I would suggest looking at using a HashMap<String, int>, or possibly HashMap<enum, int>. You may need to use Integer instead of int; I'm a little fuzzy on whether Java stores primitives as references or as values.

Yes, you must write Integer instead of int. And you can't write enum just like that either, you need to specify a specific enum for it to work (just clarifying).

Otherwise, yes, I'd say a Map is indeed the best structure, and a HashMap is probably the best choice for strings, but as already has been said, if you only need a limited and well known set of named variables, a parser combined with getters and setters will probably work just as well.

Neftren
2012-12-23, 07:33 PM
So... Version Control (specifically: GitHub).

I was looking into bundling code from other libraries into my own projects, and stumbled across Git submodules. Unfortunately, everything I'm reading about them makes it sound as if they're completely half-baked, and horribly unwieldy. Anyone have any thoughts on them, or perhaps suggestions as to alternatives?

Miscast_Mage
2013-01-02, 04:58 AM
So, I want to start learning how to build/use databases in Java; just looking for any guides or info useful for someone who hasn't used databases before, but does anyone have any recommendations? Is there any particular one I should go for (MySQL/JDBC/etc)?

factotum
2013-01-02, 07:37 AM
JDBC isn't a database in its own right, as far as I know--it's a method for connecting to a database from Java. As far as databases are concerned, what OS are you targeting? The freebie SQL Server Express is Windows-only, but it gives you better tools to work with than MySQL does. I have no experience with PostgreSQL or Oracle, sorry.

The Succubus
2013-01-02, 07:58 AM
A question for y'all.

I'm thinking about a career change to the wonderful world of IT but I'm not sure what would be an appropriate starting qualification to aim for. I've got a fair amount of PC knowledge - installing OSes, mucking around with drivers, fixing new hardware - a gamer's toolkit basically. A friend suggested a Comp TIA A+ course or possibly the Linux+ version. I've also been looking at the CCNA but I fear it might be a little too advanced.

Can any UK playgrounders offer me advice?

Neftren
2013-01-02, 03:48 PM
So, I want to start learning how to build/use databases in Java; just looking for any guides or info useful for someone who hasn't used databases before, but does anyone have any recommendations? Is there any particular one I should go for (MySQL/JDBC/etc)?
JDBC isn't a database in its own right, as far as I know--it's a method for connecting to a database from Java. As far as databases are concerned, what OS are you targeting? The freebie SQL Server Express is Windows-only, but it gives you better tools to work with than MySQL does. I have no experience with PostgreSQL or Oracle, sorry.

There probably isn't a way to get around using some form of SQL. I've heard good things about MariaDB (https://mariadb.org/), though I don't have any firsthand experience with it.

factotum
2013-01-02, 04:31 PM
I'm thinking about a career change to the wonderful world of IT

This is the point where I have to run up and knock you into unconsciousness to prevent you making such a ghastly mistake, isn't it? :smallwink:

Seriously, can't offer too much advice because my route into the IT world was rather unorthodox--my degree is in Electrical and Electronic Engineering, and I then spent nearly a decade programming for a living before heading into the world of sysadmin. A lot of IT and programming work is getting outsourced to India nowadays, too, so the job prospects aren't as good as you might like them to be.

Emmerask
2013-01-02, 05:03 PM
This is the point where I have to run up and knock you into unconsciousness to prevent you making such a ghastly mistake, isn't it? :smallwink:

Seriously, can't offer too much advice because my route into the IT world was rather unorthodox--my degree is in Electrical and Electronic Engineering, and I then spent nearly a decade programming for a living before heading into the world of sysadmin. A lot of IT and programming work is getting outsourced to India nowadays, too, so the job prospects aren't as good as you might like them to be.

Well at least in Germany there are about one trillion job offers for programmers (mainly php, android, iphone and java stuff)

Recaiden
2013-01-04, 01:22 PM
I would suggest looking at using a HashMap<String, int>, or possibly HashMap<enum, int>. You may need to use Integer instead of int; I'm a little fuzzy on whether Java stores primitives as references or as values.

Values, which is why you have to wrap it in an Integer class instead of just using it (I think. It might actually just require classes for the templates).

Razanir
2013-01-07, 02:16 PM
How do I run php programs from the command line? And before you ask, I'm using Windows 7

Grinner
2013-01-07, 04:26 PM
How do I run php programs from the command line? And before you ask, I'm using Windows 7

Have you got a PHP server set up?

factotum
2013-01-07, 05:41 PM
I'm not overly familiar with PHP, but if you just have a standalone program I'm pretty sure you can run it by prefacing it with the name of the PHP interpreter EXE, e.g. something like:

PHP my_program.php

If it's something that's designed to work on a web server then you'd need one set up in order to run the program, which is a massively complicated topic.

Grinner
2013-01-07, 05:51 PM
If it's something that's designed to work on a web server then you'd need one set up in order to run the program, which is a massively complicated topic.

MoWes Portable (http://www.chsoftware.net/en/mowes/mowesportable/mowes.htm) was extremely easy to setup. You just select which packages you want on the download page and unzip the download.

I don't think it's made to handle the demands of an actual server, but it more than suffices for the purposes of learning PHP.

Razanir
2013-01-07, 05:59 PM
How do I set it up for executing from the command line? I set up a small local server to run programs off of, but my class requires it to work correctly from the command line

Grinner
2013-01-07, 06:42 PM
How do I set it up for executing from the command line? I set up a small local server to run programs off of, but my class requires it to work correctly from the command line

Have you added php.exe's directory the the PATH environment variable?

Razanir
2013-01-07, 08:06 PM
Have you added php.exe's directory the the PATH environment variable?

I tried that. Didn't work. BUT, I found a brute force solution.


>cd "C:\php"
>php "[insert file path here]"

The Succubus
2013-01-10, 05:29 AM
Back again,

With a little luck, I should have my Linux Mint OS set up on my second hard drive this weekend and I was advised by someone that learning Python could be beneficial when messing around in Linux.

Do any of you know much about Python as a language? Is it fairly simple to understand and use? How does one go about compiling it, etc?

It's been years since I last did coding - it'll be fun to put my programming hat back on again, even briefly. =)

Teddy
2013-01-10, 05:46 AM
Back again,

With a little luck, I should have my Linux Mint OS set up on my second hard drive this weekend and I was advised by someone that learning Python could be beneficial when messing around in Linux.

Do any of you know much about Python as a language? Is it fairly simple to understand and use? How does one go about compiling it, etc?

It's been years since I last did coding - it'll be fun to put my programming hat back on again, even briefly. =)

I know practically nothing, but thankfully, it's a very simple language if you know any other object-oriented (or at least imperative) programming languages, so with some help from the API, I can hack together simple scripts without too much hassle anyway. The only real quirk as I see it is its somewhat off-standard indentation rules.

I'm not sure about compiling, my experiments tells me Python uses an interpretter rather than a compiler. Either way, to start programming, install Python on your computer, open a plain text document (.txt), write your program and save it as a .py file. Then you can run it from the command line by writing "python filename.py" (you may have some problems with finding either Python or the file, in which case I suggest calling the command from Python's directory and using the full file path rather than just the filename).

The Succubus
2013-01-10, 06:06 AM
My previous programming experience consists of some vaguely remembered Pascal lessons from my Computer Studies A-level, some self taught Visual Basic that almost caused me to fail my A-level* and some Amstrad Basic from the days when I thought getting my CPC to spam rude words over and over was the pinnacle of programming skill. ^_^

10 PRINT "[REDACTED]"
20 GOTO 10

Computers were magic boxes back when I was six. They still are sometimes. :smallsmile:

* I bet you're curious now, aren't you....;)

factotum
2013-01-10, 07:44 AM
If you definitely want to look at Python then I'm sure there are Windows interpreters available for it. Isn't PHP the usual language used, though? Pretty sure that's what the P in LAMP (Linux, Apache, MySQL, PHP) is...

Also, why are you putting Linux on a second drive? That has the disadvantage you have to reboot your machine to use it. If all you're doing is looking at Linux programming then it would be more efficient to install something like VirtualBox and create yourself a Linux virtual machine; you could run such a thing at the same time as your Windows installation. You'd need a bit more RAM to do this, but Linux doesn't require that much so a spare gig would be enough for most things. (You can also use the WUBI version of Ubuntu if you want to run Linux under Windows--works quite well).

Of course, if there are specific reasons why all this has to be the way you've described, ignore me... :smallsmile:

The Succubus
2013-01-10, 08:06 AM
If you definitely want to look at Python then I'm sure there are Windows interpreters available for it. Isn't PHP the usual language used, though? Pretty sure that's what the P in LAMP (Linux, Apache, MySQL, PHP) is...

Also, why are you putting Linux on a second drive? That has the disadvantage you have to reboot your machine to use it. If all you're doing is looking at Linux programming then it would be more efficient to install something like VirtualBox and create yourself a Linux virtual machine; you could run such a thing at the same time as your Windows installation. You'd need a bit more RAM to do this, but Linux doesn't require that much so a spare gig would be enough for most things. (You can also use the WUBI version of Ubuntu if you want to run Linux under Windows--works quite well).

Of course, if there are specific reasons why all this has to be the way you've described, ignore me... :smallsmile:

I'd like to learn to use Linux au naturalle, as it were. To learn how it works on a real hard drive, with real PC components, to learn how to do Linux driver troubleshooting, and maybe even learn how to compile kernals and do custom setups.

The reason I want to do it on a second disk is because if it all goes fruit-shaped as it inevitably will, the SSD with Windows on will be unscathed and fine. Besides, partitioning hard disks is a bitch, I've found. -.-

I'll be using Linux from time to time, rather than constantly because although a fair percentage of the games I play work in Linux, not all of them do sadly, so I still need a fully working Windows PC for most of the time. However, I'll be looking to do as much as I can in Linux though. =)

Teddy
2013-01-10, 08:44 AM
If you definitely want to look at Python then I'm sure there are Windows interpreters available for it.

Are you thinking of IDE interpretters? Because, as I said, Python (http://www.python.org/download/) itself is an interpretter, but it lacks an IDE in and on itself.

Wookieetank
2013-01-10, 09:31 AM
I'd like to learn to use Linux au naturalle, as it were. To learn how it works on a real hard drive, with real PC components, to learn how to do Linux driver troubleshooting, and maybe even learn how to compile kernals and do custom setups.

The reason I want to do it on a second disk is because if it all goes fruit-shaped as it inevitably will, the SSD with Windows on will be unscathed and fine. Besides, partitioning hard disks is a bitch, I've found. -.-

I'll be using Linux from time to time, rather than constantly because although a fair percentage of the games I play work in Linux, not all of them do sadly, so I still need a fully working Windows PC for most of the time. However, I'll be looking to do as much as I can in Linux though. =)

If you haven't found it, or had it suggested yet, definitely check out wine for getting games to run in Linux. Some games take a lot of effort with all the extra bits you have to do to get them to run properly, but for the most part it greatly increases the number of games you can get to run in Linux without too much hassle.

As for python, I find it to be a very fun language to use, and very straight forward. I'm still learning it myself, but compared to what I do know (C++ and some C) it seems less messy, at least syntacticly. For instance:

Python:

print "Hello world!"

C:

#include<stdio.h>

int main(void)
{
printf("Hello World!");
}

It does get a bit interesting when you try to turn python files into .exe but there's oodles of online resources for python. Also depending on what you want to do with python, I know a number of good tutorial sites if you're interested (everything from an in browser compiler to how to program a rougelike).

The Succubus
2013-01-10, 09:45 AM
Oooo, yes please! I'd love some links like that! If you know any good Python books as well, I have a book token in urgent need of using. =3

I also understand there's a Linux version of Dungeons of Dredmor too....;)

Leolo
2013-01-10, 10:17 AM
I have a problam with regular expressions in Java.
The program gets a string representing a mathmatical formula (a+b-3, for exemple), then you put values for the variables (possible 2 for a and 4 for b), and a method in the class returns the result (in this exemple, 3). I had a version that crashed in certain conditions due to bad design, so I commented out everything and started again.

After doing some modifications to the formula (converting from ab to a*b), I try to isolate the oparaters using String.split("[a-zA-Z0-9]"). This returns a String array, which always contains empty strings. I can bypass that, but I rather know why I get empty strings, and how to avoid it in the future.

You mean like this?



String test="a*b-c/d";
String[] split = test.split("[a-zA-Z0-9]");
int ctr=0;
for(String s:split){
System.out.println("operator "+(++ctr)+": "+s);
}


The reason why (the first) element of the array is empty is that you have set all letters and numbers as split argument. It is as if you would split a comma seperated text into an array that starts with a comma. So ";a;b;c".split(";") results in [],[a],[b],[c]

Same is true if your variables are more than one char long. So "way/time=speed".split("[a-zA-Z0-9]"); would result in

operator 1:
operator 2:
operator 3:
operator 4: /
operator 5:
operator 6:
operator 7:
operator 8: =

A better way to do this would to first split the text into blocks of brackets recursive until no brackets exist. So

"(1+a)*(10/(-b+2))" would become ["1+a",["10/","-b+2"]]

When you have found an text without brackets split this into blocks of plus or minus (recursive, until no plus or minus exists) and replace every empty element with 0.

So you now got:
[["1","a"],[["10/"],["0","b","2"]]]

now you replace all variables (for example with 2 and 3) and use the operators of the deepest level (that's because you should do this recursivly) so 0-3+2= -1

You replace this level and get:
[["1","a"],["10/","-1"]]

Now you calculate those next levels. So 10/-1 is minus 10 and 1+2 is 3.

You get ["3","-10"] and calculate this with the operator "*". The solution is -30.

Teddy
2013-01-10, 10:46 AM
As for python, I find it to be a very fun language to use, and very straight forward. I'm still learning it myself, but compared to what I do know (C++ and some C) it seems less messy, at least syntacticly. For instance:

Python:

print "Hello world!"

C:

#include<stdio.h>

int main(void)
{
printf("Hello World!");
}

Given, both #include and main are lines that'll take up less than a percent of any larger project, and the added parantheses are just as much of a hassle as the indentation rules for Python, i.e. no a lot.

Also, unlike C, Python was developed as a scripting language, and sacrifices large scale performance for lower developement times.

Wookieetank
2013-01-10, 10:52 AM
Oooo, yes please! I'd love some links like that! If you know any good Python books as well, I have a book token in urgent need of using. =3

I also understand there's a Linux version of Dungeons of Dredmor too....;)

In Browser Tutorial (http://www.trypython.org/#)

How to make a Roguelike (WARNING: site also contains a rather comprehensive list of all roguelikes) (http://roguebasin.roguelikedevelopment.org/index.php?title=Complete_Roguelike_Tutorial,_using _python%2Blibtcod)

Two books on making games with python and pygame (http://inventwithpython.com/)

Pygame homepage (also has links to how tos) (http://pygame.org/news.html)

The obligatory everything python (http://python.org/)

As for actual books, I'm not sure of what to get. Once I can get to my jump drive though I do have a number of ebooks that might be useful, I'll post the names once I find them.

Grinner
2013-01-10, 12:03 PM
How about these for starters? *

Think Python (http://greenteapress.com/thinkpython/thinkpython.html)
The Python Game Book (http://thepythongamebook.com/en:start)

*Full disclosure: I don't actually know Python. I'm merely regurgitating suggestions made in another thread; I think Rawhide suggested one of them too.

Neftren
2013-01-10, 12:11 PM
Back again,

With a little luck, I should have my Linux Mint OS set up on my second hard drive this weekend and I was advised by someone that learning Python could be beneficial when messing around in Linux.

Do any of you know much about Python as a language? Is it fairly simple to understand and use? How does one go about compiling it, etc?

It's been years since I last did coding - it'll be fun to put my programming hat back on again, even briefly. =)

If you're looking to do Linux programming, you should consider looking at C/C++ as well. Most of the Linux kernel is written in C, though I hear the ancient Linux Wizards (Torvalds and the like) wrote in straight Assembly... :smalleek:

As a language, I love Python. It's excellent for its simplicity, both to pick up and use. Python is an interpreted language (so, everything evaluated in sequence at runtime), and Python is frequently called a scripting language. Some more complex packages will automagically compile your Python files (*.py) into bytecode files (*.pyc), which are wholly unintelligible to your text editor, but run much faster. :smallbiggrin:


I know practically nothing, but thankfully, it's a very simple language if you know any other object-oriented (or at least imperative) programming languages, so with some help from the API, I can hack together simple scripts without too much hassle anyway. The only real quirk as I see it is its somewhat off-standard indentation rules.

I'm not sure about compiling, my experiments tells me Python uses an interpretter rather than a compiler. Either way, to start programming, install Python on your computer, open a plain text document (.txt), write your program and save it as a .py file. Then you can run it from the command line by writing "python filename.py" (you may have some problems with finding either Python or the file, in which case I suggest calling the command from Python's directory and using the full file path rather than just the filename).
Given, both #include and main are lines that'll take up less than a percent of any larger project, and the added parantheses are just as much of a hassle as the indentation rules for Python, i.e. no a lot.

Also, unlike C, Python was developed as a scripting language, and sacrifices large scale performance for lower developement times.

Someone keeps telling me there's a library out there that can (re)compile Python code that executes faster than a C program equivalent. PyPy I think? I haven't personally tried it, but compilation does exist... in a way (outside of compiling to Bytecode, similar to Java).

Since this is Linux, Python should be installed by default into /usr/bin/pythonXY or something along those lines, and should be accessible on the default environment variables path (e.g. type "python" in your shell and a python interpreter should appear). If for some reason it isn't, you'll have to go looking for it ('which python') and then add it to your environment variables.


If you definitely want to look at Python then I'm sure there are Windows interpreters available for it. Isn't PHP the usual language used, though? Pretty sure that's what the P in LAMP (Linux, Apache, MySQL, PHP) is...

Also, why are you putting Linux on a second drive? That has the disadvantage you have to reboot your machine to use it. If all you're doing is looking at Linux programming then it would be more efficient to install something like VirtualBox and create yourself a Linux virtual machine; you could run such a thing at the same time as your Windows installation. You'd need a bit more RAM to do this, but Linux doesn't require that much so a spare gig would be enough for most things. (You can also use the WUBI version of Ubuntu if you want to run Linux under Windows--works quite well).

Of course, if there are specific reasons why all this has to be the way you've described, ignore me... :smallsmile:

P on the LAMP stack is typically PHP, yes (or Perl). I don't think The Succubus explicitly mentioned web servers though (correct me if I'm wrong).

The most common Python install is probably CPython (obviously built on C), though other versions exist.


Are you thinking of IDE interpretters? Because, as I said, Python (http://www.python.org/download/) itself is an interpretter, but it lacks an IDE in and on itself.

Python ships with the IDLE editor, though I wouldn't go so far as to say it's an IDE. :smallbiggrin:

Sublime Text (http://www.sublimetext.com/) is an excellent editor, and is cross platform. Or you could join the raging debate between Vim and Emacs users... :smalleek:


1


Succubus, what sort of Python programming are you looking to do exactly?

Wookieetank
2013-01-10, 12:19 PM
Sublime Text (http://www.sublimetext.com/) is an excellent editor, and is cross platform. Or you could join the raging debate between Vim and Emacs users... :smalleek:


[

Or you could use notepad++ and have no idea what the difference between VIm and Emacs even is. :smallwink: Although i hear I should look into both depending on who I ask.

Neftren
2013-01-10, 12:35 PM
Or you could use notepad++ and have no idea what the difference between VIm and Emacs even is. :smallwink: Although i hear I should look into both depending on who I ask.

Notepad++ is Windows only (and as we're looking at Linux development...).

Now, Notepad++ does run in WINE, but running it in WINE is one of the most frustrating experiences I have ever had with software running in WINE. Making a small edit to the file outside of Notepad++ while the file is still open in Notepad++? NOPE! Boom! It throws a fit, and either closes the file or kicks you to the desktop before crashing and burning in a horrible fit.

And no, this had nothing to do with any other software on the machine or installation incompetence on my part (at least, I'd hope not), as it was a fresh out of the box OpenSUSE install, and the only thing I'd done up to that point was 'sudo zypper install wine' before downloading the Windows install binary. Something along those lines anyways... WINE might have been installed already. Anyways...


Edit: as for the Vim vs. Emacs debate, it is necessary to link the relevant xkcd (http://xkcd.com/378/) strip.

You might also be interested in Wikipedia's article (http://en.wikipedia.org/wiki/Editor_war), and what the folks over at Stack Exchange (http://unix.stackexchange.com/questions/986/vim-vs-emacs-and-no-this-is-not-a-flame-war) have to say.

Wookieetank
2013-01-10, 01:33 PM
Notepad++ is Windows only (and as we're looking at Linux development...).

Now, Notepad++ does run in WINE, but running it in WINE is one of the most frustrating experiences I have ever had with software running in WINE. Making a small edit to the file outside of Notepad++ while the file is still open in Notepad++? NOPE! Boom! It throws a fit, and either closes the file or kicks you to the desktop before crashing and burning in a horrible fit.

And no, this had nothing to do with any other software on the machine or installation incompetence on my part (at least, I'd hope not), as it was a fresh out of the box OpenSUSE install, and the only thing I'd done up to that point was 'sudo zypper install wine' before downloading the Windows install binary. Something along those lines anyways... WINE might have been installed already. Anyways...


Edit: as for the Vim vs. Emacs debate, it is necessary to link the relevant xkcd (http://xkcd.com/378/) strip.

You might also be interested in Wikipedia's article (http://en.wikipedia.org/wiki/Editor_war), and what the folks over at Stack Exchange (http://unix.stackexchange.com/questions/986/vim-vs-emacs-and-no-this-is-not-a-flame-war) have to say.

Good to know. Although now I'm tempted to try notepad++ with ubuntu and see what it does/how awesomely I can mangle things up. Supposing I can pull myself away from my lappy (damnit steam quit having sales already! ><).

Teddy
2013-01-10, 02:05 PM
Someone keeps telling me there's a library out there that can (re)compile Python code that executes faster than a C program equivalent. PyPy I think? I haven't personally tried it, but compilation does exist... in a way (outside of compiling to Bytecode, similar to Java).

Well, from what I've understood, Java programs may execute mariginally faster than their C equivalents, so it's not outside the realm of possibility for compiled Python as well...


Python ships with the IDLE editor, though I wouldn't go so far as to say it's an IDE. :smallbiggrin:

More like a plain text editor with some fancy colours and semi-automatic indentation. :smallwink:

Neftren
2013-01-10, 02:15 PM
Well, from what I've understood, Java programs may execute mariginally faster than their C equivalents, so it's not outside the realm of possibility for compiled Python as well...

On closer examination, PyPy appears to be Python's bootstrapped interpreter (i.e. Python interpeter written in RPython).

I'm not really going to go into the Java vs. C/C++ debate, other than to say this is an optimisation problem that could swing either way.

factotum
2013-01-10, 05:34 PM
Now, Notepad++ does run in WINE, but running it in WINE is one of the most frustrating experiences I have ever had with software running in WINE.

Were you just attempting that for fun? WINE is usually used to run stuff that there simply isn't an equivalent of in Linux (e.g. games, as mentioned earlier), but last time I checked, there are approximately 873 million different text editors available in Linux... :smallwink:

Neftren
2013-01-10, 10:24 PM
Were you just attempting that for fun? WINE is usually used to run stuff that there simply isn't an equivalent of in Linux (e.g. games, as mentioned earlier), but last time I checked, there are approximately 873 million different text editors available in Linux... :smallwink:

In hindsight, I was kind of an idiot about the whole thing. I wasn't really satisfied with the stuff already on the machine, and I didn't really like the look and feel of a lot of existing editors. I spend most of my time working in OSX, where desktop applications have excellent look and feel--the same cannot be said of "Free Software" on Linux. Nothing I found could really compare to Xcode and Dashcode. Since those are unavailable in Linux, I turned to Notepad++ since it was the next most familiar thing, and it does run in WINE (albeit poorly, as I later discovered).

Then I stumbled on Sublime Text and have never looked back. It really knocks the park out of literally every other editor or IDE I've used, with the exception of Xcode for C/C++ development (or developing C/C++ and Python in parallel), and Visual Studio for working on Microsoft stuff.

Emmerask
2013-01-11, 09:33 AM
Then I stumbled on Sublime Text and have never looked back. It really knocks the park out of literally every other editor or IDE I've used, with the exception of Xcode for C/C++ development (or developing C/C++ and Python in parallel), and Visual Studio for working on Microsoft stuff.

I completely agree Sublime Text really is awesome!
Though nothing beats intelliJ, its practically magic combined with chuck norris:smallwink:

Balain
2013-01-22, 12:02 AM
This new computer science course is going to drive me nuts I think. It has nothing to do with it being in java, or any of the logic, or anything like that. It has to do with getting help and citing sources. Now don't get me wrong, I have no problem with citing sources, but it seems to be going overboard.

For example, our prof today should an example of code for reading a file. with a

do
{
a bunch of stuff
}
while(filepointer != null)


The thing is I have been programming on and off for over 25 years. A little for work, but mostly on my own. something like that is standard, yet if I do something like it in my code, if I don't say in the documentation

*this code from prof joe blow from cpsc course on jan 22*

i would get 0% and maybe kicked out of the course for cheating.

On top of that if I am having problems and seek help I can't post/show/say any of my code to any one (except prof and TA) or again I risk getting kicked out for cheating because another student might see/hear my code.

Emmerask
2013-01-22, 06:40 PM
This new computer science course is going to drive me nuts I think. It has nothing to do with it being in java, or any of the logic, or anything like that. It has to do with getting help and citing sources. Now don't get me wrong, I have no problem with citing sources, but it seems to be going overboard.

For example, our prof today should an example of code for reading a file. with a

do
{
a bunch of stuff
}
while(filepointer != null)


The thing is I have been programming on and off for over 25 years. A little for work, but mostly on my own. something like that is standard, yet if I do something like it in my code, if I don't say in the documentation

*this code from prof joe blow from cpsc course on jan 22*

i would get 0% and maybe kicked out of the course for cheating.

On top of that if I am having problems and seek help I can't post/show/say any of my code to any one (except prof and TA) or again I risk getting kicked out for cheating because another student might see/hear my code.

Thats seems extremely arbitrary (especially for simple stuff like a filereader) ^^
Well I guess he doesn´t want you guys to copy paste most of your code (which can lead to working programs especially if they are not too complex)
but wants you to really understand what you are doing, ie reading a sample code explaining how to solve problem xyz and then writing the thing.

How he will ever be able to enforce it though is beyond me especially with nice little things like refactor rename :smallwink:

akma
2013-01-23, 05:44 AM
*help with old question I raised*

Thank you.


Well, from what I've understood, Java programs may execute mariginally faster than their C equivalents, so it's not outside the realm of possibility for compiled Python as well...


I don`t get why people are so obssesed with speed of execution. Even if C code is 3 times faster then Java, most things will still run faster then a blink of an eye. It would only matter in programs that realy take a lot from the computer. Besides, there are other factors to consider (Java is cross platform, for exemple).

In another issue, I decided to start programming for Android, using Java. How relevent is Java ME to Android development? Any resources you can recommend to me? Any tips?

Emmerask
2013-01-23, 06:23 AM
Its a pretty simple step from java me to android
though a few things differ greatly:

1)ui library is more extensive and more complicated
2)only one ui thread
3)you have to be much more careful with threads and thread safety
4)limited resources (due to deployment on a phone)
5)no extensive database stuff, sqlite must suffice
6)xml and json are pretty important ^^

this video list might help you:

http://www.youtube.com/view_play_list?p=586D322B5E2764CF

and of course there is:

http://stackoverflow.com which is also the official help platform

Another tip would be use Intellij instead of other ides it really makes life more easy

http://www.jetbrains.com/idea/

The Succubus
2013-01-23, 06:49 AM
How do folks like my avatar for Basic Avatar Week? Didn't really have enough space to do Visual Basic.

As for what I'm looking to do in Python, probably a similar thing to shell scripting I guess. As mentioned above, I'm learning about Linux at the moment and it'd be cool if I could build a "toolkit" to do basic automated tasks with.

Plus a language to write simple games in would be nice. I recall stuff like Laser Squad and Lords of Chaos from my CPC days and it'd be cool if I could write something like that.

akma
2013-01-23, 07:48 AM
Its a pretty simple step from java me to android
though a few things differ greatly:


I actully have no background in Java ME, just Java SE (and thanks for the rest of the post). Would that be an issue?

factotum
2013-01-23, 01:52 PM
Plus a language to write simple games in would be nice. I recall stuff like Laser Squad and Lords of Chaos from my CPC days and it'd be cool if I could write something like that.

If you're thinking about Java then they do more than simple games in it--Minecraft is written in Java, for example. I believe it makes use of a thing called the Lightweight Java Game Library to provide 3D capabilities and the like:

http://lwjgl.org/

Neftren
2013-01-23, 03:06 PM
How do folks like my avatar for Basic Avatar Week? Didn't really have enough space to do Visual Basic.

As for what I'm looking to do in Python, probably a similar thing to shell scripting I guess. As mentioned above, I'm learning about Linux at the moment and it'd be cool if I could build a "toolkit" to do basic automated tasks with.

Plus a language to write simple games in would be nice. I recall stuff like Laser Squad and Lords of Chaos from my CPC days and it'd be cool if I could write something like that.

Hmm... shell scripting is probably best done with shell scripting. :smalltongue: Might want to look into the bash reference manual for that.

If you're looking to invoke command line utilities and so on, you should consider C, or perhaps C++ depending on what you're looking to do.

Simple games programming ... as slow as it is, try pygame (http://www.pygame.org/news.html).

Gryffon
2013-01-23, 03:13 PM
He probably doesn't mean actual shell scripting. Scripting in the bash shell can be horribly mind-wrecking. It's probably best to avoid it. Python is definitely a decent language to get into, and has a pretty low barrier to entry.

Balain
2013-01-23, 07:53 PM
I am new to java and oop so this may sound like a stupid question.

I create a file called Guess.java.

In it I include import statements first. Then create a class called Game and the have the Guess class. so it looks like this



import java.stuff
import java.morestuff

public class Game
{
stuff

public void getstuff()
{
more stuff
}

.....
}

public class Guess
{
public static void main(String[] args)
{
stufff

Game.getstuff();
Game.STUFF();

more stuff
....
}
}


As you can guess, when I run javac it complains about Game and wants it in it's own file. My thought was I want to use Game in Guess so I made it public and everything in it public. I can't have multiple files so what do I do, make Game private? Put Game in Guess so it looks like:



public class Guess
{
public class Game
{
stuff
}

public static void main(Strings[] args)
{
Game.stuff
}

}

Teddy
2013-01-24, 07:18 AM
I am new to java and oop so this may sound like a stupid question.

I create a file called Guess.java.

In it I include import statements first. Then create a class called Game and the have the Guess class. so it looks like this



import java.stuff
import java.morestuff

public class Game
{
stuff

public void getstuff()
{
more stuff
}

.....
}

public class Guess
{
public static void main(String[] args)
{
stufff

Game.getstuff();
Game.STUFF();

more stuff
....
}
}


As you can guess, when I run javac it complains about Game and wants it in it's own file. My thought was I want to use Game in Guess so I made it public and everything in it public. I can't have multiple files so what do I do, make Game private? Put Game in Guess so it looks like:



public class Guess
{
public class Game
{
stuff
}

public static void main(Strings[] args)
{
Game.stuff
}

}


Yes, you should be able to put the Game class inside Guess, but no matter what you do, each compiled class is going to end up in its own .class file due to the way Java works (Guess.class and Game$Guess.class (at least I think it was an $)). Are you not allowed to have more than one compiled java file, or does the restriction only affect the source file (.java)?

Inglenook
2013-01-25, 02:36 AM
I've started learning Python fairly recently with the end goal of creating a (relatively) simple computer game.

I've got most of the basics done, so far—character selection, saving and loading games, etc. But the lack of a GUI is driving me crazy on some fundamental level. And I have a niggling worry that I'll finish the game only to discover that I have to start from scratch because I didn't design my code around the GUI. So I'd like to work on the game logic + GUI simultaneously.

My problem is trying to find the right combo of language and GUI framework. And I guess the former should take precedence over the latter, so these are the main four I've been looking at:


Python: I have a working knowledge of it already, but there seems to be a surprising lack of coherent documentation. I understand that programming is jargon-y by nature, but it feels almost as if the people who write the documentation go out of their way to be exclusive of beginners. :smallsigh: Plus there's the whole 2.7/3.x divide that makes the right documentation even harder to find. And a lot of the GUI frameworks for Python seem to be dead projects (e.g. Pygame?).
C++: I've heard this is a really good language to know all-around, but I've also heard that it's much more confusing than Python, and much harder to read. And I don't really understand its strengths and weaknesses compared to, say, Python. But it seems to be infinitely better documented.
C#: Windows-only, I think? So I'd rather use something else.
Java: I'm trying to avoid Java, since I've been told that it's going the way of the dinosaur (perhaps even more quickly due to the recent security problems).

I don't think there's an engine for the type of game I'm writing (sort of stat-based strategy, strongly text-based), so I'm looking for a framework for now.

Ideally I'd like something cross-platform. I don't need anything complicated as far as GUI—text, buttons, forms, photos, and that's it. But I have no idea what sort of technical features I'm supposed to be looking for in a framework.

TL;DR version: For programming a simple(ish) game, is it worth learning a language other than Python in order to have better documentation and GUI frameworks? And what framework should I use?

ETA: And I've tried TKinter for Python, and it seemed pretty awful. And I've heard people say it's awful compared to a lot of frameworks.

Anima
2013-01-25, 03:01 AM
Well there are actually several python game engines/frameworks apart from pygame. You might want to look at cocos2D (There is also a version made for iOS but that's a different engine.)
For 3D games there is Panda3D, but that is probably overkill for your project anyway.

The engine I have the most experience with is Ren'Py which is based on pygame. It's build for visual novels, but pretty flexible.
If you only need a traditional GUI framework instead of a game framework you could try wxpython. It's pretty much the most popular GUI framework at the moment. I find the documentation a bit lacking at times though.

factotum
2013-01-25, 03:06 AM
And I have a niggling worry that I'll finish the game only to discover that I have to start from scratch because I didn't design my code around the GUI.

Visual BASIC aside, you should never write your back-end code in such a way that the GUI has to be a certain way for it to work, because it makes it a pain to change if you decide the GUI isn't right. Have the two things as separate codebases with a strictly defined way of talking to each other!

IthilanorStPete
2013-01-25, 10:50 AM
How important is the platform-independence to you? I admittedly haven't used it much, but C# with .NET seems rather nice. It's easy to pick up from Java or other C-like languages, and it seems pretty easy to code GUIs, especially if you have access to Visual Studio.

Neftren
2013-01-25, 02:16 PM
I've started learning Python fairly recently with the end goal of creating a (relatively) simple computer game.

I've got most of the basics done, so far—character selection, saving and loading games, etc. But the lack of a GUI is driving me crazy on some fundamental level. And I have a niggling worry that I'll finish the game only to discover that I have to start from scratch because I didn't design my code around the GUI. So I'd like to work on the game logic + GUI simultaneously.

You might want to initially consider the GUI as an interface between users and the command line interface. So rather than scripting a button to perform some action, script the button to call the command line script with some parameters to perform said action. Then when you go to build your GUI, you can go back and change things.

Another way of looking at this is the Model-View-Controller (http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller).


My problem is trying to find the right combo of language and GUI framework. And I guess the former should take precedence over the latter, so these are the main four I've been looking at:


Python: I have a working knowledge of it already, but there seems to be a surprising lack of coherent documentation. I understand that programming is jargon-y by nature, but it feels almost as if the people who write the documentation go out of their way to be exclusive of beginners. :smallsigh: Plus there's the whole 2.7/3.x divide that makes the right documentation even harder to find. And a lot of the GUI frameworks for Python seem to be dead projects (e.g. Pygame?).
C++: I've heard this is a really good language to know all-around, but I've also heard that it's much more confusing than Python, and much harder to read. And I don't really understand its strengths and weaknesses compared to, say, Python. But it seems to be infinitely better documented.
C#: Windows-only, I think? So I'd rather use something else.
Java: I'm trying to avoid Java, since I've been told that it's going the way of the dinosaur (perhaps even more quickly due to the recent security problems).

I don't think there's an engine for the type of game I'm writing (sort of stat-based strategy, strongly text-based), so I'm looking for a framework for now.

Ideally I'd like something cross-platform. I don't need anything complicated as far as GUI—text, buttons, forms, photos, and that's it. But I have no idea what sort of technical features I'm supposed to be looking for in a framework.

TL;DR version: For programming a simple(ish) game, is it worth learning a language other than Python in order to have better documentation and GUI frameworks? And what framework should I use?

ETA: And I've tried TKinter for Python, and it seemed pretty awful. And I've heard people say it's awful compared to a lot of frameworks.

Python is perhaps the best documented language I have ever used. What are you looking for in a graphics framework? If you're looking to do game programming, remember that a lot of graphics frameworks (e.g. Java Swing) are focused on producing windows and event driven interfaces.

Razanir
2013-01-26, 01:09 PM
I'm in a programming debate with one of my friends. (About Java)

Are public variables fine, or should you provide accessors/mutators? Defend your position.

PairO'Dice Lost
2013-01-26, 02:48 PM
I'm in a programming debate with one of my friends. (About Java)

Are public variables fine, or should you provide accessors/mutators? Defend your position.

Depends entirely on the scope and intended use of your project. The product my team is developing at work has several hundred thousand lines in several dozen files, and it interacts with more than four other products developed by different teams. It's not in Java, but it still has global variables accessible by outside functions, and in that context using public variables that could be modified from anywhere would be an absolute nightmare for debugging and workflow tracing.

I've also written many programs for my own use, which are narrowly-scoped and fairly small; I've given them to plenty of people to use, but I'm the only one who's ever going to work on them. In that context, writing up accessors and mutators for all the variables I need to use in multiple files is a waste of time and effort, since I wouldn't really gain any of the benefits of encapsulation.

Most of the time, the problems caused by public variables arise when someone thinks they're working on the latter kind of project but either it is the former kind or it was the former kind and grew into the latter kind over time. As long as you use accessors and mutators when they're really needed, using public variables the rest of the time is fine.

akma
2013-01-26, 03:58 PM
I'm in a programming debate with one of my friends. (About Java)

Are public variables fine, or should you provide accessors/mutators? Defend your position.

I have the philosophy that variables should be as public as possible. If the variable can hold any value, and I`m sure it would be the same with subclasses, I make it public (changing it directly couldn`t harm the code, so why write unnescery getter and setter methods?).

If I want to preform some other actions whenever the value is changed, or if certain values would cause issues (null for Object refrence, in some cases) I make the variable protected.

If, for some reason, I want to make sure that even subclasses would be restricted in their ability to modify the variable, I make it private.

Capt Spanner
2013-01-27, 01:43 PM
I'm in a programming debate with one of my friends. (About Java)

Are public variables fine, or should you provide accessors/mutators? Defend your position.

A common school of thought is to keep a variable private unless it you have situation:



class Foo {
private:
Bar x;
public:
Bar getX() const {return x;}
void setX(Bar val) {x = val;}
};


You might as well just make x public, right?

However, I have found that I've been in this situation and I've wanted to replace x* with something else (whenever I used it it was being converted into different units which weren't human friendly) so I changed it to get() and set() functions which would do the conversion for me because this conversion was happening thousands of times per frame and became a real bottleneck.

This made me wish I'd kept x private and just used get()/set() functions for it because I could have just changed the class definition. As it was I had to go and change the many references to it by hand. :-(

*It wasn't actually called x. I forget what exactly it was.

Teddy
2013-01-27, 02:08 PM
The official Java Code Convention discourages public class or instance variables unless there's a good reason for it. Writing basic getters and setters is no great effort to start with anyway.

Razanir
2013-01-27, 03:30 PM
The official Java Code Convention discourages public class or instance variables unless there's a good reason for it. Writing basic getters and setters is no great effort to start with anyway.

I looked it up and saw this:

One example of appropriate public instance variables is the case where the class is essentially a data structure, with no behavior. In other words, if you would have used a struct instead of a class (if Java supported struct), then it's appropriate to make the class's instance variables public.

What if the only methods it contains beyond getters and setters are for exporting XML and JSON? It sounds now to me like that would be an appropriate place to use public variables (which goes against everything I learned in AP)

Teddy
2013-01-27, 04:43 PM
What if the only methods it contains beyond getters and setters are for exporting XML and JSON? It sounds now to me like that would be an appropriate place to use public variables (which goes against everything I learned in AP)

Well, if you know for sure that you never will want to add or change functionality, and no one else other than you is going to have to maintain or interface your code, well, then I suppose it's okay. But as I said, writing getters and setters is a non-effort, and can generally be done automatically in more advanced IDEs.

Razanir
2013-01-27, 04:50 PM
Well, if you know for sure that you never will want to add or change functionality, and no one else other than you is going to have to maintain or interface your code, well, then I suppose it's okay. But as I said, writing getters and setters is a non-effort, and can generally be done automatically in more advanced IDEs.

Yeah... I'm still using BlueJ (although I am using getters and setters).

Does anyone have a recommendation for a more advanced IDE that still has that map of all your classes and dependencies? That part of the interface is the only real reason I'm still using BlueJ; I don't want to give it up

Emmerask
2013-01-28, 08:03 PM
Yeah... I'm still using BlueJ (although I am using getters and setters).

Does anyone have a recommendation for a more advanced IDE that still has that map of all your classes and dependencies? That part of the interface is the only real reason I'm still using BlueJ; I don't want to give it up

I´m going to sound like a broken record but
IntelliJ, it even has it in a pretty nice matrix structure

http://www.jetbrains.com/idea/features/dependency_analysis.html

or the normal uml class diagram

http://www.jetbrains.com/idea/features/uml_class_diagram.html

akma
2013-01-29, 05:28 AM
The official Java Code Convention discourages public class or instance variables unless there's a good reason for it. Writing basic getters and setters is no great effort to start with anyway.

I`d like to note that some classes in the offical Java API break this convention.
Exemples:

http://docs.oracle.com/javase/7/docs/api/java/awt/Polygon.html
http://docs.oracle.com/javase/7/docs/api/java/awt/Rectangle.html

Razanir
2013-01-29, 01:58 PM
I`d like to note that some classes in the offical Java API break this convention.
Exemples:

http://docs.oracle.com/javase/7/docs/api/java/awt/Polygon.html
http://docs.oracle.com/javase/7/docs/api/java/awt/Rectangle.html


Oh wow, it does.

java.awt.Polygon, lines 253-260:

if (x < bounds.x) {
bounds.width = bounds.width + (bounds.x - x);
bounds.x = x;
}
else {
bounds.width = Math.max(bounds.width, x - bounds.x);
// bounds.x = bounds.x;
}


I think by the conventions, wouldn't it be } else { all on one line?

Ashtar
2013-01-29, 07:22 PM
Just wondering if any of you has had (or has) access to an Intel Xeon Phi (http://www.intel.com/content/www/us/en/processors/xeon/xeon-phi-detail.html) card? I would love to run a benchmark problem before I receive it in the office.

We should be getting one in the office mid-february to run our massive optimisations of energy assets on. I am very excited! Hardware has really advanced massively in the last few years with the advent of graphic card number crunchers, sadly the problem we have was not one that translated to the graphic card easily, whereas the Xeon phi is just a 60 core, 240 thread monster that I expect will give us excellent numbers...

So do any of you do highly parallel programming, optimization problems or large workloads? OpenMP, MPI or others parallelization techniques?

Mystic Muse
2013-02-02, 02:48 AM
I need some help with a program for school that I'm derping on. Miscrosoft Visual Basic 2010

http://i1206.photobucket.com/albums/bb443/Zernobog888/Capture-3_zps60322d2c.png

I'm supposed to fix the error, but I can't remember/think of how.

Emmerask
2013-02-02, 07:56 AM
You can´t make a label to a string, a label object is a lot more then the string it displays, it will most likely (not a vb expert^^) have stuff like textcolor, backgroundcolor, other format stuff, enabled disabled bool etc in it.

what you can do however is

lblEnding.Text = decEnding.ToString("2")

ie setting the text of the label to the string

Mystic Muse
2013-02-02, 12:40 PM
Thanks a bunch.:smallsmile:

I'll be sure to remember this thread when I'm having trouble with homework in the future.

Neftren
2013-02-02, 01:38 PM
Just wondering if any of you has had (or has) access to an Intel Xeon Phi (http://www.intel.com/content/www/us/en/processors/xeon/xeon-phi-detail.html) card? I would love to run a benchmark problem before I receive it in the office.

We should be getting one in the office mid-february to run our massive optimisations of energy assets on. I am very excited! Hardware has really advanced massively in the last few years with the advent of graphic card number crunchers, sadly the problem we have was not one that translated to the graphic card easily, whereas the Xeon phi is just a 60 core, 240 thread monster that I expect will give us excellent numbers...

So do any of you do highly parallel programming, optimization problems or large workloads? OpenMP, MPI or others parallelization techniques?

I do a lot of OpenCL programming. Haven't had a chance to use one of the Intel cards though. We were more interested in scaling across multiple GPUs, and I'd much rather submit jobs to the supercomputer for MPI work. :smallbiggrin:

Let me know how it goes though! My mentor was looking into buying a rig of Teslas, so...

Razanir
2013-02-02, 06:02 PM
Is this bad practice?

public class SomeClass {
private OtherClass o = new OtherClass();

public void someMethod() {
System.out.println(o.var);
}

private class OtherClass {
private int var = 3;
}
}

Ashtar
2013-02-02, 08:13 PM
Well it simply shouldn't work. The OtherClass.var being private means it cannot be accessed from the outside, not even to be read. In java, it should either be public, protected or without modifier (see here (http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html)).

Oops, sorry, forgot about the rules of Nested classes (http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html) in java. Carry on, it would work. Since it's a nested class, the outer class has access to the inner private variables.

A class instantiating another is not bad practice, but I would recommend to instantiate the OtherClass inside the SomeClass constructor (which you didn't have here in this example).

IthilanorStPete
2013-02-02, 08:26 PM
What're some examples of when using nested classes would be good? Looking at Ashtar's link, I can't really imagine when you would use one instead of incorporating that code into the main class.

Razanir
2013-02-02, 08:55 PM
A class instantiating another is not bad practice, but I would recommend to instantiate the OtherClass inside the SomeClass constructor (which you didn't have here in this example).

Oh no, I actually am instantiating it in the constructor; I just left that out to highlight the part I need.

@Ithilanor It's a simple data storing class so I don't need two parallel arrays

Teddy
2013-02-03, 05:00 AM
Is this bad practice?

public class SomeClass {
private OtherClass o = new OtherClass();

public void someMethod() {
System.out.println(o.var);
}

private class OtherClass {
private int var = 3;
}
}

Not as far as I know. Since the nestled class is private, you don't have to be afraid that someone will use the direct access to modify the value illegitimately.


What're some examples of when using nested classes would be good? Looking at Ashtar's link, I can't really imagine when you would use one instead of incorporating that code into the main class.

Sometimes you need a class for a task inside another class, but which holds no use outside said class (concider a list element in a specific type of list. Even if you make other lists, you may want to give them a different intern representation).

Other times, you may have a class so strongly linked to the first class that even if you make it public, you may want to nestle it inside the first class to make the relationship obvious (consider an Exception for a specific type of behaviour of the first class. Even if you might want to raise said exception outside the first class, making the relationship obvious is a good way to prevent misuse).

Razanir
2013-02-08, 01:15 PM
printf and NumberFormat. Both work just fine for formatting numbers for output. How would I go about it if I wanted some dollar amounts in accounting format



NumberFormat.getCurrencyFormat():
$1.00
$10.00
$100.00

Accounting format:
$ 1.00
$ 10.00
$100.00

Capt Spanner
2013-02-08, 07:49 PM
printf and NumberFormat. Both work just fine for formatting numbers for output. How would I go about it if I wanted some dollar amounts in accounting format



NumberFormat.getCurrencyFormat():
$1.00
$10.00
$100.00

Accounting format:
$ 1.00
$ 10.00
$100.00


For printf() you'd use the width and precision modifier: "%[width].[precision]f" for a float. Precision is the number of decimal places and width is the number of characters it takes up (including decimal point), so your second example would be:

printf("$%6.2f",val);
I personally prefer cout:


cout << "$" << setiosflags(ios::fixed)
<< right << setwidth(6) << setprecision(2) << val;

I realise this is far more verbose than printf, but also (I think) easier to read and easier to customise programmatically.

Razanir
2013-02-08, 10:16 PM
For printf() you'd use the width and precision modifier: "%[width].[precision]f" for a float. Precision is the number of decimal places and width is the number of characters it takes up (including decimal point), so your second example would be:

printf("$%6.2f",val);
I personally prefer cout:


cout << "$" << setiosflags(ios::fixed)
<< right << setwidth(6) << setprecision(2) << val;

I realise this is far more verbose than printf, but also (I think) easier to read and easier to customise programmatically.

It's also not supported in the language I'm using (Java) :smallbiggrin:

Keris
2013-02-09, 10:15 AM
It's also not supported in the language I'm using (Java) :smallbiggrin:
Fortunately, Java does implement a number of printf functions, including one in PrintStream (http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html#printf%28java.lang.String,%20java .lang.Object...%29), and helpfully they use a format syntax drawn from C (http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax). If you want to store the string internally, you can use the String.format (http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#format%28java.lang.String,%20java.lang .Object...%29) function instead. There are other ways of doing it, but those two both work.

Example code using your data and the format string from Capt Spanner:

class FormatDemo {
public static void main(String[] args) {
String format = "$%6.2f%n";
// The addition of a %n to the format string just adds a line
// break at the end.

// Using printf()
System.out.printf(format, (float) 1);
System.out.printf(format, (float) 10);
System.out.printf(format, (float) 100);
// The values need to be cast because otherwise an exception
// is thrown - Integers are not floating points but neither
// is the precision field valid when formatting integers.
System.out.println();

// Using String.format()
String val1 = String.format(format, (float) 1);
String val2 = String.format(format, (float) 10);
String val3 = String.format(format, (float) 100);
System.out.print(val1);
System.out.print(val2);
System.out.print(val3);
}
}
Output:

$ 1.00
$ 10.00
$100.00

$ 1.00
$ 10.00
$100.00

Mystic Muse
2013-02-11, 03:24 AM
Okay, I need some help again. :smallsigh: (Microsoft Visual Basic)

http://i1206.photobucket.com/albums/bb443/Zernobog888/Capture4_zpsd1ed8644.png

Here's what the base program looks like. I need to modify it so that the program can calculate a sales commission based on the number entered, using the (As the book calls it) If/ElseIf/Elf form of the Ef then else statement.


Monthly sales
Commission Rate
0-19,999.99
4%
20,000-29,999.99
5%
30,000-39,999.99
6%
40,000-49,999.99
7%
50,000 or more
9%
Less than 0
0%

http://i1206.photobucket.com/albums/bb443/Zernobog888/Capture4_zps90075413.png

There's what the program itself looks like, if that'll help at all.

EDIT: I specifically have to enter in 22,000 and get back the commission accurate to 2 decimal places.

factotum
2013-02-11, 07:26 AM
You'd have to do something like assigning the values from the text box to a numeric variables (say, MonthlySales), then do your calculation:

If MonthlySales < 0 Then Commission = 0
Else If MonthlySales >= 0 And MonthlySales <= 19999999 Then Commission = MonthlySales * 0.04
.
.
.
Else Commission = MonthlySales * 0.09
End If

(The bit in the middle left as an exercise for the reader). Have to say that I wouldn't use an If...Then construct for this anyway, because it's going to be a pain to maintain if any of the brackets or percentages change, but if that's what the book is telling you to do that's the way to go about it.

Emmerask
2013-02-11, 12:51 PM
You could also just start with the highest and work down to lowest, this way you only have to check against one statement ie:

if MonthlySales >= 50000 Then Commission = MonthlySales * 0.09
else if MonthlySales >= 40000 Then Commission = MonthlySales * 0.07
.
.
.
else if MonthlySales >= 0 Then Commission = MonthlySales * 0.04

at least if vb treats else if the same as java which I´m fairly certain it will
ie leave the rest of the else ifs alone after finding the first correct one...after all why call it ELSE if otherwise :smallsmile:

/edit oh and don´t forget to check the user entry in the MonthlySales Field, either check it after the user typed or make the textfield only accept numeric values and points.

Neftren
2013-02-11, 01:52 PM
Does anyone here have any skill with C systems programming? I've been trying to read file permissions of all files in a directory, but everything comes up [----------] (i.e. 000) when I lstat() and bitwise & to check the flag.

PairO'Dice Lost
2013-02-11, 02:47 PM
Does anyone here have any skill with C systems programming? I've been trying to read file permissions of all files in a directory, but everything comes up [----------] (i.e. 000) when I lstat() and bitwise & to check the flag.

My guess is that the variable you're ANDing the permissions with is incorrect somehow, like you forgot to initialize the value or it's shifted one bit to the left or something. Can you post the code?

Neftren
2013-02-11, 04:15 PM
My guess is that the variable you're ANDing the permissions with is incorrect somehow, like you forgot to initialize the value or it's shifted one bit to the left or something. Can you post the code?

It was actually a silly mistake. I was looping through and forgot to update the current path, so it was always one-behind the index (i.e. reading the above directory permissions).

akma
2013-02-13, 04:50 PM
I want that everytime I`ll press the print screen key it would automatically save the generated image in some folder.
I`m assuming I can somehow accsess the code preformed by keyboard buttons, but I have no idea how to even approach the issue. Some directions would be greatly appreciated.

factotum
2013-02-13, 04:57 PM
If you want to capture a keypress like that then you need to write an application that implements a system-wide keyboard hook. Doing that is really getting down and dirty in the oily bits of Windows, though, not something you want to be doing unless you're really good at this sort of thing.

Neftren
2013-02-13, 05:00 PM
I want that everytime I`ll press the print screen key it would automatically save the generated image in some folder.
I`m assuming I can somehow accsess the code preformed by keyboard buttons, but I have no idea how to even approach the issue. Some directions would be greatly appreciated.

I think what you want instead is an AutoHotKey script.

Grinner
2013-02-13, 05:01 PM
If you want to capture a keypress like that then you need to write an application that implements a system-wide keyboard hook. Doing that is really getting down and dirty in the oily bits of Windows, though, not something you want to be doing unless you're really good at this sort of thing.

Fortunately for the rest of us, there's AutoIt (http://www.autoitscript.com/site/autoit/). :smallamused:

Neftren
2013-02-13, 05:04 PM
Fortunately for the rest of us, there's AutoIt (http://www.autoitscript.com/site/autoit/). :smallamused:

Hm, this actually looks rather nifty.

1

Unrelated note... Does anyone know of a pure-python implementation of Subversion or Mercurial? I'm looking for something similar to Dulwich (for GitHub).

Or even better, a pure-python implementation of Git-Hg and Git-Svn ...

Grinner
2013-02-13, 05:08 PM
Hm, this actually looks rather nifty.

Legend has it that AutoHotKey is a fork of an earlier, open source version of AutoIt.

Razanir
2013-02-13, 08:21 PM
I'm back with another private/protected/public question:

Why is it recommended to have private variables in an abstract class then use getters and setters in subclasses? I heard this from a TA today and the logic makes no sense. I can understand no non-private variables in most classes, but not for use with subclasses. Why wouldn't you just make them protected if you want those fields to be in the subclass?

Teddy
2013-02-14, 05:24 AM
I'm back with another private/protected/public question:

Why is it recommended to have private variables in an abstract class then use getters and setters in subclasses? I heard this from a TA today and the logic makes no sense. I can understand no non-private variables in most classes, but not for use with subclasses. Why wouldn't you just make them protected if you want those fields to be in the subclass?

A quick guess is that it would let someone subclass your class as a means for accessing and manipulating the variables directly without using the getters/setters, which would break the encapsulation.