3 ms·
I think you have a different interpretation of “hidden” than Andy. He is talking about control flow that is not visible to the programmer at all. In Zig, you c
by kweingar 3y ago
I think you have a different interpretation of “hidden” than Andy.
He is talking about control flow that is not visible to the programmer at all. In Zig, you can understand the control flow of a particular code snippet just by learning Zig. In some other languages, operator overloading means that when you are reading unfamiliar code, you can never be sure what functions might be called.
- adontz 3y ago>> operator overloading means that when you are reading unfamiliar code, you can never be sure what functions might be called. This just means abstraction were abused. Which as I said, they can be. Nevertheless most popular programming languages (C++, C#, Python, Java, etc.) have overloaded operators, you can write "hello " + "world" (or equivalent) in any of these languages.
- defen 3y agoWhere does the memory for the combined string come from? Even if Zig had operator overloading it's not clear how a runtime `string1 + string2` could work.
- adontz 3y agoSomething like this would do https://en.cppreference.com/w/cpp/named_req/Allocator https://en.cppreference.com/w/cpp/named_req/Allocator
- defen 3y agoIn practice what would the actual code look like (pseudo-code is fine). How would I concatenate strings at runtime using `+`, once with one allocator and then again with another allocator?
- adontz 3y ago>> once with one allocator and then again with another allocator? I would: 1. Prohibit concatenating strings with different allocators. Strings with the same allocator can be concatenated. 2. Provide StringBuilder for concatenating anything in an effective manner. It's not only about different allocators, but supporting C-style strings and reducing number of allocations. So '+' is only for strings with same allocator, same UTF encoding, same everything. I'm really not fond of implicit type conversions.
- xigoi 3y ago> operator overloading means that when you are reading unfamiliar code, you can never be sure what functions might be called. How so? It’s clear that `a + b` calls the `+` function.