Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Alternatives to sed + awk
- Date: Thu, 10 Mar 2011 07:25:43 +0100
- From: Josh Glover <jmglov@example.com>
- Subject: Re: [tlug] Alternatives to sed + awk
- References: <AANLkTim_-D9CFYC8TNp33ni85zB+QBA7jV=BpLN=4SbZ@example.com> <4D6F8D94.9040109@example.com> <87ei6nl906.fsf@example.com> <AANLkTimk1z41fSvQQmU+7fE-1Krd_kuo3_z-1SYD5rW6@example.com> <87ipvskik1.fsf@example.com> <AANLkTi=_6DoBt+xfQVOwM6KyKrxxgA_Ec9bhp751f15y@example.com> <8762rsjkdx.fsf@example.com> <AANLkTik=tHOgTRvcvNd0qsx9-o9MuqBnWUjkWVn+0U_7@example.com> <87vczro8pk.fsf@example.com>
On 10 March 2011 06:17, Stephen J. Turnbull <stephen@example.com> wrote: > It is admittedly relatively hard to add syntax in Python. I've not yet written enough Python to need a good DSL, so I'll let you know how it goes when I do. :) I do actually like Python quite a bit; getattr and getattr let me do a lot of instance_evaly things when I need to, and the language is nice and regular. Any language that has an implementation of FlexMock[1][2] is OK by me! > However, again it seems to me to be easy to abuse. Sure, but so's C. > "Use in haste, repent at leisure" seems to be the watchword of programmers. There will always be hastily written code requiring penance; I don't think it is the province of the language to try to prevent bad code. The bad coders will just find a way to write their bad code anyway. ;) > However, the basic syntax of Lisp aka "Lots of Irritating Single > Parentheses" is detested by many. Just like Python's whitespace requirements, you get used to it. > Modifying methods can be done by subclassing. However, Python's > approach is to decorate them: Ruby usually uses method chaining to decorate. Rails even provides an extension for this: alias_method_chain <func>, <decorator> e.g. def func 1 + 1 == 2 end def func_with_decorator puts "Blah blah blah" func_without_decorator end alias_method_chain :func, :decorator The more generic decorator supplied in your example would probably be implemented using a Proc object: def trace(func) if debug: Proc.new do puts "Entering #{func}" result = func.call puts "Leaving #{func}" result end else: func end end > BTW, since Ruby apparently allows you to omit parentheses, how do you > distinguish between returning the value of a function call and the function > itself, eg, in the argument to the trace invocation above? functions themselves are not first class objects as in Python; you need to turn them into a Proc (or, more powerfully a Binding) object. > > def test_crappy_class > > crap = CrappyClass.new > > assert_equal 0, crap.instance_eval{@example.com > > crap.increment > > assert_equal 1, crap.instance_eval{@example.com > > end > > But, IIUC, in Python the member `value' is not hidden, so you just write > > def test_crappy_class > crap = CrappyClass.new > assert_equal(0, crap.value) > crap.increment() > assert_equal(1, crap.value) Sure. What's the difference, really? In Ruby, instance variables are hidden by default, which is a nice signal to programmers that they shouldn't be considered part of a class's API. But if you need to get at them, you can do it. > That end" end end end looks like gdb. ;-) Heh heh. > I see the attraction of the Ruby features for quick hacking, but I > also see the attraction of two-year-olds to swimming pools not > surrounded by fences. The latter is a disaster; I hope you never > regret succumbing to the temptation of monkey-patching-supported-by- > syntax. ;-) Monkey patching is not a tool I use lightly. Cheers, Josh [1] http://flexmock.rubyforge.org/ [2] http://has207.github.com/flexmock/
- Follow-Ups:
- Re: [tlug] Alternatives to sed + awk
- From: Stephen J. Turnbull
- References:
- [tlug] Alternatives to sed + awk
- From: Nguyen Vu Hung
- Re: [tlug] Alternatives to sed + awk
- From: Alexander Danilov
- Re: [tlug] Alternatives to sed + awk
- From: Stephen J. Turnbull
- Re: [tlug] Alternatives to sed + awk
- From: Alexander Danilov
- Re: [tlug] Alternatives to sed + awk
- From: Stephen J. Turnbull
- Re: [tlug] Alternatives to sed + awk
- From: Josh Glover
- Re: [tlug] Alternatives to sed + awk
- From: Stephen J. Turnbull
- Re: [tlug] Alternatives to sed + awk
- From: Josh Glover
- Re: [tlug] Alternatives to sed + awk
- From: Stephen J. Turnbull
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Assembly Language v C and Embedded Development: gcc for PIC16F84? probably not available
- Next by Date: Re: [tlug] Assembly Language v C and Embedded Development: !gcc for PIC16F84
- Previous by thread: Re: [tlug] Alternatives to sed + awk
- Next by thread: Re: [tlug] Alternatives to sed + awk
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links