tag:blogger.com,1999:blog-2524678972955021559.post2228365388992621202..comments2023-08-07T09:15:42.586-07:00Comments on Jay Bazuzi's coding blog: Prevent infinitely many bugs with this one simple trickUnknownnoreply@blogger.comBlogger11125tag:blogger.com,1999:blog-2524678972955021559.post-10565528879612816452017-08-07T18:26:29.032-07:002017-08-07T18:26:29.032-07:00You're making me dig in to the reasons behind ...You're making me dig in to the reasons behind my sense of design, which is a good thing...<br /><br />I try to save inheritance for is-a relationships. It may not be clear why I think that applies here, and inheriting implementation sure is convenient.<br /><br />The classes I am advocating for are parts of the domain model, and do not generally belong in code that uses C# as a way to write the inputs to another system, like XmlSerializer or Entity Framework. It would be easier to explain this in real code, if you have a project you can share on GitHub.Jay Bazuzihttps://www.blogger.com/profile/08378140547104387042noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-81685018094406678352017-08-07T17:34:25.244-07:002017-08-07T17:34:25.244-07:00Why do you want to avoid a base class, or for that...Why do you want to avoid a base class, or for that matter avoid providing CaseInsensitiveString for general/public use? I recognize that it would probably be best to avoid sending such a type across an interop boundary, but I'm building an application not a framework.<br /><br />I'm abandoning efforts to get XmlSerializer to convert my type. My next attempt will be some codegen to implement a pattern like:<br />[XmlIgnore]<br />CaseInsensitiveString ServerName { get; private set; }<br />[XmlAttribute("ServerName"]<br />string _xml_ServerName { get { return ServerName.ToString(); } set { ServerName = new CaseInsensitiveString(value); } }Tim!https://www.blogger.com/profile/08020958201438047629noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-48499732452951537212017-08-07T16:52:37.434-07:002017-08-07T16:52:37.434-07:00A case-insensitive string base class is exactly wh...A case-insensitive string base class is exactly what I want to avoid.<br /><br />I'm OK with:<br /><br />class ServerName<br />{<br /> CaseInsensitiveString Value;<br />}<br />Jay Bazuzihttps://www.blogger.com/profile/08378140547104387042noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-11005725540146699362017-08-07T13:55:55.698-07:002017-08-07T13:55:55.698-07:00I think I can do what I need by implementing IConv...I think I can do what I need by implementing IConvertible.Tim!https://www.blogger.com/profile/08020958201438047629noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-17758879705027328572017-08-07T13:46:15.366-07:002017-08-07T13:46:15.366-07:00My thought is that CaseInsensitiveString would be ...My thought is that CaseInsensitiveString would be a base class encapsulating the case insensitive functionality, then there could exist subclasses representing the specific business logic properties.<br /><br />In my case we have several distinct kinds of data that each want case insensitive comparison semantics: server name, (NTFS) path, several kinds of named identifiers. It doesn't make sense to reimplement the casing functionality once for each kind of property; that's barely an improvement over implementing it once for each comparison operation.<br /><br />In my case, xml documents on disk and their in-memory representation are an intrinsic part of the application. The binaries would be useless without the data we distribute with them.Tim!https://www.blogger.com/profile/08020958201438047629noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-60803158157615690252017-08-04T19:42:58.491-07:002017-08-04T19:42:58.491-07:00A few abstract thoughts; we can make them more con...A few abstract thoughts; we can make them more concrete later:<br /><br />- I don't have much used for a class called CaseInsensitiveString, with the possible exception of allowing them in a private field of a value class.<br /><br />- I'm talking about classes used within the application core and at its ports, not when interfacing to an external dependency. [DataContract]s aren't really C#...Jay Bazuzihttps://www.blogger.com/profile/08378140547104387042noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-3019794788538847022017-08-04T12:37:48.782-07:002017-08-04T12:37:48.782-07:00Xml is the primary use case.
If I try to use Case...Xml is the primary use case.<br /><br />If I try to use CaseInsensitiveString as an XmlAttribute or XmlText, I get "Cannot serialize member... XmlAttribute/XmlText cannot be used to encode complex types."<br /><br />If I try to use CaseInsensitiveString as an XmlElement, I get no value unless I expose the string-behind as a public property, which is undesirable, and in which case the value gets serialized with an extra layer of indirection that I don't want.Tim!https://www.blogger.com/profile/08020958201438047629noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-25623273893785740642017-08-03T16:29:58.507-07:002017-08-03T16:29:58.507-07:00Tim, I learned how to do this in C# first!
- Mak...Tim, I learned how to do this in C# first! <br /><br />- Make the Value field readonly.<br /><br />- Use https://preview.nuget.org/packages/Bazuzi.ValueTypeAssertions/<br /><br />I've never had a problem making serialization work. What protocol are you working in?Jay Bazuzihttps://www.blogger.com/profile/08378140547104387042noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-20023975149302982482017-08-03T15:58:19.011-07:002017-08-03T15:58:19.011-07:00I think this is a great idea but it seems to be un...I think this is a great idea but it seems to be unpossible in C# since string is baked into the language and the framework so deeply. I can get the class to work standalone, but I can't figure out a clean serialization story, plus I lose interning and the reference type passed by value semantics. :(Tim!https://www.blogger.com/profile/08020958201438047629noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-77848576369561373932017-08-02T19:47:16.823-07:002017-08-02T19:47:16.823-07:00Yeah, what you describe is an important concern.
...Yeah, what you describe is an important concern.<br /><br />I'd like to shift the question from "how we detect design feedback in tests" do "how do we detect design feedback from anywhere?"<br /><br />That's partly the purpose of this blog post, to present some ideas about detecting and responding to design feedback. I'll keep writing.<br /><br />Pairing, even with someone that's is not a refactoring expert, will help both of you get better.Jay Bazuzihttps://www.blogger.com/profile/08378140547104387042noreply@blogger.comtag:blogger.com,1999:blog-2524678972955021559.post-1633834667338641012017-07-30T13:34:43.610-07:002017-07-30T13:34:43.610-07:00Regarding Test Feedback, combined with Eric’s late...Regarding Test Feedback, combined with Eric’s latest blog “TDD is for pros”( https://blogs.msdn.microsoft.com/ericgu/2017/06/22/notdd/) . I think there should be more discussion on “test design feedback”. Lacking a defined way to “listen to design feedback”, it makes me feel like how to draw an owl (http://knowyourmeme.com/memes/how-to-draw-an-owl) . So, any plan to write a blog about how to identify typical test feedback and how to fix it? 😉<br /><br />-William LiAnonymoushttps://www.blogger.com/profile/12553384009068668838noreply@blogger.com