On May 27, 2009, at 12:35 PM, J Haas wrote:

> On May 22, 9:01 am, Roger Pack <rogerpack2... / gmail.com> wrote:
>> Tony's point was that certain constructs, like case statements,  
>> won't be
>> transformable into indentation only blocks.  Does that make sense?
>
> No, it doesn't, because I don't see why case statements are not
> transformable into indent-only blocks. I've _done_ them using the
> quick-and-dirty hacky script and they work just fine. (In cases like
> Joshua's impossible.rb I had to make a minor modification to the
> script to have it inject 'end ' rather than 'end\n', but it still
> worked fine.)
>
> Code speaks louder than words, right? Here's some real-world code...
> it's application_controller.rb from the AuthLogic example (http://
> github.com/binarylogic/authlogic_example/tree):
>
> -----------------
>
> # Filters added to this controller apply to all controllers in the
> application.
> # Likewise, all the methods added will be available for all
> controllers.
>
> class ApplicationController < ActionController::Base
> helper :all
> helper_method :current_user_session, :current_user
>
> On May 27, 2009, at 12:35 PM, J Haas wrote:
>
>> On May 22, 9:01 am, Roger Pack <rogerpack2... / gmail.com> wrote:
>>> Tony's point was that certain constructs, like case statements,  
>>> won't be
>>> transformable into indentation only blocks.  Does that make sense?
>>
>> No, it doesn't, because I don't see why case statements are not
>> transformable into indent-only blocks. I've _done_ them using the
>> quick-and-dirty hacky script and they work just fine. (In cases like
>> Joshua's impossible.rb I had to make a minor modification to the
>> script to have it inject 'end ' rather than 'end\n', but it still
>> worked fine.)
>>
>> Code speaks louder than words, right? Here's some real-world code...
>> it's application_controller.rb from the AuthLogic example (http://
>> github.com/binarylogic/authlogic_example/tree):
>>
>> -----------------
>>
>> # Filters added to this controller apply to all controllers in the
>> application.
>> # Likewise, all the methods added will be available for all
>> controllers.
>>
>> class ApplicationController < ActionController::Base
>> helper :all
>> helper_method :current_user_session, :current_user
>> filter_parameter_logging :password, :password_confirmation
>>
>> private
>>    def current_user_session
>>      return @current_user_session if defined?(@current_user_session)
>>      @current_user_session = UserSession.find
>>    end
>>
>>    def current_user
>>      return @current_user if defined?(@current_user)
>>      @current_user = current_user_session &&
>> current_user_session.record
>>    end
>>
>>    def require_user
>>      unless current_user
>>        store_location
>>        flash[:notice] = "You must be logged in to access this page"
>>        redirect_to new_user_session_url
>>        return false
>>      end
>>    end
>>
>>    def require_no_user
>>      if current_user
>>        store_location
>>        flash[:notice] = "You must be logged out to access this page"
>>        redirect_to account_url
>>        return false
>>      end
>>    end
>>
>>    def store_location
>>      session[:return_to] = request.request_uri
>>    end
>>
>>    def redirect_back_or_default(default)
>>      redirect_to(session[:return_to] || default)
>>      session[:return_to] = nil
>>    end
>> end
>>
>> -----------------
>>
>> Nothing particularly special about this code, right? Pretty standard
>> Ruby, if a bit simple? 37 non-blank, non-comment lines, of which 9
>> consist of the bare word "end". I defy anyone to tell me that the  
>> code
>> would be less readable as this:
>>
>> -----------------
>>
>> # Filters added to this controller apply to all controllers in the
>> application.
>> # Likewise, all the methods added will be available for all
>> controllers.
>>
>> class ApplicationController < ActionController::Base
>> helper :all
>> helper_method :current_user_session, :current_user
>> filter_parameter_logging :password, :password_confirmation
>>
>> private
>>    def current_user_session:
>>      return @current_user_session if defined?(@current_user_session)
>>      @current_user_session = UserSession.find
>>
>>    def current_user:
>>      return @current_user if defined?(@current_user)
>>      @current_user = current_user_session &&
>> current_user_session.record
>>
>>    def require_user:
>>      unless current_user:
>>        store_location
>>        flash[:notice] = "You must be logged in to access this page"
>>        redirect_to new_user_session_url
>>        return false
>>
>>    def require_no_user:
>>      if current_user:
>>        store_location
>>        flash[:notice] = "You must be logged out to access this page"
>>        redirect_to account_url
>>        return false
>>
>>    def store_location:
>>      session[:return_to] = request.request_uri
>>
>>    def redirect_back_or_default(default):
>>      redirect_to(session[:return_to] || default)
>>      session[:return_to] = nil
>>
>>
> As this debate unfolds I've watched the stronger criticisms fall  
> apart.  The
> strongest type of criticism would be that it can't be done, or that  
> it's too
> hard to do.  But the impossible examples seem to be defeated fairly  
> easily.
> Moreover, the solutions are backward compatible to existing Ruby.
>
> Now when I look at this latest example I see some ordinary code  
> that's 44 lines
> long.  With the pythonic scheme it looks like it's only 35 lines  
> long.  I find
> it difficult to convince myself that it's a good idea to make code  
> 25% larger
> just to preserve some ends of dubious value.
>
> I suppose I could try to come up with some nonsense argument that  
> 'end' makes
> everything more readable.  But that would just be prejudice.  It's  
> trivially
> easy to read.  It can't just be me.  There seems to be no shortage  
> of Python
> folk who have no problem either.  Objectively, being forced to  
> explicitly type
> 'end' all the time seems to takes up a whole lot of space.
>
> filter_parameter_logging :password, :password_confirmation
>
> private
>    def current_user_session
>      return @current_user_session if defined?(@current_user_session)
>      @current_user_session = UserSession.find
>    end
>
>    def current_user
>      return @current_user if defined?(@current_user)
>      @current_user = current_user_session &&
> current_user_session.record
>    end
>
>    def require_user
>      unless current_user
>        store_location
>        flash[:notice] = "You must be logged in to access this page"
>        redirect_to new_user_session_url
>        return false
>      end
>    end
>
>    def require_no_user
>      if current_user
>        store_location
>        flash[:notice] = "You must be logged out to access this page"
>        redirect_to account_url
>        return false
>      end
>    end
>
>    def store_location
>      session[:return_to] = request.request_uri
>    end
>
>    def redirect_back_or_default(default)
>      redirect_to(session[:return_to] || default)
>      session[:return_to] = nil
>    end
> end
>
> -----------------
>
> Nothing particularly special about this code, right? Pretty standard
> Ruby, if a bit simple? 37 non-blank, non-comment lines, of which 9
> consist of the bare word "end". I defy anyone to tell me that the code
> would be less readable as this:
>
> -----------------
>
> # Filters added to this controller apply to all controllers in the
> application.
> # Likewise, all the methods added will be available for all
> controllers.
>
> class ApplicationController < ActionController::Base
> helper :all
> helper_method :current_user_session, :current_user
> filter_parameter_logging :password, :password_confirmation
>
> private
>    def current_user_session:
>      return @current_user_session if defined?(@current_user_session)
>      @current_user_session = UserSession.find
>
>    def current_user:
>      return @current_user if defined?(@current_user)
>      @current_user = current_user_session &&
> current_user_session.record
>
>    def require_user:
>      unless current_user:
>        store_location
>        flash[:notice] = "You must be logged in to access this page"
>        redirect_to new_user_session_url
>        return false
>
>    def require_no_user:
>      if current_user:
>        store_location
>        flash[:notice] = "You must be logged out to access this page"
>        redirect_to account_url
>        return false
>
>    def store_location:
>      session[:return_to] = request.request_uri
>
>    def redirect_back_or_default(default):
>      redirect_to(session[:return_to] || default)
>      session[:return_to] = nil
>
>
As I've watched this debate unfold I've watched the stronger  
criticisms fall
apart.  The strongest type of criticism would be that it can't be  
done, or that
it's too hard to be done.  But the impossible examples seem to be  
defeated
fairly easily.   Moreover, the solutions are backward compatible to  
existing
Ruby.

Now when I look at this latest example I see some ordinary code that's  
44 lines
long.  With the pythonic scheme it looks like it's only 35 lines  
long.  I find
it difficult to convince myself that it's a good idea to make code 25%  
larger
just to preserve some ends of dubious value.

I suppose I could try to come up with some nonsense argument that  
'end' makes
everything more readable.  But that would just be prejudice.  The  
pythonic
example is trivially easy to read.  It can't just be me.  There seems  
to be no
shortage of Python folk who have no problem.   Objectively, the ends  
just take
up a whole lot of space.