The Artima Developer Community
Sponsored Link

Weblogs Forum
Ruby, PHP and a Conference

43 replies on 3 pages. Most recent reply: Feb 23, 2006 9:25 PM by Tom Robinson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 43 replies on 3 pages [ « | 1 2 3 | » ]
Keith Ray

Posts: 658
Nickname: keithray
Registered: May, 2003

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 6:54 AM
Reply to this message Reply
Advertisement
"Resumption was tried for systems in the 60's, but failed, most likely because of the resulting high coupling between the various points an exception could be thrown and the points where it was caught."

My understanding is that resumption is still alive and well in various smalltalk implementations. The freeware "Bottom Feeder" RSS reader, written in Cincom Smalltalk, uses resumption to handle parsing problems.

http://www.google.com/search?hl=en&q=resuming+exception+cincom+smalltalk

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 7:07 AM
Reply to this message Reply
> > ... I don't care for
> > languages that 'make it easy' to do X. They generally
> > make it easy to do X in a aubstandard way.
>
> Just because you misused the feature doesn't make it a bad
> idea or "substandard".

I didn't muisuse a feature. I didn't say the feature was substandard. WTF are you talking about?

> This is just another feature you
> can either exploit or shoot yourself in the foot with.

And it appears to me that using it properly takes about as much work as it would to implement the same feature without the sugar. That's the point.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 7:09 AM
Reply to this message Reply
> puts is not a statement (unlike in Python, which makes
> Pythons print somewhat inconsistent) it is a plain Kernel
> module method.

puts "at beginning"

Isn't a statement? Then what do you call what would be called a statement in any other language in Ruby?

James Britt

Posts: 21
Nickname: jbritt
Registered: Mar, 2003

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 7:58 AM
Reply to this message Reply
Indeed, and please see http://www.ruby-doc.org for the most current Ruby documentation, and information on how to help contribute more

Joe Van Dyk

Posts: 2
Nickname: joevandyk
Registered: Jan, 2006

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 8:41 AM
Reply to this message Reply
> > > ... I don't care for
> > > languages that 'make it easy' to do X. They
> generally
> > > make it easy to do X in a aubstandard way.
> >
> > Just because you misused the feature doesn't make it a
> bad
> > idea or "substandard".
>
> I didn't muisuse a feature. I didn't say the feature was
> substandard. WTF are you talking about?
>
> > This is just another feature you
> > can either exploit or shoot yourself in the foot with.
>
> And it appears to me that using it properly takes about as
> much work as it would to implement the same feature
> without the sugar. That's the point.

Yes, using retry involves a ton of work. I spent hours writing this trivial function, because I used retry!

def get_number
begin
print "Please enter a number (no strings, floats, etc plz)\n > "
digit = gets
Integer(digit)
rescue ArgumentError => e
puts "oh no you didn't"
puts e
retry
end
end


n = get_number
puts "you entered #{ n }"
=====================
Please enter a number (no strings, floats, etc plz)
> no
oh no you didn't
invalid value for Integer: "no\n"
Please enter a number (no strings, floats, etc plz)
> 3.45
oh no you didn't
invalid value for Integer: "3.45\n"
Please enter a number (no strings, floats, etc plz)
> 45
you entered 45

James Gray

Posts: 1
Nickname: jeg2
Registered: Jan, 2006

Ruby's Blocks Posted: Jan 27, 2006 9:07 AM
Reply to this message Reply
There is a tutorial for Ruby's blocks on my blog:

http://blog.grayproductions.net/articles/2006/01/05/code-as-a-data-type

It might help some who are struggling with how and when to use them. Well, that's my hope, at least.

Nice article Bruce.

James Edward Gray II

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 9:44 AM
Reply to this message Reply
> > And it appears to me that using it properly takes about
> as
> > much work as it would to implement the same feature
> > without the sugar. That's the point.
>
> Yes, using retry involves a ton of work. I spent hours
> writing this trivial function, because I used retry!

And the value of that example is trivial. This is fine if you have a human user. I don't have human users in most of the code I write. You can't assume that there will eventually be a success. In computer science this is called an infinite loop.

The above is a perfect analog to the code that crashed our system.

Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 9:46 AM
Reply to this message Reply
A common idiom for retry is network/database connections that, for whatever reason, occasionally flake out for a second. I use an idiom similar to this for database connections. For example:

count = 0
begin
DBI.connect(...)
rescue DBI::Error
if count < 3
sleep 10
count += 1
retry
end
raise # Re-raise the error if 3 failed attempts
end

Generally speaking, you'll always want a retry used in a conditional manner. You know, just like those potentially dangerous "while" loops. :-P

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 9:55 AM
Reply to this message Reply
> Generally speaking, you'll always want a retry used in a
> conditional manner. You know, just like those potentially
> dangerous "while" loops. :-P

Exactly, since we already have loops this syntactical sugar is just an unecessary redundancy. The only time it makes things easier than using a normal loop is if you do something stupid with it.

count = 0;

while(true)
{
try...
catch...
if ++count > 2
rethrow
sleep 10
}


What's so hard about that? Why do we need more silly syntax to implement something that's already easy?

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 9:58 AM
Reply to this message Reply
Sorry, let me finish that psuedo-code.


count = 0;

while(true)
{
try...
catch...
if ++count > 2
rethrow
else
sleep 10
continue

break
}

Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 10:34 AM
Reply to this message Reply
> def get_number
> begin
> print "Please enter a number (no strings, floats, etc
> etc plz)\n > "
> digit = gets
> Integer(digit)
> rescue ArgumentError => e
> puts "oh no you didn't"
> puts e
> retry
> end
> end

Interesting usecase. But when you deal with user input you will probably define a set of events and write a statemachine calling event handlers like get_number. I would wonder if each event-handler uses own control flow primitives handling events too. In a comparable situation I defined a "return RETRY" statement that was consistent with the complete event-handling machinery.

For syntactical matters I'm in favour for better visibility of flow control than retry supports.

Rich Morin

Posts: 3
Nickname: rdm
Registered: Jan, 2006

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 10:37 AM
Reply to this message Reply
I came to PHP, curiously, by way of Ruby. I had been quite impressed with the power and convenience of Embedded Ruby and wished that I had a way to do something like this in my everyday web pages. Although I could have hassled with getting Ruby and Erb support, I tried PHP and found it to be quite a reasonable solution. FWIW, I put most of my PHP function definitions into a separate file, then include them in the "working" pages.

I started out using PHP very simply, as kind of a "macro preprocessor" for HTML. For example, I have an "ah" function that I use to generate "<a href=..." sequences. Aside from letting me break up long URLs and predefine common strings, this also lets me add "target" attributes, etc.

<?= $WP = 'http://en.wikipedia.org/wiki';
ah("$WP/Semantic_Wiki", 'Semantic wikis'); ?> are interesting.

More recently, I have used PHP to do oddball tasks such as generating sidebar navigation links and "print-friendly" pages for a set of web pages (http://www.cfcl.com/rdm/MBD), calculating the fourth Wednesday of the month for the Beer and Scripting SIG (http://www.cfcl.com/rdm/bass), etc. I've even started to lurk on the MediaWiki (http://www.mediawiki.org/wiki/MediaWiki) mailing lists...

Dale Nagata

Posts: 2
Nickname: dnagata
Registered: Jan, 2006

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 10:41 AM
Reply to this message Reply
puts looks like the standard C function

rescue/retry looks similar to Eiffel
(I don't know either Ruby or Eiffel more than surface skimming; does retry reset the state of local variables/member data back to the beginning as well?)

adding methods to an existing class looks like Objective-C categories
(seems to work fine for small scale development, but could run afoul of namespace issues in the large, e.g. if every 3rd party library you use adds their favourite extension methods to the standard string class. I think I heard that C# 3.0 was going to add this)

embedding PHP code with HTML content looks like ASP
(or ASP looks like PHP... :-)

Python seems to be feeling the heat from Ruby these days

Joe Shelby

Posts: 101
Nickname: acroyear
Registered: Jun, 2003

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 6:48 PM
Reply to this message Reply
I'm with the others on the PHP thing (Drak.net has gotten specific requests to not upgrade). Like all major PHP upgrades (and a large number of minor ones like 4.1 to 4.2), backwards compatibility is severely broken and many (including me) really don't have the time to upgrade our scripts or endure the downtime for that. Often, the upgrade catches one by surprise when suddenly you get emails saying "your site doesn't work". io.com's upgrade from 4.2 to 4.3 i didn't detect for days, all because a "security" fix broke how i was fetching a variable.

php5 adds significantly to the sysadmin's load as well. mysql support is no longer "easily" installed just by tagging a flag on your make call. you have to build the system, and then add the modules separately. a better design perhaps in the long run, but not an easy one for admins used to typing a string and hitting return and getting a .exe.

Personally, I want php5 because with 5 out all of the open source code build on php4's limited ability to handle XML is effectively abandoned. i may implement a php4 version of the php5 xml api if i can find the time to study the api, but that's a lot of time and work i'd rather not do.

Joe Van Dyk

Posts: 2
Nickname: joevandyk
Registered: Jan, 2006

Re: Ruby, PHP and a Conference Posted: Jan 27, 2006 7:15 PM
Reply to this message Reply
> > > And it appears to me that using it properly takes
> about
> > as
> > > much work as it would to implement the same feature
> > > without the sugar. That's the point.
> >
> > Yes, using retry involves a ton of work. I spent hours
> > writing this trivial function, because I used retry!
>
> And the value of that example is trivial. This is fine if
> you have a human user. I don't have human users in most
> of the code I write. You can't assume that there will
> eventually be a success. In computer science this is
> called an infinite loop.
>
> The above is a perfect analog to the code that crashed our
> system.

errr, ok.

DATABASE_CONNECTION_RETRIES = 3

def connect_to_database
retries = 0
begin
# connect to database code here that raises some exception
rescue DatabaseConnectionError
puts "Oh no!"
retries += 1
retry if retries < DATABASE_CONNECTION_RETRIES
end
end


No infinite loop there or human users!

Flat View: This topic has 43 replies on 3 pages [ « | 1  2  3 | » ]
Topic: Software as Services Previous Topic   Next Topic Topic: OpenOffice 2.0 passes the first trial-by-fire

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use