3 ms·
As an average Ruby developer. The first 100ms I saw: if request.get? # serve authorization page HTML else # grant permissions to app end I know
by Existenceblinks 7y ago
As an average Ruby developer. The first 100ms I saw:
if request.get?
# serve authorization page HTML
else
# grant permissions to app
end
I know that's really smell. Why would I put a serious statement inside `else` block?
- wolco 7y agoCould you explain that further. Why would you avoid a serious statement in an else? Would this be more acceptable? The negative on the if if !request.get?
- adverbly 7y agoI assume the correct pattern for finite possible inputs would be something like if request.post? || request.put? || more... # do dangerous thing else # do safe thing This of course ignores the smell which others have pointed out where with rails you would ideally have a totally different method get called in the first place for a GET vs a POST as you can have different actions for them in the controller.
- Existenceblinks 7y agoBecause unknown gives anxiety. Robot: if !request.get? do_nothing else kill_one_person end What are possible states for NOT `!get?`, I have to think twice or all day thinking. The problem is that real world program may have exception state you can't think of. If you write down a set of finite state; {A,B,C,D}. if A # For A, do nothing else # for B or C or D, kill a man end It's sure that if not A, it's going to be B|C|D. But what if it isn't? You could get an exceptional Z which will kill a man too. You know A better anything "else".