Any guides for good coding in Ruby?

F

Florian Gross

James said:
I can't decide if it's just the example or the whole section, but this
one just doesn't feel right to me. I would much rather have a class
rendering itself (who better qualified?), then providing accessor like
data for others to do it. Push, don't pull, right?

I think this is related to double dispatch. There'll probably be a
Surface#draw that takes an object and calls #to_canvas on it. This way
both objects can handle part of the drawing contract by meeting in the
middle.
 
T

Travis Smith

* James Edward Gray II (Mar 22, 2005 23:50):
Seriously, though, the 80 character boundary is a thing of the past.
Terminals (not to mention emulators) can be made wider, 132 being a good
"standard" setting, so it's not even about backwards compatibility
anymore. I find that I can write code the way I want it if I'm not
constrained to 80 characters per line. (I only switched to a
132-character-wide terminal about 3 months ago, though, so I may change
my mind yet again.),

I disagree. I use 80 character width for everything. I have three
xterms spanned across my screen - all 80 characters wide. My IDEs have
the size of the window limited to 80 characters wide. It's the perfect
size. If a line goes too far then I know it's too complicated (expect
strings, string often span lines) or I'm writing in Java. I think Java
kills the 80 characters wides... That's another story though.

I think everyone who doesn't use 80 characters (or less) should be
shot. But just in the foot, so they'll learn the error of their ways.
:)
 
T

Travis Smith

* James Edward Gray II (Mar 23, 2005 01:40):
Be kind to yourself: expand your horizon,

I have, and later in the day they come back and bite me in the butt
because something else it's formatted to the wider size.
 
S

Sam Roberts

Quoting (e-mail address removed), on Wed, Mar 23, 2005 at 09:02:39AM +0900:
* Sam Roberts (Mar 23, 2005 00:50):
It's very easy to do with vim. Simply leave your 'ts' alone, set 'sw' to
8, don't set 'sts' and don't set 'et'. Those are all default settings
by the way.

GNU indent can be set to use any of a variety of indentation
"standards". It can also be configured to your hearts delight.

Yeah, but it conveniently default to GNUs.
well, I could have spelled them out, but that wouldn't have changed
much ;-). (The full command is
:set tabstop& shiftwidth& softtabstop& expandtab&

Hm, well, true, leave smarttab at its default setting (of off) as well,
nikolai (the ???who the hell messes with the smarttab
setting????-kinda guy)

I longer have the need to use this style and am quite happy with my
settings, but none of the approaches above gave me any indentation at
all, sorry. Or was I supposed to manually press TAB every time I wanted
an indent? When I selected and did =, it indented like:

void foo(void)
{
int i;
if(1)
{
}
^^^^^^^^ this is a TAB.

I use vim 6.3, and ran with vim -u /dev/null to take my settings out of
it.

Cheers,
Sam
 
C

Csaba Henk

* Nikolai Weibull <[email protected]> [2005-03-23 09:11:59 +0900]:
Boy, I don't know where all this came from, I thought the majority
were all on the same page, but maybe it is because of
all the new people. Maybe we should have a coding standard
linked from ruby-lang.

Btw, doesn't anyone know of a good ruby code indenter proggie?

That would also relax the headache of those who want to include the code
in books or webpages.

Csaba
 
J

James Edward Gray II

Btw, doesn't anyone know of a good ruby code indenter proggie?

That would also relax the headache of those who want to include the
code
in books or webpages.

Write it up and send it in to Ruby Quiz. You know I'm a sure thing for
running that one! ;)

James Edward Gray II
 
J

Jim Weirich

James Edward Gray II wrote:

[... questionable OO design advice ...]
I think this is related to double dispatch. There'll probably be a
Surface#draw that takes an object and calls #to_canvas on it. This way
both objects can handle part of the drawing contract by meeting in the
middle.

This is often handled by the bridge pattern. The canvas object provides low
level primitives (which can be reimplemented for different media) and the
graphical objects draw themselves using the facilities provided by the canvas
objects.

The problem with that particular example is (1) it has little to do with API
design (as it internally admits) and (2) the advice itself is questionable.
Although there are times a pure data object makes sense, the advice is worded
in a way that seems to recommend it. That kind of thought leads to anemic
domain models that are all data and little behavior.
 
J

Jim Freeze

* James Britt said:
Does mixing tabs & spaces munge YAML text?

YAML does not support tabs for indention.
That is something _why gave much consideration too.
 
B

Bill Guindon

The 80 char limit never was about terminals. It was about punched cards.

Yes, but they were based on clay tablets iirc.

ps: Arfin, if you're still reading this... Welcome to Ruby :)

without a doubt the strangest thread I've seen triggered by a new user question.
 
J

Jim Freeze

* Nikolai Weibull said:
* Jim Freeze (Mar 23, 2005 01:30):

There's no good reason to change the width of tabs. Your editor should
be able to emulate this behaviour anyway. In vim, to get two-space
indents:

Thats exactly my point.
Let 'v' = space
Let '^' = tab

Consider:

def func
statement
end

For normal code, 'def' is indented 2 spaces. But, when I get a 'tab' persons
version, I usually see spaces sprinkled throughout, like so:

vvdef
v^def
^ def

Since I usually get all of these combinations in a single file, there is
no one tab setting that will work for all cases. And, 'tab'ers usually don't
take measures to ensure there are no spaces mixed in with their
indentation.

Now, I'm not silly enough to think that this small argument
is going to convince anyone not already convinced, to stop using
tabs and use spaces only. I just wanted to make it clear that this
'one' reason not to use tabs was valid. There are many others.

However, being pragmattic and all, we found it easier in our corporation
to follow the ruby standard and use 2 spaces for indentations.
It is the first coding standard taught. :)

Everybody still uses their tab keys[1], but spaces are placed instead
of tabs. And, since we didn't employ superman, no one could tell
that the indents were spaces and not tabs when writing or reading code.
So, the 'tab'ers didn't care either.

--
Jim Freeze
Code Red. Code Ruby


[1] The main editors were emacs, vi or vim. Each can set tabs to 2 spaces.
 
C

Csaba Henk

Write it up and send it in to Ruby Quiz. You know I'm a sure thing for
running that one! ;)

Well, rather than bugging me, why don't you make it the next Quiz? :)

Csaba
 
B

Bertram Scharpf

Am Mittwoch, 23. Mär 2005, 06:09:50 +0900 schrieb Arfin:
Is there some kind of class to format numbers? Something to let you
transform:

1 => "0001"

"%04d" % 1
class Integer
def addZero
return "0" + self.to_s if self.to_s.length == 1
return self.to_s
end
end
t = Time.now
p "The date is: #{t.year}#{t.month.addZero}#{t.day.addZero}"

Time.strftime "%Y%m%d"

Bertram
 
N

Nikolai Weibull

* Sam Roberts (Mar 23, 2005 13:10):
I longer have the need to use this style and am quite happy with my
settings, but none of the approaches above gave me any indentation at
all, sorry. Or was I supposed to manually press TAB every time I
wanted an indent? When I selected and did =, it indented like:

I must have misunderstood what you wanted to be done. Did you want
GNU-style indentation in Vim? Then you need to mess with the
'cinoptions' option:

:set shiftwidth=2 expandtab cinoptions=>2sn-s{s^-s:s

is an example setting that may work well,
nikolai
 
N

Nikolai Weibull

* Sascha Ebach (Mar 23, 2005 02:50):
Yes, I think so. I cannot remember that I really need a tab in any
programming language I have used. If I need a tab in my strings I can
simply do a "\t". Do you know of any circumstance you actually _need_
a tab?

Well, the point of the Tab character is to move you to the next
tab-stop, which is usually set to every eight columns. This makes very
much less of a difference if the tab-stop is set to a smaller value,
e.g., less than four,
nikolai
 
F

Florian Gross

Csaba said:
Well, rather than bugging me, why don't you make it the next Quiz? :)

That would be an interesting one as well. I wonder if we could suggest
Ripper for the dirty parsing work? (Or else people will try writing a
custom one and run into trouble.)
 
J

James Edward Gray II

Well, rather than bugging me, why don't you make it the next Quiz? :)

I apologize. My intention was not to "bug you."

Ruby Quiz eats a lot of my time even when I'm not writing quizzes and
summaries or solving the problems. That's why I've always maintained
that it's a community supported service. I do try to pull my share of
the work as well.

That basically means that when an idea like this pops up, you have to
choices: You're time schedule or mine. I do try to watch these
threads and catalog ideas as I see them, if they interest me.

Still, it can take me a while to get around to them. Right now, it
would be at least a month before I could write this one up. I still
have Hal Fulton's Life post in my idea folder, because I need to solve
it before I can figure out how to use it and I haven't found the time
for that yet. (Hint, hint, if anyone is looking for a quiz idea--you
can find Hal's post in the archives.)

So don't get too mad at me for trying to drum up a little business.
Just trying to keep everything running smoothly, like everyone expects.
I did note this idea; I like it; I'll write it up when I get a
chance...

Those of you who have submitted quizzes are my truly heros, just in
case I don't say that enough. Here's the list of names for all to see:

Gavin Kistner (quiz and summary!)
Jamis Buck
Brian Candler
Jim Menard
Fredrik Jagenheim
Martin DeMello
Glenn Parker (quiz and summary!)
Jim Weirich
Bob Sidebotham
Hans Fugal
Matthew D Moss

You'll soon see work from:

Timothy Byrd (submitted a quiz and is interested in summarizing)
Mauricio Fernández and Florian Gross (contributed to a quiz idea of
mine)
Jason Bailey (submitted a quiz)

I'm very grateful to each and every one of you!

James Edward Gray II
 
H

Hal Fulton

James said:
Still, it can take me a while to get around to them. Right now, it
would be at least a month before I could write this one up. I still
have Hal Fulton's Life post in my idea folder, because I need to solve
it before I can figure out how to use it and I haven't found the time
for that yet. (Hint, hint, if anyone is looking for a quiz idea--you
can find Hal's post in the archives.)

After I mentioned that, I realized it wasn't very clear. I intended to
write some "back end" code to make it clearer how the "front end"
worked -- and maybe I will do that soon. Soon as the mystical 25th
hour is added to the day. Well, maybe sooner.

FWIW, I wasn't thinking of anything graphical at all really -- not like
Conway's "Game of Life" or anything -- just numerical.


Hal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top