There are no strings on me
https://www.scattered-thoughts.net/writing/there-are-no-strings-on-me/ [www.scattered-thoughts.net]
2023-11-23 03:52
tags:
programming
type-system
There is a kind of magic to those systems that is worth experiencing. But it’s also worth examining why we prefer to build puppets.
Because I’ve had days where I’ve had to debug my surly emacs boy, and I’ve quickly discovered that his behaviour has very little to do with the code that I’m reading. Methods overridden at runtime, traces that end with a call to a closure that no longer exists, event handlers whose execution order depends on side-effects during module loading, stack-traces which contain multiple different versions of the same function. On the worst days I find myself debugging code that doesn’t even exist on disk but was evaluated in the repl weeks before.
source: L
Generics can make your Go code slower
https://planetscale.com/blog/generics-can-make-your-go-code-slower [planetscale.com]
2022-03-30 18:46
tags:
article
compiler
go
perf
programming
type-system
Go 1.18 is here, and with it, the first release of the long-awaited implementation of Generics is finally ready for production usage. Generics are a frequently requested feature that has been highly contentious throughout the Go community. On the one side, vocal detractors worry about the added complexity. They fear the inescapable evolution of Go towards either a verbose and Enterprisey Java-lite with Generic Factories or, most terrifyingly, a degenerate HaskellScript that replaces ifs with Monads. In all fairness, both these fears may be overblown. On the other side, proponents of generics believe that they are a critical feature to implement clean and reusable code at scale.
This blog post does not take sides in that debate, or advise where and when to use Generics in Go. Instead, this blog post is about the third side of the generics conundrum: It’s about systems engineers who are not excited about generics per se, but about monomorphization and its performance implications. There are dozens of us! Dozens! And we’re all due for some serious disappointment.
Very thorough.
source: HN
node.example.com Is An IP Address
https://tuckersiemens.com/posts/node-example-com-is-an-ip-address/ [tuckersiemens.com]
2020-12-30 02:19
tags:
bugfix
networking
programming
python
type-system
This takes a bit to get to the punchline, but man, good old duck typing for the win.
It turns out that, under certain conditions, the ipaddress module can create IPv6 addresses from raw bytes. My assumption is that it offers this behavior as a convenient way to parse IP addresses from data fresh off the wire.
Does node.example.com meet those certain conditions? You bet it does. Because we’re using Python 2 it’s just bytes and it happens to be 16 characters long.
source: L
Implementing a Type-safe printf in Rust
https://willcrichton.net/notes/type-safe-printf/ [willcrichton.net]
2020-08-17 04:35
tags:
programming
rust
text
type-system
I show how to use heterogeneous lists and traits to implement a type-safe printf in Rust. These mechanisms can ensure that two variadic argument lists share important properties, like the number of format string holes matches the number of printf arguments.
source: HN
Making Illegal States Unrepresentable
https://buttondown.email/hillelwayne/archive/making-illegal-states-unrepresentable/ [buttondown.email]
2020-04-19 14:43
tags:
intro-programming
type-system
It’s a concept I find very helpful. But if you look for examples online almost everything either “let’s prevent dividing-by-zero” or “let’s enumerate the cases in a data type”. We can more creative than that! Some examples of “illegal states unrepresentable” that I found useful but have not seen anyone else talk about online:
source: L
Porting to TypeScript Solved Our API Woes
https://www.executeprogram.com/blog/porting-to-typescript-solved-our-api-woes [www.executeprogram.com]
2020-04-09 05:14
tags:
development
javascript
programming
type-system
web
We ported our React frontend from JavaScript to TypeScript, but left the backend in Ruby. Eventually, we ported the backend to TypeScript too.
With the Ruby backend, we sometimes forgot that a particular API property held an array of strings, not a single string. Sometimes we changed a piece of the API that was referenced in multiple places but forgot to update one of those places. These are normal dynamic language problems in any system whose tests don’t have 100% test coverage. (And it will still happen even with 100% coverage; it’s just less likely.)
Dynamically scoped variables in Go
https://dave.cheney.net/2019/12/08/dynamically-scoped-variables-in-go [dave.cheney.net]
2019-12-12 06:56
tags:
go
programming
testing
type-system
What we want is to be able to access a variable whose declaration is neither global, or local to the function, but somewhere higher in the call stack. This is called dynamic scoping. Go doesn’t support dynamic scoping, but it turns out, for restricted cases, we can fake it.
How can I have a C++ function that returns different types depending on what the caller wants?
https://devblogs.microsoft.com/oldnewthing/20191106-00/?p=103066 [devblogs.microsoft.com]
2019-11-07 03:12
tags:
cxx
programming
type-system
Fighting the Async fragmentation
https://vorner.github.io/2019/09/29/figthting-the-async-fragmentation.html [vorner.github.io]
2019-10-01 19:23
tags:
concurrency
library
programming
rust
type-system
This is about some dead ends when trying to fix the problem of Rust’s async networking fragmentation. I haven’t been successful, but I can at least share what I tried and discovered, maybe someone else is having the same bugging feeling so they don’t have to repeat them. Or just maybe some of the approaches would work for some other problems. And because we have a bunch of success stories out there, having some failure stories to balance it doesn’t hurt.
The story of a V8 performance cliff in React
https://v8.dev/blog/react-cliff [v8.dev]
2019-08-29 18:15
tags:
garbage-collection
javascript
jit
perf
programming
type-system
Previously, we discussed how JavaScript engines optimize object and array access through the use of Shapes and Inline Caches, and we’ve explored how engines speed up prototype property access in particular. This article describes how V8 chooses optimal in-memory representations for various JavaScript values, and how that impacts the shape machinery — all of which helps explain a recent V8 performance cliff in React core.
source: L
Models of Generics and Metaprogramming: Go, Rust, Swift, D and More
http://thume.ca/2019/07/14/a-tour-of-metaprogramming-models-for-generics/ [thume.ca]
2019-07-21 22:14
tags:
article
compiler
compsci
programming
type-system
In some domains of programming it’s common to want to write a data structure or algorithm that can work with elements of many different types, such as a generic list or a sorting algorithm that only needs a comparison function. Different programming languages have come up with all sorts of solutions to this problem: From just pointing people to existing general features that can be useful for the purpose (e.g C, Go) to generics systems so powerful they become Turing-complete (e.g. Rust, C++). In this post I’m going to take you on a tour of the generics systems in many different languages and how they are implemented. I’ll start from how languages without a special generics system like C solve the problem and then I’ll show how gradually adding extensions in different directions leads to the systems found in other languages.
source: L
Detecting in C++ whether a type is defined
https://devblogs.microsoft.com/oldnewthing/20190708-00/?p=102664 [devblogs.microsoft.com]
2019-07-11 18:37
tags:
cxx
programming
series
type-system
How 2 TypeScript: Get the last item type from a tuple of types
https://dev.to/miracleblue/how-2-typescript-get-the-last-item-type-from-a-tuple-of-types-3fh3 [dev.to]
2019-06-18 02:50
tags:
javascript
programming
type-system
Kinda like a normal array lookup!
But what if you don’t know the length of the tuple? Hmm... how do we get TypeScript to tell us the length and then let us use that length to pick out the last item, all at compile time?
What should you do if somebody passes a null pointer for a parameter that should never be null? What if it’s a Windows Runtime class?
https://devblogs.microsoft.com/oldnewthing/20190613-00/?p=102590 [devblogs.microsoft.com]
2019-06-14 01:17
tags:
programming
type-system
windows
If you put the cases of in-process and out-of-process callers together, you see that the conclusion is “Go ahead and dereference those pointers.” If the caller is in-process, then it’s okay to crash because you are crashing the caller’s process (which happens to be the same process that you are in). If the caller is out-of-process, then the RPC layer will prevent invalid null pointers from getting through.
There’s an additional wrinkle to this general principle, however, for the case where you are implementing a Windows Runtime class.
Go has no type for types in the language
https://utcc.utoronto.ca/~cks/space/blog/programming/GoNoTypeForTypes [utcc.utoronto.ca]
2019-05-16 13:32
tags:
go
programming
type-system
Part of what this means is that in Go, you cannot write an expression like ‘x := y.(type)’ not just because the language syntax forbids it, but because there is no standard type that the variable x can be. If you wanted to allow this, you would have to create a new Go type and define what its behavior was.
A new runtime for Nim
https://nim-lang.org/araq/ownedrefs.html [nim-lang.org]
2019-03-27 22:35
tags:
garbage-collection
malloc
nim
programming
type-system
In this blog post I explore how the full Nim language can be used without a tracing garbage collector. Since strings and sequences in Nim can also be implemented with destructors the puzzle to solve is what to do with Nim’s ref pointers and new keyword.
Type-specific allocation turns every “use after free” bug into a logical bug but no memory corruption can happen. So ... we have already accomplished “memory safety without a GC”. It didn’t require a borrow checker nor an advanced type system. It is interesting to compare this to an example that uses array indexing instead of pointers:
Interesting approach.
source: L
.NET Internals Cookbook
https://blog.adamfurmanek.pl/2019/02/16/net-internals-cookbook-part-0/ [blog.adamfurmanek.pl]
2019-03-09 18:47
tags:
csharp
dotnet
programming
series
type-system
In this series I answer various .NET questions. Some of them are asked during interviews, some of them I see on the internet, some of them are completely made up. The goal is to provide short answer with links to references if needed. This is by no means a .NET tutorial or experts reference, this is just a bunch of useful answers to refresh your knowledge.
Some of this gets pretty deep actually.
source: L
Typed nils in Go 2
https://dave.cheney.net/2017/08/09/typed-nils-in-go-2 [dave.cheney.net]
2019-02-18 21:36
tags:
go
programming
type-system
This is an experience report about a gotcha in Go that catches every Go programmer at least once. The following program is extracted from a larger version that caused my co-workers to lose several hours today.
You’ve probably realised the cause of this problem is the dreaded typed nil, a gotcha that has its own entry in the Go FAQ. The typed nil emerges as a result of the definition of a interface type; a structure which contains the concrete type of the value stored in the interface, and the value itself.
Typed nils are an entirely logical result of the way dynamic types, aka interfaces, are implemented, but are almost never what the programmer wanted.
The linked post is a good read as well: https://research.swtch.com/interfaces
to increment some counter on the page
https://twitter.com/chordbug/status/1092824183124488192 [twitter.com]
2019-02-05 20:28
tags:
html
intro-programming
javascript
tweet
type-system
web
node.innerText += 1 doesn’t work (0 → 01 → 011 → ⋯), but node.innerText -= -1 works fine (0 → 1 → 2 → ⋯)
A JavaScript Typed Array Gotcha
https://nullprogram.com/blog/2019/01/23/ [nullprogram.com]
2019-01-23 03:45
tags:
c
javascript
programming
standard
type-system
So, oldValue is 255. This is a double precision float because all numbers in JavaScript (outside of the bitwise operations) are double precision floating point. Add 1 to this value to get 256, which is newValue. When newValue is stored in the array via PutValue(), it’s converted to an unsigned 8-bit integer, which truncates it to 0.
However, newValue is returned, not the value that was actually stored in the array!