Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: A multi-markup reader in less than 100 lines of Python code (gist.github.com)
30 points by miraculixx 19 days ago | hide | past | web | favorite | 17 comments



I love the praised projects "xxx in yyy lines of code in zzz". While the reality almost always is: not documented, not tested, badly written glue for some libraries doing the real job.

I'd love to see here really well designed, documented, and implemented projects doing complicated stuff in simple way.


You should look at the code before commenting (clearly, you did not). You might actually like this one.


Weirdly this one does have tests, but they're in the execution section?


It's supposed to be self-contained which is why the tests are inside __main__. If I have the time I'll add a --selftest argument or so


I suspect two of these lines are more important than others:

> import json

> import yaml


Yeah, something like:

> I just invented terminal web browser in two lines of Shell code!

    #!/bin/sh
    links2


Not at all

More like I'm tired to write 20 lines of code each time I have some object or a file that needs parsing, and it can be any kind of markup


yes, see installation one-line command, as a comment below the gist


To be honest, your reader is not "in less than 100 lines of Python code" because you use external Python libs.


Can you use built-in libs and have it still count? Can you use anything other than built-in functions? Python itself uses quite a few external libs too and Python itself is also an external dependency.

You can make a useful thing by only adding 100 lines of glue to existing libraries is still a useful thing.


We've had these discussions many times. Of course it makes sense to use libraries.

For me, what stood out in this submission was that none of the 100 lines are talking about markup. Thus what we have here is 100 lines of front-end and tests.


Yes, however it still does what the headline said. The point being its small and useful


Yeah I know real programmers write binary machine code in large strings of 0 and 1 :)


The reminds me of a meeting in about 2003 where I showed a little POC I had made doing a RDDL http://www.rddl.org/ parser for the OIOXML project https://en.wikipedia.org/wiki/OIOXML and the guy who was pushing for using RDDL with me was maybe a little bit too praising of what I had done - calling it a framework etc. - making me uncomfortable.

This overpraising prompted a non-technical member of the agency (who fancied himself technical) to announce that it certainly didn't deserve to be called a framework because it could be done in one line of JavaScript and he would be happy to demonstrate it to anyone who cared to see.

Demonstration never came out but I always assumed he had mistaken RDDL for RSS and had a library for parsing RSS from somewhere, maybe the one that OReilly had at the time which I think was named after some marsupial, and somewhere he'd seen an example one-liner using it.

I just remember his super confident braying "It's only a one liner, I'll show it at my desk."


The thing is you can't parse json and yaml from either a file-like or a string object in one line of Python. To achieve that you end up writing at least 3-4 lines of checking logic each time, plus some try/catch blocks. I had to parse yaml or json in about 20 different places in our system and it was just not useful to repeat the same code everywhere. Now these 20 places are now all using this markup function, with the requirement met that the respective calling code is not more complex than before but (fail) safer and more flexible (support json and yaml at the choice of the end user).


I mean, it's 100 or so lines of using actual markup reading libraries with some dubious glue code and reinventing the unittest standard library.

It really only screams "Node.js dev's first Python library" to me.


How is the code dubious and where does it reinvent the unittest library?

Besides I'm not a nodejs dev nor is this my first library.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: