News for hackers. Stuff that matters.
Re:Source code for Dutch DigiD app released under Dutch Open... by melvinmelih on Wednesday January 18, 2023 @09:21AM (#34426879)
Re:Source code for Dutch DigiD app released under Dutch Open... by seydor on Wednesday January 18, 2023 @09:24AM (#34426905)
LLMs can do better
Re:Source code for Dutch DigiD app released under Dutch Open... by eugenekolo on Wednesday January 18, 2023 @09:31AM (#34426992)
This one's pretty fancy from the big GPT.

``` Here is an example of Python code that can print a loading bar at different completion percentages:

def print_loading_bar(percent): bar_length = 20 hashes = '#' * int(percent * bar_length / 100) spaces = ' ' * (bar_length - len(hashes)) print(f'\rLoading... [{hashes}{spaces}] {percent}%', end='')

for i in range(101): print_loading_bar(i) time.sleep(0.1) ```

Re:Source code for Dutch DigiD app released under Dutch Open... by tgv on Wednesday January 18, 2023 @12:58PM (#34430292)
Should be C#, though, and for just 11 steps.
Re:Source code for Dutch DigiD app released under Dutch Open... by jpcrs on Wednesday January 18, 2023 @09:53AM (#34427300)
I don't know why so many people are saying that this is bad code.

Besides the redundant checks, it's really simple, so simple that an intern, maybe even someone who doesn't code, can understand and update it.

It's performant, most compilers will cache the strings.

People trying to justify more complex one-liners with "what if you change the symbol, or just show 5 characters" etc. These scenarios wouldn't take more than 5 minutes to adapt this code, and anyone could do it.

For me, this code with a good set of tests doesn't get much better.

Re:Source code for Dutch DigiD app released under Dutch Open... by jeroenhd on Wednesday January 18, 2023 @09:56AM (#34427333)
It's easy to read, simple to maintain, and performant code. Maybe one of those newer switch expressions would make the code even clearer, but they already left the redundant lower bound checks in so I think the way this looks is quite intentional.

Much easier to read than `int count = (int)Math.Floor(percentage / 10); return new String("#", count) + new String("-", 10 - count));` in my opinion and not worth writing a custom progress component for.

Re:Source code for Dutch DigiD app released under Dutch Open... by radicalbyte on Wednesday January 18, 2023 @11:06AM (#34428456)
I agree; there are things in the code base that I personally dislike (a number of classes which could be decomposed into smaller units) but overall it's pretty good.

I had the honour of being able to review this under NDA before it was made public (pro bono, and limited to static analysis and an hour poking around suspicious looking classes). I've seen a lot of .Net code in my time and this was surprisingly good. Sure there are things which could be improved, but you'll find an order of magnitude more issues in most other code (especially dynamic languages, which are magnets inadvertent issues affecting correctness).