Unofficial Programming Thread II

Post » Tue May 17, 2011 1:55 pm

Can anyone suggest some good learning material for Python (perhaps even directed at Java programmers), preferably free. Please, no guides for beginning programmers, those get boring too fast. ;) Also, please don't just link me to what you found on Google, I could've http://www.google.com/search?q=python+for+java+programmers. I'm looking for recommendations and personal input. :)

I know you don't want courses for beginners, but I'd still feel remiss if I didn't mention MIT's great http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/. The first couple of lectures will be a little boring for you, but the course is quite thorough and full of exercises. It might not be the right resource for you, but I think it certainly merits a look.

http://diveintopython.org is a Python book aimed specifically at experienced programmers.

Finally, there's the http://www.pythonchallenge.com/. This isn't really a tutorial at all, just a series of problems to solve using Python. You'll need to spend considerable time looking through the documentation and you'll have to download a few additional modules as you go (all free), so I've found this to be a fun learning tool. Probably not great as your primary learning tool, but definitely a lot less dry.
User avatar
lolly13
 
Posts: 3349
Joined: Tue Jul 25, 2006 11:36 am

Post » Tue May 17, 2011 5:28 am

Except for linear f()s, you can't do it via a matrix alone. Use a vertex shader.

Thanks for the help but I ended up doing it manually for each vertex since I only have 25 vertices anyway.

Here's what I did:

Spoiler
#include #include #include double doublePI, PIdiv60, half_sqrt3;double r, phi = 0.0, theta = 0.0, cosphi, sinphi;double viewerposition_x = 1.0, viewerposition_y = 0.0, viewerposition_z = 0.0;double viewerup_x = 0.0, viewerup_y = 0.0, viewerup_z = 1.0;double scale_x = 1.0, scale_y = 1.0, scale_z = 1.0;double temp;double A = 0.0, B = 1.0, u, i, o, p;void keyfunc(unsigned char key, int x, int y){    switch (key){        case 'x': scale_x -= 0.05; break;        case 'X': scale_x += 0.05; break;        case 'y': scale_y -= 0.05; break;        case 'Y': scale_y += 0.05; break;        case 'z': scale_z -= 0.05; break;        case 'Z': scale_z += 0.05; break;        case '+': B += 0.05;                  u = (-0.5) * (A*(-0.5) + B );                  i = (0.5) * (A*(-0.5) + B );                  o = (-0.5) * (A*(0.5) + B );                  p = (0.5) * (A*(0.5) + B );                  break;        case '-': B -= 0.05;                  u = (-0.5) * (A*(-0.5) + B );                  i = (0.5) * (A*(-0.5) + B );                  o = (-0.5) * (A*(0.5) + B );                  p = (0.5) * (A*(0.5) + B );                  break;        case '*': A += 0.05;                  u = (-0.5) * (A*(-0.5) + B );                  i = (0.5) * (A*(-0.5) + B );                  o = (-0.5) * (A*(0.5) + B );                  p = (0.5) * (A*(0.5) + B );                  break;        case '/': A -= 0.05;                  u = (-0.5) * (A*(-0.5) + B );                  i = (0.5) * (A*(-0.5) + B );                  o = (-0.5) * (A*(0.5) + B );                  p = (0.5) * (A*(0.5) + B );                  break;        case 27: exit(1); break;    }        glMatrixMode(GL_MODELVIEW);    glLoadIdentity();    gluLookAt(viewerposition_x, viewerposition_y, viewerposition_z, 0.0, 0.0, 0.0, viewerup_x, viewerup_y, viewerup_z);    glScaled(scale_x, scale_y, scale_z);}void specialkeyfunc(int key, int x, int y){    switch(key){        case GLUT_KEY_LEFT: if((temp = phi - PIdiv60) < 0.0) phi = doublePI - PIdiv60; else phi = temp; break;        case GLUT_KEY_RIGHT: if((temp = phi + PIdiv60) > doublePI) phi = PIdiv60; else phi = temp; break;        case GLUT_KEY_UP: if((temp = theta + PIdiv60) > doublePI) theta = PIdiv60; else theta = temp; break;        case GLUT_KEY_DOWN: if((temp = theta - PIdiv60) < 0.0) theta = doublePI - PIdiv60; else theta = temp; break;        case GLUT_KEY_PAGE_DOWN: if((temp = r * 1.05) > 20.0) r = 20.0; else r = temp;                                 glMatrixMode(GL_PROJECTION);                                 glLoadIdentity();                                 glOrtho(-r, r, -r, r, -10.0, 1000.0);                                 break;        case GLUT_KEY_PAGE_UP: if((temp = r / 1.05) < half_sqrt3) r = half_sqrt3; else r = temp;                               glMatrixMode(GL_PROJECTION);                               glLoadIdentity();                               glOrtho(-r, r, -r, r, -10.0, 1000.0);                               break;        case GLUT_KEY_HOME: r = 2.0 * half_sqrt3; phi = theta = 0.0;                            glMatrixMode(GL_PROJECTION);                            glLoadIdentity();                            glOrtho(-r, r, -r, r, -10.0, 1000.0);                            break;        case GLUT_KEY_END: scale_x = scale_y = scale_z = 1.0; break;        case GLUT_KEY_INSERT: A = 0.0; B = 1.0;                              u = (-0.5) * (A*(-0.5) + B );                              i = (0.5) * (A*(-0.5) + B );                              o = (-0.5) * (A*(0.5) + B );                              p = (0.5) * (A*(0.5) + B );                              break;    }        sinphi = sin(phi);    cosphi = cos(phi);    viewerposition_z = r * sin(theta);    viewerup_z = cos(theta);    viewerposition_x = r * cosphi * viewerup_z;    viewerposition_y = r * sinphi * viewerup_z;    viewerup_x = (-cosphi) * viewerposition_z;    viewerup_y = (-sinphi) * viewerposition_z;        glMatrixMode(GL_MODELVIEW);    glLoadIdentity();    gluLookAt(viewerposition_x, viewerposition_y, viewerposition_z, 0.0, 0.0, 0.0, viewerup_x, viewerup_y, viewerup_z);    glScaled(scale_x, scale_y, scale_z);}void drawScene(void){    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        glBegin(GL_LINES);    glColor3d(1.0, 0.0, 0.0);    glVertex3d(0.0, 0.0, 0.0);    glVertex3d(B, 0.0, 0.0);    glEnd();        glBegin(GL_LINES);    glColor3d(0.0, 1.0, 0.0);    glVertex3d(0.0, 0.0, 0.0);    glVertex3d(0.0, B, 0.0);    glEnd();        glBegin(GL_LINES);    glColor3d(0.0, 0.0, 1.0);    glVertex3d(0.0, 0.0, 0.0);    glVertex3d(0.0, 0.0, 1.0);    glEnd();        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);    glColor3d(1.0, 1.0, 1.0);        glBegin(GL_POLYGON);    glVertex3d(u, u, -0.5);    glVertex3d(i, u, -0.5);    glVertex3d(p, o, 0.5);    glVertex3d(o, o, 0.5);    glEnd();        glBegin(GL_POLYGON);    glVertex3d(u, i, -0.5);    glVertex3d(i, i, -0.5);    glVertex3d(p, p, 0.5);    glVertex3d(o, p, 0.5);    glEnd();        glBegin(GL_POLYGON);    glVertex3d(i, u, -0.5);    glVertex3d(i, i, -0.5);    glVertex3d(p, p, 0.5);    glVertex3d(p, o, 0.5);    glEnd();        glBegin(GL_POLYGON);    glVertex3d(u, u, -0.5);    glVertex3d(u, i, -0.5);    glVertex3d(o, p, 0.5);    glVertex3d(o, o, 0.5);    glEnd();        glFlush();    glutSwapBuffers();    glutPostRedisplay();}void init(){    glEnable(GL_DEPTH_TEST);    glClearColor(0.0, 0.0, 0.0, 0.0);    glEnable(GL_LINE_SMOOTH);    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);    glEnable(GL_BLEND);    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    u = (-0.5) * (A*(-0.5) + B );    i = (0.5) * (A*(-0.5) + B );    o = (-0.5) * (A*(0.5) + B );    p = (0.5) * (A*(0.5) + B );    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glOrtho(-r, r, -r, r, -10.0, 1000.0);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();    gluLookAt(viewerposition_x, viewerposition_y, viewerposition_z, 0.0, 0.0, 0.0, viewerup_x, viewerup_y, viewerup_z);    glScaled(scale_x, scale_y, scale_z);}void resizeWindow(int w, int h){    glViewport(0, 0, (GLsizei) w, (GLsizei) h);}int main(int argc, char** argv){    doublePI = 2.0 * M_PI;    PIdiv60 = M_PI / 60.0;    half_sqrt3 = sqrt(3.0) / 2.0;    r = 2.0 * half_sqrt3;        glutInit(&argc,argv);    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);    glutInitWindowPosition(20, 60);    glutInitWindowSize(640, 640);    glutCreateWindow("Branko Kockica");    init();    glutKeyboardFunc(keyfunc);    glutSpecialFunc(specialkeyfunc);    glutReshapeFunc(resizeWindow);    glutDisplayFunc(drawScene);    glutMainLoop();    return(0);}


The function is f(z) = A*z + B, at first A = 0 and B = 1 (so f(z)*x = x and f(z)*y = y).

Left, right, up and down arrows rotate the view,
page up and page down zoom in/out,
home resets the view,
X and shift+X scale x-axis,
Y and shift+Y scale y-axis,
Z and shift+Z scale z-axis,
End resets the scale factors,
+ and - increase/decrease B factor,
* and / increase/decrease A factor,
Insert resets A and B factors,
Esc quits.





I hate linear algebra.
User avatar
James Potter
 
Posts: 3418
Joined: Sat Jul 07, 2007 11:40 am

Post » Tue May 17, 2011 8:11 am

Could someone help me print the contents of a directory in C#?

Here's the code...
public void Old (string name)		{			string content;			string filepath = JournalDir + name;			bool fileExists;			string[] entryfiles = new string[49];			Console.Clear ();			foreach (string entryfiles in Directory.GetFiles (JournalDir));			{				Console.WriteLine (entryfiles);			}			fileExists = File.Exists (filepath);			if (fileExists == false) {				Error_Methods.EntryNotFound ();			}			StreamReader entry = new StreamReader (filepath);			content = entry.ReadLine ();			Console.WriteLine (content);			Console.WriteLine ("Press any key to continue...");			Console.ReadKey ();			entry.Close ();			Console.Clear ();			MainClass.Welcome ();		}



Edit: Nevermind. I figured it out.
User avatar
Genevieve
 
Posts: 3424
Joined: Sun Aug 13, 2006 4:22 pm

Post » Tue May 17, 2011 9:03 am

What would be a good database to use with a small program? I could do MS Access but people can get into it quick, Visual Studio 2010 allows you to create and edit a SQL Compact Database but I am having a tough time with that, and I downloaded MySQL and was even more lost. It wouldn't be anything super huge or fancy online just a small local thing. Not too sure what I would use it for but thought I would give it a try.
User avatar
Julie Ann
 
Posts: 3383
Joined: Thu Aug 23, 2007 5:17 am

Post » Tue May 17, 2011 3:22 am

SQLite is fairly simple and is generally used for quite a lot of small databases.
User avatar
aisha jamil
 
Posts: 3436
Joined: Sun Jul 02, 2006 11:54 am

Post » Tue May 17, 2011 11:27 am

SQLite is fairly simple and is generally used for quite a lot of small databases.

Is it easy to add data to the table through .NET? Or through a GUI to set it up?
User avatar
Sabrina Steige
 
Posts: 3396
Joined: Mon Aug 20, 2007 9:51 pm

Post » Tue May 17, 2011 11:57 am

Nvm, If I do what i'm actually supposed to do I have it figured out.
User avatar
Smokey
 
Posts: 3378
Joined: Mon May 07, 2007 11:35 pm

Post » Tue May 17, 2011 8:31 am

Is it better to allow VS2010 to create theinterface fo rmy database or should I do it by hand? I noticed if you drag the DB to the WinForm it automatically puts together the connection strings and a basic interface for accessing the records.
User avatar
tegan fiamengo
 
Posts: 3455
Joined: Mon Jan 29, 2007 9:53 am

Post » Tue May 17, 2011 1:07 pm

Do you guys think I'd get in any form of trouble if I wrote http://fallout.wikia.com/wiki/Journal-It_Software? (Which is an in-game Fallout program in-case you didn't follow the link)

EDIT: Not sell it or anything. Just write it and show it to you guys.
User avatar
Trish
 
Posts: 3332
Joined: Fri Feb 23, 2007 9:00 am

Post » Tue May 17, 2011 12:45 pm

I don't think you would but you should email the developers and ask them. Maybe if you changed the name and did not make it look the same or use game assets but I am no lawyer, so I still suggest emailing them and asking.
User avatar
Liii BLATES
 
Posts: 3423
Joined: Tue Aug 22, 2006 10:41 am

Post » Tue May 17, 2011 2:42 am

If I were to learn Python would it be good to start with Python 3 or go back to 2.x? I figure the newest would be best but the MIT video lectures I will use might use 2.x so I was wondering. Are they that much different?

I am still trying to learn C# but I figure it can't hurt to know other languages, at least the basic syntax. I don't want a programming job but figure some could be useful skills to have.
User avatar
Bek Rideout
 
Posts: 3401
Joined: Fri Mar 02, 2007 7:00 pm

Post » Tue May 17, 2011 3:18 am

If I were to learn Python would it be good to start with Python 3 or go back to 2.x? I figure the newest would be best but the MIT video lectures I will use might use 2.x so I was wondering. Are they that much different?

Most libraries are made for 2.x versions of Python, so in my opinion I'd stick with them.
User avatar
Jon O
 
Posts: 3270
Joined: Wed Nov 28, 2007 9:48 pm

Post » Tue May 17, 2011 9:51 am

http://goo.gl/EoL4x
User avatar
Christine
 
Posts: 3442
Joined: Thu Dec 14, 2006 12:52 am

Post » Tue May 17, 2011 9:21 am

Hmmm, so i've been working on this client/server chat program in c# again and i think i got it working. The problem is i dont want to put in a boat load of time and effort into polishing and tweaking it if there is a serious bug/doesnt work like i thought it does. Would anyone be interested in helping me to test it out? The only things needed are the program itself, and ports 21 and 23 forwarded to your pc. Its really really simple just gimme a PM if your interested :)
User avatar
Alba Casas
 
Posts: 3478
Joined: Tue Dec 12, 2006 2:31 pm

Post » Tue May 17, 2011 1:46 pm

Hey, I've got another problem with C that I could use some help with. I'm probably missing something really obvious, but bear with me.

The program I'm making is supposed to combine several text files into one new file. In part of the program the user can input the names of anywhere up to 10 files from a single line of input(these names need to be stored into a struct data type, for use later on in the program), and I can't figure out how to make that work. The two main ways I've tried it with are with fgets(which doesn't work because it only stops after a new-line character), and scanf. Scanf works if I format it like this:

 scanf("%s %s %s", &structName.a, &structName.b, &structName.c) 


But, of course if I don't fill in all the variables the call of scanf won't end. Using multiple calls of scanf also doesn't work(the first call of scanf will just eat up all of the user's input until the new-line).



One other thing that I'm wondering is if it's possible to use a loop with structs. My program works perfectly if I'm only combining two files, and could work with combining 10 files into one if I expanded it(putting aside the user input issue), but it would be extremely bloated with repeats of the same block of code(tweaked slightly each time for each individual element of the variable) since loops don't seem to be easily done with structs(you can't increment a name...). Does anyone have tips on how I can make a loop work? Or should I just live with the ridiculous amount of bloat?
User avatar
Eric Hayes
 
Posts: 3392
Joined: Mon Oct 29, 2007 1:57 am

Post » Tue May 17, 2011 10:04 am

Anyone interested in starting some opensource .NET project with me? I am stuck on ideas and sometimes I don't feel like coding but I do want to get more experience with C#. I know I can pickup books and find random ideas online but those are tough due to alot of times not being interested in them.

I am not too concerned about working with graphics per se, maybe an image viewer would be an idea, so no major games or anything like that, but smaller projects would be nice.

Right now I am finishing up a semester here at school (couple weeks left) so I don't know how much time I have but I can make some since I tend to procrastinate anyways. When I get home for Christmas break I want to be productive and not game as much so I will have about 3 weeks or so to work on something.
User avatar
Katie Louise Ingram
 
Posts: 3437
Joined: Sat Nov 18, 2006 2:10 am

Post » Tue May 17, 2011 10:14 am

Does anyone here have experience with MATLAB?

I could do with some help with an ODE solver :)
User avatar
Ian White
 
Posts: 3476
Joined: Thu Jul 19, 2007 8:08 pm

Post » Tue May 17, 2011 1:16 am

So looks like tomorrow I have a phone interview for an internship as an assistant programmer, any ideas what I should expect from it? It is for a .NET position if I recall correctly and I am still learning C#, though I have a familiarity with VB.NET syntax (though not used it at all for any real programs) and only wrote a few small personal things with C# by using a bunch of Googling and MSDN.
User avatar
dell
 
Posts: 3452
Joined: Sat Mar 24, 2007 2:58 am

Post » Tue May 17, 2011 11:48 am

Hey, I've got another problem with C that I could use some help with. I'm probably missing something really obvious, but bear with me.

The program I'm making is supposed to combine several text files into one new file. In part of the program the user can input the names of anywhere up to 10 files from a single line of input(these names need to be stored into a struct data type, for use later on in the program), and I can't figure out how to make that work. The two main ways I've tried it with are with fgets(which doesn't work because it only stops after a new-line character), and scanf. Scanf works if I format it like this:

 scanf("%s %s %s", &structName.a, &structName.b, &structName.c) 


But, of course if I don't fill in all the variables the call of scanf won't end. Using multiple calls of scanf also doesn't work(the first call of scanf will just eat up all of the user's input until the new-line).



One other thing that I'm wondering is if it's possible to use a loop with structs. My program works perfectly if I'm only combining two files, and could work with combining 10 files into one if I expanded it(putting aside the user input issue), but it would be extremely bloated with repeats of the same block of code(tweaked slightly each time for each individual element of the variable) since loops don't seem to be easily done with structs(you can't increment a name...). Does anyone have tips on how I can make a loop work? Or should I just live with the ridiculous amount of bloat?

You have one line and you want to turn that into 1..10 character strings that represent file names? And, a space character would work as the separator? Not that there is scanf and sscanf. You can read the line and then parse it with the latter. See if that works. sscanf returns the number of results that you can also check. This number can be anything from zero to the expected number of results (10). It could also return EOF, which is some negative number.

The complex way you could do it is loop the character string until the end of line character '\0' after reading the line with sscanf or fgets. You need a temporary char string. On each space character ' ' you stop and copy the temporary char string to the struct. Now, I don't know how your struct is arranged. If you insist on having 10 separate named variables instead of a pointer array, you could do a switch case on an integer, and you always increase the integer by one, when you have found and added a string. In each case, you can then strcpy the character whereever you want.

If this was C++, I would do stream operations on the string. If this was VB, a single Split(input, " ") would return an array directly.
Does anyone here have experience with MATLAB?

I could do with some help with an ODE solver :)

Matlab was the main piece of software they used at the university math classes, but I'm quite bad at it..
So looks like tomorrow I have a phone interview for an internship as an assistant programmer, any ideas what I should expect from it? It is for a .NET position if I recall correctly and I am still learning C#, though I have a familiarity with VB.NET syntax (though not used it at all for any real programs) and only wrote a few small personal things with C# by using a bunch of Googling and MSDN.

I'm bad with interviews too, but they probably just want to hear about you, and maybe hear what you have done or studied. If it's for an internship, they shouldn't expect years of programming experience, at least in my opinion. You have to start somewhere, you know. I think it helps if you study the company or whatever the interviewer represents before the interview. It might be good if you figured something to ask too. If it's .NET, I would assume they expect C# mostly, but it could be anything from phones, client/server stuff, to PC applications, as it's quite a broad concept.

I know I went to my job interview and I had only just glanced the short description of the company and opened up their webpage. They asked me do I know anything about the company, and I honestly told them that I don't really, but they hired me anyways after having me program some very simple loop algorithm in C on a paper. I didn't really know anything about PL/SQL, and very little about VB, but those are like my main programming languages right now after 2 years. Ok, I've had a long experience with other languages though.. I expected to code in C++ though.

It depends so much on the employer.. Hopefully they have a good program on how to turn interns into experienced programmers :).
User avatar
Max Van Morrison
 
Posts: 3503
Joined: Sat Jul 07, 2007 4:48 pm

Post » Tue May 17, 2011 12:08 pm

So looks like tomorrow I have a phone interview for an internship as an assistant programmer, any ideas what I should expect from it? It is for a .NET position if I recall correctly and I am still learning C#, though I have a familiarity with VB.NET syntax (though not used it at all for any real programs) and only wrote a few small personal things with C# by using a bunch of Googling and MSDN.


A popular thing for programmers to ask you to do in an interview is write a linked list or other similar data structure, so it would be worth brushing up on that sort of stuff before you go in. Otherwise just try an be confident and if you don't know something, just tell them you don't instead of faffing about and wasting their time. You won't be expected to know everything, they'll be looking for potential rather than someone that can come in and contribute straight away in that sort of role.
User avatar
dean Cutler
 
Posts: 3411
Joined: Wed Jul 18, 2007 7:29 am

Post » Tue May 17, 2011 2:16 pm

A popular thing for programmers to ask you to do in an interview is write a linked list or other similar data structure, so it would be worth brushing up on that sort of stuff before you go in. Otherwise just try an be confident and if you don't know something, just tell them you don't instead of faffing about and wasting their time. You won't be expected to know everything, they'll be looking for potential rather than someone that can come in and contribute straight away in that sort of role.

Well looks like it was just a 'what do you know, and what have you done" type of interview. If they call me again then I will worry but as long as I am honest I should still have a shot at the internship.
User avatar
K J S
 
Posts: 3326
Joined: Thu Apr 05, 2007 11:50 am

Post » Tue May 17, 2011 5:10 am

Anyone interested in starting some opensource .NET project with me? I am stuck on ideas and sometimes I don't feel like coding but I do want to get more experience with C#. I know I can pickup books and find random ideas online but those are tough due to alot of times not being interested in them.

I am not too concerned about working with graphics per se, maybe an image viewer would be an idea, so no major games or anything like that, but smaller projects would be nice.

Right now I am finishing up a semester here at school (couple weeks left) so I don't know how much time I have but I can make some since I tend to procrastinate anyways. When I get home for Christmas break I want to be productive and not game as much so I will have about 3 weeks or so to work on something.


I'd be willing to help. I'd probably be more of a burden though :/
User avatar
Prohibited
 
Posts: 3293
Joined: Tue Jun 12, 2007 6:13 am

Post » Tue May 17, 2011 1:29 pm

I'd be willing to help. I'd probably be more of a burden though :/

Nobody would be a burden. It would a spare time project for something that would be of common interest to people or a series of projects that multiple people can pick up or stop working on at any time. Nothing serious that would be sold later (though that defeats the purpose of open source), just a for fun group of projects.
User avatar
April
 
Posts: 3479
Joined: Tue Jun 20, 2006 1:33 am

Post » Tue May 17, 2011 9:32 am

Nobody would be a burden. It would a spare time project for something that would be of common interest to people or a series of projects that multiple people can pick up or stop working on at any time. Nothing serious that would be sold later (though that defeats the purpose of open source), just a for fun group of projects.

Well then I'm up for it. I don't really have any ideas though... :confused:
User avatar
lucy chadwick
 
Posts: 3412
Joined: Mon Jul 10, 2006 2:43 am

Post » Tue May 17, 2011 5:17 am

Well then I'm up for it. I don't really have any ideas though... :confused:

What language do you write in? I use C# and am not familiar with how to load non-.NET assemblies yet. Using those written in .NET seems easy enough at least to reference them, dynamically loading them on the other hand is not as easy.
User avatar
Jonathan Windmon
 
Posts: 3410
Joined: Wed Oct 10, 2007 12:23 pm

PreviousNext

Return to Othor Games