ruby wish-list

D

Day

so (whatever Hash#- does) it involves making a copy of the hash and
changing that instead, whereas #delete is destructive.

Which means if you use #- you're creating a new object and #delete
does not, right? It may not be much of a drain, but you want to cut
back on object creation when it's obviously superfluous, right?


Ben
 
R

Roger Pack

Yeah my wish would be for a syntax that "makes sense" for deleting
objects (seeing that [] adds them) which wouldn't create new objects but
would act like delete.
:)
Just wishing.
 
J

J. Cooper

I personally hate elsif [as opposed to elseif or else if]. I imagine it
comes from some lesser language. Come on, is 'e' so damn hard to type?
 
R

Roger Pack

My latest wish--a GC that actually worked, instead of mongrel processes
that take 600MB and growing :)
lol
 
G

Gary Wright

My latest wish--a GC that actually worked, instead of mongrel
processes
that take 600MB and growing :)

You can't determine from the size of a process whether the GC is
working or not since memory (even when freed by the GC) is never
returned to the OS. So with a magic 100% perfect GC, the memory
footprint of your process will always reflect its peak memory usage.

You also have to determine if the GC is failing to collect dead
objects or if you simply have some obscure references that are
keeping large groups of objects on life support.

Gary Wright
 
R

Roger Pack

You can't determine from the size of a process whether the GC is
working or not since memory (even when freed by the GC) is never
returned to the OS. So with a magic 100% perfect GC, the memory
footprint of your process will always reflect its peak memory usage.

that being the case then my wish would be clarified as a GC that was
fast and freed memory when no longer needed (appropriately and
bug-free).
Cheers!
-Roger
 
A

Alexey Verkhovsky

2) a GC that is 'user-definable' (run after this definable threshold,
this often), and (asidedbly), a GC that can run in its own (native)
thread so it doesn't pause execution of normal threads.

Is available in JRuby :)
4) the optional ability to have it display the whole backtrace on
uncaught exceptions (and also for all existing threads).

Not sure if anyone has mentioned that already, but this is simply a
matter of either changing TRACE_HEAD and TRACE_TAIL #defines, and
recompiling Ruby, or wrapping your "main" in something like

begin
...
rescue Object => e
puts e.message
print ' '
puts e.backtrace.join("\n ")
exit -1
end
 
S

Suraj Kurapati

Alexey said:
puts e.backtrace.join("\n ")

puts e.backtrace

puts will automatically insert the platform-dependent line-break for
you. (Note that join("\n") is not sufficient to produce proper
line-breaks on Windows).
 
N

Nobuyoshi Nakada

Hi,

At Fri, 15 Feb 2008 06:50:23 +0900,
Suraj Kurapati wrote in [ruby-talk:291073]:
puts e.backtrace

puts will automatically insert the platform-dependent line-break for
you.

Alexey uses indentation.
(Note that join("\n") is not sufficient to produce proper
line-breaks on Windows).

Not true always. It depends on whether the output is opened in
text mode or in binary mode.
 
R

Roger Pack

Not sure if anyone has mentioned that already, but this is simply a
matter of either changing TRACE_HEAD and TRACE_TAIL #defines, and
recompiling Ruby, or wrapping your "main" in something like

Yeah I've done that before and it's like a breath of fresh air when the
output includes the entire trace. Ahh.

My next wish, ruby-genie!
Some type of variable that holds the 'last return value'
so, for example, in irb
:)
 
J

Joel VanderWerf

Roger said:
My next wish, ruby-genie!
Some type of variable that holds the 'last return value'
so, for example, in irb

irb(main):001:0> 35+89
=> 124
irb(main):002:0> _
=> 124
 
C

Clifford Heath

Alexey said:
Not sure if anyone has mentioned that already, but this is simply a
matter of either changing TRACE_HEAD and TRACE_TAIL #defines, and
recompiling Ruby, or wrapping your "main" in something like

begin
...
rescue Object => e
puts e.message
print ' '
puts e.backtrace.join("\n ")
exit -1
end

Note that $! (which contains the current exception) is still defined
when Ruby is about to exit on an exception, while it's processing the
END blocks. You can get the same effect without wrapping main by adding
your exception printing code in an END block, which can be anywhere:

END { puts $!.backtrace*"\n\t" }

Clifford Heath.
 
R

Roger Pack

Roger said:
My personal ruby wish-list (for any feedback):

I guess it's been suggested here before, but I have often wished for a
way to have 'tighter' control over the variables passed to a parameter.
Sometimes duck typing doesn't immediately catch errors, until you run
through certain (possibly rare sequences). So anyway my wish is for
checking of parameters. Fortunately it seems already possible (as about
30% of rush wishes seem :p )



# a class to match

class Number
def Number.matches? param
return true if param.class == Fixnum or param.class == Float or
param.class == BigDecimal
end
end


def verify_params params_to_verify
for param, should_match_this_class in params_to_verify do
if should_match_this_class.respond_to? :matches?
raise 'poor parameter' unless should_match_this_class.matches?
param
else
raise 'poor parameter' unless param.class ==
should_match_this_class
end
end

end

def method_1 a, b, c
verify_params a => Number, b => String

end

Ahh. Type checking at last.
Ok you may begin to throw the stones :)
I actually like this setup since it helps describe the parameters.
Thanks :)

-R
 
D

David A. Black

Hi --

Roger Pack wrote:

# a class to match

class Number
def Number.matches? param
return true if param.class == Fixnum or param.class == Float or
param.class == BigDecimal
end
end


def verify_params params_to_verify
for param, should_match_this_class in params_to_verify do
if should_match_this_class.respond_to? :matches?
raise 'poor parameter' unless should_match_this_class.matches?
param
else
raise 'poor parameter' unless param.class ==
should_match_this_class
end
end

end

def method_1 a, b, c
verify_params a => Number, b => String

end

Ahh. Type checking at last.

It's class checking actually, not type checking. Type is different
from class in Ruby.


David
 
R

Roger Pack

It's class checking actually, not type checking. Type is different
from class in Ruby.


David

In that case I shall refer to it as "parameter verification" nobody
would disagree with that :)
 
N

Nobuyoshi Nakada

Hi,

At Sat, 22 Mar 2008 07:33:56 +0900,
Roger Pack wrote in [ruby-talk:295325]:
# a class to match

class Number
def Number.matches? param
return true if param.class == Fixnum or param.class == Float or
param.class == BigDecimal
end
end

Numeric === obj
 
R

Roger Pack

Next wish :)
I wish that you could make arrays more easily. As in

a = [1,2,3]
a.map{|n| n,n }

and it would work :)
-R
 
T

Thomas Wieczorek

Next wish :)
I wish that you could make arrays more easily. As in

a = [1,2,3]
a.map{|n| n,n }

and it would work :)

You want to create a two-dimensional array, right?
It works when you add square braces:

a = [1,2,3]
a.map{|n| [n,n] }
 
R

Roger Pack

You want to create a two-dimensional array, right?
It works when you add square braces:

a = [1,2,3]
a.map{|n| [n,n] }
Yeah I'm just a little lazy and dislike all the brackets :)
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top