Topic: How do you guys get so smart? Using &, #, {}, [], etc

You guys throw around the accurate use of brackets, curly braces, quotes, ampersands and pounds signs like their use is so obvious!  Where does a good programmer (like me), learn the mish/mosh of symbol combinations, that a RoR newbie (like me) needs to know?

Example, I can't search the internet for

"#{something here}"

or
sections.delete_if(&:blank?)

but yet it these very things I need more detail and information about!  Isn't there a methodical approach to connecting these dots: "this means this, and can go here, here or here..."

Also, where the heck is this "path" DEFINED?

<%= link_to 'Display All Districts', districts_path %>

I know you guys have a secret society, but I want in!!  Neither my father nor my big brother was in it --so how the heck do I get in it?  -LOL

Would appreciate any good recommendations for online learning 
(BTW, thanks to the folks at railsforum!)

Re: How do you guys get so smart? Using &, #, {}, [], etc

This is more of an "Other Rails Programming" question, not a tutorial, but:

Most of what you're asking about punctuation marks is core Ruby syntax.  Has nothing, inherently, to do with Rails.  This should not be surprising: _languages_ (such as Ruby) define the structural elements (keywords and punctuation marks) programmers use to express low-level concepts, while _frameworks_ (such as Rails) define packages of functionality in terms of identifiers (class and method names).

So when you ask "what does "#{foo}" mean," the answer is "go get your Ruby book and look it up.  That's core Ruby functionality, and if you're having trouble with that you're not going to get very far with Rails, so brush up on the fundamentals first."  Not to be dismissive or derisive or anything like that, but it's true.  Consider an analogy: what kind of response would you expect if you dropped in on a hobby robotics website and said "hey, how do I know whether to use a resistor or a capacitor in such-and-such situation?"  They'd rightly say "dude, if you don't know the difference between a resistor and a capacitor, you probably have no business trying to build a robot.  Not yet, anyway.  Learn the fundamentals, then try again."

Now for questions like "where does districts_path get defined?  I can't find a definition for it anywhere when I grep my entire code base," that's a valid Rails question.  You're asking about a variable (Or is it a method?  Or a helper somewhere?) that seems to have meaning, yet you can't find a definition for.  Believe me, I've been there too.  What you have to understand about rails is:

1) Naming conventions drive practically everything,
2) Rails is big on taking things you have defined (say, a resource) and defining other things for you, on the fly, based on that.  So if you make a resource called "District", and you've used the scaffold generator, among the zillion other things you'll end up with is a "districts_path" that is shorthand for the top-level URL for that resource.  You have to understand the naming convention for routes to understand that all the routes you define cause a "whatever_path" and "whatever_url" helpers also to be defined for you.  You have to understand the dynamic nature of Rails to understand that those things get defined for you at run-time by the "map.resources" line that the scaffold generator added to your routes.rb file, which is why you won't find "districts_path" anywhere in your source code.

In my opinion, learning the many, many naming conventions that Rails uses and the many, many circumstances in which parts of the framework (or also, plugins and gems) use a naming convention to define other stuff for you, is absolutely the hardest part of learning Ruby.  I wish I could say "just get such-and-such book and you'll be fine," except that I haven't yet seen a Rails book that included a comprehensive reference to the naming conventions and dynamic aspects of Rails.  AWDWR, probably the most heavily relied-upon Rails book, doesn't and I consider that to be the book's most serious failing.

You kind of just have to stick with it, blunder your way along, and eventually it will all start to make sense.

Last edited by cloister (2009-06-30 13:00:19)

Re: How do you guys get so smart? Using &, #, {}, [], etc

cloister, that is a fantastic answer.  Thank you so much. 

Although I am excited by the notion of a robust, full-stack environment like RoR, I now have a clearer understanding of the difference between the two, and what I need to do to get a society membership! smile   

(Hey, at least I know the difference between a resistor and a capacitor!)

As far as online resources... any good direction in the future would be greatly appreciated as well.

Re: How do you guys get so smart? Using &, #, {}, [], etc

Check out http://guides.rubyonrails.org for a bunch of guides on Rails specific things. There are also plenty of Ruby tutorial type resources to be found from Google.