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.
500 Lines or Less
51–60 of 70 posts
Re: 500 Lines or Less
#52From: 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.
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
#53Offtopic. 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.
Re: 500 Lines or Less
#54I 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
#55Offtopic. 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
#readme { order: -1; }
You could add that to the page style (using a browser plugin).
Re: 500 Lines or Less
#56From: 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…
Re: 500 Lines or Less
#57How about a competition to see who can write the clearest code for the next guy, in minimal lines of code?
I still haven't quite worked out the code vs comments ratio.
Re: 500 Lines or Less
#58Hi, 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.
Re: 500 Lines or Less
#59This 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
#60Hi, 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?
Though external library size can be important, does it come into play when talking about your own code structure?