PDA

View Full Version : Coding Choosing a programming class



JeenLeen
2014-04-17, 11:38 AM
I'm considering taking a class on a coding language. I took an online class on SQL about a year ago and enjoyed that a lot, and it's served me pretty well in my job as well.

At the program I'm looking at, I see C#, Python 3, and Perl. Could some of you tell me the pros and cons between them, including what their main usefulness is?

My coding experience thus far is some C++ (although I've forgotten a lot of it), a touch of HTML from high school, some VBA, and SQL. I'd find it easier to use a language similar to C++, but it might serve me better to learn something different and thus broaden my skill set.
For personal use, a programming language I could use to make routine some somewhat tedious tasks would be nice. Professionally, at the moment I doubt any would be of much help but anything that works well in synch with databases would probably help me later on.

As a little background about the program... there's probably little in there I couldn't learn picking up a "___ for Dummies"--SQL for Dummies had almost everything the class had, although I admit the class gave some opportunities to explore things I didn't understand--but I find I lack motivation to just pick up a book and learn it unless I have a particular project (or job interview) in mind.

ChristianSt
2014-04-17, 12:07 PM
I haven't had that much experience with C# and Python, but from doing a few minutes research on the net, C# seems to be closest to C++.
Wikipedia even lists "C# is built on the syntax and semantics of C++, allowing C programmers to take advantage of .NET and the common language runtime."

Python and Perl are often used for scripting, i.e. it doesn't need to be compiled, but the script (the code) is executed by an interpreter "on the fly".


So if you want a language closer to C++ pick C#.
If you want a language to write scripts, choose Python or Perl (though I can't really say which would be better for you).


(and I wouldn't really toss SQL and HTML into that comparison ...)

JeenLeen
2014-04-17, 03:22 PM
This is a basic question, but what does scripting (" i.e. it doesn't need to be compiled, but the script (the code) is executed by an interpreter "on the fly"") mean?

I understand from C++ using a compiler to put the code 'together' in a .exe file. Is Python or Perl more like (to use a bad analogy I'm sure) using the Command prompt in Windows to execute commands instantly?

factotum
2014-04-17, 03:30 PM
Sort of. Really it just means you don't have the compile stage before running the program, so it makes little difference in the coding you do. (It has to be noted that C#.NET CLR programs are not actually compiled all the way down to machine language either--they're compiled to a sort of intermediate bytecode which is then interpreted by the framework).

I suppose the critical question is: are you aiming cross-platform here, or are you targeting Windows? C# is almost entirely Windows-based--although the open source Mono framework attempts to allow .NET applications to be developed and run on non-Windows platforms, it's not commonly used. Python and Perl are far more heavily used in non-Windows environments and are thus probably a better choice if you're going for cross-platform development.

ChristianSt
2014-04-17, 04:00 PM
This is a basic question, but what does scripting (" i.e. it doesn't need to be compiled, but the script (the code) is executed by an interpreter "on the fly"") mean?

I understand from C++ using a compiler to put the code 'together' in a .exe file. Is Python or Perl more like (to use a bad analogy I'm sure) using the Command prompt in Windows to execute commands instantly?

Non-scripting languages (like C++ or Java) need to be compiled into bytecode of some sort (C++ gets compiled to machine code, Java gets compiled to java bytecode that is executed through the Java Virtual Machine) before they can be executed.

Scripting languages can execute your code directly (for example from the command line) by calling it by the interpreter.


So you normally still write your code the same way, but the execution setup is different. And for small programs it is imo nice to not need the compilation step each time.



And yes, I hadn't really considered the (sort of) Windows-dependency on C#, which is something that imo isn't that great.

PairO'Dice Lost
2014-04-17, 04:38 PM
One of the major benefits of scripting languages is that they tend to be "higher level" languages, meaning they have more levels of abstraction between you and the machine code so they require less work on the programmer's part to deal with the fine details. (This isn't an inherent quality of compilation vs. interpretation, the majority of languages just happen to be designed that way.) I'm going to assume you've worked with arrays in C before, since it's a fairly introductory topic, so I'll use arrays to compare how high- or low-level C and Python are and how easy or difficult they are to work with.

If you want to make an array in C, you need to declare an array variable with a type and a size:


int array[10];
array[0] = 5;
array[1] = 7;

If you want to change the type of the array you need to make a new variable, if you want to increase the size of the array, you need to make a new variable, and so on. In Python, you just declare a generic array:


array = []
array.append(5)
array.append("foo")

It can hold objects of any type (or combination of types), it automatically resizes for you, and does some other wonderful magical things.

Want to iterate through an array and print everything in it?

C:

int x;
for (x = 0; x < 10; x++)
{
printf("%d", array[x]);
}

Python:

for item in array:
print item

Want to copy part of an array into another array?

C:

int big_array[20];
int small_array[10];

//Put 20 things into big_array here

int x;
for (x = 3; x < 13; x++)
{
small_array[x-3] = big_array[x];
}

Python:

big_array = []

# Put 20 things into big_array here

small_array = big_array[3:13]

And so on and so forth. Scripting/interpreted languages are generally slower than traditional/compiled languages, but from the perspective of learning and using a language at a beginner level, the simplicity of using scripting languages wins out. I use C, Python, and SQL in my day job, and Python is by far my favorite to work with.

TL;DR: Learn Python. :smallwink:

Seerow
2014-04-17, 04:44 PM
One of the major benefits of scripting languages is that they tend to be "higher level" languages, meaning they have more levels of abstraction between you and the machine code so they require less work on the programmer's part to deal with the fine details. (This isn't an inherent quality of compilation vs. interpretation, the majority of languages just happen to be designed that way.) I'm going to assume you've worked with arrays in C before, since it's a fairly introductory topic, so I'll use arrays to compare how high- or low-level C and Python are and how easy or difficult they are to work with.

If you want to make an array in C, you need to declare an array variable with a type and a size:


int array[10];
array[0] = 5;
array[1] = 7;

If you want to change the type of the array you need to make a new variable, if you want to increase the size of the array, you need to make a new variable, and so on. In Python, you just declare a generic array:


array = []
array.append(5)
array.append("foo")

It can hold objects of any type (or combination of types), it automatically resizes for you, and does some other wonderful magical things.

Want to iterate through an array and print everything in it?

C:

int x;
for (x = 0; x < 10; x++)
{
printf("%d", array[x]);
}

Python:

for item in array:
print item

Want to copy part of an array into another array?

C:

int big_array[20];
int small_array[10];

//Put 20 things into big_array here

int x;
for (x = 3; x < 13; x++)
{
small_array[x-3] = big_array[x];
}

Python:

big_array = []

# Put 20 things into big_array here

small_array = big_array[3:13]

And so on and so forth. Scripting/interpreted languages are generally slower than traditional/compiled languages, but from the perspective of learning and using a language at a beginner level, the simplicity of using scripting languages wins out. I use C, Python, and SQL in my day job, and Python is by far my favorite to work with.

TL;DR: Learn Python. :smallwink:

Also relevant

http://imgs.xkcd.com/comics/python.png

Deadline
2014-04-17, 06:32 PM
Sure, learning Python might give you the measly ability to fly, but mastering Perl will give you Wizard Powers!TM

Seerow
2014-04-17, 07:09 PM
Sure, learning Python might give you the measly ability to fly, but mastering Perl will give you Wizard Powers!TM

I dunno, in the first (and sadly only) class I took that included Python, the Professor described Python as "black magic".

PairO'Dice Lost
2014-04-17, 07:28 PM
I dunno, in the first (and sadly only) class I took that included Python, the Professor described Python as "black magic".

Hardly. Perl works the blackest of black magics, Python is a paladin by comparison. :smallamused:

valadil
2014-04-17, 09:16 PM
I've never touched C#. It's primarily a Windows thing and I don't really know much about that.

I've done a fair bit with each of Python and Perl. If you don't have a specific goal in mind, I'd say go with Python. Each language already has a library that solves all your problems. But in Python's case, there's exactly one library for each problem.

In Perl's ecosystem you'll find a dozen different libraries (and there are a dozen more you didn't find) for any one problem, and the worst part is that nobody will tell you which is the right one. Perl rewards expertise. If you take the time to look at all the libraries you'll learn which is accepted as the best one. You'll learn which loop over a file descriptor is the most efficient (FTR, I think it's <>, but I'm no expert). And you'll learn all sorts of shortcuts like $_, $`, $$, and $% (I made up at least half of those, but I'm sure they're legit Perl).

I'm not saying Perl is a bad language. For someone who spends a ton of time with it, the learning curve pays off. If you don't have a specific goal in mind, I'm guessing you're doing this casually, and the learning curve won't pay off.

PairO'Dice Lost
2014-04-17, 09:57 PM
And you'll learn all sorts of shortcuts like $_, $`, $$, and $% (I made up at least half of those, but I'm sure they're legit Perl).

Yes they are. (http://www.kichwa.com/quik_ref/spec_variables.html)

factotum
2014-04-18, 06:45 AM
TL;DR: Learn Python. :smallwink:

I think it's a little unfair to be comparing Python with C, given the latter language was designed for operating system kernels and is barely one step removed from raw machine code. C# is a considerably different beast. (Also a bit puzzled that you apparently believe having really poor type safety is a *positive* feature of a language, but c'est la vie, I suppose :smallwink:).

Incidentally, you can resize an array in C# pretty easily:


char[] array = new char[5];

// Some code manipulating the array would presumably be here

Array.Resize(ref array, 10);

// Array now has 10 elements instead of 5.

PairO'Dice Lost
2014-04-18, 11:45 AM
I think it's a little unfair to be comparing Python with C, given the latter language was designed for operating system kernels and is barely one step removed from raw machine code. C# is a considerably different beast. (Also a bit puzzled that you apparently believe having really poor type safety is a *positive* feature of a language, but c'est la vie, I suppose :smallwink:).

I'm not comparing performance, niche applicability, or security, just ease of learning and using the language for a relative novice. Someone who didn't know what an interpreted language is until yesterday isn't going to be writing drivers or buffer exploits any time soon. :smallwink:

He wants to learn a language that can automatic routine tasks and interface with databases; Python is definitely the better tool for the former, and it's a lot easier than C for the latter.


Incidentally, you can resize an array in C# pretty easily

I know C# is relatively easy, but I will never recommend it because all of the Windows-specific programming ecosystem is the devil. :smallfurious:

(Just kidding. Mostly. More seriously, I don't do any Windows development, so I'm much more partial to platform-independent languages.)

JeenLeen
2014-04-18, 11:53 AM
Python sounds like a winner to me. I like the familiarity C# offers, since I know a little C++, and I'll probably work mostly with Windows, but being able to work outside of Windows would be nice.

And Python looks more easy-to-understand than Perl... and I dislike typing $, which seems common in Perl. (A silly reason, but my fingers just don't have that key memorized. :smallsmile:)

Thanks for the advice and examples of code. And I'm enjoying the conversation, so please keep on commenting, anyone who's interested.

Jasdoif
2014-04-18, 12:07 PM
I know C# is relatively easy, but I will never recommend it because all of the Windows-specific programming ecosystem is the devil. :smallfurious:

(Just kidding. Mostly. More seriously, I don't do any Windows development, so I'm much more partial to platform-independent languages.)Having done Microsoft development as the large part of my job for the last several years....I really can't recommend C# for CLR stuff. It works, sure, but it's always seemed like a low-level syntax aimed at a high-level language to me, and feels clumsy.

VB.Net, which is way better than Visual Basic (and VBA) had ever dreamed of being (low bar, I know), is a lot easier to work with and feels cleaner. And isn't difficult to use...at least not until you're trying to interact with other Microsoft products (I'm looking at you, SharePoint!), but you'd have the same kind of difficulties regardless of what language you're using.


All that said, though, VB.NET isn't one the options in the OP, and on occasion I've used Python to generate text to copy into VB files :smalltongue:

PairO'Dice Lost
2014-04-18, 12:34 PM
And Python looks more easy-to-understand than Perl... and I dislike typing $, which seems common in Perl. (A silly reason, but my fingers just don't have that key memorized. :smallsmile:)

It's not just $, either, and it's worse than you think. Perl has three kinds of variables: scalars (normal variables, with a $ in front), arrays (arrays, with a @ in front), and hashes (key-value stores, with a % in front). So you declare them with my $scalar, my @array, and my %hash.

Annoying to type, but not too bad...but wait! An array holds scalars, so to access the second item in array it's not @array[1], it's $array[1], because array[1] is a scalar. And if you want to pass an array to a function, you don't want to pass the whole thing, that's inefficient, you only want to pass an array reference, which is a scalar, like my $ref = \@array. And then to get that back into an array inside the function, you need to do my @array = @{$ref} (or just @$ref, but it's easy to misread that)...or you can just access an item without dereferencing it, which uses an arrow like a C pointer ($ref->[1]).

Yay Perl. And yet it's still one of my favorite languages, 'cause in what other language can you smack your head on the keyboard and have the resulting gibberish run as a valid and useful program? :smallbiggrin:

shawnhcorey
2014-04-18, 01:50 PM
Hardly. Perl works the blackest of black magics, Python is a paladin by comparison. :smallamused:

Hardly. Python is the pickup truck of languages: lightweight, versatile, easy on gas. Perl is the 18-wheeler: large loads, cost effective, long-distance hauler. :smallbiggrin:

The differences between interpreted languages and compiled ones has become blurry. Python and Perl compile their code at each run into an intermediate form which is executed. Java compiles into Java Bytecode which is then interpreted. C, C++, C# and family are compiled into a binary image of relocatable machine code (tho the need to be relocatable is no longer required on modern computers). Basically, don't worry about compiling or interpreting languages. The difference doesn't matter much on modern computers.

Deadline
2014-04-18, 02:20 PM
Basically, don't worry about compiling or interpreting languages. The difference doesn't matter much on modern computers.

Unless you are developing software where efficiency and performance are important issues (so, certain types of games, operating systems, high-performance networking software, etc). If you are writing business software, web applications, flash games, or the like, the performance issues that interpreted and scripting languages suffer aren't relevant. Or rather, their ease of use and ability to rapidly develop for far outweigh any concerns about performance.

As a note about the languages available to you, C# isn't a terrible choice. It uses almost identical syntax to Java, so you'd effectively be learning two languages there. But if this is just a thing you are doing to broaden your horizons, Python is probably the easiest to learn and manipulate.

Perl is the language of Lovecraftian horrors. It contains "secrets that man was not meant to know", and will drive you to the brink of jibbering insanity, but it is quite powerful as well.

factotum
2014-04-18, 03:49 PM
C, C++, C# and family are compiled into a binary image of relocatable machine code

As I said above, that's not true for C#--like all .NET CLR languages, it's compiled to an intermediate bytecode. You can put raw machine code into a C# program, but you have to mark those sections as "unsafe" specifically to tell the .NET interpreter that Here Be Dragons it doesn't want to be messing with.

Solse
2014-04-18, 07:07 PM
I don't have much experience with C#, but I feel that Python is good as a general-purpose language, while Perl is more for sysadmin stuff and doing useful tasks with your computer (moving around files, regexing, etc).

shawnhcorey
2014-04-18, 07:17 PM
I don't have much experience with C#, but I feel that Python is good as a general-purpose language, while Perl is more for sysadmin stuff and doing useful tasks with your computer (moving around files, regexing, etc).

True but CPAN turns Perl into a real workhorse. If you have a difficult task to do, chances are someone has already done it, done it better, and put it in CPAN. With CPAN, Perl can do anything.

valadil
2014-04-18, 10:02 PM
True but CPAN turns Perl into a real workhorse. If you have a difficult task to do, chances are someone has already done it, done it better, and put it in CPAN. With CPAN, Perl can do anything.

I agree with this and stand by my previous statement. Thirty other people have put that code on CPAN and nobody will tell you which of those libraries is worth using and which is junk.

JeenLeen
2014-04-21, 09:18 AM
I don't have much experience with C#, but I feel that Python is good as a general-purpose language, while Perl is more for sysadmin stuff and doing useful tasks with your computer (moving around files, regexing, etc).

Can Python do things like move groups of files from one folder to another, rename files, etc.?
I knew one guy who wrote a script (I guess) to rename all of his music files. I could see something like that being useful, or something like moving files in one location to different locations based on their names.

PairO'Dice Lost
2014-04-21, 11:59 AM
Can Python do things like move groups of files from one folder to another, rename files, etc.?

It can, as can pretty much any modern language, it's just that different languages have strengths in different areas.

Perl is considered to be more of a "sysadmin language" because (A) you can make really quick and dirty hacks with it if you don't use strict and use warnings, the "please stop me from shooting myself in the foot" interpreter directives, (B) the fact that regular expressions (things you can use to classify strings, like "Iron Man [I]{1,3}\..{3}" matches "Iron Man I.avi" and "Iron Man III.jpg" but not "Iron Man 2.mpeg") are "native" to Perl (you don't need to use any special modules or anything, they're as easy to use as arrays or math) means working with lots of files is easy, (C) the fact that it's an older language means that its modules have had most of the bugs ironed out, which may not be the case for the newest version of more recent languages, and (D) you can do a lot of code as one-liners, which is great for scripting because you can just copy-paste a one-liner into a terminal and have it work well.

Neftren
2014-04-22, 02:01 AM
I think you may be approaching this the wrong way. Essentially, you've given three possible programming languages, and asked for pros/cons for each. Sure, every language has its merits, and its flaws, but using pros and cons of a language to determine which one you're going to learn next seems very square peg, round hole (in my mind anyways).

Have you considered asking something along the lines of "I would like to do _______. Which programming language best suits this task?" To quote a rather well-known rant against PHP (http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/), "Part of what makes a good developer is the ability to choose the tools that work best." So, what is it you want to do?

JeenLeen
2014-04-23, 04:00 PM
I think you may be approaching this the wrong way. Essentially, you've given three possible programming languages, and asked for pros/cons for each. Sure, every language has its merits, and its flaws, but using pros and cons of a language to determine which one you're going to learn next seems very square peg, round hole (in my mind anyways).

Have you considered asking something along the lines of "I would like to do _______. Which programming language best suits this task?" To quote a rather well-known rant against PHP (http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/), "Part of what makes a good developer is the ability to choose the tools that work best." So, what is it you want to do?

Sorry for a late reply; it's been a busy week.

I think I want to learn a language that would let me do a lot of different things. Really vague, I know. Part of it is things like moving and renaming/organizing files en masse, but being able to create a decent AI tic-tac-toe game would be a fun challenge as well. Character creation programs for tabletop RPGs could be nice.
I like how VBA lets me automate tedious and frustrating tasks in Excel. If it could perform some tedious/routine calculations and spit them out into a text file (or even into Word or Excel), that would be nice. It just occurred to me that a simple line of code to copy & paste, then hit run, which opens all my favorite webcomics could be nice to help me easily check them all; or perhaps it opens them depending on what day it is, so I get those that should update on a given day.


On a side note, I'm going to be learning some SAS in my job in the next couple months. But SAS is really limited (statistical language) and expensive, so obviously not my go-to language.

factotum
2014-04-24, 01:40 AM
You can do those things in pretty much any dedicated programming language (the reason you can't do them in VBA is because it's designed for doing stuff to Excel documents, not being a general purpose language). Heck, since you already have experience with Excel VBA, you could probably look at VB.NET using Microsoft's free Express development environment! Really, the only reasons for choosing one language over another are (a) personal preference and (b) what platform you intend to be developing for, unless you have to do some exotic project that requires a specific language or library to work.

ChristianSt
2014-04-24, 03:07 AM
Really, the only reasons for choosing one language over another are (a) personal preference and (b) what platform you intend to be developing for, unless you have to do some exotic project that requires a specific language or library to work.

If you don't have a target/use case in mind, then yes, you can choose basically whatever language you like.

That being said, I don't share your opinion that it is basically personal preference. Yes, you can pretty much do anything in any programming language, but certain tasks are much easier with certain languages.

The most important is probably which paradigm the compared languages have. It makes a huge difference whether a language is functional, procedural or object-oriented (or supports multi-paradigm).

wumpus
2014-04-25, 09:07 AM
First, I'd recommend choosing based on the teacher. Since these are all basically scripted languages with garbage collection, it shouldn't matter that much between them. If they have the same teacher, I'd ask the teacher: if they can explain one much better, obviously that will work best.

I'd avoid Perl myself. You have to use Perl all the time or you forget critical pieces, also it is the notorious example of "write only code". If this isn't a problem (you write one-use scripts all the time as a system administrator), you should already know Perl.

From the looks of it (I've never used C#, but did use VBasic way back when), you will be grumpy if you have to make a gui with python. It isn't that bad, but nothing like the slickness of VBasic (and C# appears to have inherited that slickness). The problem with python GUIs is that it isn't integrated into the language, so you have to use some other languages toolkit (Guido included Tk's, there are bindings for things like Qt as well).

And of course, the big issue with C# is that you are tied to windows (or mono). Considering the rise of Android and iOS, this could be a problem (personally, I switched from Visual Basic to Python because integrating C/C++ libraries was so much easier (the gui issue pales besides trying to integrate a C++ library into visual basic), and found that I just *loved* Python.