Hacker News new | ask | show | jobs
by its_magic 143 days ago
I would just say, on a positive note, it looks exactly like something a 17 year old would create--a brilliant 17 year old who is going places in life, that is.

I would strongly reiterate that the GIGANTIC RAT'S NEST of brackets needs to be cleaned up as that will never, ever fly.

The root of the problem seems to be either a) you're doing some kind of auto-generation of code in a crazy way, or b) a dogged insistence on not putting 'else if' on the same line due to some kind of stylistic concern...the sort of mistake a very bright but slightly autistic young man might make.

Refactor the code to fix this please and you will have to admit it ends up looking WAY nicer, and most importantly, will be a thousand times easier to maintain.

Keep it up, you will go far. The next version will be better. They always are.

Congrats on getting on HN!

1 comments

Thank you for the kind words and the specific, actionable feedback.

You've pinpointed the exact issue - it's option (b). I developed a personal style coding in isolation and didn't learn conventional formatting. The "else if on separate lines" pattern became a habit that snowballed into that brace nesting.

I'm fixing it now. You're absolutely right that it will be much more maintainable.

The "brilliant 17 year old" comment means a lot. I'm learning that part of brilliance is knowing when to follow established patterns. Thank you for the mentorship through critique.

The cleanup starts today.

Good man. Like I said, it's obvious you're going places.

D is a good language. You chose well. Walter Bright would be happy to see what you're doing here.

If you're not using version control yet, now's a good time to start, as it will help with the cleanup work. Fossil is my favorite as it's easier to use than git, but whatever you like is fine. More people use git than fossil so it's good to learn it and master it. It's very easy to introduce some kind of subtle bug in situations like this, but with version control you can check carefully after each change to make sure the code still works properly, and if not, easily see the problem and fix it or revert and try again.

clang-format would be the perfect tool for this also, even though it's not designed to work on D. The language is close enough to C++ in syntax that it should do the job, at least helping you get rid of the brackets in one go without screwing anything up too much. I recommend basing your styling on the "Microsoft" preset and customizing from there. That's also known as the "Allman" style, with the brackets starting on their own lines. With the brackets lined up like this it helps to see where code blocks begin and end. But you can use whatever style you like of course, just experiment and see what looks good to you.

Ultimately it comes down to just Doing the Right Thing. Sometimes that's the same as following established patterns, and sometimes it means breaking them. As you gain more experience you'll figure it out.

I think HN lets you post the same link once a month, so spend a while cleaning it up good and making it look as pretty as you can, then post it up again next month, on a Friday or Saturday to get more eyes on it. Send me the link when you do and I'll have another look. Here's my email:

domain: killthe.net

name: dave

Here's a good clang-format config file to get you started:

http://killthe.net/clang-format

Use it like this, from your source directory.

  find -name '*.d' | xargs clang-format --style=file:clang-format -i
Just make sure to have a backup copy first, or version control, before running that command as it might screw things up.