Live data from Hacker News

Things from Python I'd miss in Go

yosefk.com

111–120 of 142 posts

Re: Things from Python I'd miss in Go

#111

Earlier quoted context omitted.

> OTOH, Go's type system, as opposed to its error-handling approach, is a real problem for generic functions. Though if you just mean non-generic higher-level functions, this is less of an issue. Without generic types, I don't think generic programming is very common in Go and exceptions won't be missed much yet. However, if they ever get around to adding them, I expect dominoes to fall :) > To fit with the Go conven…

> exceptions won't be missed much yet. Exceptions won't be missed at all, with or without generic programming, because, and I get tired of saying this, Go has exceptions . panic/recover/defer provide all the functionality of raise/catch/finally -- the main difference in structure being that (1) the context is always a function, not some other block within a function, and, (2) "recover" is done within a deferred funct…

Defer is basically finally without block structure, triggered instead by the popping of the surrounding procedural call context. So instead of a block, you have to create a new function instead to unwind...how is the extra complexity of avoiding simple block structure worth it?

And what is the equivalent of catch if we have an equivalent of finally? It seems to be recover, which allows a deferred execution to query what exception has occurred, correct? Is there a good discussion of why this is better than try/catch/finally?

Re: Things from Python I'd miss in Go

#112
post #60
post #29

Earlier quoted context omitted.

It looks like the author found the worst use case for Go in comparison to a library that Python absolutely soars in and uses that as a basis for this argument. Go does not have something as nice as numpy. For numeric computing, by all means use Python. He then makes some crazy statements about operator overloading as if that is the essence of a good language. I disagree. I don't want operator overloading. I almost ne…

Erm... so: * I didn't "find" my use cases - they found me. All are real things I do with Python. * I'd switch to something faster than Python, and finding more errors statically, if it wasn't for the bunch of things I'd miss. * I like C better than C++ though the former lacks operator overloading; it's not "the essence of a good language", just one thing I use in Python. * Further evidence that "I'm not here to bitch…

You've been saying that it's just about your own use cases, but your statements in that post are much more general. For example:

> What does Go have that Python lacks? Performance, static typing.

That's a very simplistic view. Being a long term Python developer that switched to Go as the preferred language years ago, here are some of the things I appreciate on the other side of that fence:

- Performance, indeed.

- Static typing, yes.

- A simpler language specification (a big one for me, game changer for large code bases in large teams)

- Interfaces based on structural typing ("static duck typing", as some say)

- Much better control of memory layout (struct with 2 int64s takes 128 bits in memory, a list of those takes N*128bits)

- Built-in micro-threads (goroutines)

- A runtime that schedules (means, you can block, despite concurrency)

- Buffered and unbuffered channels managed by the runtime (with select, etc)

- Builds native static executables, fast (maybe you don't care, many people do)

- A much better organized standard library

- A very good http server _and_ client package in the standard library

- Good crypto packages and APIs in the standard library

- Error handling without exceptions (that's a pro for me and many, feel free to disagree)

- A very elegant system to define access control (private/public) on vars/funcs/types/fields/consts/etc.

- All names inside files that are part of a package ("directory") are part of the same namespace (allows better organizing code than with Python's file-is-a-module style)

- Code files that can see declarations out of order (improves code organization)

- gofmt! godoc! Love those.

- None of the Python 2 => 3 migration mess (people are being told to program in a pseudo-language that is neither Python 2 nor 3 in recent times)

And so on... That's not to judge your use of Python, though. By all means stick with Python if it suits your needs.

As a last point, if you're interested in Qt bindings, I've been working on this:

https://github.com/go-qml/qml

Some applications coming out of it:

http://blog.labix.org/2014/04/25/qml-contest-results

Re: Things from Python I'd miss in Go

#113
post #6
post #3

Towards the end of the article there seems to be a confusion between servers and web servers. Yes, Go is nice for writing servers, no, web servers aren't the only things out there doing 'serving' in systems-land. Three examples from CloudFlare all written in Go: 1. Our Internet compression/optimization technology called Railgun 2. Our DNS server 3. Our CA infrastructure All are networked, all are highly concurrent. A…

"Also, our entire logging and analysis infrastructure is being migrated to Go." This intrigues me. I've been moving a lot of ETL into Go (as it's pretty well suited to this), but I still end up doing a lot of the analytics in Spark (for bigger work) or Pandas or R (for smaller bits of data). What are you guys planning on doing for the analytics? Or is it more of straight up time series work (so you can use influx + w…

"Also, our entire logging and analysis infrastructure is being migrated to Go." This intrigues me....

Go is great for this kind of stuff. Spark is great when you have a lot of custom queries, but if you have a few fixed queries writing a simple solution in Go have have huge gains.

I worked to implement a web service + simple map reduce (with network transparency) + a time series DB (storage engine too, NOT using levelDB like influx) all in Go and the result was it is many times faster than an order of magnitude larger hadoop cluster, BigQuery, etc for the limited operations it supports.

Re: Things from Python I'd miss in Go

#114

Earlier quoted context omitted.

I try to advocate polyglot programming - using the best tool for the job - everywhere I go, but unfortunately people are largely allergic to the idea. Most programmers don't want to learn new tools, much less new paradigms or methodologies. Even worse, the management agrees - the upside of building better systems isn't convincing enough to justify a temporary drop in performance while learning. More to the point, I d…

The drop in performance isn't just while learning. I worked somewhere where I had to regularly use TCL, Java, PHP, C++ and Python - each was the most suitable tool for the job (at the time the tool was written anyway) but the constant context switching caused a real and permanent performance hit.

> but the constant context switching caused a real and permanent performance hit

Maybe context switches were too frequent? Or the opposite, too rare, which could lead to repeating the learning overhead each time? Personally I didn't notice any slowdown due to switching between languages and technologies - other then at the beginning, when I was learning them.

Re: Things from Python I'd miss in Go

#115
post #77

Earlier quoted context omitted.

> It looks like the author found the worst use case for Go in comparison to a library that Python absolutely soars in and uses that as a basis for this argument. But you also seem to be using a bit of a straw man here as well, aren't you? You focus how he picked numpy and operator overloading. Ok how about REPL, does go have one? No. Does it support dynamic code loading? Does it have exceptions? He wants exceptions.…

> how about REPL, does go have one? No. What? https://github.com/rocky/go-fish "Yet another Go REPL"

Made by a third party, it doesn't come with Go. Granted neither is numpy.

Re: Things from Python I'd miss in Go

#116

Earlier quoted context omitted.

> exceptions won't be missed much yet. Exceptions won't be missed at all, with or without generic programming, because, and I get tired of saying this, Go has exceptions . panic/recover/defer provide all the functionality of raise/catch/finally -- the main difference in structure being that (1) the context is always a function, not some other block within a function, and, (2) "recover" is done within a deferred funct…

Defer is basically finally without block structure, triggered instead by the popping of the surrounding procedural call context. So instead of a block, you have to create a new function instead to unwind...how is the extra complexity of avoiding simple block structure worth it? And what is the equivalent of catch if we have an equivalent of finally? It seems to be recover, which allows a deferred execution to query w…

> Defer is basically finally without block structure, triggered instead by the popping of the surrounding procedural call context. So instead of a block, you have to create a new function instead to unwind...how is the extra complexity of avoiding simple block structure worth it?

How is function structure any more complex than block structure?(I mean, visually, sure, there are potentially a few extra sigils, but structurally how is a block different than a nullary function?)

> And what is the equivalent of catch if we have an equivalent of finally?

Recover within a deferred function provides the ability to do the functionality of catch -- I wouldn't call it a one-for-one equivalent (the combination of features is equivalent, but there isn't a one-for-one correspondence between the individual features except between panic and raise/throw.)

Re: Things from Python I'd miss in Go

#117
post #70
post #20

It's ironic that the author dismisses C++ to a small niche: > Those who still stick to C++, after all these years, either really can't live with the "overheads" (real time apps - those are waiting for Rust to mature), or think they can't (and nothing will convince them except a competitor eventually forcing their employer out of business). Yet later he gives a good example for an important area where C++ is still unb…

If you want/need maximum performance, why are you programming in a "high-level language"? Many of the highest-performance scientific computing libraries are written in assembly or use inline assembly instructions. The vast majority of scientific programmers don't need to write at this level. I challenge you to write a native C++ matrix-matrix-multiply algorithm that generally outperforms the matrix-matrix-multiply av…

I am sorry to say this, but I sure will be happier if this oft repeated vapid trope stops getting repeated. There is more to performance than memory layout and caching.

There is a big difference between optimization in the small and optimization in the large. It is precisely because you need maximum performance and correctness that you need high-level languages. Quite ironically your comment itself illustrates the point well. One could have written high-perf apps entirely in the style of OpenBlas. Sensible people dont and for a reason.

I am going to copy a previous comment of mine on this topic.

--

I will not be surprised if it beats C by generating C code itself, but C code that no human would write by hand. It has been done before in programming history (not just C, fortran has been beaten as well http://dl.acm.org/citation.cfm?id=200989 http://link.springer.com/chapter/10.1007/978-3-642-19014-8_1.... http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.150.... although the prior art focuses on Lisp I think Haskell and ML like languages are better equipped for this). Imperative code is a lot harder to reason about, and low level code is a lot harder to write if one cares about correctness and performance simultaneously. Specialized functional languages has a history of beating C implementations. It could be faster still if one removes the constraint that one has to generate C code, for example coroutines and proper tail calls become easier to implement. The bottomline is that correctness is easier to achieve with functional, and performance with imperative. So we would need both and they meet in a compiler.

Take the example of Stalin and StalinGrad, they are Lisps. Their compile times are epic, but once done they have a history of generating faster code than C for specific applications (a specific example where it will excel is multidimensional numeric integration where the function to be integrated is passed as an input). The main reason why they would be able to generate faster code is that they are smarter about inlining. The reason they are smarter about inlining is that programmers intent is better preserved when encoded in a higher level language.

Can a programmer not write the same correct code in C by hand ? Perhaps they can, but it will take longer and would be more error prone and likely to be costlier to produce, unless one takes the help of these higher level abstractions primitives, but then you aren't really writing in C anymore. Can the C compiler not be equally smart ? possibly, but it will be a lot harder to make a C compiler smart than a functional language compiler smart. Functional languages leave a lot of room for the compiler to do its thing, C while not as bad as Java still over-specifies how exactly something needs to be computed (my way or the highway). Add the fact that when code is written in a higher level, but optimization friendly language one can enjoy the benefits of compiler techniques yet to come. It future-proofs the code to an extent and amortizes the effort that went into writing the compiler.

Re: Things from Python I'd miss in Go

#118
post #60

Earlier quoted context omitted.

Erm... so: * I didn't "find" my use cases - they found me. All are real things I do with Python. * I'd switch to something faster than Python, and finding more errors statically, if it wasn't for the bunch of things I'd miss. * I like C better than C++ though the former lacks operator overloading; it's not "the essence of a good language", just one thing I use in Python. * Further evidence that "I'm not here to bitch…

You've been saying that it's just about your own use cases, but your statements in that post are much more general. For example: > What does Go have that Python lacks? Performance, static typing. That's a very simplistic view. Being a long term Python developer that switched to Go as the preferred language years ago, here are some of the things I appreciate on the other side of that fence: - Performance, indeed. - St…

> - Performance, indeed.

I have been really disappointed and underwhelmed by Go's performance (I have not tried the gccgo yet). For such a simple, statically typed language I was expecting really an order of magnitude better performance. So, in light of Cython and Pypy the performance story is quite murky, the other points do stand.

Re: Things from Python I'd miss in Go

#119
post #105

Earlier quoted context omitted.

> If you want/need maximum performance, why are you programming in a "high-level language"? Because going to assembly offers so little benefit (if at all), that it doesn't justify the huge increase in effort and susceptibility to bugs in most cases (and even then, inline assembly is usually sufficient). > Many of the highest-performance scientific computing libraries are written in assembly or use inline assembly ins…

edit: Jack Poulson's Elemental, and Andreas Waechter's IPOPT are also written in C++, and are both very important libraries within scientific computing and optimization, to add a few more examples of the usefulness of C++. I'm trying to make the point that C++ occupies a weird place in the abstraction-vs-performance tradeoff. For high abstraction and friendliness, C++ doesn't do nearly as nice of a job as MATLAB or P…

I think we're approaching this from two different directions: you from the library user's, and I from the library writer's perspective.

Sure, if there's a good library available that handles all the bottleneck computation, then there's no need to write anything in C++ – just use Python or whatever. But if you actually have to implement a kernel, you can't do it in Python or Matlab.

Regarding assembly: I still believe that assembly is unsuitable except for the simplest of algorithms. Sure, you can optimize the crap out of DGEMM or DAXPY, with SIMD, cache-optimization, and prefetching – but in the end, it's still a very simple algorithm, with a very simple data layout and predictable access patterns. But as soon as it gets a little more complex (e.g., graph algorithms, or a SAT solver), you can forget about assembly. Heck, I doubt you could even get a measurable performance benefit.

> But your claim that C++ is the best language for such work would be highly contested by many high performance computing specialists.

My personal, subjective, and completely unscientific opinion on this is that these people are domain experts, which know how to design fast algorithms and data structures, but not necessarily how to make the best use of a complex language like C++. Or they're extending legacy code. In short: for non-technical reasons (analogy: Haskell and Scala are better languages than Java, and yet a lot more Java code is written).

> The latest version of MPI, MPI-3, drops explicit support for C++ bindings. If C++ was so dominant, why would explicit bindings be dropped?

Maybe because they didn't offer much over the C bindings, and even some C++ projects (e.g. Boost) used them?

Re: Things from Python I'd miss in Go

#120
post #9

In the beginning i missed repl, but i've realised using repl in the first place was a mistake.. Now i rely on docs(godoc is awesome) and when i need to test something i use go playground.

I missed a REPL at first too, which made me play a bit with REPL-for-Go ideas, but that didn't end up on anything really convenient. What solved the problem was rethinking why the REPL was convenient in the first place, leading to the creation of hsandbox: http://labix.org/hsandbox Despite it being created for Go, I got quite fond of the approach. Nowadays I also use it for Python, C, etc.

Great tool. In Go, I usually write a throwaway_test.go in whatever package I'm hacking on, and use "go test" as my REPL. (With the intent that these experiments and crude checks should become unit tests later, anyway.) For exploring packages that I'm not developing, this is a nice variation from the Go playground.
Post reply on HN