News for hackers. Stuff that matters.
Re:A Go “clone” of the great and famous Requests library by spenczar5 on Friday June 26, 2015 @09:57AM (#9784342)
These ports from Python and Ruby (like Martini, for another example) are well-intentioned, but I don't think they're a good idea to use. The original libraries get a lot of their expressive power from polymorphism - Requests gets a tremendous amount of mileage out of letting you pass in keyword arguments to the `get` method, for example.

Go prefers that you be more explicit and use more function declarations, even if it means repetition in the library code. When developers try to get around this, you see awkward constructs like the pointer-to-a-config-struct used here.

Re:A Go “clone” of the great and famous Requests library by coldtea on Friday June 26, 2015 @10:51AM (#9784782)
I personally welcome those kind of ports and hate blind insistent on "idiomatic" code.

Idiomatic Java, Perl and other languages were shit for a long time, they only improved when some brave soulds fed up with it and explorer non-idiomatic solutions (like the Play framework). And some things I see in "idiomatic" Go make my hair crawl...

Re:A Go “clone” of the great and famous Requests library by ORioN63 on Friday June 26, 2015 @11:29AM (#9785171)
I'm going to disagree with you there.

Idiomatic code is so called, because people familiar with the language can quickly read it. It makes reading code a much lighter task.

Frameworks are a different thing. Frameworks build around its host language, but normally are meant to use in a specific way. In its own idiomatic way.

Re:A Go “clone” of the great and famous Requests library by coldtea on Friday June 26, 2015 @01:04PM (#9786105)
>Idiomatic code is so called, because people familiar with the language can quickly read it. It makes reading code a much lighter task.

In the case of Java circa 2000-2006 it needlessly messed up code, making it more difficult and slow to read EVEN for people familiar with the language.

Following conventions doesn't make code better to read automatically just because people are already familiar with them -- those conventions should be good in the first place for that to happen.

Node has the callback hell "idiom" many are familiar with. And yet if somebody rewrote the code with async, await, even the people "familiar" with callbacks would be able to read it faster and understand it better.

Re:A Go “clone” of the great and famous Requests library by mattkrea on Friday June 26, 2015 @07:19PM (#9788301)
I don't think this is universal as it hasn't applied where I work. Without understanding how promises work they are no easier and it doesn't help that many things exists that do not use the standard .then() and .catch().
Re:A Go “clone” of the great and famous Requests library by coldtea on Friday June 26, 2015 @08:56PM (#9788607)
Async/await is not the same as bare promises though with then() and catch.
Re:A Go “clone” of the great and famous Requests library by bliti on Friday June 26, 2015 @03:12PM (#9787059)
Also consider that idioms evolve over time. Java from the 90s (or C++) reads different.
Re:A Go “clone” of the great and famous Requests library by coldtea on Friday June 26, 2015 @08:57PM (#9788610)
That's my point. They reason they evolve is that people don't blindly stick to the idioms and try other approaches which then stick on.
Re:A Go “clone” of the great and famous Requests library by 0xdeadbeefbabe on Friday June 26, 2015 @11:33AM (#9785209)
What did your hair do when you saw idiomatic perl?
Re:A Go “clone” of the great and famous Requests library by coldtea on Friday June 26, 2015 @01:05PM (#9786117)
It stood up and whispered to my ear to move to Python, which I did, circa 1997.
Re:A Go “clone” of the great and famous Requests library by hahainternet on Saturday June 27, 2015 @06:08AM (#9789692)
When you realised that Python had extremely similar problems to Perl but hadn't even managed things like Unicode support in 2015, what did you do?
Re:A Go “clone” of the great and famous Requests library by evmar on Friday June 26, 2015 @10:10AM (#9784449)
I immediately noticed this as well. This API has flags for "asynchronous" requests, but Go style is to provide a blocking API, and let the caller decide to use a goroutine if they need concurrency.
Re:A Go “clone” of the great and famous Requests library by XorNot on Friday June 26, 2015 @10:43AM (#9784697)
Constructing a channel (as it does though) is just pragmatic though and definitely not any less go-like.

You get a channel - you can read from it until it's closed which is always safe. Go-routines are cheap so you don't care about the background details. For simplifying HTTP, this is great.

Re:A Go “clone” of the great and famous Requests library by levigross on Friday June 26, 2015 @10:56AM (#9784843)
Originally the API was completely asynchronous (every "request" function returned a channel).

I got a lot of feedback that I shouldn't do that, so I moved the asynchronous requests to specific functions e.g GetAsync and made the standard API synchronous.

Re:A Go “clone” of the great and famous Requests library by sagichmal on Friday June 26, 2015 @01:35PM (#9786381)
You should go further, removing the async methods altogether. In Go, making sync APIs async is trivial and well-understood.
Re:A Go “clone” of the great and famous Requests library by dvirsky on Friday June 26, 2015 @11:51AM (#9785412)
The first project I published in Go almost 3 years ago, was a similar port of the python logger. While today I find this "I want to log like I do in python" approach a bit silly, IMO the Go standard logging package is still lacking, and I'm still using my python-ish port, not because it's similar to python, but because it has things like formatting, context printing and most importantly logging levels.
Re:A Go “clone” of the great and famous Requests library by cat9 on Friday June 26, 2015 @12:14PM (#9785638)
What's your take on Logrus? It seems like it would cover your major concerns, and it's widely recommended.

https://github.com/Sirupsen/logrus

Re:A Go “clone” of the great and famous Requests library by dvirsky on Friday June 26, 2015 @04:06PM (#9787407)
it's nice, very similar to my API sans the structured messages thing.
Re:A Go “clone” of the great and famous Requests library by levigross on Friday June 26, 2015 @12:07PM (#9785567)
I am not trying to do things in the "Python way". I am trying to bring some of the same flexibility I get when using the Python requests library to Go.
Re:A Go “clone” of the great and famous Requests library by tenken on Friday June 26, 2015 @12:31PM (#9785805)
There's nothing wrong with porting something to another language so your project Stack is all in 1 language. Nuts to having a million languages and cryptic dependencies. More singular platforms are easier to maintain for sysadmins and developers alike.

If the porting language isn't as expressive as the original source -- oh well thats a price i'm willing to pay.