Ruby for the wrong reason

Hi

A few months ago, I started learning Python - my first language for a
project I want to do (personal) which will involve several facets
including MySql/postgres database and gui frontend I need to create on
windows xp. So I started this in python and I use Eric 4 ide.

At the time I had no knowledge and tossed up between Ruby and Python,
I chose python because I thought it had been around longer so may be
more mature.

So why Ruby now, well honestly my 3rd daughter has been born two days
ago Ruby Jean, why would I program Python when my daughter is Ruby?

My question would Eric4 still be a good choice for Ide in Ruby, code
completion, highlighting(syntax) and debugging would be required in
IDE.

Secondly I found capturing the date input from a console in python to
be a little long winded, below is the script I wrote in python would
this be significantly easier in Ruby.

Which version of Ruby should I use 1.8.6, 1.9.1 or a preview version
of 1.9.2?

My python script to capture date input and check for errors.

import datetime as dt
def ObtainDate():
isValid=False
while not isValid:
userIn = raw_input("Type Date dd/mm/yy: ")
try: # strptime throws an exception if the input doesn’t match
the pattern
d1 = dt.datetime.strptime(userIn, “%d/%m/%y”)
isValid=True
print d1, type(d1) # 2003-07-15 00:00:00 <type
‘datetime.datetime’>
“convert datetime object to a 10 character string”
d2 = str(d1)[:10]
print d2, type(d2) # 2003-07-15 <type ‘str’>
except:
print “Try again! dd/mm/yy\n”
Fname = “data.dat”
newFname = d2 + Fname
return newFname
print ObtainDate()

flebber wrote:

Hi

A few months ago, I started learning Python - my first language for a
project I want to do (personal) which will involve several facets
including MySql/postgres database and gui frontend I need to create on
windows xp. So I started this in python and I use Eric 4 ide.

At the time I had no knowledge and tossed up between Ruby and Python,
I chose python because I thought it had been around longer so may be
more mature.

I went through this same process, even tried learning Perl which I
disliked,
tasted like I chalk in my mouth. Being a C++ developer, Ruby was my
natural
choice (front runner). Python lost me because I thought it was just
stupid to
only have indentations to declare code blocks. Other Python users told
me I
would overcome this. Someone did a good job of trying to sell me Python

  • Django
    as the way to go. So even though Ruby was more fun and felt natural to
    me, I
    still struggled with what to go with.

In the end I didn’t pick Ruby, Ruby picked me. I just when with what
felt good
to me and then the rest didn’t matter what was better.

There are never no wrong reasons, it’s better to explore and then go
with the
flow for what feels good to you, not someone else.

So why Ruby now, well honestly my 3rd daughter has been born two days
ago Ruby Jean, why would I program Python when my daughter is Ruby?

My question would Eric4 still be a good choice for Ide in Ruby, code
completion, highlighting(syntax) and debugging would be required in
IDE.

Someone was capturing the various IDE in a spreadsheet, I don’t have
that email
around…possibly they will reply with the link soon =)

But I suggest you take a look at Aptana, it’s got everything you need
and it
will also allow you to create Rails applications.

Enjoy and save the python for the wife :wink:

import datetime as dt
“convert datetime object to a 10 character string”
d2 = str(d1)[:10]
print d2, type(d2) # 2003-07-15 <type ‘str’>
except:
print “Try again! dd/mm/yy\n”
Fname = “data.dat”
newFname = d2 + Fname
return newFname
print ObtainDate()


Kind Regards,
Rajinder Y.

http://DevMentor.org
Do Good ~ Share Freely

On Tue, Oct 6, 2009 at 9:44 AM, Rajinder Y. [email protected]
wrote:

Someone was capturing the various IDE in a spreadsheet, I don’t have that
email around…possibly they will reply with the link soon =)

here you go :slight_smile:

if eric4 ends up being a good ruby ide, please add an entry for it

martin

flebber wrote:

Hi

A few months ago, I started learning Python - my first language for a
project I want to do (personal) which will involve several facets
including MySql/postgres database and gui frontend I need to create on
windows xp. So I started this in python and I use Eric 4 ide.

At the time I had no knowledge and tossed up between Ruby and Python,
I chose python because I thought it had been around longer so may be
more mature.

So why Ruby now, well honestly my 3rd daughter has been born two days
ago Ruby Jean, why would I program Python when my daughter is Ruby?

My question would Eric4 still be a good choice for Ide in Ruby, code
completion, highlighting(syntax) and debugging would be required in
IDE.

Secondly I found capturing the date input from a console in python to
be a little long winded, below is the script I wrote in python would
this be significantly easier in Ruby.

Which version of Ruby should I use 1.8.6, 1.9.1 or a preview version
of 1.9.2?

My python script to capture date input and check for errors.

import datetime as dt
def ObtainDate():
isValid=False
while not isValid:
userIn = raw_input("Type Date dd/mm/yy: ")
try: # strptime throws an exception if the input doesn’t match
the pattern
d1 = dt.datetime.strptime(userIn, “%d/%m/%y”)
isValid=True
print d1, type(d1) # 2003-07-15 00:00:00 <type
‘datetime.datetime’>
“convert datetime object to a 10 character string”
d2 = str(d1)[:10]
print d2, type(d2) # 2003-07-15 <type ‘str’>
except:
print “Try again! dd/mm/yy\n”
Fname = “data.dat”
newFname = d2 + Fname
return newFname
print ObtainDate()

This is a good example for you to investigate on your own. It will
introduce you to ruby’s documentation(or lack thereof).

Here’s how I would do it in python:

def get_new_fname(fname):
while True:
try:
s = raw_input("Enter a date (dd/mm/yy): ")
in_format = “%d/%m/%y”
dt_obj = dt.datetime.strptime(s, in_format)
break
except ValueError:
print “Wrong format! Try again.”

out_format = "%Y-%m-%d"
prefix = dt_obj.strftime(out_format)

new_fname = "%s%s" % (prefix, fname)
return new_fname

name = “data.dat”
new_name = get_new_fname(name)
print new_name

–output:–
2009-10-05data.dat

flebber wrote:

Secondly I found capturing the date input from a console in python to
be a little long winded, below is the script I wrote in python would
this be significantly easier in Ruby.

No. I think in ruby the code would be almost exactly the same–except
it’s significantly harder to figure out in ruby because there is no
documentation about the format specifiers you can use with strftime()
and strptime(). Amazing, huh?

Which version of Ruby should I use 1.8.6, 1.9.1 or a preview version
of 1.9.2?

ruby and python are in the same state of evolution right now–both are
in the midst of a major version change. In both cases, the newer
versions won’t have as many libraries available to them because most
libraries have not yet been rewritten to accommodate the latest version.
So the choice is: go with ruby 1.8.6 and have more libraries available
to you, or go with ruby 1.9.x to learn the latest greatest language
changes. I think most people probably have 1.8.6 and 1.9.x installed
side by side(in python it would be 2.6.x and 3.x). They probably use
1.8.6 for their serious programs, and then they play around with 1.9.x
to learn the new stuff.

Sounds like what I had trouble with (regarding Python) hated the
indentations, especially when porting from Python 2 - 3 what a nightmare
:smiley:

For an IDE (if you are using OS X) I’d suggest Textmate, it has
everything you could possibly want (C, C++, Python, Ruby, Ruby on Rails,
PHP, Perl, etc) it costs about £40 ($60 ish) but is well worth it. As
for Ruby version, 1.8.7 works great with Rails and is the prefered
version. I use 1.8.6 (or .7) on Snow Leopard and the same on Linux I
think, though personally, I’d always prefer to go with the most stable
and newest version (being 1.9.1).

Regards, Adam

— On Tue, 6/10/09, Rajinder Y. [email protected] wrote:

From: Rajinder Y. [email protected]
Subject: Re: Ruby for the wrong reason
To: “ruby-talk ML” [email protected]
Date: Tuesday, 6 October, 2009, 4:14 AM

flebber wrote:

Hi

A few months ago, I started learning Python - my first language for a
project I want to do (personal) which will involve several facets
including MySql/postgres database and gui frontend I need to create on
windows xp. So I started this in python and I use Eric 4 ide.

At the time I had no knowledge and tossed up between Ruby and Python,
I chose python because I thought it had been around longer so may be
more mature.

I went through this same process, even tried learning Perl which I
disliked, tasted like I chalk in my mouth. Being a C++ developer, Ruby
was my natural choice (front runner). Python lost me because I thought
it was just stupid to only have indentations to declare code blocks.
Other Python users told me I would overcome this. Someone did a good job
of trying to sell me Python + Django as the way to go. So even though
Ruby was more fun and felt natural to me, I still struggled with what to
go with.

In the end I didn’t pick Ruby, Ruby picked me. I just when with what
felt good to me and then the rest didn’t matter what was better.

There are never no wrong reasons, it’s better to explore and then go
with the flow for what feels good to you, not someone else.

So why Ruby now, well honestly my 3rd daughter has been born two days
ago Ruby Jean, why would I program Python when my daughter is Ruby?

My question would Eric4 still be a good choice for Ide in Ruby, code
completion, highlighting(syntax) and debugging would be required in
IDE.

Someone was capturing the various IDE in a spreadsheet, I don’t have
that email around…possibly they will reply with the link soon =)

But I suggest you take a look at Aptana, it’s got everything you need
and it will also allow you to create Rails applications.

Enjoy and save the python for the wife :wink:

import datetime as dt
        “convert datetime object to a 10 character string”
        d2 = str(d1)[:10]
        print d2, type(d2) # 2003-07-15 <type ‘str’>
      except:
        print “Try again! dd/mm/yy\n”
    Fname = “data.dat”
    newFname = d2 + Fname
    return newFname
print ObtainDate()

– Kind Regards,
Rajinder Y.

http://DevMentor.org
Do Good ~ Share Freely

On Oct 6, 7:49 pm, Adam B. [email protected]
wrote:

To: “ruby-talk ML” [email protected]

At the time I had no knowledge and tossed up between Ruby and Python,

this be significantly easier in Ruby.
userIn = raw_input("Type Date dd/mm/yy: ")
print “Try again! dd/mm/yy\n”
Fname = “data.dat”
newFname = d2 + Fname
return newFname
print ObtainDate()

– Kind Regards,
Rajinder Y.

http://DevMentor.org
Do Good ~ Share Freely

So If I use version 1.8.6 and later want to update my project to the
1.9 series would this be a hard conversion?

flebber wrote:

On Oct 6, 7:49�pm, Adam B. [email protected]
wrote:

To: “ruby-talk ML” [email protected]

At the time I had no knowledge and tossed up between Ruby and Python,

this be significantly easier in Ruby.
� � � ���userIn = raw_input("Type Date dd/mm/yy: ")
� � � � � ���print “Try again! dd/mm/yy\n”
� ���Fname = “data.dat”
� ���newFname = d2 + Fname
� ���return newFname
print ObtainDate()

– Kind Regards,
Rajinder Y.

http://DevMentor.org
Do Good ~ Share Freely

So If I use version 1.8.6 and later want to update my project to the
1.9 series would this be a hard conversion?

For Ruby, no. Tt has no specific indentations to follow (within reason)
and the only things that have changed as far as I know (been a while
since I read the release docs) 1.9.1 adds some new functionality to Ruby
but doesn’t change the syntax (like Python 2 - 3 did).
With my program I was working on, I was using 1.9.1 (on my old linux
distro) and also running it on my Mac (1.8.7), so as far as the scope of
my program was concerned, the versions were universally capable of
running on either system with zero changes.

Hope this helps!

Hi –

On Tue, 6 Oct 2009, Adam B. wrote:

??? ???Fname = “data.dat”
So If I use version 1.8.6 and later want to update my project to the
1.9 series would this be a hard conversion?

For Ruby, no. Tt has no specific indentations to follow (within reason)
and the only things that have changed as far as I know (been a while
since I read the release docs) 1.9.1 adds some new functionality to Ruby
but doesn’t change the syntax (like Python 2 - 3 did).
With my program I was working on, I was using 1.9.1 (on my old linux
distro) and also running it on my Mac (1.8.7), so as far as the scope of
my program was concerned, the versions were universally capable of
running on either system with zero changes.

The syntax has actually changed in certain respects. See:

http://dablog.rubypal.com/2009/1/14/10-things-to-be-aware-of-in-moving-to-ruby-1-9

and the sequel post (there’s a link).

David

From: “7stud --” [email protected]

No. I think in ruby the code would be almost exactly the same–except
it’s significantly harder to figure out in ruby because there is no
documentation about the format specifiers you can use with strftime()
and strptime(). Amazing, huh?

Reveals:

http://ruby-doc.org/core/classes/Time.html#M000298

Regards,

Bill

Hi –

On Tue, 6 Oct 2009, 7stud – wrote:

flebber wrote:

Secondly I found capturing the date input from a console in python to
be a little long winded, below is the script I wrote in python would
this be significantly easier in Ruby.

No. I think in ruby the code would be almost exactly the same–except
it’s significantly harder to figure out in ruby because there is no
documentation about the format specifiers you can use with strftime()
and strptime(). Amazing, huh?

I usually go straight to the system library documentation for this
stuff, but ri Time#strftime will help you too.

David

On Oct 6, 2009, at 1:16 AM, 7stud – wrote:

No. I think in ruby the code would be almost exactly the same–except
it’s significantly harder to figure out in ruby because there is no
documentation about the format specifiers you can use with strftime()
and strptime(). Amazing, huh?

Amazingly wrong, yeah:

---------------------------------------------------------- Time#strftime
time.strftime( string ) => string

  Formats _time_ according to the directives in the given format
  string. Any text not listed as a directive will be passed through
  to the output string.

  Format meaning:

    %a - The abbreviated weekday name (``Sun'')
    %A - The  full  weekday  name (``Sunday'')
    %b - The abbreviated month name (``Jan'')
    %B - The  full  month  name (``January'')
    %c - The preferred local date and time representation
    %d - Day of the month (01..31)
    %H - Hour of the day, 24-hour clock (00..23)
    %I - Hour of the day, 12-hour clock (01..12)
    %j - Day of the year (001..366)
    %m - Month of the year (01..12)
    %M - Minute of the hour (00..59)
    %p - Meridian indicator (``AM''  or  ``PM'')
    %S - Second of the minute (00..60)
    %U - Week  number  of the current year,
            starting with the first Sunday as the first
            day of the first week (00..53)
    %W - Week  number  of the current year,
            starting with the first Monday as the first
            day of the first week (00..53)
    %w - Day of the week (Sunday is 0, 0..6)
    %x - Preferred representation for the date alone, no time
    %X - Preferred representation for the time alone, no date
    %y - Year without a century (00..99)
    %Y - Year with century
    %Z - Time zone name
    %% - Literal ``%'' character

     t = Time.now
     t.strftime("Printed on %m/%d/%Y")   #=> "Printed on 04/09/2003"
     t.strftime("at %I:%M%p")            #=> "at 08:56AM"

James Edward G. II

On Monday 05 October 2009 10:45:08 pm flebber wrote:

Which version of Ruby should I use 1.8.6, 1.9.1 or a preview version
of 1.9.2?

If it’s a brand-new project, use 1.9.1.

Unless you do something strange, it should be portable backwards to
1.8.7, and
with a few (very small) patches, to 1.8.6.

As others say, not all libraries will be available on 1.9.1, but the
vast,
VAST majority are. If you have a choice between two libraries, one which
works
on 1.9.1, and one which doesn’t, that’s a strong hint about which is
more
actively maintained.

And all other things equal, 1.9.1 is twice as fast as 1.8.6, so there
isn’t a
good reason not to use it.

On an existing project, that depends entirely on whether the project has
been
ported to 1.9 yet.

The preview version, you could install it side by side and test, to make
sure
everything still works. But you generally want to use a stable version
– just
not a stable-as-in-Debian-stable version :wink:

And to think, this whole dilemma could have been avoided if you named
her Python.

On Tue, Oct 6, 2009 at 6:54 AM, James Edward G. II
[email protected]wrote:

---------------------------------------------------------- Time#strftime
%b - The abbreviated month name (Jan'') %U - Week number of the current year, %Z - Time zone name %% - Literal %‘’ character

   t = Time.now
   t.strftime("Printed on %m/%d/%Y")   #=> "Printed on 04/09/2003"
   t.strftime("at %I:%M%p")            #=> "at 08:56AM"

James Edward G. II

If anyone is curious where the information James provided can be found:


“Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

On 2009-10-06, David M. [email protected] wrote:

And all other things equal, 1.9.1 is twice as fast as 1.8.6, so there isn’t a
good reason not to use it.

As of sometime recently, there were reports of some Rails stuff not
working
on it, which might be a good reason.

-s

On Oct 6, 2009, at 8:14 AM, Glen H. wrote:

On Tue, Oct 6, 2009 at 6:54 AM, James Edward G. II
[email protected]wrote:


Time#strftime

If anyone is curious where the information James provided can be
found:

LMGTFY - Let Me Google That For You

Also, when you see those long dashed lines with the class/module and
possibly a method name on the right, that tells you what to type into
ri. I literally typed:

ri Time#strftime

James Edward G. II

James Edward G. II wrote:

On Oct 6, 2009, at 1:16 AM, 7stud – wrote:

No. I think in ruby the code would be almost exactly the same–except
it’s significantly harder to figure out in ruby because there is no
documentation about the format specifiers you can use with strftime()
and strptime(). Amazing, huh?

Amazingly wrong, yeah:

Not at all:

  1. $ri Date::strptime

--------------------------------------------------------- Date::strptime
Date::strptime(str=’-4712-01-01’, fmt=’%F’, sg=ITALY)

 Create a new Date object by parsing from a String according to a
 specified format.

 +str+ is a String holding a date representation. +fmt+ is the
 format that the date is in. See date/format.rb for details on
 supported formats.

 The default +str+ is '-4712-01-01', and the default +fmt+ is '%F',
 which means Year-Month-Day_of_Month. This gives Julian Day Number
 day 0.

 +sg+ specifies the Day of Calendar Reform.

 An ArgumentError will be raised if +str+ cannot be parsed.

Good luck finding and then digging through the source code of
format.rb to locate anything on the format specifiers.

  1. $ri Date#strftime

---------------------------------------------------------- Date#strftime
strftime(fmt=’%F’)

 (no description...)

And from the official Standard Library Documentation for ‘date’:

strptime(str=’-4712-01-01’, fmt=’%F’, sg=ITALY)

Create a new Date object by parsing from a String according to a
specified format.

str is a String holding a date representation. fmt is the format that
the date is in. See date/format.rb for details on supported formats.

The default str is ’-4712-01-01’, and the default fmt is ’%F’, which
means Year-Month-Day_of_Month. This gives Julian Day Number day 0.

sg specifies the Day of Calendar Reform.

An ArgumentError will be raised if str cannot be parsed.

strftime(fmt=’%F’)

[Source]

That last one is a real doozy–and quite typical of ruby Standard
Library documentation.

On Oct 6, 2009, at 1:33 PM, 7stud – wrote:

That last one is a real doozy–and quite typical of ruby Standard
Library documentation.

You’ve been shown the format option from the documentation. I’m not
sure how much more proof you require.

I agree that they could be copied to the Date methods and any specific
format options for those methods could be added. But to say there’s
no documentation was just plain wrong.

You’ve obviously gone into the source to find them once, to bad you
didn’t create a documentation patch while you were there.

James Edward G. II

2009/10/6 7stud – [email protected]:

  +str+ is a String holding a date representation. +fmt+ is the

  (no description…)
specified format.

strftime(fmt=‘%F’)

[Source]

That last one is a real doozy–and quite typical of ruby Standard
Library documentation.

In this case I use the strftime(3) man page but windows users are at a
disadvantage here.

The man pages can be found on the web, though.

And while there are things that could use better documentation there
is no need to replicate documentation of ancient function which is
standardized in POSIX and wherever else.

Thanks

Michal