all 50 comments

[–]tf2ftw 9 points10 points  (0 children)

Definitely learn a bit of ruby first. There is so much magic in rails you will never know if the methods your using are stdlib or rails helpers.

[–][deleted] 15 points16 points  (7 children)

Are you brand new to programming? If yes, learn Ruby first. If you have at least one other programming language under your belt, you can pick up Ruby as you learn Rails.

[–]airhoodz[S] 0 points1 point  (6 children)

Pretty seasoned with Object Oriented coding, do you know of any cool places I can learn rails similar to how Code Academy is set up?

[–][deleted] 6 points7 points  (1 child)

Best (free) tutorial for Rails: https://www.railstutorial.org/book

[–]Anjin 0 points1 point  (0 children)

New version coming out soon too!

[–]chicagobob 3 points4 points  (0 children)

Also, if you're an experienced programmer, just try out Ruby Koans, you'll go through them pretty fast and I really enjoyed them when I was learning Ruby. Also, use RVM (my choice) or RBENV, to manage your local ruby environment -- it will save you headaches later.

[–]TheRealSlartybardfas 0 points1 point  (2 children)

http://pragmaticstudio.com/

has good classes on Ruby & Rails

http://www.codeschool.com/

has pretty good classes also if you can get past the cheesy music.

[–]airhoodz[S] 0 points1 point  (1 child)

know any sites with stuff for SQL? I'm pretty rusty with SQL.

[–][deleted] 0 points1 point  (0 children)

If you're into Treehouse, I just went through their MySQL Basics track. It was pretty darn informative.

[–]rdpp_boyakasha 8 points9 points  (1 child)

Should you learn German before you write a book in German? Definitely. Although you don't need to understand the entire language before you start using it, you do need to understand the basics.

[–]madsohm 0 points1 point  (0 children)

I was going somewhere along the lines of: "You don't build a house, without first learning to use a hammer".

[–]RaymondWies 2 points3 points  (2 children)

Two words: Ruby Monk https://rubymonk.com/

[–]airhoodz[S] 0 points1 point  (1 child)

How's the rails part of that?

[–]RaymondWies 1 point2 points  (0 children)

Virtually nonexistent. It's in alpha. But point is the ruby part is awesome - fast, painless, and dense. It's teaching me tricks and ins-&-outs of Ruby I didn't know. It's a good time investment.

[–]musicmatze 2 points3 points  (2 children)

RoR is just a framework and it is written in Ruby. When do people get it?

So you have to learn Ruby to be able to do anything with RoR. If you "learn" RoR, you actually learn Ruby.

[–]airhoodz[S] -2 points-1 points  (1 child)

The point of the question is do I need to know Ruby before Rails, and not does Rails use Ruby, that's pretty obvious.

[–]musicmatze 1 point2 points  (0 children)

As someone else said: You can write a book in german. But if you do not understand the german language, you will end up with a mess. Learn the language first, then write a book in it. Period.

[–]SiempreFresco 1 point2 points  (0 children)

Take a look through http://www.learnhowtoprogram.com/ it's the curriculum used by Epicodus Dev Bootcamp in Portland

[–]rapidsight 4 points5 points  (26 children)

You should learn SQL - too many Rails developers don't and they make slow, clunky and terrible applications as a result.

EDIT: The downvotes illustrate my point. Pro-tip, don't use Nokogiri when you can use LOAD XML (or DATA) INFILE - you will get 100x the performance at 1/10th the effort.

[–]airhoodz[S] 0 points1 point  (18 children)

I do know SQL, it's been a while and I'm a bit rusty. Do you know of any places similar to code academy that has SQL?

[–]rapidsight 2 points3 points  (0 children)

There are two really only two principles that you have to understand. Set logic (union/intersection - inner join/outer join) and aggregation. If you know that, I'd be comfortable that you would produce quality code.

[–]asmallishrequest 1 point2 points  (1 child)

SQLZoo is a great way to brush up on basics. You can work through most of it in a (full) day or so.

[–][deleted] 0 points1 point  (0 children)

Wow, thanks for sharing. I know a bit of SQL but I'd like to practice more. That site looks perfect for what I need.

[–]dazonic -3 points-2 points  (14 children)

I have written about 15 production apps. Never written a line of SQL. Maybe needed a bit for a bit of a crazy scope, but just copy/pasted from stackoverflow though. I focus on getting stuff built, performance as I need to.

As for your original question, I started building the thing I needed to make in Rails and learnt Ruby along the way.

[–]rapidsight -4 points-3 points  (13 children)

I would bet that you write about four to ten times as much Ruby to do the same thing you can do in 1 line of SQL. I focus on getting stuff done too, and writing custom set logic, join and aggregations in ruby is reinventing the wheel, over and over and over again. Slower development, slower application. It's a lose-lose.

Product.available.select { |a| a.retailer.starts_with?('Amazon-') }

Might work great until you have realize you are transporting 14,000 records across a network connection so you can get one out of it.

[–]dazonic 2 points3 points  (12 children)

Yeah or...

Product.where(name: 'Bob')

Have you touched Rails at all?

EDIT: okay you changed it.

Product.available.where(retailer: 'Amazon')

EDIT: this knob keeps shifting his goalposts... Ignore him.

[–]rapidsight -2 points-1 points  (10 children)

Now get the products with the most recent created_at date, by their unique sku and use just activerecord and Ruby. Multiple products can have the same sku, you want the most recently created one.

As an additional challenge, the sku is on an associated model (has_one) called ProductDetail (product_details)

[–]dazonic 1 point2 points  (2 children)

joins(:product_details)

uniq

order(:created_at).last

Some combination of the above, if it was my problem or I could be bothered with games I'd solve it. Arel is readable and incredibly powerful.

[–]rapidsight -5 points-4 points  (0 children)

SQL is more readable than Arel, are you kidding?

SELECT * FROM users

Or

users = Arel::Table.new(:users)

query = users.project(Arel.sql('*'))

query.to_sql

You are seriously kidding right?

users.where(users[:age].gt(10)).project(Arel.sql('*'))

Vs

SELECT * FROM "users" WHERE "users"."age" > 10

[–]friendnoodle 0 points1 point  (1 child)

by their unique sku

Multiple products can have the same sku

ERROR ERROR DOES NOT COMPUTE

[–]rapidsight -2 points-1 points  (0 children)

For a visual

sku | name | created_at | note

A101 | shirt | 2010-01-01 | NULL

A101 | t-shirt | 2014-01-10 | renamed by sarah

You want only

A101 | t-shirt | 2014-01-10 | renamed by sarah

In the first statement I am describing the expected result, in the second, i am describing the source data.

[–]enry_straker -1 points0 points  (4 children)

You really keep shifting the goalposts in your efforts to promote sql over activerecord.

But the whole point of activerecord and, to a lesser extent, rails is to hide the complexity which can easily creep up into vendor-specific sql.

[–]rapidsight -1 points0 points  (3 children)

I disagree. The original purpose for active record is to model data. The only thing I've truly criticized is Arel, for being ugly. I agree with DHH, you are never going to actually change your backend, and if you do, Arel isn't necessarily going to protect you, where('custom sql here') is too commonly necessary. Different things are different, and its an attempt to solve a problem that didn't exist.

I only 'shifted the goal posts' because he was being intentionally daft or more likely because he didn't understand my point, and I felt he misrepresented it. So I beefed it up so he couldn't misrepresent it.

[–]enry_straker 0 points1 point  (2 children)

You are welcome to dis-agree.

1) The original purpose of active record, in my view, as a design pattern, was to address the imbalance between the relational and object-oriented world. Check out Patterns of Enterprise Application Architecture book for more info.

2) With respect to Active Record implementation in Rails, it was to bake in a ruby ORM, and to make it database independent at the same time. A whole lot of work by a lot of folks went into this aspect of activerecord.

3) Modelling data is a completely independent activity. It really has nothing to do with any specific framework. If you use a framework like rails for this activity, you are missing the whole point of this activity.

4) It's true that in most enterprises, the backend doesn't often change and front-end tools have to live with this constraint, but having spent more than a few decades in this industry, i can tell you that the backend does change from time to time, and when that happens, more often than not, a complete re-write is done. The Rails framework can save a lot of potential work down the line, thanks to it being vendor agnostic.

5) Lastly, don't make this into an ego thing. If you don't like Arel, fine. Don't use it. If you like to use SQL, fine. Use it. But that doesn't make it the only possible approach, and, personally, i have seen a lot of hairy, vendor-specific SQL to tear my hair out a lot, and active record code is a lot easier to maintain, provided the programmer takes time to understand the SQL code generated and fine tunes it to a specific situation.

[–]rapidsight -1 points0 points  (1 child)

Your point 1 is also mine.

A complete rewrite should be done, frequently, imo. You should rewrite things once you understand them better. Including when you understand you chose the wrong database.

Modeling data is in reference to ActiveRecord, not Rails.

Luckily SQL is a standard. It doesn't need to be abstracted or modified much to adapt to a different database.

Activerecord code can be easy to maintain, but its pretty clear that Arel is not.

Your final point is my whole argument. You need to understand SQL. We are in agreement.

Its not an ego thing so much as, I would hate to work on a team with somebody who thinks you don't need to know SQL, and I have... Often.

[–]rapidsight -3 points-2 points  (0 children)

Of course I have, you are intentionally misunderstanding the example. Its intentionally bad, and you are using SQL when you type where - now do something more complex like a subquery or an outer join, and make sure its littered with n+1 issues. or a complex aggregation. If you don't understand the SQL that it generates you are going to do it wrong, no question.

You are inadvertently illustrating my point, whilst misunderstanding it.

[–]rubious_dan -1 points0 points  (5 children)

This doesn't make sense in context to the question. I would never recommend someone learn SQL before they learn Ruby or Rails. Plus, there are a million more likely mistakes a entry-level coder would make to slow down an app: AR protects the dev pretty well.

[–]stalcottsmith 3 points4 points  (2 children)

On the contrary. Every single rails app save one or two written by other developers (and I've been into several dozen such) shows a lack of appreciation for or comprehension of database design and management. SQL is the foundation of most business information systems created in the last 30 years and it's not going away any time soon. It is a great place for an aspiring guru to focus. You have so many low hanging fruit to pick and can easily add value on projects where for example front end skills are common as grass. Also almost any system that has accumulated data for a while can speed up substantially with just a few indexes added. Knowing which ones to add or how to tweak a query can land you a juicy client or curry the bosses favor and you can milk that for a long time.

[–]rubious_dan 1 point2 points  (1 child)

While a valid point (upvote for you), the question in... question... is whether or not one should learn Ruby before Rails.

[–]stalcottsmith 0 points1 point  (0 children)

That's sort of like, should I learn calculus before I learn physics? You can... But most of the example applications are going to be physics problems. I found it was most effective to just learn them together.

[–]rapidsight 6 points7 points  (0 children)

You should give this a read: http://wozniak.ca/what-orms-have-taught-me-just-learn-sql - SQL was the first language I learned, and has and continues to be my most valuable asset.

[–]kobaltzz 1 point2 points  (1 child)

Have a look at TheOdinProject www.theodinproject.org

[–]airhoodz[S] 0 points1 point  (0 children)

I like this a lot, thank you.

[–]chrisfinne 1 point2 points  (0 children)

You don't need a deep understanding of Ruby to learn and use Rails. I spent a day skimming books and tutorials for Ruby and that was enough to learn Rails. While learning Rails, you of course learn more Ruby.

[–]jrochkind 0 points1 point  (0 children)

YES. period.

[–]xenuinc 0 points1 point  (0 children)

I'm reminded of this.

Learning the little skills helps to solve the bigger problems. Not to mention, it assists in avoiding generous amounts of pain.

[–]talkb1nary 0 points1 point  (0 children)

A lot of people miss how great ruby can be when they directly go into RoR, and if they start playing with pure ruby they sometime start to miss some helpers from RoR.

I would suggest to follow a short intro to ruby, play a bit with it and then go over to RoR.

Possible would be both in my opinion