[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnulib-tool.py: lists vs. sets
From: |
Collin Funk |
Subject: |
Re: gnulib-tool.py: lists vs. sets |
Date: |
Sun, 7 Apr 2024 06:06:43 -0700 |
User-agent: |
Mozilla Thunderbird |
Hi Bruno,
On 4/7/24 4:56 AM, Bruno Haible wrote:
> In my opinion, both are good ways to express the same thing.
> The second one is more expressive; but we all can store a 3-lines
> snippet of code in our short-term memory.
Yeah, it isn't bad. Just personal preference I guess. Two more lines
for me to make typos though. :)
> The interesting question here is: is table2 a possibly long list?
> If yes, then can we convert it to a set, without impairing the
> clarity of the code?
There are probably some places where it would make sense. The test
suite should help catch any divergence from gnulib-tool.sh's sorting
behavior.
Since gnulib-tool.py doesn't have a speed issue, I'll probably focus
more on being a code janitor and cleaning up a bit.
That reminds me, is there a reason why in many places there is
something like this:
newtail = []
for item in tail:
newtail += [item]
instead of this?
newtail = []
for item in tail:
newtail.append(item)
I like the second more, but I can't tell if it is another overly
strong personal preference of mine...
Not that we will notice this, but an interesting implementation
detail:
>>> import timeit
>>> timeit.timeit(stmt='var += ["a"]', setup='var = []', number=100000000)
6.761068544998125
>>> timeit.timeit(stmt='var.append("a")', setup='var = []', number=100000000)
1.7367604600003688
Collin
- gnulib-tool.py: Fix 'consider-using-with' pylint warnings., Collin Funk, 2024/04/05
- gnulib-tool.py: Use 'Any' instead of type unions in GLConfig., Collin Funk, 2024/04/05
- Re: gnulib-tool.py: Fix 'consider-using-with' pylint warnings., Bruno Haible, 2024/04/05
- Re: gnulib-tool.py: Fix 'consider-using-with' pylint warnings., Collin Funk, 2024/04/05
- Re: gnulib-tool.py: lists vs. sets, Bruno Haible, 2024/04/06
- Re: gnulib-tool.py: lists vs. sets, Collin Funk, 2024/04/06
- Re: gnulib-tool.py: lists vs. sets, Bruno Haible, 2024/04/07
- Re: gnulib-tool.py: lists vs. sets,
Collin Funk <=
- Re: Python list micro-benchmarks, Bruno Haible, 2024/04/07
- Re: Python list micro-benchmarks, Collin Funk, 2024/04/07
- Re: Python list micro-benchmarks, Paul Eggert, 2024/04/07
- Re: Python list micro-benchmarks, Collin Funk, 2024/04/07
- Re: Python list micro-benchmarks, Bruno Haible, 2024/04/08
- Re: Python list micro-benchmarks, Collin Funk, 2024/04/08
- Re: Python list micro-benchmarks, Bruno Haible, 2024/04/08
- Re: Python list micro-benchmarks, Paul Eggert, 2024/04/08
- Re: Python list micro-benchmarks, Collin Funk, 2024/04/08
- gnulib-tool.py: Prefer 'list.append(item)' over 'list += [item]'., Collin Funk, 2024/04/08