tag:blogger.com,1999:blog-6918427997759942244.post4219903762823693922..comments2021-08-15T21:31:41.100-04:00Comments on Elegant Coding: Math You Can Useelegantcodinghttp://www.blogger.com/profile/12373582469986942814noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-6918427997759942244.post-56505093937015860792013-09-07T15:12:51.910-04:002013-09-07T15:12:51.910-04:00Note: The issue here may be that I simply understa...Note: The issue here may be that I simply understand what you're putting out but am simply unfamiliar with the formal representation of it. I would be remiss to assume it makes sense to everyone. Sagehttps://www.blogger.com/profile/11147806837249570194noreply@blogger.comtag:blogger.com,1999:blog-6918427997759942244.post-7711014798120079232013-09-07T14:47:29.819-04:002013-09-07T14:47:29.819-04:00I think this specific example isn't a strong c...I think this specific example isn't a strong case for the importance of these mathematical theories in programming. Your refactored code merely makes sense; it doesn't require anyone to understand the theory to be able to simply understand, by pure logic, that the refactored code has the same effect as the original. <br /><br />In the original code we basically have a Pass/Fail scenario where Condition 1 is Fail and Condition 2 is Pass: If A!=B OR C!=D, Fail, otherwise, Pass (meaning A=B AND C=D because either statement returning false would result in Failure). <br /><br />It seems only logical to reform the statement so your pass conditions are strictly met and your failure conditions are met via "else" aka "any other result." So if A=B & C=D, Pass, otherwise, Fail. <br />Sagehttps://www.blogger.com/profile/11147806837249570194noreply@blogger.comtag:blogger.com,1999:blog-6918427997759942244.post-21345618890830626822013-08-29T11:56:27.494-04:002013-08-29T11:56:27.494-04:00You converted an equation with negative attitude &...You converted an equation with negative attitude "if((a != b) || (c != d))" into an equation with positive attitude "if((a == b) && (c == d))" :) . I did the same an year back, without knowing any maths. Let me share my experience with you.<br /><br />I am very poor at maths and there was this old code at work where there are 6 or 8 variables spread over 3 lines combined in various odd ways with && and || along with weird negations (!). The whole conditional-statement was totally unclear, clumsy and complete mess when it comes to one question: What this conditional check is doing ? (How it is doing something was a bigger mess). I was supposed to add some feature to that software and that conditional-statement was coming in the way, not to mention previous maintainers faced the same issue but that code still lied there for years. And then I decided to clean it up out of frustration.<br /><br />Guess What, I read your article only today but I did the same thing at that time, plus I grouped several statements into one, learned the "why" behind the conditional by reading code and even removed some statements. I did this without any knowledge of logic, set theory or De Morgan's laws. In fact, I learned all of this technique from comp.lang.c --> "positivity is easier to understand than negation". I have been to comp.lang.c, wrote several thousand lines of code at work and I stil gang in there to learn.<br /><br />My question you just used Maths as language to do that while I read the same English from comp.lang.c . Does that mean Maths gives same benefits as experience in programming ? That it is actually not Maths but a certain kind of thinking required to solve problems in programming ?Anonymousnoreply@blogger.com