Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Brian Bush
Brian Bush
4,398 Points

Loops, Arrays, Strings etc.

I was just looking over the JavaScript and Ruby libraries and I noticed that both of them have these types in their language. (Loops, Arrays, Strings, and so on) My question is do they use the same code for these types? or are they similar enough it makes it easy going from learning JS to Ruby? I would imagine that even if they did have different code for each, they execute the same way, just with different coding?

3 Answers

As far as style, variables are assigned without declaring the variable's type. That's known as "duck typing" or dynamic typing.

They act very differently at execution time. Some people consider JS untyped, which is inaccurate. It's actually weakly typed. It allows you do to all kinds of silly, invalid, and insecure things but allows for greater flexibility.

Ruby is strongly typed, which means all types are checked prior to execution. Ruby sometimes seems weakly typed because it allows you to mix types in certain operations, but it's performing conversions on the fly, not actually letting you smash types together.

James Barnett
James Barnett
39,199 Points

> noticed that both of them have these types in their language. (Loops, Arrays, Strings, and so on)

Paul Graham - Judging by the examples of types he gave, I think he means structures not data types.

Structure is addressed in the first sentence. Both languages are duck typed.

James Barnett
James Barnett
39,199 Points

Nearly all programming languages use the same structures for example Ruby, JavaScript, Python, Objective-C, Java they all use those. Learning to think algorithmically is a skill that is very transferable between languages.

There are of course major syntax differences in nearly all cases. There are of course some major differences in implementation which you have to learn about when learning the syntax.

Brian Bush
Brian Bush
4,398 Points

thank you both for the quick replies. would either of you recommend to learn php before ruby? or vice versa?

If your main goal is to get a job right now, PHP is probably a better bet. As a language Ruby is superior but PHP is not as bad as it's reputation, especially in recent versions. The Ruby toolset is useful outside of Ruby itself. I don't write much Ruby code professionally but I do extensively use tons of Ruby gems like Jekyll every day.

You should probably learn them both.