Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #465503

Re: The substantiation that -highhorse asked for

From owl <owl@rooftop.invalid>
Newsgroups comp.os.linux.advocacy
Subject Re: The substantiation that -highhorse asked for
Date 2018-09-01 16:28 +0000
Organization O.W.L.
Message-ID <9b0z880b3.ago@rooftop.invalid> (permalink)
References (9 earlier) <JgxhD.7$UI2.1@fx18.iad> <g89z0b083.a44@rooftop.invalid> <9fgiD.16490$Vl2.3553@fx46.iad> <8a0b0803ga.ahy@rooftop.invalid> <h9xiD.40843$4S3.8856@fx47.iad>

Show all headers | View raw


DFS <nospam@nospam.com> wrote:
> On 8/31/2018 3:40 PM, owl wrote:
>> DFS <nospam@nospam.com> wrote:
>>> On 8/29/2018 10:31 AM, owl wrote:
>>>> DFS <nospam@nospam.com> wrote:
>>>>> On 8/29/2018 2:14 AM, owl wrote:
>>>>>> DFS <nospam@nospam.com> wrote:
>>>>
>>>>> affirmative
>>>
>>>
>>>> But who would write it that way, and why?
>>>
>>> Someone drunk at 2:14am, because they were drunk.
>>>
>>>
>>>> Sure, there's no if statements,
>>>> but that comes at the expense of 1,000,001 function pointers.  And the
>>>> nested ternaries constitute conditional tests anyway.  Not to mention
>>>> less readability.  It would run faster, use less stack, and be much more
>>>> readable and faster to design and write without error, by just using a
>>>> list of ifs.
>>>
>>> Congrats on beating up your own strawman.
>> 
>> How so?  I showed that striving for some subjective code "elegance" by
>> reducing the number of visible ifs (your desire), when carried to the
>> extreme of zero, is detrimental to performance.  
> 
> 'when carried to the extreme'... strawman in the house!
> 

Carried to its natural conclusion.

> 
>> Your code contains the
>> same number of conditional tests in the loop as would be run without
>> the loop, takes longer to code, is more prone to errors in construction,
>> is arguably less readable, is less flexible in condition actions, and
>> provides no performance benefit.  But somehow that makes it more elegant
>> than a straight if/else sequence?
> 
> 
> Are you arguing just to argue?

Yes.

>  Or did Feeb promise favors?
> 
> 'Cause his stupid hard-coded one if-then-else for each income bracket is 
> silly.  Each year he has to check if the code corresponds one-on-one to 
> the number of income brackets.
> 
> I'm reasonable; in the past this was my typical code for setting dates 
> on an Access screen, after you choose from a list of date periods:
> 
> Public Function getStartDate(period As String) As Date
> If period = "YTD" Then
>   getStartDate = "01-Jan-" & DatePart("yyyy", Date)
>  ElseIf period = "Today"         Then getStartDate = Date
>  ElseIf period = "Yesterday"     Then getStartDate = Date - 1
>  ElseIf period = "Last Week"     Then getStartDate = Date - 6
>  ElseIf period = "Last 2 Weeks"  Then getStartDate = Date - 13
>  ElseIf period = "Last Month"    Then getStartDate = Date - 30
>  ElseIf period = "Last 3 Months" Then getStartDate = Date - 90
>  ElseIf period = "Last 6 Months" Then getStartDate = Date - 180
>  ElseIf period = "Last Year"     Then getStartDate = Date - 365
>  ElseIf period = "Last 2 Years"  Then getStartDate = Date - (365 * 2)
>  ElseIf period = "Last 3 Years"  Then getStartDate = Date - (365 * 3)
>  ElseIf period = "Last 4 Years"  Then getStartDate = Date - (365 * 4)
>  ElseIf period = "Last 5 Years"  Then getStartDate = Date - (365 * 5)
>  ElseIf period = "Last 10 Years" Then getStartDate = Date - (365 * 10)
>  ElseIf period = "Last 15 Years" Then getStartDate = Date - (365 * 15)
> End If
> 
> End Function
> 
> 
> I could make a couple clunky for...loops, but in this case it's 
> inappropriate.
> 

No ifs, ands, or buttloops...

#!/bin/bash
declare -A starts
if [ ${#} -ne 1 ];then
  echo "feed me a date period"
  exit
fi
datefmt="+%d-%b-%Y"
starts["YTD"]=$(date -d "Jan 1" ${datefmt}) 
starts["Today"]=$(date -d "today" ${datefmt})
starts["Yesterday"]=$(date -d "today -1 days" ${datefmt})
starts["Last Week"]=$(date -d "today -6 days" ${datefmt})
starts["Last 2 Weeks"]=$(date -d "today -13 days" ${datefmt})
starts["Last Month"]=$(date -d "today -30 days" ${datefmt})
starts["Last 3 Months"]=$(date -d "today -90 days" ${datefmt})
starts["Last 6 Months"]=$(date -d "today -180 days" ${datefmt})
starts["Last Year"]=$(date -d "today -1 year" ${datefmt})
starts["Last 2 Years"]=$(date -d "today - 2 years" ${datefmt}) 
starts["Last 3 Years"]=$(date -d "today - 3 years" ${datefmt}) 
starts["Last 4 Years"]=$(date -d "today - 4 years" ${datefmt}) 
starts["Last 5 Years"]=$(date -d "today - 5 years" ${datefmt}) 
starts["Last 10 Years"]=$(date -d "today - 10 years" ${datefmt}) 
starts["Last 15 Years"]=$(date -d "today - 15 years" ${datefmt}) 
echo ${starts["${1}"]}
anon@lowtide:~/code/ifs$ 
anon@lowtide:~/code/ifs$ ./startdate YTD
01-Jan-2018
anon@lowtide:~/code/ifs$ ./startdate "Last 15 Years"
01-Sep-2003
anon@lowtide:~/code/ifs$ ./startdate "Last Week"
26-Aug-2018
anon@lowtide:~/code/ifs$ 

Back to comp.os.linux.advocacy | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-28 08:28 -0400
  Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-28 09:20 -0700
    Re: The substantiation that -highhorse asked for fr314159@gmail.com - 2018-08-28 11:27 -0700
      Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-28 11:39 -0700
      Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-29 09:46 -0400
    Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-28 14:52 -0400
      Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-28 12:20 -0700
  Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-28 17:21 +0000
    Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-28 14:46 -0400
      Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-28 19:14 +0000
        Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-28 12:30 -0700
          Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-28 20:09 +0000
            Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-28 13:58 -0700
              Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-28 21:16 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-28 14:31 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-28 21:43 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-28 15:06 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-28 22:26 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-28 15:35 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-28 23:14 +0000
                Re: The substantiation that -highhorse asked for Snit <usenet@gallopinginsanity.com> - 2018-08-28 14:57 -0700
            Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-28 23:11 -0400
              Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-29 06:14 +0000
                Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-29 09:34 -0400
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-29 14:31 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-29 11:01 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-31 12:33 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-31 09:16 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-31 16:53 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-31 10:22 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-31 17:53 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-08-31 11:36 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-09-01 13:45 +0000
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-09-01 13:59 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-09-01 08:15 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-09-01 16:00 +0000
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-09-01 11:20 -0700
                Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-31 15:00 -0400
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-31 19:40 +0000
                Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-09-01 10:15 -0400
                Re: The substantiation that -highhorse asked for Steve Carroll <fretwizzer@gmail.com> - 2018-09-01 08:22 -0700
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-09-01 16:28 +0000
                Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-09-01 16:39 -0400
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-09-01 22:00 +0000
                Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-09-01 18:27 -0400
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-09-01 22:40 +0000
                Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-09-01 19:09 -0400
                Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-09-01 23:59 +0000
        Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-28 23:01 -0400
          Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-29 06:26 +0000
  Re: The substantiation that -highhorse asked for "F. Russell" <fr@random.info> - 2018-08-28 19:25 +0000
    Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-29 09:32 -0400
      Re: The substantiation that -highhorse asked for fr314159@gmail.com - 2018-08-29 06:46 -0700
        Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-08-29 09:55 -0400
          Re: The substantiation that -highhorse asked for fr314159@gmail.com - 2018-08-29 08:02 -0700
            Re: The substantiation that -highhorse asked for DFS <nospam@nospam.com> - 2018-09-01 10:14 -0400
          Re: The substantiation that -highhorse asked for owl <owl@rooftop.invalid> - 2018-08-29 15:12 +0000

csiph-web