[{"data":1,"prerenderedAt":155},["ShallowReactive",2],{"project-25405875":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":14,"rank_in_year":15,"shown_in_year":16,"top":17,"tier":18,"category":19,"subcategory":20,"format":21,"keywords":22,"reception":28,"sentiment":29,"stance_mix":30,"scored_comments":33,"aspects":34,"strip":37,"post_text":29,"what":39,"said":63,"maker_in_thread":92,"shape":99,"grid":103,"attempts":116,"same_week":117,"maker_shows":147,"maker_hidden":148,"reader_version":149,"card":150},"25405875","Design by Contract (tm)","C++","title","Show HN: Design by Contract (tm) – C++","https:\u002F\u002Fgithub.com\u002FBambofy\u002Fdbc_cpp","github.com","Bambo",1607859771,2020,6,2758,3028,92,"shown","languages","c++ contract library","library",[23,24,25,26,27],"design by contract","c++","preconditions","invariants","assertions","quiet",null,{"positive":31,"neutral":32,"mixed":31,"critical":32},0,1,2,{"design":35,"docs":36},{"positive":31,"critical":32},{"positive":31,"critical":31},[31,31,32,31,38,31],3,{"problem":40,"audience":29,"pricing":29,"motivation":29,"time_to_build":29,"stack":50,"openness":61,"stage":62,"team_size":62},{"value":41,"source":42,"evidence":43},"Checking preconditions, postconditions and invariants in C++ code","inferred",[44,47],{"id":45,"by":11,"text":46},"25422984","You can't implement the assertions at compile time since they are predicates evaluated at runtime. This is also why it is a performance hit on the code. I chose to use C-style…",{"id":48,"by":11,"text":49},"25422892","Yes OLD stores the value of the variable before the execution of the DO. This is because all of the virtual methods that have been overriden are visited in order to gather their…",[51,56],{"value":6,"source":42,"evidence":52},[53,55],{"id":54},"post",{"id":45,"by":11,"text":46},{"value":57,"source":58,"evidence":59},"C-style macros","maker",[60],{"id":45,"by":11,"text":46},"open_source","unknown",{"praise":64,"objections":65,"requests":78,"questions":83,"alternatives":91},[],[66],{"value":67,"source":68,"evidence":69},"Runtime contract checks are a performance cost and throwing exceptions on violation is the wrong response","commenter",[70,74],{"id":71,"by":72,"text":73},"25412652","ncmncm","Every pre-, post-, and invariant condition violation represents a programming error, at an indeterminate point in the past, rendering the state of the computation unknown, and…",{"id":75,"by":76,"text":77},"25409303","guenthert","Uh, run-time tests using C-style macros, much like assertions. Frankly, I would have been more impressed by some template\u002Fconstexpr magic implementing compile-time tests.",[79],{"value":80,"source":68,"evidence":81},"Compile-time checks using templates or constexpr instead of runtime macros",[82],{"id":75,"by":76,"text":77},[84],{"value":85,"source":68,"evidence":86},"What the OLD keyword does",[87],{"id":88,"by":89,"text":90},"25407663","progfix","I don't understand what 'OLD' does. EDIT: Apparently it refers to the variable with the value at the entry point.",[],{"comments":38,"answered":31,"key":93},[94,97,98],{"id":95,"text":96},"25422763","The exception throwing is a compromise, it allows you to view the stack trace in an IDE to find out which assertions failed.",{"id":45,"text":46},{"id":48,"text":49},{"commenters":100,"max_depth":33,"maker_replies":38,"first_comment_mins":101,"lifespan_hours":102},4,284,33,[104,106,108,110,112,114],[71,31,31,105,72,31],"commenter\u002Fneutral\u002Fidea",[95,31,31,107,11,32],"commenter\u002Fneutral\u002Fdesign",[75,32,32,109,76,31],"project\u002Fcritical\u002Fdesign",[45,32,31,111,11,32],"commenter\u002Fneutral\u002Fperformance",[88,33,38,113,89,31],"project\u002Fneutral\u002Fdocs",[48,33,31,115,11,32],"project\u002Fneutral\u002Fdesign",[],[118,123,128,133,138,143],{"id":119,"name":120,"points":121,"category":122},"25372464","SongBox",647,"web_saas",{"id":124,"name":125,"points":126,"category":127},"25434753","33Mail",442,"productivity",{"id":129,"name":130,"points":131,"category":132},"25414389","Typesense Books Search",424,"data",{"id":134,"name":135,"points":136,"category":137},"25405259","A Book Like Foo",344,"learning_science",{"id":139,"name":140,"points":141,"category":142},"25429685","Polotno Studio",180,"dev_tools",{"id":144,"name":145,"points":146,"category":142},"25394567","Devbook",168,7,false,"v2",{"id":151,"name":5,"line":6,"ai":148,"cat":19,"year":13,"points":14,"comments":14,"rec":28,"s":29,"top":17,"kw":152,"maker":11,"domain":10,"tier":18,"attempts":31,"strip":153,"url":9,"mix":154,"praise":-1,"objection":67,"sub":20},25405875,[23,24,25,26,27],"001030",[31,32,31,32],1793991020146]