Re:Git log in JSON format
by m1el on Sunday July 12, 2015 @10:55AM
(#9873657)
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.
Re:Git log in JSON format
by bpicolo on Sunday July 12, 2015 @09:52AM
(#9873489)
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
by wingerlang on Sunday July 12, 2015 @05:08AM
(#9872977)
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.
Re:Git log in JSON format
by merb on Sunday July 12, 2015 @01:51PM
(#9874262)
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.
Re:Git log in JSON format
by s_kilk on Sunday July 12, 2015 @10:52AM
(#9873643)
>> 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
by rossy on Saturday July 11, 2015 @08:15PM
(#9872066)
> What if there's a double quote in a commit message?
This is what I want to know too. Unless I'm missing something, it doesn't do any escaping. The last time I did something like this, I used %n and %x00 to delimit the output of git log, and converted it to a JavaScript object on the JavaScript side. Git log isn't smart enough to write JSON by itself.
Re:Git log in JSON format
by tracker1 on Sunday July 12, 2015 @12:21AM
(#9872576)
Agreed on better output to text, then process, but I'd suggest the record & group separators... It always surprises me when people use more exotic characters for something that's been defined forever (practically) in computer terms for this purpose.
Re:Git log in JSON format
by lmitchell on Saturday July 11, 2015 @10:24PM
(#9872384)
I did something very similar for work last summer and we basically realized the same thing - null-delimited fields seemed like the only way to really be safe.
Re:Git log in JSON format
by lowmagnet on Saturday July 11, 2015 @08:29PM
(#9872094)
Only somewhat related, the really neat tool code-maat[0] can do a lot with your commit data, but it uses plain CSV. It provides a bunch of canned reports you can run on your repo as well.
Here's how I would do it, using libgit2 and proper JSON output: https://gist.github.com/m1el/42472327b4be382b02eb
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.
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
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.
If you knew Python you'd know exactly what that means. But zokier is right, a map is probably a better choice here.
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.
This is what I want to know too. Unless I'm missing something, it doesn't do any escaping. The last time I did something like this, I used %n and %x00 to delimit the output of git log, and converted it to a JavaScript object on the JavaScript side. Git log isn't smart enough to write JSON by itself.
http://www.theasciicode.com.ar/ascii-control-characters/reco...
[0] https://github.com/adamtornhill/code-maat