
Show HN: A multi-markup reader in less than 100 lines of Python code - miraculixx
https://gist.github.com/miraculixx/900a28a94c375b7259b1f711b93417d3
======
pleasecalllater
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.

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

~~~
miraculixx
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

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

> import json

> import yaml

~~~
app4soft
Yeah, something like:

> I just invented terminal web browser in two lines of Shell code!
    
    
        #!/bin/sh
        links2

~~~
miraculixx
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

------
bryanrasmussen
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/](http://www.rddl.org/) parser for the
OIOXML project
[https://en.wikipedia.org/wiki/OIOXML](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."

~~~
miraculixx
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).

------
Hamuko
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.

~~~
miraculixx
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.

