Live data from Hacker News

Ask HN: Is my code any good?

news.ycombinator.com

11–20 of 44 posts

Re: Ask HN: Is my code any good?

#11
Looks pretty nice and clean. I don't know how you are using firebase in the app. But it seems you aren't using authentication. Which basically means that anyone can delete all the data in your firebase instance.

Re: Ask HN: Is my code any good?

#12
I've not written any swift apps yet, but I have written some objective c and the (effectively) empty test directory is definitely an indicator that this code will be hard to change.

Re: Ask HN: Is my code any good?

#15
post #10
post #4

Earlier quoted context omitted.

I wanted to get some feedback on my code design and structure. I think that is difficult to get via automated code review.

That's not what your question asks for. Anyway, in my experience, the ability to test with ease is one dimenision of design quality.

How is that not what was asked? The phrasing of the question makes it immediately obvious, at least to me, that the OP was looking for a design critique. (Unless of course the question was edited since you wrote your initial comment.)

Re: Ask HN: Is my code any good?

#18
post #17

How long have you been coding total? Was Design+Code your sole source for learning how to program?

No I have been coding now for close to an year now. But this is my first project with Swift. I have also watched the video lectures of the iOS development course offered by Stanford on iTunes.

Re: Ask HN: Is my code any good?

#19
post #16

After several years in a test-driven development team, seeing your test directory made me cringe :/

Yeah I know I need follow the best practices. I have started writing tests for the next update. But do you recommend TDD for iOS development?

Devil's advocate: I feel like TDD for iOS is a bit of a wasteland, and don't usually bother with it personally, unless there's some especially dense mission-critical business logic that I need to be 100% confident in.

Re: Ask HN: Is my code any good?

#20
Have they fixed testing with Swift yet? I am normally a pretty test driven person, but honestly, Apple makes it pretty annoying to use tests with Swift, so I don't blame you for your lonely scaffold.

I'd say overall it looks pretty well written app code, especially if you say you're a beginner. One thing I'd like to point out is that in my (limited Swift) experience, stuff like this:

https://github.com/NikantVohra/HackerNewsClient-iOS/blob/mas...

...where you're force casting/unboxing/whateveritscalled a bunch of things is a smell. Sometimes it's unavoidable because of the weirdness between Cocoa and Swift, so typically your interface builder outlets will be riddled with that stuff, but for your own internal APIs, try and keep things as option-less as possible.

UI code is pretty challenging to keep organized, especially when platforms encourage using things like two-way bindings and keeping state all over the place. I'd recommend checking out Gary Bernhardt's talk "Boundaries" and Andy Matuschak's similar writings (sorry, can't think of anything off the top of my head), as they have some good ideas for demarcating the line between functional parts of your code that should be super clean and the anything goes world of external UI APIs.

Good luck and keep coding!

Post reply on HN