logoalt Hacker News

thaynetoday at 6:19 AM1 replyview on HN

> the convention is kind of to have a constructor pattern with a NewStruct(...) *Struct method that initializes all properties

But that doesn't stop you from declaring a var s Struct, and never initializing it, or making a NewStruct {}.

> can't you build your own validator for that with the reflect package in the Add() method of your UI graph

Besides the fact that that would almost certainly significantly hurt performance, how would you be able to differentiate between unitialized data and data that was intentionally set to the zero value?


Replies

olmo23today at 11:23 AM

> But that doesn't stop you from declaring a var s Struct, and never initializing it, or making a NewStruct {}.

Static analysis tools can catch this, no?