Deutsch   English   Français   Italiano  
<20240409181656.240@kylheku.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.unix.shell,comp.unix.programmer,comp.lang.misc
Subject: Re: Command Languages Versus Programming Languages
Date: Wed, 10 Apr 2024 01:35:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 95
Message-ID: <20240409181656.240@kylheku.com>
References: <uu54la$3su5b$6@dont-email.me> <uudrfg$2cskm$1@dont-email.me>
 <87r0fp8lab.fsf@tudado.org> <uuehdj$2hshe$1@dont-email.me>
 <87wmpg7gpg.fsf@tudado.org> <LISP-20240402085115@ram.dialup.fu-berlin.de>
 <LISP-20240402091729@ram.dialup.fu-berlin.de>
 <wrap-20240402092558@ram.dialup.fu-berlin.de>
 <uui7hf$3gona$1@dont-email.me> <uuj1o5$3pvnq$1@dont-email.me>
 <87plv6jv1i.fsf@nosuchdomain.example.com>
 <wwv5xwyifq8.fsf@LkoBDZeT.terraraq.uk>
 <if-20240404121825@ram.dialup.fu-berlin.de> <uund4g$ugsb$1@dont-email.me>
 <uuofjh$19pfd$1@dont-email.me> <uuq0fp$1lcgf$2@dont-email.me>
 <86frvzo01i.fsf@williamsburg.bawden.org> <uuq4q9$1mbbf$1@dont-email.me>
 <20240408082037.00002d7c@gmail.com> <uv1q7n$3oohj$1@dont-email.me>
 <20240408155834.00003597@gmail.com> <wwvle5nnfk8.fsf@LkoBDZeT.terraraq.uk>
 <uv2t6t$3o6o$2@dont-email.me> <uv2upa$42fo$2@dont-email.me>
 <uv3feh$83fj$2@dont-email.me> <uv4mnf$hled$3@dont-email.me>
Injection-Date: Wed, 10 Apr 2024 01:35:11 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a02df6af16e190f6c7ee895d512b8f84";
	logging-data="732462"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+a1Ki1dsarHfgpk5kqBhMzMTx3PBEAQ1A="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:CZxWBPwi43SERrwBfIcpIfJWq0U=
Bytes: 6339

On 2024-04-10, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Tue, 9 Apr 2024 15:22:25 +0200, David Brown wrote:
>
>> You could try doing what almost every other Python programmer does - use
>> smaller functions and drop the silly line continuations.
>
> Fine. Try that with the example I gave.

Maybe you have a Python-coding niece or nephew in the fifth grade who can
reformat it for you?

Meanwhile:

Pass 1:

def fill_in_depreciations(tax_year) :
    """
    (re)inserts depreciation entries for the specified tax year,
    based on currently-entered assets.
    """

    sql.cursor.execute("delete from payments where kind = %s and tax_year = %s",
                       ["D", tax_year])
    for entry in get_each_record(table_name = "assets, asset_depreciations",
                                 fields = [
                                    "assets.description as description",
                                    "assets.initial_value as initial_value",
                                    "assets.when_purchased as when_purchased",
                                    "assets.depreciation_rate as rate",
                                    "assets.depreciation_method as method",
                                    "asset_depreciations.depreciation_amount as amount",
                                 ],
                                 condition = "assets.asset_id = asset_depreciations.asset_id and"
                                             " asset_depreciations.tax_year = %s",
                                 values = [tax_year]):
        sql.cursor.execute("insert into payments set when_made = %(when_made)s,"
                           " description = %(description)s, other_party_name = \"\","
                           " amount = %(amount)d, kind = \"D\", tax_year = %(tax_year)d"
                           % { "when_made" : end_for_tax_year(tax_year) - 1,
                               "description" : sql_string("%s: %s $%s at %d%% from %s" %
                                                          (entry["description"],
                                                           entry["method"],
                                                           format_amount(entry["initial_value"]),
                                                           entry["rate"],
                                                           format_date(entry["when_purchased"]))),
                               "amount" : - entry["amount"],
                               "tax_year" : tax_year })



Pass 2: fits into 80 cols and everything:

def fill_in_depreciations(tax_year) :
    """
    (re)inserts depreciation entries for the specified tax year,
    based on currently-entered assets."
    """

    table = "assets, asset_depreciations"

    fields = ["assets.description as description",
              "assets.initial_value as initial_value",
              "assets.when_purchased as when_purchased",
              "assets.depreciation_rate as rate",
              "assets.depreciation_method as method",
              "asset_depreciations.depreciation_amount as amount"]

    condition = ("assets.asset_id = asset_depreciations.asset_id and"
                 " asset_depreciations.tax_year = %s")

    insert = ("insert into payments set when_made = %(when_made)s,"
              " description = %(description)s, other_party_name = \"\","
              " amount = %(amount)d, kind = \"D\", tax_year = %(tax_year)d")

    sql.cursor.execute("delete from payments where kind = %s and tax_year = %s",
                       ["D", tax_year])

    for entry in get_each_record(table_name = table_name, fields = fields,
                                 condition = condition, values = [tax_year]):
        desc = sql_string("%s: %s $%s at %d%% from %s" %
                          (entry["description"],
                           entry["method"],
                           format_amount(entry["initial_value"]),
                           entry["rate"],
                           format_date(entry["when_purchased"])))
        sql.cursor.execute(insert %
                           {"when_made" : end_for_tax_year(tax_year) - 1,
                            "description" : desc,
                            "amount" : - entry["amount"],
                            "tax_year" : tax_year})

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca