Live data from Hacker News

500 Lines or Less

github.com

51–60 of 70 posts

Re: 500 Lines or Less

#51
post #50

From: https://github.com/aosabook/500lines/blob/master/ci/code/hel... s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.send(request) response = s.recv(1024) s.close() Is that correct use of TCP? It seems to rely on response not being fragmented.

No it is not. You must keep reading from the socket until you have read as many bytes as required - he isn't even checking how many bytes recv returned.

Re: 500 Lines or Less

#52
post #50

From: https://github.com/aosabook/500lines/blob/master/ci/code/hel... s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.send(request) response = s.recv(1024) s.close() Is that correct use of TCP? It seems to rely on response not being fragmented.

It's definitely not right as far as the C interface is concerned - and Google indicates that the Python interface doesn't do anything extra. That said, it probably does generally work considering the small size of the messages, especially if the dispatcher is run locally. It's unlikely that a two-byte or ten-byte message would get fragmented, though it technically could - and that's all that is sent by the dispatcher.

That said, this should be a loop that combines all the responses until you receive a response of length zero, indicating EOF. The actual code to correctly handle this is really simple if you don't do any extra error handling - but it's not obvious if you haven't done some socket programming before.

This code will probably work until the dispatcher and clients are expanded upon, resulting in more complex messages that eventually lead to sporadic fragmentation.

Re: 500 Lines or Less

#53
post #40

Offtopic. Why, in github, is the README always below the repository files, if the first thing you want to read about a project is the README? Edit: Could we take the convention on HN to always link to the README in a github repo? In this case that would be: https://github.com/aosabook/500lines/blob/master/README.md

I considered Github links to be essentially content-free noise for several years because I did not know about their "README.md" convention. I think that people who live and breathe github probably don't realize how confusing their interface can be to a newcomer.

You didn't think to just scroll down?

Re: 500 Lines or Less

#54
This is a really interesting book by some brilliant people.

I wonder if the problems selected are the ones that many people would select though.

What would people here select as, say, the top 5 or 10 things to write in a short amount of code. Say perhaps in 1K lines of code.

A web browser? A compiler? A simple relational database?

Re: 500 Lines or Less

#55
post #40

Offtopic. Why, in github, is the README always below the repository files, if the first thing you want to read about a project is the README? Edit: Could we take the convention on HN to always link to the README in a github repo? In this case that would be: https://github.com/aosabook/500lines/blob/master/README.md

.repository-content { display: flex; flex-direction: column; }

#readme { order: -1; }

You could add that to the page style (using a browser plugin).

Re: 500 Lines or Less

#56
post #50

From: https://github.com/aosabook/500lines/blob/master/ci/code/hel... s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.send(request) response = s.recv(1024) s.close() Is that correct use of TCP? It seems to rely on response not being fragmented.

It's definitely not right as far as the C interface is concerned - and Google indicates that the Python interface doesn't do anything extra. That said, it probably does generally work considering the small size of the messages, especially if the dispatcher is run locally. It's unlikely that a two-byte or ten-byte message would get fragmented, though it technically could - and that's all that is sent by the dispatcher…

[deleted]

Re: 500 Lines or Less

#57

How about a competition to see who can write the clearest code for the next guy, in minimal lines of code?

Sometimes optimising for the least lines of code leads to less clarity than being a bit more verbose and explaining yourself better.

I still haven't quite worked out the code vs comments ratio.

Re: 500 Lines or Less

#58
post #17

Hi, I'm the editor of 500Lines. Thanks for posting this! A few notes: - Code golf was strictly discouraged throughout the review process. When authors were faced with implementing functionality poorly to fit more in, we generally cut scope instead. - 500 lines was selected as a limiting criteria because it is easy to specify and understand. You will see that the chapters written e.g. with Clojure do "more" (for some…

How can one contribute to this project? I personally ascribe to the belief that there's no better way to learn something than by implementing it yourself and would like to grant what help and background in writing and development I have.

I think the project should highlight quality, meaning review burden, but I think everyone should be encouraged to do their own 500 line repositories and share them (call me crazy but something like hashtags wouldn't be a bad thing for these sort of themed repositories)

Re: 500 Lines or Less

#59
post #54

This is a really interesting book by some brilliant people. I wonder if the problems selected are the ones that many people would select though. What would people here select as, say, the top 5 or 10 things to write in a short amount of code. Say perhaps in 1K lines of code. A web browser? A compiler? A simple relational database?

interpreter for an interactive fiction language

Re: 500 Lines or Less

#60
post #31
post #17

Hi, I'm the editor of 500Lines. Thanks for posting this! A few notes: - Code golf was strictly discouraged throughout the review process. When authors were faced with implementing functionality poorly to fit more in, we generally cut scope instead. - 500 lines was selected as a limiting criteria because it is easy to specify and understand. You will see that the chapters written e.g. with Clojure do "more" (for some…

The first thing I looked through, the pedometer/ directory, has a project that itself may be Don't you think including huge external libraries like that defeats the spirit of showing things that are 500 lines or less?

I don't think so. Would you rule out things like the python standard library?

Though external library size can be important, does it come into play when talking about your own code structure?

Post reply on HN