What to learn: Perl, Python or Ruby?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Which Language

Perl
5
11%
Python
23
50%
Ruby
12
26%
Ruby On Rails
0
No votes
All of the above
6
13%
 
Total votes: 46

Thefox14
Posts: 14
Joined: Mon Oct 26, 2009 5:48 am UTC

What to learn: Perl, Python or Ruby?

Postby Thefox14 » Mon Oct 26, 2009 5:58 am UTC

Hey all,
I've been programming for a little while and keep hearing about how cool/useful Perl, Ruby and Python are. I love learning new languages so I figured I'd learn one of these.

I looked online trying to find the general uses of Perl, Python and Ruby but couldn't find a great answer. Could someone please give me an explanation?

So, which language do you think would be a good choice?

If you need any more info feel free to ask!

Thanks for all help!

-Fox
Last edited by Thefox14 on Mon Oct 26, 2009 6:00 pm UTC, edited 1 time in total.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Berengal » Mon Oct 26, 2009 6:11 am UTC

I'd vote "all three", but there was no option for it. Lacking that, I voted Ruby, since it's the most significantly different from other languages, and embodies the spirits of perl, smalltalk and lisp.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

poohat
Posts: 230
Joined: Mon Apr 07, 2008 6:21 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby poohat » Mon Oct 26, 2009 10:43 am UTC

either of the not-perl options

User avatar
spudtheimpaler
Posts: 181
Joined: Thu May 24, 2007 11:57 am UTC
Location: München

Re: What to learn: Perl, Python or Ruby?

Postby spudtheimpaler » Mon Oct 26, 2009 1:59 pm UTC

poohat wrote:either of the not-perl options

I'm interested in this as I'm due to learn a scripting language... I was going to go with Ruby. I'm curious why you say non-perl though?
Fueled by tea and bad maths since 1983...

User avatar
ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: What to learn: Perl, Python or Ruby?

Postby ash.gti » Mon Oct 26, 2009 3:41 pm UTC

It would be worth while to learn all 3, but i'd say python's the easiest to learn, as its a little more simple than the others. They are all pretty interchangeable in their uses. A lot of ruby programmers do a lot of meta programming which can take a while to get your heard around. Ruby is used a lot in web stuff, but its pretty good for general scripting. Perl is great at text processing and for making your life easy, thanks to CPAN. CPAN is perl's external library of community maintained libraries for everything from rotating logs to compiling a linux kernel to simple login scripts for Apache.

A lot of people use python for teaching and for science based stuff (it has some really good features that are easy to add like a graphing thing).

Ruby has probably the most limited range of uses of the 3, mainly ruby has been used for web stuff in the past, although it is occasionally used elsewhere. Its perfectly capable of doing the same stuff as perl or python, I'd argue, it just doesn't have as large of a user base.

Perl and python are two opposite extremes of what can happen in a programming language. Most people consider perl hard to read and sometimes difficult to follow because it has some unconventional ways of doing things, and many different was of doing things. Python on the other hand, as one of its main design considerations, is there should be 1 way of doing things, the python way of doing things. Perl's philosophy is more "there is more than one way to do it". Perl 5 has a kind of hacked on OO system too, and a few annoying quirks (lists are automatically flattened, you can't put certain objects in arrays which means you have to put references which gets confusing) but perl 5 is great for text processing, thanks to its built in regular expression system. PCRE (perl compatible regular expressions) are the most common style of regular expressions and they are a fundamental part of perl 5.

Python is very structured and enforces a lot of constraints on what your capable of, and how you can extend python (with say a compiled extension). A lot of people like it because of its structuredness, you can't really obfuscate python code, hardly at all.

Perl 6 is also something worth looking into. I'd consider it a vastly different beast than perl 5. If you want to learn a new scripting language, perl 6 is pretty impressive. Its a complete re-wite of perl from the ground up that had a specification first. There are a few implementations, but 1 main one thats called Rakudo (means "the way of the camel") which implements a huge portion of the specification. No implementations fully support the spec yet, and the spec keeps changing whenever it gets feedback from the actual developers about things that are working and things that aren't working. It has a number of really neat features, including an even more integrated and fundamentally involved regular expression system, multi-methods, classes and traits, a grammar syntax that lets you extend the basic grammar system of perl 6, and even a system for adding new operators to the language.
# drinks WAY to much espresso

User avatar
bocochoco
Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

Re: What to learn: Perl, Python or Ruby?

Postby bocochoco » Mon Oct 26, 2009 5:26 pm UTC

This poll lacks a "none of the above" option. c-style syntax is superior!
Image

User avatar
ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: What to learn: Perl, Python or Ruby?

Postby ash.gti » Mon Oct 26, 2009 5:55 pm UTC

bocochoco wrote:This poll lacks a "none of the above" option. c-style syntax is superior!


perl uses a c-style syntax

examples:

Code: Select all

perl:
for ($count = 10; $count >= 1; $count--) {
    print "$count ";
}
print "Blastoff.\n";

c:
for (int count = 10; count >= 1; count--) {
    printf("%d ", count);
}
printf("Blastoff.\n");


Key differences: perl has sigils to represent the way your attempting to access the variable, c has data types (perl is dynamically typed), and in perl print is a language construct not a function call.
# drinks WAY to much espresso

Thefox14
Posts: 14
Joined: Mon Oct 26, 2009 5:48 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby Thefox14 » Mon Oct 26, 2009 6:02 pm UTC

Thanks for all the responses, its really appreciated

I edited the poll to include an All the above option and I've gained some curiosity about Ruby on Rails as well.

Right now I've been working a lot with web applications and php. I think I'll be working with databases, apps, and websites as my main focus for a while, so based on that which one would you choose?

Thanks again for all the help guys!

-Fox

User avatar
bocochoco
Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

Re: What to learn: Perl, Python or Ruby?

Postby bocochoco » Mon Oct 26, 2009 7:16 pm UTC

Thefox14 wrote:Thanks for all the responses, its really appreciated

I edited the poll to include an All the above option and I've gained some curiosity about Ruby on Rails as well.

Right now I've been working a lot with web applications and php. I think I'll be working with databases, apps, and websites as my main focus for a while, so based on that which one would you choose?

Thanks again for all the help guys!

-Fox


If you don't know Ruby, don't think about Ruby on Rails yet. Gotta learn Ruby first.

poohat
Posts: 230
Joined: Mon Apr 07, 2008 6:21 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby poohat » Mon Oct 26, 2009 8:15 pm UTC

spudtheimpaler wrote:
poohat wrote:either of the not-perl options

I'm interested in this as I'm due to learn a scripting language... I was going to go with Ruby. I'm curious why you say non-perl though?

illogical hacky language with the dumbest syntax ever and a silly design philosophy which disincentivizes writing readable code. Also the best thing about perl is that if you stop using it for more than two months then youll forget almost everything about the language and have to relearn all the arbitrary syntax/hacks from scratch

good libraries though.

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Emu* » Mon Oct 26, 2009 8:23 pm UTC

Grails is pretty awesome and runs on Java servers such as Apache Tomcat. (Grails -> groovy on kinda-rails, groovy is compiled into java bytecode)
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

|Erasmus|
Branson
Posts: 2643
Joined: Tue Oct 30, 2007 7:53 am UTC
Location: Sydney, Australia
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby |Erasmus| » Mon Oct 26, 2009 11:58 pm UTC

Emu* wrote:Grails is pretty awesome and runs on Java servers such as Apache Tomcat. (Grails -> groovy on kinda-rails, groovy is compiled into java bytecode)

I heard Sun were developing some JavaFx script which was supposed to be a compiled-to-java-bytecode scripting language for that kind of purpose. It might have better support by now than this one. Just throwing it out there.

Perl is executable line noise (not always true, but often). If you like that kind of thing, go for it.

The languages do have different uses though. For simple command-line apps that I want to be reusable I use python. I am yet to learn perl, but it is apparently easier (and certainly seems like it would be quicker) to automate simple file-manipulation/regex related tasks in.

Decide what you want the language to be used for, and pick what seems most appropriate, as with almost all programming tasks.

poohat
Posts: 230
Joined: Mon Apr 07, 2008 6:21 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby poohat » Tue Oct 27, 2009 2:25 am UTC

its not that perl makes it easier to write those sort of scripts, its that it has a lot of syntactic shortcuts which let you do the same thing in fewer lines of code (even though the logic is the same). This can be useful if youre writing a quick script, but it has downsides relating to readability etc.

gorcee
Posts: 1501
Joined: Sun Jul 13, 2008 3:14 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby gorcee » Tue Oct 27, 2009 4:55 pm UTC

Perl's a great language for teaching yourself to document your code.

Because one day you'll write something, and then three years later you'll want to do something similar. Then you'll look at your Perl code and say, "what the fuck, what asshole wrote this?" and you'll have no one to blame but yourself.

poohat
Posts: 230
Joined: Mon Apr 07, 2008 6:21 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby poohat » Tue Oct 27, 2009 7:36 pm UTC

more like 3 days

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby You, sir, name? » Tue Oct 27, 2009 9:21 pm UTC

I'll tell you why you shouldn't learn the languages. Go for the one that seems least undesirable.

Perl: It's a proven fact that it's impossible to distinguish a paper of garbled nonsense composed by a monkey with a typewriter and a valid perl program.
Python: It's a nice language to learn programming in, but I wouldn't want to live there.
Ruby: Ruby is a fanatical cult. And not in the good, mass marriage / constant sex orgy way either. More like the tracksuit wearing, mass suicide way.
Ruby on rails: See ruby.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
OOPMan
Posts: 314
Joined: Mon Oct 15, 2007 10:20 am UTC
Location: Cape Town, South Africa

Re: What to learn: Perl, Python or Ruby?

Postby OOPMan » Wed Oct 28, 2009 7:42 am UTC

I voted Python. I don't think Ruby on Rails should be an option for the same reason that Django isn't an option (Ie. A language framework does not fit in the list)
Image

Image

Thefox14
Posts: 14
Joined: Mon Oct 26, 2009 5:48 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby Thefox14 » Wed Oct 28, 2009 3:57 pm UTC

Thanks for all the great feedback guys!

Well i'm between python and ruby. Both look like great languages so I think I'm going to pick both ruby and python and see which one I like working with the best.

You guys have any tips or good tutorials you'd suggest for someone just starting in these languages?

User avatar
Monika
Welcoming Aarvark
Posts: 3672
Joined: Mon Aug 18, 2008 8:03 am UTC
Location: Germany, near Heidelberg
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Monika » Wed Oct 28, 2009 5:03 pm UTC

Why not to learn Perl: Test Shows 99.99% of High School Seniors Can't Read Perl
... Perl experts were astounded by the results. "I was amazed that none of the students were able to read this simple sentence:
$_='while(read+STDIN,$_,2048){$a=29;$c=142;if((@a=unx"C*",$_)
[20]&48){$h=5;$_=unxb24,join"",@b=map{xB8,unxb8,chr($_^$a[--$h+84])}
@ARGV;s/...$/1$&/;$d=unxV,xb25,$_;$b=73;$e=256|(ord$b[4])<<9|ord$b[3];
$d=$d>>8^($f=($t=255)&($d>>12^$d>>4^$d^$d/8))<<17,$e=$e>>8^($t&
($g=($q=$e>>14&7^$e)^$q*8^$q<<6))<<9,$_=(map{$_%16or$t^=$c^=
($m=(11,10,116,100,11,122,20,100)[$_/16%8])&110;$t^=(72,@z=(64,72,$a^
=12*($_%16-2?0:$m&17)),$b^=$_%64?12:0,@z)[$_%8]}(16..271))[$_]^
(($h>>=8)+=$f+(~$g&$t))for@a[128..$#a]}print+x"C*",@a}';s/x/pack+/g;eval
I mean, come on, that's so easy," said Paul Chen, Chairman of the Learn Perl or Die Association ...


I would actually recommend you learn Java, especially as you mentioned your experience is mostly PHP so far. You would benefit from learning a strongly-typed, very object-oriented language.

If you only want to choose between Perl, Python and Ruby I would recommend Python. All three are similar to PHP in that they are weakly typed, interpreted languages (scripting languages). For Perl and Python OO is possible, but it is not central (Ruby is OO as far as I know). Python enforces some good programming practices and is readable very well. Ruby's syntax is a bit unusual ... are there other languages with an "unless" statement? Learning Ruby early might actually make it harder to learn other programming languages easily, later. A friend told me that Ruby was designed for Japanese minds, I wonder if this is true.

If you want to start learning Python, use the official tutorial http://docs.python.org/tutorial/ .
#xkcd-q on irc.foonetic.net - the LGBTIQQA support channel
Please donate to help these people

User avatar
Guff
Posts: 165
Joined: Thu Jan 03, 2008 11:56 pm UTC

Re: What to learn: Perl, Python or Ruby?

Postby Guff » Wed Oct 28, 2009 7:35 pm UTC

Monika wrote:Ruby's syntax is a bit unusual ... are there other languages with an "unless" statement?

Perl.

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Xanthir » Wed Oct 28, 2009 8:30 pm UTC

Lisp has one too. It's a great little feature for making things more readable. IF has three clauses - the test, then the two possibilities. WHEN has only two - the test, and the code to run if the test returns true. UNLESS is the same, except it runs the code when the test returns false.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby 0xBADFEED » Wed Oct 28, 2009 8:39 pm UTC

Monika wrote:All three are similar to PHP in that they are weakly typed, interpreted languages (scripting languages).

Ruby and Python are both strongly (dynamically) typed languages.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Berengal » Wed Oct 28, 2009 10:52 pm UTC

Xanthir wrote:Lisp has one too. It's a great little feature for making things more readable. IF has three clauses - the test, then the two possibilities. WHEN has only two - the test, and the code to run if the test returns true. UNLESS is the same, except it runs the code when the test returns false.

It's common for functional languages to have many different control structures. Most of them aren't keywords. For example, Haskell has 'unless' too. It's definition:

Code: Select all

unless = when . not

Oh, and when's definition:

Code: Select all

when True act = act
when False _  = return ()
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

|Erasmus|
Branson
Posts: 2643
Joined: Tue Oct 30, 2007 7:53 am UTC
Location: Sydney, Australia
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby |Erasmus| » Thu Oct 29, 2009 2:10 am UTC

Monika wrote:(Ruby is OO as far as I know)

In Ruby... -everything- is an object. That is its basic philosophy.

User avatar
ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: What to learn: Perl, Python or Ruby?

Postby ash.gti » Thu Oct 29, 2009 2:59 am UTC

The only things not objects in ruby are the control statements (if, unless, def, when, case, end, class, module, else, raises, ...), also everything returns something, even if its nil.

Code: Select all

puts (if 1 == 1
  a = 5
end).class #=> Fixnum

puts (if 1==2
  a = 5 # this never happens and there is no else clause nil is returned
end).class #=> NilClass


If you don't say return then each block of code returns the last expression in it (in this case the assignments return their result).
# drinks WAY to much espresso

Rwm28juni
Posts: 53
Joined: Sun Jul 19, 2009 1:48 pm UTC

Re: What to learn: Perl, Python or Ruby?

Postby Rwm28juni » Thu Oct 29, 2009 8:19 am UTC

I say Ruby, because it's the first language which I learned (or semi-learned). Since this is (in my opinion) a rather easy language to learn, this is a good one to start with. I realized after while that I couldn't seem to do much with it, so now I'm learning C++ :D

User avatar
Monika
Welcoming Aarvark
Posts: 3672
Joined: Mon Aug 18, 2008 8:03 am UTC
Location: Germany, near Heidelberg
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Monika » Thu Oct 29, 2009 9:43 am UTC

0xBADFEED wrote:
Monika wrote:All three are similar to PHP in that they are weakly typed, interpreted languages (scripting languages).

Ruby and Python are both strongly (dynamically) typed languages.

As far as I know "strongly typed" refers to specifying what type variables are, e.g.
int i;
Klass k;
which then automatically disallows using them as parameters to functions and methods whose parameter is specified to be of another type, as well as disallowing k.method() if method is not defined in Klass.

I would go so far to call PHP, Ruby and Python untyped, but weakly typed seems to be the preferred term (even though I don't see how something can be called typed if you can use it as parameter everywhere and call any method on it.)

|Erasmus| wrote:
Monika wrote:(Ruby is OO as far as I know)

In Ruby... -everything- is an object. That is its basic philosophy.

Yeah yeah, everything is an object, just like in Smalltalk. A rather theoretical concept. It totally doesn't matter if 3 + 4 means you call the plus method on the 3 object with the 4 parameter. Ruby still allows procedural programming and apparently it is often used ... or maybe just the simple sample programs I looked at used it.
#xkcd-q on irc.foonetic.net - the LGBTIQQA support channel
Please donate to help these people

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Emu* » Thu Oct 29, 2009 10:01 am UTC

Monika wrote:I don't see how something can be called typed if you can use it as parameter everywhere and call any method on it.


You can explicitly cast variables in PHP, but the casting tends to just happen, depending how you use it. Instead of refusing to accept the parameter, you get a result you didn't expect.
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

User avatar
Monika
Welcoming Aarvark
Posts: 3672
Joined: Mon Aug 18, 2008 8:03 am UTC
Location: Germany, near Heidelberg
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Monika » Thu Oct 29, 2009 10:05 am UTC

Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

Where did this occur / is this quote from?
#xkcd-q on irc.foonetic.net - the LGBTIQQA support channel
Please donate to help these people

User avatar
TNorthover
Posts: 191
Joined: Wed May 06, 2009 7:11 am UTC
Location: Cambridge, UK

Re: What to learn: Perl, Python or Ruby?

Postby TNorthover » Thu Oct 29, 2009 11:20 am UTC

Monika wrote:As far as I know "strongly typed" refers to specifying what type variables are, e.g.
int i;
Klass k;
which then automatically disallows using them as parameters to functions and methods whose parameter is specified to be of another type, as well as disallowing k.method() if method is not defined in Klass.

That's static typing (with the opposite being dynamic). The strong/weak distinction effectively refers to how easy casts are (how fixed the type of a single object is).

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Emu* » Thu Oct 29, 2009 11:55 am UTC

Monika wrote:
Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

Where did this occur / is this quote from?


xkcd coding contest, Nopscotch challenge. My entry was written in Java. Also, that's my sig, not part of the post.

[/offtopic]
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

|Erasmus|
Branson
Posts: 2643
Joined: Tue Oct 30, 2007 7:53 am UTC
Location: Sydney, Australia
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby |Erasmus| » Thu Oct 29, 2009 1:00 pm UTC

TNorthover wrote:
Monika wrote:As far as I know "strongly typed" refers to specifying what type variables are, e.g.
int i;
Klass k;
which then automatically disallows using them as parameters to functions and methods whose parameter is specified to be of another type, as well as disallowing k.method() if method is not defined in Klass.

That's static typing (with the opposite being dynamic). The strong/weak distinction effectively refers to how easy casts are (how fixed the type of a single object is).

Static typing is also not even necessarily related very closely to strong/weak. I'm sure berengal or someone can explain far better than I can just how strongly typed Haskell is (hint: very), despite being dynamically typed.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: What to learn: Perl, Python or Ruby?

Postby 0xBADFEED » Thu Oct 29, 2009 1:42 pm UTC

TNorthover wrote:
Monika wrote:As far as I know "strongly typed" refers to specifying what type variables are, e.g.
int i;
Klass k;
which then automatically disallows using them as parameters to functions and methods whose parameter is specified to be of another type, as well as disallowing k.method() if method is not defined in Klass.


That's static typing (with the opposite being dynamic). The strong/weak distinction effectively refers to how easy casts are (how fixed the type of a single object is).

Yes, Static/Dynamic and Weak/Strong typing are completely orthogonal. The two categories can be mixed and matched freely.

Examples:

[Static/Weak] : C, VB
Something like C is typically thought of as statically/weakly typed. Types are checked statically at compile time, but there is minimal type enforcement, casting between types is liberally allowed, and the language allows many implicit conversions.

[Static/Strong] : OCaml, Haskell
The type system strongly enforces the stated/deduced types of variables and does not allow conversion between types (for the most part). Types are checked statically at compile time. This gives the strongest guarantee of type-correctness.

[Dynamic/Strong] : Python, Ruby
Variables can have their type reassigned at runtime, but no (or very few) implicit conversions will occur between types. Type-based dispatch errors are run-time errors instead of compile-time errors. This type system is also frequently called duck-typing.

[Dynamic/Weak] : Javascript, Perl
Like other dynamic languages variables can take different unrelated types. But some implicit conversions are performed, for example, the statement 3 + "40" is legal.

The Wikipedia page on type systems is very informative. The distinction between weak/strong and static/dynamic isn't really black and white though. It's more like a sliding-scale.

Or really, more of a 2D plane with axes of Static/Dynamic and Weak/Strong with each programming language's type system being a point on the plane.

Monika wrote:I would go so far to call PHP, Ruby and Python untyped, but weakly typed seems to be the preferred term (even though I don't see how something can be called typed if you can use it as parameter everywhere and call any method on it.)

You could call them untyped, but you'd be wrong. And most programmers would look at you funny because those languages are most definitely typed. The only untyped language I can think of off the top of my head is ASM.

|Erasmus| wrote:Static typing is also not even necessarily related very closely to strong/weak. I'm sure berengal or someone can explain far better than I can just how strongly typed Haskell is (hint: very), despite being dynamically typed.

Haskell is statically/strongly typed, it just uses type-inference allowing the programmer to omit most type annotations.
Last edited by 0xBADFEED on Thu Oct 29, 2009 4:02 pm UTC, edited 5 times in total.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Berengal » Thu Oct 29, 2009 1:48 pm UTC

|Erasmus| wrote:I'm sure berengal or someone can explain far better than I can just how strongly typed Haskell is (hint: very), despite being dynamically typed.

Haskell is indeed very strongly typed. You can't use a value unless the types match exactly. For example, you can't use an Int where a Float is expected, or even where an Integer is expected; you have to explicitly use a conversion function to convert it first. Haskell isn't dynamically typed at all. The runtime doesn't even know what a type is.

In statically typed languages, types follow names. In dynamic languages they follow values. Or put another way: In statically typed languages, the type of a value is a property of the type (i.e. the type knows what values belong to it), but in dynamically typed languages the type of a value is a property of the value (i.e. the value knows what type it belongs to).

In untyped languages, there's no notion of type at all, or everything is one type. Examples: assembly, bash.
In weakly typed languages there is a notion of types, but it will treat any value as it was of the correct type even when it isn't, either by attempting to implicitly convert it or by mindlessly flailing on. Example: C
In strongly typed languages, a program won't compile/will raise a runtime exception if the type of a value doesn't match the expected type instead of trying to implicitly cast it or just treat the bits that are there as if they were the correct type. Example: Haskell
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Xanthir » Thu Oct 29, 2009 1:51 pm UTC

So Lisp is a dynamic/strongly typed language (outside of the numeric tower, which *does* do implicit conversions)? Interesting.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Berengal » Thu Oct 29, 2009 1:53 pm UTC

Xanthir wrote:So Lisp is a dynamic/strongly typed language (outside of the numeric tower, which *does* do implicit conversions)? Interesting.

You... didn't know that?
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Xanthir » Thu Oct 29, 2009 1:55 pm UTC

I've ignored any adjectives applied to the word 'typing' for a long time.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Earlz
Gets Obvious Implications
Posts: 785
Joined: Sat Jun 09, 2007 8:38 am UTC
Location: USA
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Earlz » Thu Oct 29, 2009 5:50 pm UTC

I voted for ruby because well.. it's awesome lol

If your coming from a Cish lanuage background, it may take a bit of getting use to (what!? `print @var` is the same as `print(@var)`!?) and it took me quite a while to wrap my head around the functional aspects of it such as yield and how blocks always return something... but really, once you learn it, you'll never unlearn it because it's so consistent. If you have even a hint at how something works, that probably is indeed how it works.

It also has regex embedded in the language and the way it's completely OOP is pretty nifty(it's not like Java at all, in that Java's OOPness sucks for some reason.. Maybe it's that System.Out.Print that annoys me.. ).. And all classes are open, so if you want to change how the `+` operator works on numbers, you can and it will be reflected in things like `2+2`..

I'm still new to Ruby so I haven't messed with much of the metaprogramming stuff, so can't comment on that
My new blag(WIP, so yes it's still ugly..)
DEFIANCE!
Image
This is microtext. Zooming in digitally makes it worse. Get a magnifying glass.. works only on LCD

User avatar
Vault
Posts: 169
Joined: Mon Nov 10, 2008 5:00 pm UTC
Location: Just past the event horizon
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Vault » Thu Oct 29, 2009 7:57 pm UTC

Ruby and Python are really pretty similar and you won't go wrong with either one. The biggest differences between them are probably how common idioms are expressed. Consider:

In Python

Code: Select all

for item in alist:
    dostuff(item)

versus in Ruby:

Code: Select all

alist.each { |item| dostuff item }


I like Ruby better, but you can't go wrong either way.

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: What to learn: Perl, Python or Ruby?

Postby Xanthir » Thu Oct 29, 2009 9:01 pm UTC

Yup, that's essentially the imperative vs functional paradigm. Python being heavily imperative of course likes the for loop, while Ruby being somewhat functional leans toward mapping.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 5 guests