News for hackers. Stuff that matters.
Re:Go 2, here we come by w8rbt on Thursday November 29, 2018 @10:38PM (#18566456)
Rather than writing multiple functions that take different types as args and return different types (say int8, int16, int32, etc.) but do the exact same thing, with generics, you can instead write one function that takes a number (which could be any int type) and return a number, and you only wrote one function. That is generics in a nutshell. The function is generic, not specific to one type.

Generics allow for less code, thus they are easier to debug, test and reason about. I've used them a lot in C++ and I do miss them in Go. It's not a deal breaker for me either way, but for people who write larger, more complex code, not having them makes it more difficult (more code to write, test and maintain).

C does not have generics either. Go is a lot like C in this regard.

Re:Go 2, here we come by pjmlp on Friday November 30, 2018 @12:36AM (#18566986)
C has minimal generics support since C11.
Re:Go 2, here we come by mrfusion on Thursday November 29, 2018 @10:44PM (#18566490)
Wouldn’t this make golang slow though? Isn’t that what people claim makes python slow?
Re:Go 2, here we come by shakna on Thursday November 29, 2018 @11:07PM (#18566583)
In a ahead-of-time compiled language probably not. The generic function is just a code generator for several functions that will get called in the right places, generated and put in the right places by the compiler, and then get optimised as per normal.

And no, being a dynamic language is not what makes Python slow. Lua, Nim and Scheme are all examples of dynamic languages with fast implementations.

Re:Go 2, here we come by lasagnaphil on Friday November 30, 2018 @01:31AM (#18567185)
- Generics do not make runtime performance slow, but it sure does make compile times slower (although it really depends on the type system and its implememtation) For example, C++ templates, although very powerful, makes build times order of magnitudes slow when used poorly. One of the most important features of Go is its fast compile times, but generics/contracts can potentially slow it down a lot.

- Yes, being a dynamic language slows it down a lot. For example, when evaluating a+b, the interpreter has to check the types of the variables a and b at runtime beform performing the right form of addition (it might be an int, or a string, you dont know). Even with JIT (just in time compilation) the compiler has to initially “guess” that the variables are numbers, and fall back if that is not the case. Statically typed languages do not have this problem, because you know the types of variables beforehand at compile time.

By the way, Nim is not a dynamic language. And LuaJIT is one of the the fastest dynamic language implementations because the language is very simplistic (compared to Javascript/Python/Ruby) and Mike Pall is a robot from the future...

Re:Go 2, here we come by shakna on Friday November 30, 2018 @01:49AM (#18567261)
> the interpreter has to check the types of the variables a and b at runtime beform performing the right form of addition (it might be an int, or a string, you dont know)

That's not necessarily true. In Scheme, a very dynamic language, the compiler will generally make choices about memory layout of the various values before launching into the evaluation phase. Where safe or possible to do so, it will probably reduce the number of choices that will have to be made at runtime, at compile time. The interpreter may not have to lookup what the data type is, because it may just have two bits of memory and an instruction to call. You can know what the data will be, and optimise for it. [0]

There's no reason that: b = 1; c = 2; a = a + b needs to be slower than a = 1 + 2 if b and c are never referenced before or after. But in Python, it is, because the design makes it harder to know whether or not an object should get optimised away.

> And LuaJIT is one of the the fastest dynamic language implementations because the language is very simplistic

Right, Lua is dynamic, and one of the design choices was making it simple, and so it's easier to make it faster.

[0] http://home.pipeline.com/~hbaker1/CheneyMTA.html

Re:Go 2, here we come by lasagnaphil on Friday November 30, 2018 @02:02AM (#18567311)
Didn't know about Scheme. Thanks for the link!
Re:Go 2, here we come by shakna on Saturday December 01, 2018 @03:08AM (#18575842)
If you've never met Scheme, then SICP [0, 1, 2] may be something that can change the way you program. It certainly made me better, or at least a deeper understanding.

[0] https://www.youtube.com/watch?v=2Op3QLzMgSY&list=PLE18841CAB...

[1] https://www.amazon.com/Structure-Interpretation-Computer-Pro...

[2] https://web.mit.edu/alexmv/6.037/sicp.pdf

Re:Go 2, here we come by mrfusion on Thursday November 29, 2018 @11:19PM (#18566634)
Now I have to ask, what would you say does make python slow?
Re:Go 2, here we come by shakna on Thursday November 29, 2018 @11:46PM (#18566752)
Design choices, to be blunt.

Some of it is simple stuff, like CPython being interpreted, so PyPy get's a huge boost by JITting.

Some of it is much harder stuff, like the way Python is designed to store objects in memory (a list is a pointer to a contiguous space of pointers to things that might be pointers...), and everything that hangs off each object (everything has a dict), and the awful GIL ([0]). Awful for performance, great for thread-safety.

Every single part of a language design has trade-offs. It depends on what you're trying to do whether or not they help you, or hinder you.

Sometimes you change how you're doing things because priorities change, and get a radical improvement, like Python's 3.6 Dict. Most of the time, you don't. One step at a time. Not being able to break backwards compatibility hinders the designer, if they realise a trade-off they've made was a mistake. So you get stuck with some features you'd rather not have.

[0] https://wiki.python.org/moin/GlobalInterpreterLock

Re:Go 2, here we come by johncolanduoni on Friday November 30, 2018 @12:19AM (#18566908)
To be fair, all of the aspects of the language itself you mentioned apply to JavaScript (save perhaps differences in how literally it takes `int`, etc. being objects vs. JavaScript's unboxed `number`, etc.). I suspect most of the difference is that one has had three of the largest corporations in the country competing to have the fastest implementation, in some cases for decades, and the other hasn't.
Re:Go 2, here we come by zbentley on Friday November 30, 2018 @08:23AM (#18568853)
I think a bigger reason is that Python prioritizes simplicity of internal implementation.

To be sure, the internal implementation of CPython (the only one I'm familiar with) is complicated as hell. But it's a whole lot simpler than any fast JavaScript runtime I've ever used. I think that's the result of a conscious choice by the maintainers/BDFL/community in Python, not a side effect of it having less funding (assuming that's the case).

Re:Go 2, here we come by gameswithgo on Friday November 30, 2018 @12:50PM (#18570862)
The primary difference is Javascript has serious JIT's as the normal case of running Javascript while Python is normally interpreted.
Re:Go 2, here we come by notduncansmith on Friday November 30, 2018 @11:42AM (#18570318)
I don’t think it necessarily impacts the runtime (though it could).

This could be my naïveté, but I don’t see why generics in Go couldn’t work analogously to the way they do in TypeScript, just a way for the compiler to verify the correctness of code accessing an interface{}.

Re:Go 2, here we come by w8rbt on Thursday November 29, 2018 @11:03PM (#18566565)
No. C++ is very fast. It has generics.
Re:Go 2, here we come by AsyncAwait on Friday November 30, 2018 @07:11AM (#18568506)
Also, very slow to compile.