[{"data":1,"prerenderedAt":291},["ShallowReactive",2],{"project-13913413":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":29,"sentiment":30,"stance_mix":31,"scored_comments":35,"aspects":36,"strip":39,"post_text":41,"what":42,"said":81,"maker_in_thread":141,"shape":151,"grid":154,"attempts":255,"same_week":256,"maker_shows":32,"maker_hidden":283,"reader_version":284,"card":285},"13913413","go-sumtype","A utility for running exhaustiveness checks on “sum types” in Go","title","Show HN: A utility for running exhaustiveness checks on “sum types” in Go","https:\u002F\u002Fgithub.com\u002FBurntSushi\u002Fgo-sumtype","github.com","burntsushi",1490011860,2017,75,38,590,2242,27,"notable","dev_tools","static analysis linter","cli",[24,25,26,27,28],"go","sum types","exhaustiveness check","linter","type switch","curious",0.133,{"positive":32,"neutral":33,"mixed":34,"critical":34},1,4,0,5,{"idea":37,"design":38},{"positive":32,"critical":34},{"positive":34,"critical":34},[40,34,34,34,34,34,34,34,34,34,40,40,34,40,34,34,34,34,34,34,34,35,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34],3,null,{"problem":43,"audience":58,"pricing":41,"motivation":67,"time_to_build":41,"stack":72,"openness":79,"stage":80,"team_size":80},{"value":44,"source":45,"evidence":46},"Go lacks compiler-checked sum types, so switches over variant interfaces can miss cases.","commenter",[47,51,55],{"id":48,"by":49,"text":50},"13915127","wyc","Language-level sum types are something that I miss a lot when I'm writing Go. I find myself using this error-prone pattern whenever I'm trying to represent state: ``` type…",{"id":52,"by":53,"text":54},"13919375","lobster_johnson","This looks very nice. I've been working with sum types (as far as they can be called that) in Go a lot recently, and it's frustrating how bad it is as algebraic data types in…",{"id":56,"by":11,"text":57},"13917117","In our code, we have a closed interface type with many variants, not unlike an AST. We frequently add new variants to that interface. It is nice to have a tool tell us which…",{"value":59,"source":60,"evidence":61},"Go developers who write type switches over closed interface variants.","inferred",[62,63],{"id":56,"by":11,"text":57},{"id":64,"by":65,"text":66},"13915012","jerf","\"I think that switching on types in Go is gererally a total anti-pattern.\" It's not. A thing to bear in mind is that this tool is checking interface types that are strictly…",{"value":68,"source":69,"evidence":70},"Maker wanted a tool to flag missing cases when adding new variants to a closed interface type in their code.","maker",[71],{"id":56,"by":11,"text":57},[73],{"value":74,"source":69,"evidence":75},"Go",[76],{"id":77,"by":11,"text":78},"13914061","> (not that someone can't be both, of course) Indeed! I've been writing Go code daily for years. My open source life is just a bit more consumed by Rust these days. :-)","open_source","unknown",{"praise":82,"objections":94,"requests":114,"questions":122,"alternatives":127},[83,89],{"value":84,"source":45,"evidence":85},"Useful for catching missed cases when new variants are added.",[86,87,88],{"id":56,"by":11,"text":57},{"id":52,"by":53,"text":54},{"id":64,"by":65,"text":66},{"value":90,"source":45,"evidence":91},"Fills a gap in Go's type system; compiler checks are better than none.",[92,93],{"id":48,"by":49,"text":50},{"id":52,"by":53,"text":54},[95,106],{"value":96,"source":45,"evidence":97},"Switching on types in Go is an anti-pattern; interfaces with methods are better.",[98,102],{"id":99,"by":100,"text":101},"13914173","cube2222","I think that switching on types in Go is gererally a total anti-pattern. In case you need to handle errors, in the end the type doesn't matter at all for you. You are interested…",{"id":103,"by":104,"text":105},"13914286","pbnjay","I made a similar comment on the reddit post. This seems like something handled better by interfaces. In my experience, whenever I end up writing a large type switch on an…",{"value":107,"source":45,"evidence":108},"Using a tool to bend Go toward other language features means fighting the language; use a language with sum types.",[109,113],{"id":110,"by":111,"text":112},"13914221","grabcocque","Isn't trying to hack a language to have the type system you wish it had, rather than simply using the language you wanted in the first place, something of a futile exercise? If…",{"id":99,"by":100,"text":101},[115],{"value":116,"source":45,"evidence":117},"Detect sum-type interfaces automatically rather than requiring a marker.",[118],{"id":119,"by":120,"text":121},"13914295","infogulch","From the readme: > The go-sumtype command recognizes this pattern, but it needs a small amount of help to recognize which interfaces should be treated as sum types Why is this?…",[123],{"value":124,"source":45,"evidence":125},"Why does the tool need help identifying which interfaces are sum types?",[126],{"id":119,"by":120,"text":121},[128,133,137],{"value":129,"source":45,"evidence":130},"Rust enums and other languages with algebraic data types.",[131,132],{"id":110,"by":111,"text":112},{"id":48,"by":49,"text":50},{"value":134,"source":45,"evidence":135},"Haskell data types.",[136],{"id":48,"by":49,"text":50},{"value":138,"source":45,"evidence":139},"Interface methods instead of type switches.",[140],{"id":103,"by":104,"text":105},{"comments":35,"answered":142,"key":143},2,[144,147,148],{"id":145,"text":146},"13914557","That's the case for me at least. I was even involved in choosing Go at our company a few years back. A language doesn't need to be perfect in order to enjoy using it. :-)",{"id":77,"text":78},{"id":149,"text":150},"13914405","It seems unwise to do exhaustiveness checks automatically on an interface that \"might\" be a sum type. The declaration is a single line and has the benefit of being completely…",{"commenters":18,"max_depth":35,"maker_replies":35,"first_comment_mins":152,"lifespan_hours":153},86,25,[155,157,161,163,166,169,172,174,177,180,183,186,189,190,192,194,197,200,202,205,208,210,212,214,216,219,221,223,225,228,231,233,236,239,242,245,250,253],[48,34,40,156,49,34],"project\u002Fneutral\u002Fidea",[158,34,34,159,160,34],"13917630","other\u002Fneutral\u002Fnone","aston",[110,32,34,162,111,34],"commenter\u002Fneutral\u002Fnone",[164,32,34,162,165,34],"13914399","meddlepal",[167,32,34,162,168,34],"13914512","pjmlp",[170,32,34,162,171,34],"13914554","michaelmior",[145,32,34,173,11,32],"maker\u002Fneutral\u002Fnone",[175,32,34,159,176,34],"13920593","bbcbasic",[178,32,34,162,179,34],"13914961","Zikes",[181,32,34,162,182,34],"13917161","amelius",[184,142,40,156,185,34],"13917266","Animats",[187,40,40,173,188,34],"13914052","notheguyouthink",[77,40,34,173,11,32],[119,40,40,191,120,34],"project\u002Fneutral\u002Fdesign",[149,40,34,193,11,32],"maker\u002Fneutral\u002Fdesign",[195,40,34,159,196,34],"13914082","rkangel",[198,40,34,159,199,34],"13914209","tylerhou",[201,40,34,159,196,34],"13914464",[203,40,34,159,204,34],"13914259","geodel",[206,40,34,159,207,34],"13917085","kibwen",[209,40,34,159,188,34],"13921918",[52,33,35,211,53,34],"project\u002Fpositive\u002Fidea",[99,35,34,213,100,34],"commenter\u002Fcritical\u002Fidea",[103,35,34,215,104,34],"commenter\u002Fcritical\u002Fdesign",[217,35,34,218,11,32],"13914463","commenter\u002Fneutral\u002Fdesign",[220,35,34,218,100,34],"13914733",[222,35,34,162,104,34],"13914804",[224,35,34,218,100,34],"13914958",[226,35,34,215,227,34],"13914615","andrewstuart2",[229,35,34,215,230,34],"13914726","russell_h",[64,35,34,232,65,34],"commenter\u002Fpositive\u002Fdesign",[234,35,34,235,65,34],"13915103","other\u002Fneutral\u002Fidea",[237,35,34,213,238,34],"13915633","kazinator",[240,35,34,241,65,34],"13916098","commenter\u002Fneutral\u002Fidea",[243,35,34,159,244,34],"13920423","frou_dh",[246,247,34,248,249,34],"13914155",6,"other\u002Fcritical\u002Fidea","gothrowaway",[251,247,34,159,252,34],"13917007","gothrowaway2",[56,247,34,254,11,32],"project\u002Fpositive\u002Fexecution",[],[257,261,265,269,274,278],{"id":258,"name":259,"points":260,"category":20},"13907010","Aeneas",188,{"id":262,"name":263,"points":264,"category":20},"13901005","Ladon",158,{"id":266,"name":267,"points":268,"category":20},"13906014","Klipse",111,{"id":270,"name":271,"points":272,"category":273},"13921364","Marta",106,"productivity",{"id":275,"name":276,"points":277,"category":20},"13908606","OS",97,{"id":279,"name":280,"points":281,"category":282},"13920588","FaaS",73,"infrastructure",false,"v2",{"id":286,"name":5,"line":6,"ai":283,"cat":20,"year":13,"points":14,"comments":15,"rec":29,"s":287,"top":18,"kw":288,"maker":11,"domain":10,"tier":19,"attempts":34,"strip":289,"url":9,"mix":290,"praise":84,"objection":96,"sub":21},13913413,0.13,[24,25,26,27,28],"30000000003303000000050000000000000000",[32,33,34,34],1794036553666]