For a very, very long time indeed, Perl ruled supreme among the languages to interface with a DB, be it Oracle, MySQL, Postgres or MS SQL. DBI was (and still is) a polished and useful interface which can do practically anything, from extracting query result and producing a quick little report using formats to complex things like copying Oracle to MySQL and doing it fast. Convenient things with Perl were:
1) Easy handling of piping and the ability to open commands by using
stuff like open(LPR,"|lpr")
2) Multitude of modules available on CPAN
3) Regular expressions, still unsurpassed in their versatility
4) Availability of tools like perltidy or perlcritic and Perl syntax being well understood by both editors like Vim and operating systems like Emacs.
5) The fact that everybody knew it.
I am now working for a company where everybody keeps telling that Perl is "old", Perl doesn't have an object model, it has a zoo instead, and that I should learn Python. I tried. God and Larry Ellison know that I have tried and gave it my best. The problem is, however, that I don't need a fully OO language to extract result of a query and mail it to my PHB. I need the "format" command and MIME::Lite. I was able to write the script both in Perl and Python and lo and behold, Perl was shorter and more elegant.
So, at risk that I am called a dinosaur, I am asking the respected colleagues from this group what do you you use? Is there anything even remotely akin to Perl "format" command in Python? Why is that guy van Rossum not on the FBI's most wanted list?
> For a very, very long time indeed, Perl ruled supreme among the
> languages to interface with a DB, be it Oracle, MySQL, Postgres or MS
> SQL. DBI was (and still is) a polished and useful interface which can
> do practically anything, from extracting query result and producing a
> quick little report using formats to complex things like copying
> Oracle to MySQL and doing it fast. Convenient things with Perl were:
> 1) Easy handling of piping and the ability to open commands by using
> stuff like open(LPR,"|lpr")
> 2) Multitude of modules available on CPAN
> 3) Regular expressions, still unsurpassed in their versatility
> 4) Availability of tools like perltidy or perlcritic and Perl > syntax being well understood by both editors like Vim and operating
> systems like Emacs.
> 5) The fact that everybody knew it.
> I am now working for a company where everybody keeps telling that Perl
> is "old", Perl doesn't have an object model, it has a zoo instead, and
> that I should learn Python. I tried. God and Larry Ellison know that I
> have tried and gave it my best. The problem is, however, that I don't
> need a fully OO language to extract result of a query and mail it to
> my PHB. I need the "format" command and MIME::Lite. I was able to
> write the script both in Perl and Python and lo and behold, Perl was
> shorter and more elegant.
> So, at risk that I am called a dinosaur, I am asking the respected > colleagues from this group what do you you use? Is there anything even
> remotely akin to Perl "format" command in Python? Why is that guy van > Rossum not on the FBI's most wanted list?
Oh, but I just LOVE Python!
Here's some pointers that surely will convince you:
> For a very, very long time indeed, Perl ruled supreme among the languages
> to interface with a DB, be it Oracle, MySQL, Postgres or MS SQL. DBI was
> (and still is) a polished and useful interface which can do practically
> anything, from extracting query result and producing a quick little report
> using formats to complex things like copying Oracle to MySQL and doing it
> fast. Convenient things with Perl were:
> 1) Easy handling of piping and the ability to open commands by using
> stuff like open(LPR,"|lpr")
> 2) Multitude of modules available on CPAN
> 3) Regular expressions, still unsurpassed in their versatility
> 4) Availability of tools like perltidy or perlcritic and Perl
> syntax being well understood by both editors like Vim and operating
> systems like Emacs.
> 5) The fact that everybody knew it.
> I am now working for a company where everybody keeps telling that Perl is
> "old", Perl doesn't have an object model, it has a zoo instead, and that I
> should learn Python. I tried. God and Larry Ellison know that I have tried
> and gave it my best. The problem is, however, that I don't need a fully OO
> language to extract result of a query and mail it to my PHB. I need the
> "format" command and MIME::Lite. I was able to write the script both in
> Perl and Python and lo and behold, Perl was shorter and more elegant.
> So, at risk that I am called a dinosaur, I am asking the respected
> colleagues from this group what do you you use? Is there anything even
> remotely akin to Perl "format" command in Python? Why is that guy van
> Rossum not on the FBI's most wanted list?
Neither, although I've intended to become conversant in Perl since the
last century. I do most stuff in the sillly 4GL that the ERP system I
deal with is written in, and the rest in ksh and SQL, unless Oracle
makes me debug their Perl code.
Yesterday I was poking about on the tubes in a fog, and somewhere
someone blogged about Perl 6, and how it was so different than 5 that
it would lose all the institutional memory 5 and 5.10 has accumulated,
so everyone should go to bash. Everyone has their shibboleths, I
guess. (And looking the term up in Wikipedia, I learned something
new: 'The term originates from the Hebrew word
"shibbólet" (שִׁבֹּלֶת), which literally means the part of a plant
containing grains, such as an ear of corn or a stalk of grain[3] or,
in different contexts, "stream, torrent".' Streams and BitTorent from
the ancients, who knew?)
On Tuesday, April 10, 2012 12:02:00 PM UTC-4, joel garry wrote:
> On Apr 9, 2:42 pm, Mladen Gogala <gogala.REMOVETHISmla...@google.com>
> wrote:
> > For a very, very long time indeed, Perl ruled supreme among the languages
> > to interface with a DB, be it Oracle, MySQL, Postgres or MS SQL. DBI was
> > (and still is) a polished and useful interface which can do practically
> > anything, from extracting query result and producing a quick little report
> > using formats to complex things like copying Oracle to MySQL and doing it
> > fast. Convenient things with Perl were:
> > 1) Easy handling of piping and the ability to open commands by using
> > stuff like open(LPR,"|lpr")
> > 2) Multitude of modules available on CPAN
> > 3) Regular expressions, still unsurpassed in their versatility
> > 4) Availability of tools like perltidy or perlcritic and Perl
> > syntax being well understood by both editors like Vim and operating
> > systems like Emacs.
> > 5) The fact that everybody knew it.
> > I am now working for a company where everybody keeps telling that Perl is
> > "old", Perl doesn't have an object model, it has a zoo instead, and that I
> > should learn Python. I tried. God and Larry Ellison know that I have tried
> > and gave it my best. The problem is, however, that I don't need a fully OO
> > language to extract result of a query and mail it to my PHB. I need the
> > "format" command and MIME::Lite. I was able to write the script both in
> > Perl and Python and lo and behold, Perl was shorter and more elegant.
> > So, at risk that I am called a dinosaur, I am asking the respected
> > colleagues from this group what do you you use? Is there anything even
> > remotely akin to Perl "format" command in Python? Why is that guy van
> > Rossum not on the FBI's most wanted list?
> Neither, although I've intended to become conversant in Perl since the
> last century. I do most stuff in the sillly 4GL that the ERP system I
> deal with is written in, and the rest in ksh and SQL, unless Oracle
> makes me debug their Perl code.
> Yesterday I was poking about on the tubes in a fog, and somewhere
> someone blogged about Perl 6, and how it was so different than 5 that
> it would lose all the institutional memory 5 and 5.10 has accumulated,
> so everyone should go to bash. Everyone has their shibboleths, I
> guess. (And looking the term up in Wikipedia, I learned something
> new: 'The term originates from the Hebrew word
> "shibbólet" (שִׁבֹּלֶת), which literally means the part of a plant
> containing grains, such as an ear of corn or a stalk of grain[3] or,
> in different contexts, "stream, torrent".' Streams and BitTorent from
> the ancients, who knew?)
I guess the IT community has never learned their lessons... there are lots of languages out there, scripting, 3GL, 4GL, OO, blah, blah, blah. Right now, everone is SOOO enamored with JAVA (piece-o-crap) and it's OO abilities. There are things I have done in C that made JAVA look like "B". I once took a JAVA app that just created a CSV output stream that was fed into SQLLoader and re-wrote it in C. The JAVA version could only get up to about 60K records/second ingested into the database. My "C" program did >1.8M records/sec. The original was Perl/MySQL - it did approximately 20K/min. (yes... per minute). Moral of the story:
QUIT THINKING YOU KNOW WHAT IS THE BEST TOOL AND TEST TO MAKE SURE YOU ARE USING THE BEST TOOL FOR THE JOB - REGARDLESS OF WHAT IS "COOL".
There was one more thing really bugs me... and that is the script kiddies that copy all of these "frameworks" to make their job easy, when all it does is show their laziness and ignorance. Yes, some them do cool stuff - but most perform like a PC/AT-286 with 16MB of main memory and 2 floppy disks trying to run Window7. Computer languages are really not that hard to figure out. They all do the same thing, they just do them differently.
On Tue, 10 Apr 2012 16:01:36 -0700, onedbguru wrote:
> QUIT THINKING YOU KNOW WHAT IS THE BEST TOOL AND TEST TO MAKE SURE YOU
> ARE USING THE BEST TOOL FOR THE JOB - REGARDLESS OF WHAT IS "COOL".
OK, I got it, no need for capital letters. So, how would you rate scripting languages for a DBA? What would be the criteria to determine the best tool for the job?
In article <8831365.1411.1334098896986.JavaMail.geo-discussion-forums@vbbfj25>, onedbguru <onedbg...@yahoo.com> wrote:
>On Tuesday, April 10, 2012 12:02:00 PM UTC-4, joel garry wrote:
>> On Apr 9, 2:42=C2=A0pm, Mladen Gogala <gogala.REMOVETHISmla...@google.com=
>> wrote:
>> > For a very, very long time indeed, Perl ruled supreme among the languag=
>es
>> > to interface with a DB, be it Oracle, MySQL, Postgres or MS SQL. DBI wa=
>s
>> > (and still is) a polished and useful interface which can do practically
>> > anything, from extracting query result and producing a quick little rep=
>ort
>> > using formats to complex things like copying Oracle to MySQL and doing =
>it
>> > fast. Convenient things with Perl were:
>> > 1) Easy handling of piping and the ability to open commands by using
>> > =C2=A0 =C2=A0stuff like open(LPR,"|lpr")
>> > 2) Multitude of modules available on CPAN
>> > 3) Regular expressions, still unsurpassed in their versatility
>> > 4) Availability of tools like perltidy or perlcritic and Perl
>> > =C2=A0 =C2=A0syntax being well understood by both editors like Vim and =
>operating
>> > =C2=A0 =C2=A0systems like Emacs.
>> > 5) The fact that everybody knew it.
>> > I am now working for a company where everybody keeps telling that Perl =
>is
>> > "old", Perl doesn't have an object model, it has a zoo instead, and tha=
>t I
>> > should learn Python. I tried. God and Larry Ellison know that I have tr=
>ied
>> > and gave it my best. The problem is, however, that I don't need a fully=
> OO
>> > language to extract result of a query and mail it to my PHB. I need the
>> > "format" command and MIME::Lite. I was able to write the script both in
>> > Perl and Python and lo and behold, Perl was shorter and more elegant.
>> > So, at risk that I am called a dinosaur, I am asking the respected
>> > colleagues from this group what do you you use? Is there anything even
>> > remotely akin to Perl "format" command in Python? Why is that guy van
>> > Rossum not on the FBI's most wanted list?
>> > --http://mgogala.freehos tia.com
>>=20
>> Neither, although I've intended to become conversant in Perl since the
>> last century. I do most stuff in the sillly 4GL that the ERP system I
>> deal with is written in, and the rest in ksh and SQL, unless Oracle
>> makes me debug their Perl code.
>>=20
>> Yesterday I was poking about on the tubes in a fog, and somewhere
>> someone blogged about Perl 6, and how it was so different than 5 that
>> it would lose all the institutional memory 5 and 5.10 has accumulated,
>> so everyone should go to bash. Everyone has their shibboleths, I
>> guess. (And looking the term up in Wikipedia, I learned something
>> new: 'The term originates from the Hebrew word
>> "shibb=C3=B3let" (=D7=A9=D6=B4=D7=81=D7=91=D6=B9=D6=BC=D7=9C=D6=B6=D7=AA)=
>, which literally means the part of a plant
>> containing grains, such as an ear of corn or a stalk of grain[3] or,
>> in different contexts, "stream, torrent".' Streams and BitTorent from
>> the ancients, who knew?)
>>=20
>> jg
>> --
>> @home.com is bogus.
>> =E2=80=9Cdid not realize what he was doing was in violation of the law.=
>=E2=80=9D
>> http://www.nytimes.com/2012/04/08/technology/text-message-spam-diffic... >to-stop-is-a-growing-menace.html
>I guess the IT community has never learned their lessons... there are lots =
>of languages out there, scripting, 3GL, 4GL, OO, blah, blah, blah. Right no=
>w, everone is SOOO enamored with JAVA (piece-o-crap) and it's OO abilities.=
> There are things I have done in C that made JAVA look like "B". I once t=
>ook a JAVA app that just created a CSV output stream that was fed into SQLL=
>oader and re-wrote it in C. The JAVA version could only get up to about 60K=
> records/second ingested into the database. My "C" program did >1.8M record=
>s/sec. The original was Perl/MySQL - it did approximately 20K/min. (yes..=
>.. per minute). Moral of the story:
>QUIT THINKING YOU KNOW WHAT IS THE BEST TOOL AND TEST TO MAKE SURE YOU ARE =
>USING THE BEST TOOL FOR THE JOB - REGARDLESS OF WHAT IS "COOL".
>There was one more thing really bugs me... and that is the script kiddies t=
>hat copy all of these "frameworks" to make their job easy, when all it does=
> is show their laziness and ignorance. Yes, some them do cool stuff - but =
>most perform like a PC/AT-286 with 16MB of main memory and 2 floppy disks t=
>rying to run Window7. Computer languages are really not that hard to figure=
> out. They all do the same thing, they just do them differently.
So how often are they used and how fast do they need to be? Using a 3GL like C or Java you can get things running fast, but coding and debugging - and maintaining code - take time. Writing a 1 off with a script can make a lot of sense. But if you have a high volume system and coe that needs to be run again and again, I agree with you.
On Tuesday, April 10, 2012 7:52:53 PM UTC-4, Mladen Gogala wrote:
> On Tue, 10 Apr 2012 16:01:36 -0700, onedbguru wrote:
> > QUIT THINKING YOU KNOW WHAT IS THE BEST TOOL AND TEST TO MAKE SURE YOU
> > ARE USING THE BEST TOOL FOR THE JOB - REGARDLESS OF WHAT IS "COOL".
> OK, I got it, no need for capital letters. So, how would you rate > scripting languages for a DBA? What would be the criteria to determine > the best tool for the job?
> I guess the IT community has never learned their lessons... there are
> lots of languages out there, scripting, 3GL, 4GL, OO, blah, blah,
> blah. Right now, everone is SOOO enamored with JAVA (piece-o-crap)
_That statement_ is crap. If Java would actually be that bad usage would be far less than it actually is.
I do agree though that people should think for themselves and not follow all the published fashions. Ironically in that context your statement just constitutes another published piece of advice which begs to be followed thoughtlessly.
> and it's OO abilities. There are things I have done in C that made
> JAVA look like "B". I once took a JAVA app that just created a CSV
> output stream that was fed into SQLLoader and re-wrote it in C. The
> JAVA version could only get up to about 60K records/second ingested
> into the database. My "C" program did>1.8M records/sec. The original
> was Perl/MySQL - it did approximately 20K/min. (yes... per minute).
Well, you can create such examples at will - they prove nothing: without any details they are worthless. We know nothing about your Java program and JVM used so nobody can judge whether you used the tool properly. For _any_ tool it takes time to master it and part of the equation is not only the tool itself but also the environment (i.e. people and their skills) in which it is used.
> QUIT THINKING YOU KNOW WHAT IS THE BEST TOOL AND TEST TO MAKE SURE
> YOU ARE USING THE BEST TOOL FOR THE JOB - REGARDLESS OF WHAT IS
> "COOL".
> On Tue, 10 Apr 2012 16:01:36 -0700, onedbguru wrote:
>> QUIT THINKING YOU KNOW WHAT IS THE BEST TOOL AND TEST TO MAKE SURE YOU
>> ARE USING THE BEST TOOL FOR THE JOB - REGARDLESS OF WHAT IS "COOL".
> OK, I got it, no need for capital letters. So, how would you rate
> scripting languages for a DBA? What would be the criteria to determine
> the best tool for the job?
My criteria would be how difficult it is to get a simple program working which establishes a connection to the database in question and feed data back and forth.
I usually use Ruby for my day to day scripting so I would turn to Ruby's DB support as a first choice. One very nice thing is the CSV lib which comes as part of the standard library. You also have a lot of useful tools for interacting with processes (IO.popen, Open3.popen3). Unfortunately I haven't done serious DB work in a while so I cannot tell you off hand about the current state of affairs with regard to Oracle connection support; but I am pretty sure that it exists:
http://ruby-oci8.rubyforge.org/en/
You should be able to get it with
$ gem install ruby-oci8
Apparently you need an Oracle client on the machine so you have oci lib installed.
For almost anything in a unix/linux system shell scripts with some sed/
awk sprinkled in work well.
To me that mixture is somewhat more maintainable than perl/python etc
but sure it depends on the knowledge base or lack thereof at the
site. Use some c when necessary for performance or low level stuff
( but I have not written anything in c in a real long time ).
I miss my old PL1 compiler a little that thing had everything
including the kitchen sink included.
On Apr 13, 7:48 am, onedbguru <onedbg...@yahoo.com> wrote:
> ;) It really depends.
> 1) sql
> 2) pl/sql
> 2) shell script (bash, ksh, c)
> 3) perl, python or php
> 4) DCL
> 5 (in no particular order) c, FORTRAN, COBOL, BASIC
> it really depends on the end goal and the platform needed and what is available.
Yes indeed. In Windows nowadays I like Small Basic a lot - in a
nutshell: a 3-gl on top of the Windows Scripting Host that I knew and
loved. Works a treat.
Although C# can be wicked!
For Unix, nothing beats the C-ksh-PL/SQL combo. Yes, I know perl can
do a lot. I just don't have time to learn all its nuances and I
already know the other three like the back of my hand.
As for all the other net-age languages -
Python, ruby and such, just too niche for my taste.
PHP is not bad. Same for javascript.
Java? I'm sorry, what was the question? Surely not common sense and
ease of use! Great income building language, though: I've known
projects run by its "eminences" which have lasted for over 10 years
and produced nothing! Can't beat that for income!
Yes, I know: Oracle did bet the farm (stupidly!) on java nearly 10
years ago.
I hear there are a billion coders in that language in 3rd world
countries: I'm sure that's excellent value for money. Provided it's
not my money!
> As for all the other net-age languages -
> Python, ruby and such, just too niche for my taste.
Why "too niche"? Are you referring to functionality, code base, community or what else?
> PHP is not bad. Same for javascript.
PHP does not even have proper OO, no thank you.
> Java? I'm sorry, what was the question? Surely not common sense and
> ease of use! Great income building language, though: I've known
> projects run by its "eminences" which have lasted for over 10 years
> and produced nothing! Can't beat that for income!
Well, Java is not a scripting language although there are scripting languages available on the JVM. But Scala is way more niche than Python or Ruby I'd say.
Robert Klemme wrote,on my timestamp of 16/04/2012 5:26 PM:
> On 16.04.2012 03:14, Noons wrote:
> Why "too niche"? Are you referring to functionality, code base, community or
> what else?
Niche because they were created for a subset of functionality of the net and most net technology is a niche when it comes to databases.
So is ebay, Amazon and many such others. Although of course the net folks like to agrandish themselves "because they use the same technologies".
Funny reality of course is: they don't. Neither ebay nor Amazon, google or many others use such. From my days of dealing with google's own traffic, they used a lot of perl. And specially modified - Ccode - Apache. And that was it.
Couldn't care less about community, or how many flog it.
>> PHP is not bad. Same for javascript.
> PHP does not even have proper OO, no thank you.
OO is useless for any quick database work.
> Well, Java is not a scripting language although there are scripting languages
> available on the JVM. But Scala is way more niche than Python or Ruby I'd say.
> Robert Klemme wrote,on my timestamp of 16/04/2012 5:26 PM:
>> On 16.04.2012 03:14, Noons wrote:
>> Why "too niche"? Are you referring to functionality, code base,
>> community or
>> what else?
> Niche because they were created for a subset of functionality of the net
Hmm... First of all Python, Ruby and Perl are general purpose programming languages. Perl is extremely strong in text processing but Ruby's regular expression engine is not far behind since 1.9.* version of the language. I cannot judge Python. What makes you say they were created for the net only / mostly?
> OO is useless for any quick database work.
It might depend on the overhead. I find it very convenient to create classes with a set of properties on a single line in Ruby:
Person = Struct.new :forename, :surname, :born
You can even add methods easily
Person = Struct.new :forename, :surname, :born do
def age_days; (Date.today - born).to_i end
end
I find myself often using a few self defined classes (and of course a lot of classes from the standard library) even in short ad hoc scripts. Personally I find it very helpful to use proper OO abstractions of entities of the problem domain. I wouldn't script in Java though where the syntactic and other overhead is significantly higher.
Btw., another feature which makes Ruby code quick to write and easy to read is the feature that every method can accept an anonymous callback function which helps separating iteration from processing and makes iterations and generally visitor like things very concise.
users = [...] # an array
users.each {|pers| puts pers.surname if pers.age > 18}
Plus, with that block pattern resource cleanup is simple and cannot be forgotten:
File.foreach ".bash_history" do |line|
puts line[0...10] # first 10 chars
end # implicit file close, even with exception
On Mon, 16 Apr 2012 09:26:18 +0200, Robert Klemme wrote:
>> PHP is not bad. Same for javascript.
> PHP does not even have proper OO, no thank you.
No? How comes? PHP 5.3+ has classes, with all the proper member protection, namespaces, inheritance, interfaces and everything else that comprises OO. What does it mean that "PHP doesn't have the proper OO"?
As for the question "why not python", here is a little story: I upgraded my home desktop box from F15 to F16, 64bit. As a part of the upgrade, I decided to move my CD's into my home directory. When that was done, I issued the following command:
perl -i.bak -pe 's|^/misc/|/home/mgogala|;' *.m3u
Voila. All my playlists have been fixed immediately. That's the sort of stuff that still only Perl can do. And OO is not always the answer. OO is a great thing, if used properly. Used as a religion, it is debilitating and harmful.
As for the "proper OO", you are probably referring to the fact that in PHP, as opposed to Python, the basic types are not objects, they don't have methods, so in PHP I would write something like
if (preg_match('/^\w+ 123/',$string)) {....}
instead of
import re
if re.search('^\w+ 123',string)
Here, you would have PCRE function called as a method of the "re" object. Evaluating regular expressions is a traditional procedural task, you describe it as a process: "please check if this string matches the regex". There is no benefit from expressing this as an object notation, that is why PHP is still immensely popular. I can write procedural tasks in procedural fashion, like displaying an output of a query, mixing in OO techniques where I need them. OO was invented to help people collaborate on writing large programs, by hiding complexity of the operations on objects into the classes and have other programmers. Unfortunately, people have also invented agile methodology, so now people are creating their own sets of undocumented classes, which nobody understands and is making things far less maintainable than a good procedural script. If I have to present an output from a select as an HTML table, why would I even want to mix in OO?
On Mon, 16 Apr 2012 13:18:55 +0200, Robert Klemme wrote:
> I find myself often using a few self defined classes (and of course a
> lot of classes from the standard library) even in short ad hoc scripts.
Hopefully, I will never have to maintain your script, without you being around. Your methodology doesn't have to resemble mine and understanding your classes would probably be a significant problem for me. Those classes aren't very well documented, are they?
In that case, I prefer standardized types like integer, float or string to do my evil deeds. The person who will have to untangle my scripts after me will find them much easier to understand.
> On Mon, 16 Apr 2012 09:26:18 +0200, Robert Klemme wrote:
>>> PHP is not bad. Same for javascript.
>> PHP does not even have proper OO, no thank you.
> No? How comes? PHP 5.3+ has classes, with all the proper member
> protection, namespaces, inheritance, interfaces and everything else that
> comprises OO. What does it mean that "PHP doesn't have the proper OO"?
I wasn't aware that they added it. Thanks for the education!
> As for the question "why not python", here is a little story: I upgraded
> my home desktop box from F15 to F16, 64bit. As a part of the upgrade, I
> decided to move my CD's into my home directory. When that was done, I
> issued the following command:
> And OO is not always the answer. OO is
> a great thing, if used properly. Used as a religion, it is debilitating
> and harmful.
I am not using it as a religion. It's just a very nice way to abstract things if you can add functionality to them as well.
> I can write procedural tasks in
> procedural fashion, like displaying an output of a query, mixing in OO
> techniques where I need them. OO was invented to help people collaborate
> on writing large programs, by hiding complexity of the operations on
> objects into the classes and have other programmers. Unfortunately,
> people have also invented agile methodology, so now people are creating
> their own sets of undocumented classes, which nobody understands and is
> making things far less maintainable than a good procedural script.
Well, you can't take a badly written script in an OO language or fashion as argument against OO in general. We all know that it is very possible to write spaghetti code in *any* programming language.
> If I
> have to present an output from a select as an HTML table, why would I
> even want to mix in OO?
Well, if for example, you need to manipulate the query result before writing it to the table then it might come handy if you have a record type with specific methods which receives your records. But there are often several ways to do things. Everybody should use what suits him. If it comes natural to do the HTML formatting in an OO style then do it, if not then don't. Nobody forces you to use OO. I am using OO because I feel very at home with it and it helps me write the code I need in a convenient way. That doesn't mean all my Ruby scripts only contain OO code - of course there is a lot of procedural code as well (actually every method is a procedure). If you don't like OO or do not see the benefit then don't use it. But please do not disqualify it based on bad examples.
> On Mon, 16 Apr 2012 13:18:55 +0200, Robert Klemme wrote:
>> I find myself often using a few self defined classes (and of course a
>> lot of classes from the standard library) even in short ad hoc scripts.
> Hopefully, I will never have to maintain your script, without you being
> around. Your methodology doesn't have to resemble mine and understanding
> your classes would probably be a significant problem for me. Those
> classes aren't very well documented, are they?
I did not post any documenting comments in those quickly made up examples. But choosing proper names for things (classes, methods) goes a long way already.
> In that case, I prefer standardized types like integer, float or string
> to do my evil deeds. The person who will have to untangle my scripts
> after me will find them much easier to understand.
Only if you have documented them properly because an int itself does not tell you whether it is an age or seconds since the epoch. One advantage of classes over using standard collection types (arrays, hash tables) is that you can give them names. I have waded through script code which uses nested arrays and hashes a few levels deep which was certainly as impenetrable as the short Ruby snippets I posted must occur to you. Please do note, that things like look significantly different if you knew the language and std lib.
Robert Klemme wrote,on my timestamp of 16/04/2012 9:18 PM:
> Hmm... First of all Python, Ruby and Perl are general purpose programming
> languages. Perl is extremely strong in text processing but Ruby's regular
> expression engine is not far behind since 1.9.* version of the language. I
> cannot judge Python. What makes you say they were created for the net only /
> mostly?
Because both Python and Ruby are widely used in that context and date mostly from past the .net explosion of the 00s.
Perl is an exception, granted.
> It might depend on the overhead. I find it very convenient to create classes
> with a set of properties on a single line in Ruby:
> Person = Struct.new :forename, :surname, :born
> You can even add methods easily
> Person = Struct.new :forename, :surname, :born do
> def age_days; (Date.today - born).to_i end
> end
> snippage
> Btw., another feature which makes Ruby code quick to write and easy to read is
> the feature that every method can accept an anonymous callback function which
> helps separating iteration from processing and makes iterations and generally
> visitor like things very concise.
> users = [...] # an array
> users.each {|pers| puts pers.surname if pers.age > 18}
> Plus, with that block pattern resource cleanup is simple and cannot be forgotten:
> File.foreach ".bash_history" do |line|
> puts line[0...10] # first 10 chars
> end # implicit file close, even with exception
> Robert Klemme wrote,on my timestamp of 16/04/2012 9:18 PM:
>> Hmm... First of all Python, Ruby and Perl are general purpose programming
>> languages. Perl is extremely strong in text processing but Ruby's regular
>> expression engine is not far behind since 1.9.* version of the
>> language. I
>> cannot judge Python. What makes you say they were created for the net
>> only /
>> mostly?
> Because both Python and Ruby are widely used in that context and date
> mostly from past the .net explosion of the 00s.
In section 9 you'll see that you can even match nested expressions which are non regular (i.e. context free); this can be used for example to match math expressions with arbitrary nesting of pairs of brackets.
> I use ksh with one or more sqlplus co-processes.
> Communication happens with "print -p" and "read -p", there are no limits
> to what you can achieve this way.
If conditions permit (i.e. appropriate software is installed on all systems I'd have to work with regularly) I still prefer a language which allows for definition of data types and has good integration of RDBMS communication. Granted, aforementioned precondition is not really a low bar - especially when working on a large set of different systems - so your approach might be more practical.
> Apart from world peace.
:-)
Ruby is no better at that:
irb(main):002:0> class Planet; end
=> nil
irb(main):003:0> world = Planet.new
=> #<Planet:0x85cfb2c>
irb(main):004:0> world.peace!
NoMethodError: undefined method `peace!' for #<Planet:0x85cfb2c>
from (irb):4
from /usr/local/bin/irb19:12:in `<main>'