Skip to content

Instantly share code, notes, and snippets.

@krolaw
krolaw / vsafe.md
Last active August 18, 2019 02:45
V safe and easy

Simple rules for V safety

Goal is to be as safe as rust but without the complexity. This document may be totally naive, so please give constructive feedback.

Concurrency

  1. Once a mutable variable is passed to a coroutine function or channel it can no longer be used.
  2. Variables received by coroutine closures must be immutable
  3. Channels are considered immutable
@krolaw
krolaw / Go2.0SliceComparision.md
Last active August 13, 2017 10:43
Should Go 2.0 support slice comparison?

Should Go 2.0 support slice comparison?

In the same way it is useful to compare pointers (and not their values), I came across a situation where I wanted to compare slices (and not their backing array's values), as if they were structs containing ptr, len and cap. Thus slices a == b, would be true iff a.ptr == b.ptr && a.len == b.len && a.cap == b.cap, regardless of what is contained in a or b's backing arrays. Lastly, since equality and inequality would be clearly defined, I could use slices as map keys, as changing the array data would be safe and have no impact on the keys themselves.

I was writing some temporary code that would proxy requests to an old system for third party communication drivers that hadn't yet been re-written into the new system. Requests from clients would be split out to the different drivers, but the request data slices would be shared between drivers.

Each request looked something like this:

[updateData1][driver1][driver2][driver3]:[updateData2][driver1][driver3]:[u