# Question I don't know how to summarize for the subject field

**URL:** <https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067>\
**Category:** Rails\
**Created:** [February 1, 2007, 2:41am UTC](https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067 "2007-02-01T02:41:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![R\_Mason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@R\_Mason](https://www.ruby-forum.com/u/R_Mason)\
**Post date:** [February 1, 2007, 2:41am UTC](https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067/1 "2007-02-01T02:41:55Z")

</div>

Let’s say I have a model Poll which would have multiple Options. For  
each Option a User can vote.

Let’s say in my particular case, certain Options are recurring. To save  
database space, recurring Options such as “Yes” or “No” or “Maybe” are  
stored once and then joined accordingly to relevant Polls… This makes  
a HABTM setup better than a has\_many setup (or at least I think it does)  
so:

Poll \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :options  
end

Option \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :polls  
has\_many :votes  
end

Vote \< ActiveRecord::Base  
belongs\_to :option  
belongs\_to :user  
end

The problem with this setup is that a Vote belongs to an Option, but in  
respect to a specific Poll. If I just were to count the total number of  
Votes for an Option normally - like @option.votes, then the total would  
be for all Polls combined. But I need it to be specific to the one Poll  
and can’t quite figure out the design pattern I should be using.

This would be way easier if I just used has\_many, but then stuff like  
“Yes” or “No” would be in the options table like a bajillion times.  
Maybe my approach is wrong. Let me know!

---

<div class="post-metadata">

**Author:** ![R\_Mason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@R\_Mason](https://www.ruby-forum.com/u/R_Mason)\
**Post date:** [February 1, 2007, 6:48am UTC](https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067/2 "2007-02-01T06:48:37Z")

</div>

So should one abandon all attempts at optimization merely because it  
takes more time than writing sloppier, less-well-thought-out code?

I’m just a kid trying to figure something out for learning purposes and  
to better my app. To be honest, I value that more than the monetary  
aspects of development. If I had to meet deadline then I might say  
“screw it” and do it as best I know how, but while I’m still learning  
Rails, wouldn’t it be better to take my time and learn?

I’m just saying, perhaps my approach is wrong, but you picked it apart  
on a capitalistic aspect instead of actual design.

---

<div class="post-metadata">

**Author:** ![R\_Mason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@R\_Mason](https://www.ruby-forum.com/u/R_Mason)\
**Post date:** [February 1, 2007, 4:17am UTC](https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067/3 "2007-02-01T04:17:33Z")

</div>

R Mason wrote:

> This would be way easier if I just used has\_many,  
> but then stuff like “Yes” or “No” would be in the  
> options table like a bajillion times.  
> Maybe my approach is wrong. Let me know!

IMHO, and with all due respect, your approach is dead wrong. Why are  
you  
concerned with optimizing the cost of something that is, for all intents  
and  
purposes, free? Storage costs are \< $.01/MB. And you’re going to sweat  
a  
couple of bytes? Oh yeah. “But $.01 times millions of users …” So  
let’s  
see. You’re spending how much time, at how much per hour, figuring out  
how  
to save how much?

Normally I’d say “do the math”. In a case like this, the math costs  
more  
than any answer will ever yield. Maximize human productivity. Machines  
are  
cheap.

Just my $.02.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![R\_Mason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@R\_Mason](https://www.ruby-forum.com/u/R_Mason)\
**Post date:** [February 1, 2007, 9:27am UTC](https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067/4 "2007-02-01T09:27:49Z")

</div>

just an idea:

#in your controller

# Poll has\_many options, options has\_many votes, so just do a find

with a nested include  
@poll.find :first, :conditions =\> [‘id = ?’,params[:id]], :include =\>  
{ :options =\> :votes }

# in your view

\<? @poll.options.each do |o| ?\>- \<?= "#{o.text} (#{o.votes.count} votes)" 
\<? end ?\>

---

<div class="post-metadata">

**Author:** ![R\_Mason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@R\_Mason](https://www.ruby-forum.com/u/R_Mason)\
**Post date:** [February 2, 2007, 9:11am UTC](https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067/5 "2007-02-02T09:11:12Z")

</div>

The thing is, I look at my situation as a difficulty based on my skill  
level with Rails. I was asking “is it possible?” and, “if so, how  
difficult is it?”

If what I was asking required me to write a new module or cost me more  
than, say, fifteen lines of code, then I would be against it.

My question was in part asking this. Is this attainable easily based on  
what the framework already provides, or would it require a great deal of  
extra work? I don’t regard asking the question as actual work or wasted  
time. After all, this is my own personal project. Nothing is on the  
line here; I’m still in the learning phase. One of the reason I’m  
asking is for the knowledge, I’m looking at it from a design aspect. It  
would be great to _know_ how to do what I’m asking, if it’s even  
feasible. Who knows, perhaps as I modify my app or add extra functions,  
it might become totally necessary, and I’d be asking the same question  
down the line. If not in this app, maybe the next? There’s nothing  
wrong in knowing.

You bring up personal productivity over machine productivity. This is  
part of the equation. If I can learn as much as possible now – the  
why’s and why-not’s - then it will help me in the future when and if I’m  
actually doing this kind of work for money. If, in the future, I can  
have my stuff optimized _and_ be just as productive in the process, then  
I’m just that much better than those who never felt it necessary to  
learn one way or the other.

But overall I feel that there needs to be a compromise between personal  
productivity and machine productivity. You concentrate too much on  
personal productivity and you can easily end up with crap-that-works;  
like slapping together a term paper the morning before it’s due. You  
concentrate too much on functional perfection and

But I didn’t get that answer from you, it was more like, “who cares?”

It didn’t really offend me but it did come off as kind of snippy.

---

<div class="post-metadata">

**Author:** ![R\_Mason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@R\_Mason](https://www.ruby-forum.com/u/R_Mason)\
**Post date:** [February 1, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067/6 "2007-02-01T18:00:41Z")

</div>

Hi R,

R Mason wrote:

> So should one abandon all attempts at optimization  
> merely because it takes more time than writing  
> sloppier, less-well-thought-out code?

‘Sloppy’ is not the converse of ‘optimized’. IME, the converse of  
‘optimized’ is typically ‘readable, testable, easily maintained, …’

> … while I’m still learning Rails, wouldn’t it be  
> better to take my time and learn?

Absolutely.

Perhaps it was just my reading of the query. Here are the two things in  
your post that jumped out at me:

> To save database space,  
> This would be way easier if I just

> I’m just saying, perhaps my approach is wrong,

Rereading your original post in light of what you’ve said here, I see  
we’re  
using ‘approach’ to mean two different things. Based on my reading of  
your  
post, I took you to mean ‘optimize early’ vs. ‘only optimize when it  
solves  
an _existing_ problem.’

> but you picked it apart on a capitalistic aspect  
> instead of actual design.

Perhaps it’s not intuitively obvious, but Rails is fundamentally about  
personal, not machine, productivity. If it weren’t, we wouldn’t have  
Rails’  
very readable ‘Actor.find\_by\_role\_and\_location\_and\_skills(…)’. We’d  
be  
writing raw SQL because ‘it uses fewer cycles’. We wouldn’t have  
ActiveRecord because ‘meaningless id’s waste space’. In fact, we  
wouldn’t  
even have Ruby, since interpreted languages are inherently less  
efficient  
users of machine resources. Productivity is an Economic, not a Computer  
Science, concept. That’s why my response focused on the ‘capitalistic  
aspect’.

Having said that, I’m sorry my response offended you. Welcome to the  
community and good luck!

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![R\_Mason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@R\_Mason](https://www.ruby-forum.com/u/R_Mason)\
**Post date:** [February 2, 2007, 1:53pm UTC](https://www.ruby-forum.com/t/question-i-dont-know-how-to-summarize-for-the-subject-field/84067/7 "2007-02-02T13:53:26Z")

</div>

Even if it did come across badly to you, he was making a very good  
point.  
Ok, at the moment, $/hour isn’t an issue for you (it’s not for me,  
either),  
but if you’re planning on making a career out of this sort of stuff,  
now’s  
the time to get into ‘good’ habits. Basically, when it comes to  
optimisation, forget it. There are a very small number of people on this  
list who are able and willing to optimise effectively… for a two very  
good  
reasons. 1) It’s very difficult and 2) it usually costs more to optimise  
than to “waste” resources, and there are experts who devote themselves  
almost entirely to knowing when to optimise and when to just leave it as  
it  
is.  
Hope this has helped.  
-Nathan
