I'm being retarded today. What does it mean "a string defining a type"?

Reply to this note

Please Login to reply.

Discussion

making a structure where you have to decode it first before you can find out what kind of data it is

i use a static typed language and these kinds of structures require double handling, no matter what way you do it you have to scan ahead to find the type before you know how to unpack it

if they instead made an object like:

{

"arrayType1:[1,2,3,4],

"structType:[

{"itemname":"name","description":"describe the thing"},

{"itemname":"name","description":"describe the thing"}

],

"singletonItem":{"it's just one thing"}

}

i would know what it is before i start reading it

this is what the struct looks like that i have to decode, it's an array of these:

{

"address": "0x58fff802043d6e1b620b2875e04d40860941807a56f8da603907924b6b1cbd78",

"createdAt": 1734499449276,

"data": true,

"kind": "profile-completed",

"status": "valid",

"updatedAt": 1734499449276,

"userAddress": "0xff7f1e988e5545dd2e96006d9a5f674ba224c700143d23989a5adcfc9b4b506f"

},

what lives inside "data" differs depending on "kind" and so then i have to decode it once into a generic structure, and then create the actual structure of that type and copy the data into it

this is one of the most annoying things about dealing with shit designed by javascript, c++ and Rust programmers, they all don't realise their language is doing 2x as much work to do this when having a prefix label typing the thing saves a shitload of needless work

the even stupider thing is that in Javascript, even, there is nothing stopping you doing this:

{

"entrytype1":[],

"entrytype1":[]

}

as far as i know, there is no key/vaule uniqueness invariant in JSON objects

it's really annoying for me because everything just gets turned into map[string]interface{} which means a gazillion if/then statements to figure out how to store that properly as typed data

so the alternative is to decode it, and then re-encode it in a structured format

objects are maps. So technically that's illegal in javascript when defining an object, but it is valid syntax. A broken implementation could send that over the wire.

ah, it's javascript, nobody cares lol, everything is text

yes, they have to be encoded as these two types in Go, if you can't pre-define what you are going to get:

map[string]interface{}

[]interface{}

in this case we have this:

map[string][]map[string]interface{}

it is an object, with an array of objects inside it

even better, what is inside it, is all the same object, except one field which is different depending on the text in one of the fields in the object

literally have to either write a generator or spend 2 hours manually writing a thing to unpack it because i have to refer to this shit later, and that wonderous type i just showed you is a serious pain in the ass to iterate, the maps are nondeterministically processed, so you don't know except by selecting on the specially named data field, after you pick the kind field to find out what type to pull out of the data field

anyway, just doing it the manual way because this is the most complex structure in this project i'm doing

it just would have been a lot simpler to make them have names describing what the thing is, so a map with the full set in it, and then inside it an array of the type that fits with that

it would be a more compact representation as well as easier to iterate it

this really sucks for a typed language.

but guilty as charged I also use this "blob" like fields someties.

Probably something I was used to i C

ok, it's probably just laziness and lack of intent to actually be interoperable. devs are lazy, that's a fact

yeah, especially javascript devs, they are the most despicable