Live data from Hacker News

Ask HN: What are your favorite examples of elegant software?

news.ycombinator.com

281–290 of 422 posts

Re: Ask HN: What are your favorite examples of elegant software?

#282

Earlier quoted context omitted.

This game sounds really cool, but I can't find it when I lookup "X game" or "X 4x game". Can you link it to me please?

X4 Foundations is its name https://store.steampowered.com/app/392160/X4_Foundations/ The expansion packs have expanded the size of the game world considerably, making the whole thing even more amazing

Thanks!

Re: Ask HN: What are your favorite examples of elegant software?

#283
post #166

Earlier quoted context omitted.

This is nice. One interesting choice is the decision to compute the number of observed words, N, as the default value of an optional argument, thereby ensuring that it is only computed once, while still limiting its scope to the function in which it is needed. Perhaps this is a common pattern but it's one I haven't stumbled across before. The short circuiting `or` chain is also pleasantly virtuosic. Sometimes a littl…

> One interesting choice is the decision to compute the number of observed words, N, as the default value of an optional argument, thereby ensuring that it is only computed once You're saying python computes an expression that's part of a default value when the code defining the function is run? I guess it makes sense now that i say it, I wouldn't have automatically assumed that. That's an interesting one to remember…

[deleted]

Re: Ask HN: What are your favorite examples of elegant software?

#284
post #166

Earlier quoted context omitted.

This is nice. One interesting choice is the decision to compute the number of observed words, N, as the default value of an optional argument, thereby ensuring that it is only computed once, while still limiting its scope to the function in which it is needed. Perhaps this is a common pattern but it's one I haven't stumbled across before. The short circuiting `or` chain is also pleasantly virtuosic. Sometimes a littl…

> One interesting choice is the decision to compute the number of observed words, N, as the default value of an optional argument, thereby ensuring that it is only computed once You're saying python computes an expression that's part of a default value when the code defining the function is run? I guess it makes sense now that i say it, I wouldn't have automatically assumed that. That's an interesting one to remember…

Python's default arguments are evaluated and stored once. This can cause issues, for example the naive "default to []" program:

    >>> def function(b, a=[]):
    ...     a.append(b)
    ...     print(a)
    ... 
    ...     
    >>> function(1)
    [1]
    >>> function(2)
    [1, 2]
    >>> function(3, [4])
    [4, 3]
    >>> function(5)
    [1, 2, 5]
A correct implementation would be:

    >>> def function2(b, a=None):
    ...     if a is None: a = []
    ...     a.append(b)
    ...     print(a)

Re: Ask HN: What are your favorite examples of elegant software?

#286
post #166

Earlier quoted context omitted.

This is nice. One interesting choice is the decision to compute the number of observed words, N, as the default value of an optional argument, thereby ensuring that it is only computed once, while still limiting its scope to the function in which it is needed. Perhaps this is a common pattern but it's one I haven't stumbled across before. The short circuiting `or` chain is also pleasantly virtuosic. Sometimes a littl…

> One interesting choice is the decision to compute the number of observed words, N, as the default value of an optional argument, thereby ensuring that it is only computed once You're saying python computes an expression that's part of a default value when the code defining the function is run? I guess it makes sense now that i say it, I wouldn't have automatically assumed that. That's an interesting one to remember…

Yep and that's also the source of the footgun:

def foobar(my_list=[]): my_list.append(42)

A cursory glance suggests this function appends a number to an empty list every time it's run. But actually, the default argument is evaluated once when the function is defined, so calling this function repeatedly will continue to append to that same list.

Re: Ask HN: What are your favorite examples of elegant software?

#289
pandoc comes to mind, one of those pieces of software that “just works.” I’m not a Haskell guy but pandoc makes me wonder sometimes.

Visual Basic (cue the hecklers). Yes the language is awful. But the tool was great. I wish Microsoft (or somebody) would release a new version for full-stack apps with a drag-and-drop UI with js event handlers, easy backend framework, and a one-button “deploy to cloud” button for testing. Then a “publish” button that sets up your CI pipeline for production deployments. I feel like we’ve raised the white flag in terms of what software development should look like in 2022. Writing yaml feels like banging rocks together compared to possible alternatives.

Re: Ask HN: What are your favorite examples of elegant software?

#290

Not a specific piece of software, but a characteristic of a limited percentage of anonymous internal systems--one of the most beautiful things to witness in the realm of design is a system undergoing catastrophic stress when the designers anticipated and planned for such events, and in usually a very short period of time you see the results of extensive planning spool out, design features hidden from view and unappre…

any examples?
Post reply on HN