Live data from Hacker News

Git log in JSON format

gist.github.com

11–17 of 17 posts

Re: Git log in JSON format

#11

Earlier quoted context omitted.

Every time I see this pattern, a part of me dies inside. collection = [] for i in data: collection.append(fn(i)) Why not just [fn(i) for i in data] ?

First example is way, WAY, more readable. Honestly, if I didn't read the first one I would probably not have figured out what the other one does without research.

You are kidding.

The Map one exactly describe what it does. it 'maps' the data. Which means it describes it in the way function fn is telling it. Which is really easy to read if you understand english...

Re: Git log in JSON format

#12
post #11

Earlier quoted context omitted.

First example is way, WAY, more readable. Honestly, if I didn't read the first one I would probably not have figured out what the other one does without research.

You are kidding. The Map one exactly describe what it does. it 'maps' the data. Which means it describes it in the way function fn is telling it. Which is really easy to read if you understand english...

> Which is really easy to read if you understand english

Maybe I missed something, but how does this

> [fn(i) for i in data]

read easier if you know english? You need to know the syntax of "[...]" to know what it does.

The top/first example, however, actually reads like english.

Re: Git log in JSON format

#13
post #11

Earlier quoted context omitted.

You are kidding. The Map one exactly describe what it does. it 'maps' the data. Which means it describes it in the way function fn is telling it. Which is really easy to read if you understand english...

> Which is really easy to read if you understand english Maybe I missed something, but how does this > [fn(i) for i in data] read easier if you know english? You need to know the syntax of "[...]" to know what it does. The top/first example, however, actually reads like english.

List comprehension are a very common thing in Python.

If you knew Python you'd know exactly what that means. But zokier is right, a map is probably a better choice here.

Re: Git log in JSON format

#14
post #10

Earlier quoted context omitted.

Every time I see this pattern, a part of me dies inside. collection = [] for i in data: collection.append(fn(i)) Why not just [fn(i) for i in data] ?

If we are nitpicking then why not map(fn, data) ?

List comprehensions are more direct, support more than just a function call, and in py3 map returns an iterable instead of a list (granted, easily solvable by list(map()) but it's an extra concern)

List comprehensions are the very recommended strategy for constructing python lists, not to mention they're simply a fantastic language feature. Very direct, readable, and hard to get wrong.

Python loses out a lot on it's functional sorts of functions (filter, map) because you can't use method chaining on a list for them, imo

Re: Git log in JSON format

#15
post #11

Earlier quoted context omitted.

You are kidding. The Map one exactly describe what it does. it 'maps' the data. Which means it describes it in the way function fn is telling it. Which is really easy to read if you understand english...

> Which is really easy to read if you understand english Maybe I missed something, but how does this > [fn(i) for i in data] read easier if you know english? You need to know the syntax of "[...]" to know what it does. The top/first example, however, actually reads like english.

>> You need to know the syntax of "[...]" to know what it does.

Anyone with even a basic understanding of python (the language of the examples we've been discussing here) should know this syntax. If they didn't I'd be worried.

Re: Git log in JSON format

#16
post #6

Every time I see people using printf to generate structured data formats, a part of me dies inside. Here's how I would do it, using libgit2 and proper JSON output: https://gist.github.com/m1el/42472327b4be382b02eb

Every time I see this pattern, a part of me dies inside. collection = [] for i in data: collection.append(fn(i)) Why not just [fn(i) for i in data] ?

You are right, list comprehension are cool and I often use them.

However, in this particular case, IMO, it would make things worse because I would have to write a multi-line list comprehension. Multi-line list comprehensions have bad readability. The object literal is too big to be included in list comprehension.

I could move commit->object conversion to a function, but then I would have used map. And it would have created one more indirection.

The current state is my deliberate choice.

Re: Git log in JSON format

#17
post #11

Earlier quoted context omitted.

You are kidding. The Map one exactly describe what it does. it 'maps' the data. Which means it describes it in the way function fn is telling it. Which is really easy to read if you understand english...

> Which is really easy to read if you understand english Maybe I missed something, but how does this > [fn(i) for i in data] read easier if you know english? You need to know the syntax of "[...]" to know what it does. The top/first example, however, actually reads like english.

I never talked about fn(i) for i in data. That's pythonic as somebody explain but the map one is the most readable and appears in more and more languages, even Java.
Post reply on HN