The Ur-Quan Masters Discussion Forum

The Ur-Quan Masters Re-Release => Starbase Café => Topic started by: Valos Cor on July 18, 2010, 05:04:53 am



Title: Programming
Post by: Valos Cor on July 18, 2010, 05:04:53 am
I'm interested in learning how to start modding the UQM code - starting with simple stuff like editing the dialogue etc - and learning the C programming language.  Those of you who know how to mod or know C...how did you learn?  How did you start off?  I'd appreciate knowing how you did it so I'd know how I should do it.


Title: Re: Programming
Post by: onpon4 on July 18, 2010, 05:36:20 am
There's some video tutorials on C and C++ by a user called "thenewboston". I don't know how good they are, but a lot of people seem to like his tutorials.


Title: Re: Programming
Post by: Valos Cor on July 18, 2010, 05:44:48 am
So what is thenewboston a member of? I'm not getting anything searching in this forum.  I would like to see the tutorials but also, I'd like to know how those of you who started modding or learning the code, started learning it.


Title: Re: Programming
Post by: onpon4 on July 18, 2010, 05:50:37 am
YouTube. Sorry about that.


Title: Re: Programming
Post by: Valos Cor on July 18, 2010, 05:53:08 am
Thanks, I found him - and about a hundred and something tutorials about all sorts of things, including C.


Title: Re: Programming
Post by: Valos Cor on July 18, 2010, 06:06:49 am
I rewound the tutorials from 20 or 30 or 40 something to tutorial number one about objective c programming and the guy is using Mac...I guess there might be a way to do whatever he's doing on Linux or Windows.

EDIT: Sigh...that was objective C...there's more than a hundred tutorials... more like 350.


Title: Re: Programming
Post by: onpon4 on July 18, 2010, 01:27:02 pm
I rewound the tutorials from 20 or 30 or 40 something to tutorial number one about objective c programming and the guy is using Mac...I guess there might be a way to do whatever he's doing on Linux or Windows.

EDIT: Sigh...that was objective C...there's more than a hundred tutorials... more like 350.

Objective C is a little different than C (it's used for iPhone apps). You should look at his C or C++ tutorials.

Of course, you could also try getting a book.


Title: Re: Programming
Post by: Gekko on July 18, 2010, 02:32:50 pm
I started by typing to google: "How to code c++". I learned playing guitar the same way. And I'm learning piano that way too.


Title: Re: Programming
Post by: xaionaro on July 19, 2010, 09:40:44 am
I'm interested in learning how to start modding the UQM code - starting with simple stuff like editing the dialogue etc - and learning the C programming language.  Those of you who know how to mod or know C...how did you learn?  How did you start off?  I'd appreciate knowing how you did it so I'd know how I should do it.
IMHO:
That's depend on how you want to programming. If you want to write good code, than you need big practice or/and good theory basis (for example you can start with some book about C-syntax + "The Art of Computer Programming"). But if you only want only to make a "mod" with no care for quality of the code, than you can start with C-syntax learning and modifying small foreign programs. After that you can try to make own small program. Then you need to learn UQM source code and, for example, draw-up function/file relation map [there's no good development documentation :(, so this can help to remember the code]. After that you can try to modify the UQM.


Title: Re: Programming
Post by: Dragon on July 19, 2010, 10:50:25 am
You could take a look at Cymon's Games (http://cymonsgames.com/).  It's run by guesst (now cymon) who still lurks in these forums.  He's probably one of the best people here to weigh in on this topic.

For my part I'd suggest starting small before jumping into the UQM code.  It's possible to do some very strange and confusing things in C/C++ that could leave you scratching for a good while before working out why they work.


Title: Re: Programming
Post by: Valos Cor on July 19, 2010, 08:34:14 pm
Thanks,  I've been trying to read this book called "Using C++ And Introduction to Programming".

Thanks for talking about Cymon's Games - I've been trying to remember what that was called.

thenewboston's tutorials are a heap of help!

I've been trying to make a "stat generator" by having a random number generator (that generates it from the current time) generate 3 numbers and each one being a stat.  I am no where near success (and there has to be a max number too).  Maybe that's not simple enough hehe.  Those simple C programs thenewboston has been talking about - some of them remind me of making batch files...?


Title: Re: Programming
Post by: RTyp06 on July 19, 2010, 11:34:29 pm
I think the most modern version of C and C++ is C# pronounced C "sharp" . I learned C back in the day by reading,practice, reading,practice and reading/practicing some more. This was before the huge volumes of header files, DLLs, code examples and walk throughs were available online. Most of the reference manuals and programming books I used were of the brand 'QUE'.

If I ever get serious about programming again, C# is the direction I plan to go.


Title: Re: Programming
Post by: onpon4 on July 20, 2010, 12:22:33 am
I think the most modern version of C and C++ is C# pronounced C "sharp" . I learned C back in the day by reading,practice, reading,practice and reading/practicing some more. This was before the huge volumes of header files, DLLs, code examples and walk throughs were available online. Most of the reference manuals and programming books I used were of the brand 'QUE'.

If I ever get serious about programming again, C# is the direction I plan to go.

Not quite. C# is a higher-level, proprietary language developed by Microsoft. It's probably best to not go in that direction, since there are possibly better, open source high-level languages available (i.e. Python).

There is also another interesting language based on C that I discovered near the beginning of 2nd semester last year, called C-- (http://en.wikipedia.org/wiki/C--), intended to be a lower-level (and therefore faster) language than C (i.e., assembly language). However, it probably isn't useful for most of us. :)


Title: Re: Programming
Post by: Valos Cor on July 20, 2010, 12:24:46 am
So what about graphics?  I'm thinking SDL.  So UQM is built on C right?  How did it implement the graphics?


Title: Re: Programming
Post by: Novus on July 20, 2010, 12:37:52 am
I think the most modern version of C and C++ is C# pronounced C "sharp" .
C# is a bit of a cross between several other object-oriented C-like languages, including Java and C++. Most introductory programming courses I've seen lately use Java (with Python being strongly considered as a replacement), although I've seen arguments for using pretty much every language I've ever heard of as a first programming language, including quite a few written for that purpose.

I'm not going to write an article on the subject; here's an "objective" comparison (http://portal.acm.org/citation.cfm?id=1315811). In practice, what's a "good" introductory programming language depends on you mean by "programming" and your priorities and goals, making the choice inherently subjective.

So what about graphics?  I'm thinking SDL.  So UQM is built on C right?  How did it implement the graphics?
UQM uses SDL and OpenGL for graphics; mostly SDL.


Title: Re: Programming
Post by: Valos Cor on July 20, 2010, 08:46:44 pm
I guess this its fine if I post a simple y/n question "game" program here.  It has SOMETHING to do with SC but its just one question so far but I was working hard on this because there was a bug - for some reason, if I have an if or else statement and under it I put more than one cout>> it won't work but I fixed it and I am so happy :)  I made it in C++ with Dev-C++.

Here it is:
(click to show/hide)
If I'm not supposed to post the executable file here...well, that was just the locations of the rainbow worlds :p

Right now, I'm trying to figure out what to do next.  Its supposed to fork in different paths whether you say y or n.  If you put Googlgotgoozabobble or some random letters, it'll give you a reply too.


Title: Re: Programming
Post by: Lukipela on July 20, 2010, 09:44:40 pm
I guess this its fine if I post a simple y/n question "game" program here.  It has SOMETHING to do with SC but its just one question so far but I was working hard on this because there was a bug - for some reason, if I have an if or else statement and under it I put more than one cout>> it won't work but I fixed it and I am so happy :)  I made it in C++ with Dev-C++.

Dude this is the Off Topic section. You're question doesn't have to relate to Star Control in any way. Feel free to ask any unrelated stuff about coding or penguins or anything really.


Title: Re: Programming
Post by: Valos Cor on July 20, 2010, 10:43:02 pm
Penguins!  In that case... may I present:

...uhh... there's nothing there. *looks up how to post pictures* tada!
Am I that stupid...*looks it up again*(http://imagebin.org/index.php?mode=image&id=106136)  I think it will work.
whatever, it doesn't work (yet)


Title: Re: Programming
Post by: Novus on July 21, 2010, 02:54:31 am
Dude this is the Off Topic section. You're question doesn't have to relate to Star Control in any way. Feel free to ask any unrelated stuff about coding or penguins or anything really.
That said, it would be nice if the programming stuff were in the 'Programming' thread and the penguins in a 'Penguin' thread or suchlike, just in case someone, for example, is interested in programming but scared to death of penguins.

It has SOMETHING to do with SC but its just one question so far but I was working hard on this because there was a bug - for some reason, if I have an if or else statement and under it I put more than one cout>> it won't work but I fixed it and I am so happy :)  I made it in C++ with Dev-C++.
As for your program, one of the reasons I prefer Java as a teaching language is that I can easily run students' code with zero or limited access to file systems, networks and so on, rather than trust them not to do something undesirable either intentionally or unintentionally. Another is that porting Java code from e.g. Windows to Linux is no work at all if it's properly written. Furthermore, class files are often small enough that I can easily disassemble them to figure out what they do even if source code is not provided. Since examining your program is impractical in all three ways mentioned above, I can't say much about it. Source code would help.

"It won't work" is a bit vague. That said, I suspect you forgot the curly brackets.


Title: Re: Programming
Post by: Valos Cor on July 21, 2010, 05:05:16 am
It has SOMETHING to do with SC but its just one question so far but I was working hard on this because there was a bug - for some reason, if I have an if or else statement and under it I put more than one cout>> it won't work but I fixed it and I am so happy :)  I made it in C++ with Dev-C++.
As for your program, one of the reasons I prefer Java as a teaching language is that I can easily run students' code with zero or limited access to file systems, networks and so on, rather than trust them not to do something undesirable either intentionally or unintentionally. Another is that porting Java code from e.g. Windows to Linux is no work at all if it's properly written. Furthermore, class files are often small enough that I can easily disassemble them to figure out what they do even if source code is not provided. Since examining your program is impractical in all three ways mentioned above, I can't say much about it. Source code would help.

"It won't work" is a bit vague. That said, I suspect you forgot the curly brackets.
Sorry for not including the source file.  The problem seems to be that if I put more than one cout>> under either if or else, it will not work and expect me to have a "primary-expression" before else and a semicolon before else as well even though I do have one.   I updated the file so it will have the working executable with its working source code and the notworking executable's source code.
 not  working source :http://www.4shared.com/account/file/oGzIv3FW/notworking.html (http://www.4shared.com/account/file/oGzIv3FW/notworking.html)
working exe: http://www.4shared.com/account/file/cNhn2IQO/working.html (http://www.4shared.com/account/file/cNhn2IQO/working.html)
working source: http://www.4shared.com/account/file/h3tp6fRz/working.html


Title: Re: Programming
Post by: Resh Aleph on July 21, 2010, 10:23:18 am
not  working source :http://www.4shared.com/account/file/oGzIv3FW/notworking.html (http://www.4shared.com/account/file/oGzIv3FW/notworking.html)

Note that C-like programming languages ignore multiple consecutive whitespace (including newlines, spaces and tabs), so

Code:
if (condition)
    statement1;
    statement2;
    statement3;

is interpreted just like this:

Code:
if (condition)
statement1;
statement2;
statement3;

or this:

Code:
if (condition)
    statement1;

statement2;
statement3;

and so on. The compiler interprets it like the last formatting suggests: "If condition holds, perform statement1. Then, regardless, perform statement2 and statement3."

What you need here is a block for grouping the three statements together:

Code:
if (condition)
{
    statement1;
    statement2;
    statement3;
}

The same goes for else if/else.

(To avoid confusion and bugs, some recommend to always use a block after if/else if/else, even if it's just a single statement in the block.)


Title: Re: Programming
Post by: superbutcherx on July 21, 2010, 12:45:44 pm
I've found
www.cplusplus.com/doc/tutorial/
useful at learning new things and rehearsing the old.

Even though it's for C++, the first parts of the tutorial (Basics of C++, Introduction, Control Structures, Compound Data Types) hold true for C since these parts are essentially the same for both languages.

The best way to learn how UQM works is to read and re-read the source files like crazy :)
It also helps a lot, if you have finished the game hundreds of times and played it a gazillion times. It works wonders on understanding what the functions in the source code really do.

Also, always, if you modify something in the code, add a comment with your own unique identifier at the end of the line like // ZXZ. It will save you a lot of time hunting down what you've done, especially if you leave the code alone for a couple of weeks and return to it after that. When the mod keeps growing it's not a bad idea to make a list of files that you've tinkered with and add a short summary of mods you've done to that file.


Title: Re: Programming
Post by: Megagun on July 24, 2010, 09:41:10 pm
I'm interested in learning how to start modding the UQM code - starting with simple stuff like editing the dialogue etc - and learning the C programming language.  Those of you who know how to mod or know C...how did you learn?  How did you start off?  I'd appreciate knowing how you did it so I'd know how I should do it.
My advice: drop the idea and learn to code in an easier language first. I'd recommend Java with either NetBeans or Eclipse as the IDE. Try writing some easy console apps, then write a simple game using Java + JOGL (NetBeans has a nice JOGL plugin, including a few good templates to get you started easily). Once done, rewrite parts of the game to use the fewest amount of classes possible, store data in byte arrays, and write your own implementations of a few functionalities you're using from the Java standard libraries.

Once done with that, you should have enough knowledge to start the transition to C, which would allow you to mod UQM somewhat.

Very slightly related, but still worth the read nonetheless: http://cube.wikispaces.com/How+not+to+start+a+mod


Title: Re: Programming
Post by: chenjesuwizard on August 12, 2010, 02:23:50 pm
I have a problem.
I used Winzip to extract the source code, then Dev C++ to edit the various files.
Then, what do I do? I can't compile the folder and when I compress the folder and then load it onto Dev C++ it comes up with weird coding, which it won't compile.
How do I compile it?


Title: Re: Programming
Post by: TiLT on August 13, 2010, 03:16:36 pm
I'm interested in learning how to start modding the UQM code - starting with simple stuff like editing the dialogue etc - and learning the C programming language.  Those of you who know how to mod or know C...how did you learn?  How did you start off?  I'd appreciate knowing how you did it so I'd know how I should do it.
My advice: drop the idea and learn to code in an easier language first. I'd recommend Java with either NetBeans or Eclipse as the IDE. Try writing some easy console apps, then write a simple game using Java + JOGL (NetBeans has a nice JOGL plugin, including a few good templates to get you started easily). Once done, rewrite parts of the game to use the fewest amount of classes possible, store data in byte arrays, and write your own implementations of a few functionalities you're using from the Java standard libraries.

Once done with that, you should have enough knowledge to start the transition to C, which would allow you to mod UQM somewhat.

Very slightly related, but still worth the read nonetheless: http://cube.wikispaces.com/How+not+to+start+a+mod

I'll second this, but for different reasons. Try learning a strict object oriented language first, such as C# or Java, even if you don't intend to use them much later (though stuff like C# is probably going to inspire you if you're a Windows user). Starting with C or C++ teaches you bad habits since the two languages allow you to do just about anything you like, including stuff that isn't smart to do at all. It's easier to transition down from a high-level language than to move up from a low-level language (the first time). Trust me. I've been there. It nearly messed up my ability to get through computer science classes.


Title: Re: Programming
Post by: ziper1221 on August 13, 2010, 05:12:30 pm
On, the same note, how useful is python and Java? both of them are classes offered at my school next year.


Title: Re: Programming
Post by: Death 999 on August 13, 2010, 07:43:27 pm
Java is widely used. Knowing how to use it will be useful.

Python is a very different beast. One serious mode is just to enter commands one line at a time! It too is widely used. I can't say which is better, really. If you really want to be a serious programmer, Java might be better. If you just want to get the idea of programming, python might be better? I'm not familiar enough with python to be sure.


Title: Re: Programming
Post by: onpon4 on August 14, 2010, 02:05:26 am
Java is widely used. Knowing how to use it will be useful.

Python is a very different beast. One serious mode is just to enter commands one line at a time! It too is widely used. I can't say which is better, really. If you really want to be a serious programmer, Java might be better. If you just want to get the idea of programming, python might be better? I'm not familiar enough with python to be sure.

Python is an excellent language, IMHO. Its biggest advantages are ease-of-use, cleanliness of code (due to its unusual use of whitespace for code blocks), and that it's dynamically typed. There are also a large amount of 3rd party libraries, making it useful for a huge number of tasks, including graphical programs (i.e. games) and GUIs. Finally, it is an interpreted language, meaning you don't have to compile it; you just run it.

Of course, there is one disadvantage: Python scripts can only be run if you have Python installed. However, besides the fact that most Linux distributions come with some form of Python already, there are 3rd party modules which can "freeze", i.e. compile, scripts along with necessary Python and 3rd party components (such as py2exe, py2app, and cxFreeze), allowing people who don't have Python installed to run your program.

Not knowing much about Java, I can't say which class you should pick, if you have to choose one. I would take both if possible.


Title: Re: Programming
Post by: Gekko on August 14, 2010, 03:27:59 am
Java programming probably gets you a job. At least here you end up doing GUIs with Netbeans if you know Java. I'm not sure where Python is used in the market, but I like Python more than Java. If you know C/C++, then a huge load of various doors to even extraordinary places open.

If you are considering employment, then it's also important to learn the development on other platforms. It's highly different to make a program on Windows/Linux/OS X


Title: Re: Programming
Post by: Novus on August 14, 2010, 12:52:42 pm
First of all, I would like to point out that Java and Python are quite similar languages in many ways and share the same ALGOL/C origins; if you learn one, picking up the other won't be hard. Both require a separate runtime environment that is available as free software and often included in Linux distributions but not in, for example, Windows. Although they are both general-purpose platform-independent languages, they target different uses: Python tends to see lots of use as a quick and convenient language to control or extend other programs (e.g. web servers, 3D animation software, games), while Java tends to show up in user-facing software more (applets, desktop applications).

My impression of how these two languages are developing is that Java has a stronger emphasis on building and maintaining systems (corporate priorities), while Python focuses on being clean and straightforward to write in (hacker priorities). If you're writing something to get a job done for yourself, Python may be less work, but I wouldn't want to base a major corporate infrastructure on it quite yet.

As far as learning goes, Python is probably the better bet as a first programming language (mostly because of its cleaner syntax and lack of clutter in small programs), although Java isn't much worse.


Title: Re: Programming
Post by: superbutcherx on August 19, 2010, 02:57:55 pm
I have to agree with onpon4 and Novus: Python is an excellent language for its clean, intuitive syntax and ease of use (especially when learning it as your first programming language): For example you don't have to muck around so much with different variable types as in C/C++ and it's more straightforward to manipulate files and use system command line commands. Java puts me off with its unnecessarily long-winded syntax (the likes of system.out.println vs Python's print).

I've been programming stuff for network simulators for a living a while now. My main tools have been both straight C and C++. I think those are still the "bread and butter" of programming languages in the engineering world. They tried to introduce Java in place of C in the introduction classes here in the university's computer engineering studies some years back , but have since quietly returned to teaching C.

In addition Python has been a lot of use for me when programming scripts for extracting results from tens of thousands of files. That could've been done also in C/C++, but would have been a more tardy way, with all the compilations and the quirkier format for file manipulation.


Title: Re: Programming
Post by: Death 999 on August 19, 2010, 04:42:01 pm
Java's print syntax is not unnecessarily long-winded. Flexibility and clarity come at a reasonable cost in length. And if you don't want to have to type System.out every time, feel free to declare

Code:
PrintStream a = System.out;

a.println(...);
...
a.println(...);
...
a.println(...);

which is much shorter, only four characters longer than just 'print'. And if you want to use the 'print' function, go ahead. System.out has it. But you'll have to put in the line break yourself. i.e. print("blah\n"); is the same as println("blah");
How do you print a line and end it in python?

So yeah. Once per function that prints to stdout (which shouldn't be many) java takes one line and three or four characters more than python to do the same thing.

MASSIVE BLOAT!!!!!1one


Title: Re: Programming
Post by: onpon4 on August 19, 2010, 06:49:11 pm
Quote
How do you print a line and end it in python?

Was this a serious question? I can't tell.

If it was, the print statement (now the print() function in Python 3.x) automatically ends the line normally. In Python 2.x, this is bypassed by adding a comma after the print statement; in Python 3.x, it is a print() function, and there is a parameter ('\n' by default) which specifies what the printed string ends with (normally, this is left alone or changed to '' or ' ').


Title: Re: Programming
Post by: Death 999 on August 19, 2010, 10:16:33 pm
It was a serious question. The original version of the question, before I edited it away by accident, followed up, "If print does that by default, how do you not have it automatically end the line?"

Looking at the answer...

Interesting that print was demoted to function from core syntax.


Title: Re: Programming
Post by: superbutcherx on August 20, 2010, 10:48:12 am
Java's print syntax is not unnecessarily long-winded. Flexibility and clarity come at a reasonable cost in length.

Well put! There's always pros and cons in every design choice and that's why no language can be claimed to be absolutely better than another one. For certain tasks and purposes, yes, one trumps the other, but not for every one of them.

What I meant to convey with my "unnecessarily" was that from learning-your-first programming-language point of view, it might be confusing to face a wide array of flexibility and options, when all you need for your specifc purposes is just one of them.

In that infamous basics of programming class we only used System.out.println for that one purpose -printing lines on screen-, and received quite a little in the way of explaining what is this System, why does the command come only after all those prefixes, or how it could be declared shorter as you showed in your example.

Now that I think of it, that's more a fault of the teaching being bad than the language being unwieldy.
I think the teacher tried to achieve both: a) Show us students the versatility of java by demonstrating long-winded commands b) make it easy to learn by not painstakingly explaining all the details of the command, just using one instance of it in practice to see what happens.

Unfortunately, from my POV he failed in both accounts:
Typing in long commands without seeing the point in the syntax just made it frustrating for a beginning programmer. This made me veer towards languages that seemed more "sensible" to me at the time. :)


Title: Re: Programming
Post by: onpon4 on August 20, 2010, 03:11:27 pm
In that infamous basics of programming class we only used System.out.println for that one purpose -printing lines on screen-, and received quite a little in the way of explaining what is this System, why does the command come only after all those prefixes, or how it could be declared shorter as you showed in your example.

Now that I think of it, that's more a fault of the teaching being bad than the language being unwieldy.
I think the teacher tried to achieve both: a) Show us students the versatility of java by demonstrating long-winded commands b) make it easy to learn by not painstakingly explaining all the details of the command, just using one instance of it in practice to see what happens.

Unfortunately, from my POV he failed in both accounts:
Typing in long commands without seeing the point in the syntax just made it frustrating for a beginning programmer. This made me veer towards languages that seemed more "sensible" to me at the time. :)

That's what I don't like about YouTube user thenewboston's ("Bucky") video tutorials. I've only seen his Python tutorials; there were a ton of things, especially in his wxPython tutorials, that he didn't explain; he just said "do it, I'll explain it later" and never explained them. This is a horrible long-term teaching strategy; it is VERY frustrating to be forced to use something you don't understand, especially because you don't understand how to properly manipulate it, yet almost every teacher seems to do this.


Title: Re: Programming
Post by: Death 999 on August 20, 2010, 04:58:02 pm
Well put! There's always pros and cons in every design choice and that's why no language can be claimed to be absolutely better than another one.

umm. Some languages, even serious ones, are just bad. I can't think of any reasonably modern programming language that is worse than fortran 77 at anything, except that java's 'hello world' is longer than fortran 77's. If you actually do anything more complicated than calculate the factorial of something, the balance shifts back.


Title: Re: Programming
Post by: Novus on August 21, 2010, 01:09:45 pm
umm. Some languages, even serious ones, are just bad. I can't think of any reasonably modern programming language that is worse than fortran 77 at anything, except that java's 'hello world' is longer than fortran 77's. If you actually do anything more complicated than calculate the factorial of something, the balance shifts back.
A programming language doesn't get that popular without doing something right.

I take it you've never done heavy-duty numeric processing; physics simulation people tend to swear by Fortran, even FORTRAN 77. Built-in complex arithmetic, lots of opportunities for compiler optimisations that pointers and references prevent, lots of high-performance numerical libraries; these are things that e.g. the C/Java branch of languages doesn't do or doesn't do as well as even FORTRAN 77. Admittedly, FORTRAN 77 is very annoying and limited in other ways, but that's why we have Fortran 90 (and later versions), which adds a lot of things to Fortran that users of ALGOL-like languages take for granted (e.g. recursion).


Title: Re: Programming
Post by: Megagun on August 21, 2010, 04:59:30 pm
The problem I have with Python is that it is dynamically typed, which makes having a browser open next to your IDE almost mandatory as there'd practically zero code completion when you need it. This makes researching stuff ("I want to do X, how do I do it") hard, even more so because what some function returns is pretty arbitrary...

Unlike Java, where there is nice static typing, and documentation standards are high. This makes understanding existing code a lot easier, even though code tends to bloat up a bit.


Title: Re: Programming
Post by: onpon4 on August 21, 2010, 06:14:28 pm
The problem I have with Python is that it is dynamically typed, which makes having a browser open next to your IDE almost mandatory as there'd practically zero code completion when you need it. This makes researching stuff ("I want to do X, how do I do it") hard, even more so because what some function returns is pretty arbitrary...

Unlike Java, where there is nice static typing, and documentation standards are high. This makes understanding existing code a lot easier, even though code tends to bloat up a bit.

You're not making much sense to me here. The big difference between static typing and dynamic typing is statically typed languages perform type checking at compile time, while dynamically typed languages perform type checking at run time. Dynamically typed languages are also much more flexible, though more resource-intensive, than statically typed languages. This has absolutely nothing to do with availability of documentation.

Ignoring that: First of all, you can easily look up information on specific topics, keywords, modules, functions, and classes by using the help() function in interactive mode. Second, Python comes with a comprehensive and easy to understand manual. Third, there is a great forum, python-forum.org (http://www.python-forum.org/pythonforum/index.php), where many people are willing to answer questions, and most 3rd-party modules have a forum or mailing list you can ask questions on. Considering that Java is far more widely used than Python, it makes sense that it's easier to look up help on Java, but I personally have never had much of a problem figuring something out that I was confused about.


Title: Re: Programming
Post by: Death 999 on August 21, 2010, 08:45:30 pm
A programming language doesn't get that popular without doing something right.

I take it you've never done heavy-duty numeric processing

I did a fair amount of monte carlo simulation. In Fortran 77. It was hellish.

Maybe if I had had to use complex numbers I would have found the alternatives even more hellish. But I didn't.

Lots of opportunities for compiler optimisations that pointers and references prevent, lots of high-performance numerical libraries

Interesting. I don't see that the libraries are really an intrinsic part of the language, but restricting your actions so as to permit optimization is fair enough.


Title: Re: Programming
Post by: Novus on August 21, 2010, 09:38:48 pm
I did a fair amount of monte carlo simulation. In Fortran 77. It was hellish.

Maybe if I had had to use complex numbers I would have found the alternatives even more hellish. But I didn't.
No one is disputing that FORTRAN 77 is a pain to use. Since you didn't mention what your Monte Carlo simulation was a simulation of (although I imagine it's something to do with nanoscale physics), it's hard to say whether Fortran was the right choice. Using an ancient version of Fortran certainly doesn't make things any better (unless, of course, you were doing this in . However, as I've been trying to point out, someone must have liked it enough to put you in the situation where you had to use it.

Quote
Interesting. I don't see that the libraries are really an intrinsic part of the language, but restricting your actions so as to permit optimization is fair enough.
They may not be part of the language, but they are indisputably an important part of the programming experience in most situations.


Title: Re: Programming
Post by: Megagun on August 22, 2010, 12:16:34 am
The problem I have with Python is that it is dynamically typed, which makes having a browser open next to your IDE almost mandatory as there'd practically zero code completion when you need it. This makes researching stuff ("I want to do X, how do I do it") hard, even more so because what some function returns is pretty arbitrary...

Unlike Java, where there is nice static typing, and documentation standards are high. This makes understanding existing code a lot easier, even though code tends to bloat up a bit.

You're not making much sense to me here. The big difference between static typing and dynamic typing is statically typed languages perform type checking at compile time, while dynamically typed languages perform type checking at run time. Dynamically typed languages are also much more flexible, though more resource-intensive, than statically typed languages. This has absolutely nothing to do with availability of documentation.
Since Python is dynamically typed, my IDE (Eclipse + Pydev) can't determine the type of an attribute and thus can't give me useful info when I want to do something with some value that some random function returned. Unlike my Java IDE (NetBeans, but it should be similar in Eclipse) which happily shows me information on anything I want. This is especially useful when trying to understand existing code. Place the cursor over something you don't understand, hit CONTROL+SPACE, and browse through the documentation of the class of which the selected attribute is the type.

If I get some value (integer, class instance) from a function and want to know what I can do with it in Python, I'd have to manually go through the parent function's code or documentation in order to find out what it actually returns, then go through the code for the returned class to find out what I can actually do with it. In Java, I'd just hit CONTROL-SPACE and that's it. My Python IDE sometimes gives me proper results for autocomplete (I guess whenever the codebase is tiny and it can actually determine what class a given attribute is), but mostly it doesn't.

So, indeed, typing doesn't have any direct influence on availability of documentation, but in practice I definitively noticed that documentation wasn't just on the screen whenever I wanted it quickly.


Title: Re: Programming
Post by: onpon4 on August 22, 2010, 02:27:48 am
Since Python is dynamically typed, my IDE (Eclipse + Pydev) can't determine the type of an attribute and thus can't give me useful info when I want to do something with some value that some random function returned. Unlike my Java IDE (NetBeans, but it should be similar in Eclipse) which happily shows me information on anything I want. This is especially useful when trying to understand existing code. Place the cursor over something you don't understand, hit CONTROL+SPACE, and browse through the documentation of the class of which the selected attribute is the type.

If I get some value (integer, class instance) from a function and want to know what I can do with it in Python, I'd have to manually go through the parent function's code or documentation in order to find out what it actually returns, then go through the code for the returned class to find out what I can actually do with it. In Java, I'd just hit CONTROL-SPACE and that's it. My Python IDE sometimes gives me proper results for autocomplete (I guess whenever the codebase is tiny and it can actually determine what class a given attribute is), but mostly it doesn't.

So, indeed, typing doesn't have any direct influence on availability of documentation, but in practice I definitively noticed that documentation wasn't just on the screen whenever I wanted it quickly.

It sounds to me your problem isn't the dynamic typing, but the lack of a feature that you've become used to in your Java IDE. Honestly, I am not quite understanding the problem, though. Usually I can intuitively understand what to do with a given data type; I don't need to be told what I can do with it. For example, I already know that with a string:
- I can iterate through the individual characters (since it is an iterable data type)
- Since it is an immutable data type, I cannot append new characters to it (but I can delete the entire string).
- I can concatonate the string with another string to return a larger string (perhaps to store it in a variable)
- I can pass it as a parameter for various functions and methods (i.e. print)
- etc...

Perhaps I'm not understanding you correctly, but you seem to be suggesting that you need to constantly look up how to use different data types properly, and as a result, Python is difficult because it doesn't show you this information unless you look it up in the manual or search for it with help(). If I am misunderstanding, please correct me.


Title: Re: Programming
Post by: Novus on August 22, 2010, 12:11:04 pm
Perhaps I'm not understanding you correctly, but you seem to be suggesting that you need to constantly look up how to use different data types properly, and as a result, Python is difficult because it doesn't show you this information unless you look it up in the manual or search for it with help(). If I am misunderstanding, please correct me.
I think it's more a question of not being easily able to determine which type you need to look up. In a statically typed language, determining the type of a value is easy (even if not explicitly declared). In a dynamically typed language, this may be impossible. Hence, when you're working with a complex set of objects that refer to objects and return other objects from their methods, static typing can make it a lot easier to keep track of what type of value you have at a given point in your program. Not only does this allow an IDE to provide helpful features like auto-complete, it also makes a lot of bugs detectable at compile-time.


Title: Re: Programming
Post by: Megagun on August 22, 2010, 02:31:07 pm
Perhaps I'm not understanding you correctly, but you seem to be suggesting that you need to constantly look up how to use different data types properly, and as a result, Python is difficult because it doesn't show you this information unless you look it up in the manual or search for it with help(). If I am misunderstanding, please correct me.
I think it's more a question of not being easily able to determine which type you need to look up. In a statically typed language, determining the type of a value is easy (even if not explicitly declared). In a dynamically typed language, this may be impossible. Hence, when you're working with a complex set of objects that refer to objects and return other objects from their methods, static typing can make it a lot easier to keep track of what type of value you have at a given point in your program. Not only does this allow an IDE to provide helpful features like auto-complete, it also makes a lot of bugs detectable at compile-time.
Yeah, exactly. I usually know pretty well the things I can do with strings, ints, dicts, etc; but not the things I can do with $CLASS_I_HAVE_NEVER_HEARD_OF. Java IDEs make exploring those unknown classes easy, but Python IDEs.


Title: Re: Programming
Post by: onpon4 on August 22, 2010, 03:08:06 pm
Perhaps I'm not understanding you correctly, but you seem to be suggesting that you need to constantly look up how to use different data types properly, and as a result, Python is difficult because it doesn't show you this information unless you look it up in the manual or search for it with help(). If I am misunderstanding, please correct me.
I think it's more a question of not being easily able to determine which type you need to look up. In a statically typed language, determining the type of a value is easy (even if not explicitly declared). In a dynamically typed language, this may be impossible. Hence, when you're working with a complex set of objects that refer to objects and return other objects from their methods, static typing can make it a lot easier to keep track of what type of value you have at a given point in your program. Not only does this allow an IDE to provide helpful features like auto-complete, it also makes a lot of bugs detectable at compile-time.
Yeah, exactly. I usually know pretty well the things I can do with strings, ints, dicts, etc; but not the things I can do with $CLASS_I_HAVE_NEVER_HEARD_OF. Java IDEs make exploring those unknown classes easy, but Python IDEs.

All you have to do in Python is use IDLE to edit your source code instead of some other obscure IDE. Simply enter i.e. help('module.classname') in interactive mode to look up a class. Since an interactive window is usually always open in IDLE, this is a simple matter of switching windows for a moment.


Title: Re: Programming
Post by: Megagun on August 22, 2010, 04:53:55 pm
That still doesn't get around the "knowing what class a given variable has" issue, though.. And if I have to read source code to find that out, I might aswell read the sourcecode of the class in question.

Also, Eclipse, obscure?


Title: Re: Programming
Post by: onpon4 on August 22, 2010, 05:50:29 pm
That still doesn't get around the "knowing what class a given variable has" issue, though.. And if I have to read source code to find that out, I might aswell read the sourcecode of the class in question.

Can you give an example? I'm still not understanding quite what the issue is.