tag:blogger.com,1999:blog-53811440436544528082024-03-21T06:18:34.121-07:00semanticmergePablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-5381144043654452808.post-45936098673921313522019-02-04T05:38:00.000-08:002019-02-04T05:38:34.025-08:00SemanticMerge now supports PHP<p>Supporting PHP was required by <a href="https://plasticscm.uservoice.com/forums/196398-semanticmerge/suggestions/3876536-php-please">many of our users</a>. Today we wanted to let you know that we have upgraded SemanticMerge's core diffing and merging machine to parse and understand PHP. It will now be able to detect changes at the code line distribution but also within specific PHP methods and classes, for example.</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP5IJLiFeunO20M_13GAHz0jTbDKzcngBltT_3yDykylo32bfom1YtYqDmOm7nwy8DCc3m5z9MmWDIBYGlUsSHa6LopEZ9dLmNyvlygDw85pGrhXU_3ZHWCnDGAE_AildXQKhIi6BAPH3a/s1600/semanticmerge-php-language.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="925" data-original-width="1600" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP5IJLiFeunO20M_13GAHz0jTbDKzcngBltT_3yDykylo32bfom1YtYqDmOm7nwy8DCc3m5z9MmWDIBYGlUsSHa6LopEZ9dLmNyvlygDw85pGrhXU_3ZHWCnDGAE_AildXQKhIi6BAPH3a/s1600/semanticmerge-php-language.png" /></a></div>
<a name='more'></a>
<h2 id="this-is-how-semanticmerge-works-now-with-php-merges">This is how SemanticMerge works now with PHP merges</h2>
<p>Have you ever been confused about merging or rebasing PHP code? You have a staging / testing branch with a couple of commits and you want to merge it to main development branch, crossing your fingers that no conflicts arise. With SemanticMerge's new support for PHP the number of automatic merges will dramatically increase because it now understands the language. In other words, what other merge tools consider a conflict, SemanticMerge won't; Let's say programmer A makes changes inside a method. That method, in the eyes of a random merge tool will look different than the unchanged method, but under SemanticMerge's PHP parser, it's not. That is just one example of a minimal change that could generate integration conflicts. See below other examples from the SemanticMerge's interface:</p>
<p>In this example, a changed and moved method conflicts with a changed method. The tool will identify all changes affecting the same method:</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoCxKrEIEve2OEh_bgxNMG-KRe4KkrvRNh9egP3UrOftP-kwwIHpjaeY_3E89AQoGK4CyYLEvpiiSHGQvfooDfH8aCl0iQ6EBaM2rH62aHsIT-yJ6G9yEKXbuz5vTSEL6EdrE0Q-nmn7s/s1600/gmaster-moved-method-conflict.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="882" data-original-width="1213" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoCxKrEIEve2OEh_bgxNMG-KRe4KkrvRNh9egP3UrOftP-kwwIHpjaeY_3E89AQoGK4CyYLEvpiiSHGQvfooDfH8aCl0iQ6EBaM2rH62aHsIT-yJ6G9yEKXbuz5vTSEL6EdrE0Q-nmn7s/s1600/gmaster-moved-method-conflict.png" /></a></div>
<p>An evil twin conflict will also be detected as shown below:</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwM6eSucS93vH3SNEFIspj3dmYHYDh_7x2fGgV9govWfOKzVo3f5QZgxCUaiwhaI_tLhyNupjnt9qHvxVMOnBl98kldqcOTbgaQv7a9EBXv1qKxN3xX4JYEJc9a1SAP9b62a4zpDvOI5o/s1600/gmaster-evil-twin.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="677" data-original-width="1145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwM6eSucS93vH3SNEFIspj3dmYHYDh_7x2fGgV9govWfOKzVo3f5QZgxCUaiwhaI_tLhyNupjnt9qHvxVMOnBl98kldqcOTbgaQv7a9EBXv1qKxN3xX4JYEJc9a1SAP9b62a4zpDvOI5o/s1600/gmaster-evil-twin.png" /></a></div>
<h2 id="welcome-on-board-php-developers">Welcome on board, PHP developers</h2>
<p>Invoke SemanticMerge from your development environment. If you want to try SemanticMerge's functionality with sample code before doing so with your real code you can do so anytime. When opening SemanticMerge select "open samples" and then select the PHP pane to test it out with PHP code. See below:</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjh0Q6OS66KxH-OcuO2MhsA2k-kWGViVR58Ygkfb0FrG-F06hIKZGliiGbnqRFY2byQbbdaymYICViTyVdCXy3orTdEH8j6ggMIdVnO33Xz1_niH3Z3RGHiJBes3p5bd77HMi7siOC5ylM-/s1600/semanticmerge-intro-php-support.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="879" data-original-width="709" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjh0Q6OS66KxH-OcuO2MhsA2k-kWGViVR58Ygkfb0FrG-F06hIKZGliiGbnqRFY2byQbbdaymYICViTyVdCXy3orTdEH8j6ggMIdVnO33Xz1_niH3Z3RGHiJBes3p5bd77HMi7siOC5ylM-/s1600/semanticmerge-intro-php-support.png" /></a></div>
<br />
<br />
<br />
<p>SemanticMerge is free for one month. Go ahead and give it a try with your PHP code base now.</p>
<center>
<div style="padding-bottom: 60px; padding-top: 60px;">
<div class="up_arrow">
<div class="pull-left">
<a class="read-more" href="https://users.semanticmerge.com/Download?utm_source=semanticmerge-blog&utm_medium=blog-post&utm_content=semanticmergenowsupportsphp" target="_blank">Try SemanticMerge free</a>
</div>
</div>
</div>
</center>
Jordi Mon Companyshttp://www.blogger.com/profile/14075857036607517034noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-13557868396221480102018-12-21T00:58:00.000-08:002018-12-21T02:39:51.331-08:00Cpp Cast interviews SemanticMerge team<p>I was invited to chat with the <a href="http://cppcast.com/" target="_blank">Cpp Cast</a> crew, <a href="https://twitter.com/robwirving" target="_blank">Rob Irving</a> and <a href="https://twitter.com/lefticus" target="_blank">Jason Turner</a> – the best podcast on C++ development out on the interwebs. They wanted to know more about SemanticMerge, how it parses and merges C++ code and what this means for everyday programming in C++.</p>
<p>This is a short summary of our conversation on these and many other C++ topics such as the upcoming <a href="https://www.cjdb.com.au/sg20-and-videos" target="_blank">SD20 C++ teaching group</a> or Alexander Boden's <a href="https://github.com/ashampoosystems/boden" target="_blank">Cross-Platform framework</a>.</p>
<a name='more'></a>
<div style="padding-top:60px;padding-bottom:60px;">
<div class="up_arrow"/>
<div class="pull-left">
<a class="read-more" href="http://cppcast.com/2018/12/pablo-santos/" target="_blank">Go listen to the full podcast</a>
</div>
</div>
</div>
<h2>A short story of SemanticMerge</h2>
<p>SemanticMerge's was at the core of the version control system that gave birth to Códice Software in 2005. Merge tools sit at the foundations of any version control along with branching, changeset history and many other functionalities. If, I thought, <a href="https://www.plasticscm.com/?utm_source=semanticmerge-blog&utm_medium=blog-post&utm_content=cppcastinterview" target="_blank">Plastic SCM</a> – the aforementioned version control – wanted to be a top-notch VCS then it should be powered by the highest quality merge tool we could design. Thus, developing a complete text-based merge algorithm was not enough, although the one we came up with, still provides <a href="https://www.plasticscm.com/mergemachine?utm_source=semanticmerge-blog&utm_medium=blog-post&utm_content=cppcastinterview" target="_blank">considerable advantages</a> over other syntactic tools. If we wanted to make a successful impact on the C++ programming language community our product should reduce the pain of frequent C++ code diffing and merging and enable shipping more code with better quality. In other words, that meant we needed to go a step further: into the forsaken realm of semantic merge.</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg13sLb0EXbwhzaMRPzSTzaC3DcyCQICBAlNoEQY6c5cYoPhjsNLWPQY2BwHj0dqzNdzV9z773rMW82ERRZWCtTSjJf3sfXrT2hW2fHYDvXbrarURFBwh4nGwXhA5GBFN0zErWUOVDXczEi/s1600/design-theplasticsystem.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg13sLb0EXbwhzaMRPzSTzaC3DcyCQICBAlNoEQY6c5cYoPhjsNLWPQY2BwHj0dqzNdzV9z773rMW82ERRZWCtTSjJf3sfXrT2hW2fHYDvXbrarURFBwh4nGwXhA5GBFN0zErWUOVDXczEi/s1600/design-theplasticsystem.png" data-original-width="1074" data-original-height="744" alt="Plastic SCM's first designs in 2005. Distributed repo management at its best already!" title="Plastic SCM's first designs in 2005. Distributed repo management at its best already!" /></a></div>
<center><small>Plastic SCM's first designs in 2005. Distributed repo management at its best already!</small></center>
<h2>Merging C++ code: the nightmare is over</h2>
<p>Why not make our Merge Machine work on a function or on a method levels instead of just staying at a plain-text level? We designed it to diff the code on a structural level rather than on a text positioning level, our merge tool is able to connect the dots and actually trace changes inside methods or functions. So, basically if a method gets moved by programmer B and, at the same time, programmer A changes variables in that same method, SemanticMerge will be able to detect and merge both the positional change (syntactic level) and the structural change (semantic level). This is done creating, parsing, and diffing the ASTs and then figuring out via similarity algorithms if the text blocks of the different versions in the method are actually the same to proceed with the merge.</p>
<p>A byproduct of this approach is the number of manual merges that all of a sudden become automatic. Merging semantically reduces dramatically the number of undetected changes in the same method or, in other words, the number of "new" methods consequence of changes in their components just plummets, allowing for more automatic merges to happen and thus freeing productive time of C++ developers. This can even be performed across files! If the method used as an example is moved to a different file for the purpose of a refactor and changes are being done by another developer in the same method's original version, both can be diffed and merged by SemanticMerge.</p>
<p>The precision of SemanticMerge is such that indentation and spaces will be understood and it will react in consequence. It even provides the option to reformat the any given method before merging. This is the degree of precision that SemanticMerge is capable of, saving tons of time of otherwise manual, painstaking work.</p>
<p>C++ is by far the most complex of all the languages SemanticMerge supports (these include Java, C, C#, .NET...) but SemanticMerge uses <a href="https://www.eclipse.org/cdt/" target="_blank">Eclipse CDT project</a> parser to parse C++ code, which is indeed of great help. This eventually results in 0 config requirements which at the end of the day is what end users really want from a merging tool, for it to work as soon as it is invoked.</p>
<p>Our suggestion is you read <a href="http://www.semanticmerge.com/?utm_source=semanticmerge-blog&utm_medium=blog-post&utm_content=cppcastinterview#testimonial" target="_blank">SemanticMerge's testimonials</a> and you try it out yourselves. It is completely free for one whole month.</p>
<p>I would like to thank Rob and Jason for their time and their interest. If any of you would like to ask us anything about SemanticMerge please reach us out at:</p>
<p><a href="https://twitter.com/semanticmerge" target="_blank">https://twitter.com/semanticmerge</a></p>
<p><a href="mailto:sales@codicesoftware.com?subject=Need sales info (coming from the SemanticMerge blog)" target="_blank">sales@codicesoftware.com</a></p>Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-19075828530991440202016-07-14T03:27:00.000-07:002016-07-14T03:27:53.376-07:00Solving semantic conflicts with Git and SemanticMerge<p>Here is the scenario: you have a source file with a class and some methods, and then you think it is a good idea to do some cleanup. You know, sort the methods in visibility order (public first) maybe create a subclass to wrap some functionality together, or place methods close to each other depending on how they are called, just to improve readability.</p>
<p>But, someone was doing changes to the same file concurrently (you know, it happens) and then he is less than happy to merge his fixes together with your cleanup...</p>
<p>So, here is the deal: shouldn't we try to keep the code as clean as possible? Yes, of course, sticking to whatever common style rules the team agreed to stick to. But then, in real life, isn't it a merge killer?</p>
<p>This blogpost shows how SemanticMerge helps to solve this case, when integrated with Git. For those of you who didn't know, SemanticMerge parses the code before calculating any merges. Unlike other 3-way merge tools, it is not just based on text. It can parse Java code, C#/VB.net code (Roslyn based) and C. There are also external community written parsers for Delphi and JavaScript.</p>
<a name='more'></a>
<h2>Merge scenario</h2>
<p>Well, I'm using a clone of <a href="https://github.com/aspnet/KestrelHttpServer.git" target="_blank">Kestrel Server source code</a> and more specifically working on file <a href="https://github.com/aspnet/KestrelHttpServer/blob/dev/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPool.cs" target="_blank">MemoryPool.cs</a>.</p>
<p>Here are the changes the two developers are going to perform:</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsKmvUuX-L9_aDW3cX0JUzSyQQwzuxQM9H5S3yNHcuFiOu5xlmvvU4uG93XSVT5vcd48ZmWeAsCuWd6VKZZahC0JzvVPdRnXCUVLJndnQIaoSfHUtCXUuUEFxUSXaUerGu_ivJ-S2rEDU/s1600/00-merge-case.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsKmvUuX-L9_aDW3cX0JUzSyQQwzuxQM9H5S3yNHcuFiOu5xlmvvU4uG93XSVT5vcd48ZmWeAsCuWd6VKZZahC0JzvVPdRnXCUVLJndnQIaoSfHUtCXUuUEFxUSXaUerGu_ivJ-S2rEDU/s1600/00-merge-case.png" alt="Merge case"/></a></div>
<p><samp>Base</samp> is how the code was originally (in fact, the figure is hiding all the methods not involved in the example, the code is slightly more complicated than that).</p>
<p><samp>Source</samp> (src) and <samp>Destination</samp> (dst) are the changes that the two developers are going to make.</p>
<p>Look at the icons: <strong>C</strong> stands for "changed" and <strong>M</strong> for "moved". As you can see both methods will be changed concurrently (C on both sides) and also moved by one of the developers.</p>
<p>This figure is actually taken from <a href="http://semanticmerge.com/features/#visual-merge" target="_blank">SemanticMerge</a>.</p>
<h2>Diffing the code</h2>
<p>The developer doing the cleanup (that's you in this story) can diff the changes (we're using Visual Studio Code for this example) and sees something like this:</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz276no5AQrkoNsnYT06BqE1VFPmU1jNW_pRvFIecFr52MpsHXVlQF6L2qIdq7x5zTTh5AwmLE61doayzrH7VNxm-N2V__5wxHimbNsPFycIM7BLh1W5BlPWTa4rIL3y193DtSDWeKVl8/s1600/01-classic-diff.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz276no5AQrkoNsnYT06BqE1VFPmU1jNW_pRvFIecFr52MpsHXVlQF6L2qIdq7x5zTTh5AwmLE61doayzrH7VNxm-N2V__5wxHimbNsPFycIM7BLh1W5BlPWTa4rIL3y193DtSDWeKVl8/s1600/01-classic-diff.PNG" alt="Classic diff"/></a></div>
<p>Needless to say, "traditional" diff is not very helpful with moved code.</p>
<p>You can always run <kbd>git difftool</kbd> from the command line to get a "move aware" diff:</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifVQYhUpVfpogAwnJE3QvuUFL1bYDLBm3VqiA2Jeo6BWrCaPhseOJhiYZWATOCBhMIH9Gl4o_y_5NUPDexC_mq3v85bXQTBUjz7bFcXBJJE6UpXad_xTEimxKGX22rV5E7ICyzgdWuGjg/s1600/02-semantic-diff.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifVQYhUpVfpogAwnJE3QvuUFL1bYDLBm3VqiA2Jeo6BWrCaPhseOJhiYZWATOCBhMIH9Gl4o_y_5NUPDexC_mq3v85bXQTBUjz7bFcXBJJE6UpXad_xTEimxKGX22rV5E7ICyzgdWuGjg/s1600/02-semantic-diff.PNG" alt="Semantic diff"/></a></div>
<h2>Merging</h2>
<p>To create the actual conflict, I used two branches: <samp>task001</samp> where I was doing the refactor/reorganization of the file, <samp>master</samp> where I just modified the methods.</p>
<p>Then, I checked out <samp>master</samp> and merged from <samp>task001</samp>:
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMu1PyxgEUcWdmLKKV8aIEFgOnePtOjPT4xmgmJzUC08s6Blyd2Bn8OGK_uYQvu2JJ-P0qCH80LyMbaxF9PNcATXwuu5Y0bEj4G2Z_h2aPFdTbjn7y6hRJx7YxY1idnAOdvs31xkHXLpE/s1600/03-running-git-merge.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMu1PyxgEUcWdmLKKV8aIEFgOnePtOjPT4xmgmJzUC08s6Blyd2Bn8OGK_uYQvu2JJ-P0qCH80LyMbaxF9PNcATXwuu5Y0bEj4G2Z_h2aPFdTbjn7y6hRJx7YxY1idnAOdvs31xkHXLpE/s1600/03-running-git-merge.png" alt="Running git merge"/></a></div>
<p>And, as expected, Git detects a conflict on <code class="file">MemoryPool.cs</code>.</p>
<p>Solving it with SemanticMerge will be simpler than it seems. Just run git mergetool (provided you configured Git to use SemanticMerge as its merge tool, which is quite simple to achieve (see <a href="https://youtu.be/VAyBaDpIkFk" target="_blank">how to make it</a>).</p>
<p>The key issue you face when trying to merge code that has been moved is that traditional merge tools are not "code aware". They don't parse the code, and as such they just try to match lines that are close. But, that fails when the methods are reordered like in this case.</p>
<p>Since SemanticMerge parses the code first, it "knows" where methods are, and calculates the conflicts on a method by method basis (or function per function, property by property, and so on, depending on the actual language):</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZrustqxcNtg4upEBi4ZxuwslDgK6lSR9ys1aJWesUgu3Fy1mBSU9ybS7pyK6KomCP9qbC_0zwFy3Qu2iNCVwqAd_LKNYAxoJ_Cr2KBDVCPYWvY1rJAew09MKqZRPKj_4XswlN0AQ0_Tw/s1600/04-mergetool-explained.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZrustqxcNtg4upEBi4ZxuwslDgK6lSR9ys1aJWesUgu3Fy1mBSU9ybS7pyK6KomCP9qbC_0zwFy3Qu2iNCVwqAd_LKNYAxoJ_Cr2KBDVCPYWvY1rJAew09MKqZRPKj_4XswlN0AQ0_Tw/s1600/04-mergetool-explained.png" alt="Merge tool explained"/></a></div>
<p>I added red circles to the screenshot to highlight some interesting points:</p>
<ul>
<li>There are only 2 conflicts to solve. Remember, only 2 methods were changed.</li>
<li>The tool starts with the first conflict, <code>Dispose()</code> in this case. Check how the 3 versions involved are aligned on the <code>Dispose()</code> method. I mean, check the line numbers. Remember <code>Dispose()</code> was moved up and changed, and modified in the original location by the other developer. SemanticMerge detects the conflict, but also shows it in a way that is easy to understand. Traditional "line sync" is broken to sync on actual methods.
<li>Finally, check line <samp>177</samp> on the left and <samp>72</samp> on the right. These are the actual changes made to the method.</li>
</ul>
<p>You also see the <strong>C</strong> and <strong>M</strong> icons on the method declarations. There are dropdowns there to let you run the merge of the <code>Dispose()</code> method. It will be an automatic merge since the lines are not colliding.</p>
<p>And, the same will happen for the <code>Return()</code> method that was moved down.</p>
<h2>Wrapping up</h2>
<p>Git does a great job calculating the 3 contributors (base, yours and theirs) involved on each file merge. It implements merge tracking to do that, it calculates the common ancestor and then asks an external tool to handle the job when there are manual conflicts (conflicts its algorithm can't figure out without manual intervention).</p>
<p>By plugin Semantic to Git, you extend the "merge power" you are used to inside the files. And since <strong>location dependent</strong> conflicts are no longer a conflict, cleaning up code and reordering methods are not the root of all merge evil anymore.</p>
<p><em>But all of this works just "inside" the same file. What we really need is a merge tool that tracks moved code across files!</em> - I hear you say. Yep, that's correct, but we need to develop our custom merge driver for Git to do that. Something we will definitely do, so stay tuned.</p>
<p>If you want to download the tool and give it a try, just go to <a href="http://www.semanticmerge.com" target="_blank">www.semanticmerge.com</a>.</p>
<h2>Bonus track</h2>
<p>If you found this blogpost interesting, you might want to watch the tool in action. You can see the same scenario described above here:</p>
<center><iframe width="640" height="480" src="https://www.youtube.com/embed/pAR8nHS6Pl8" frameborder="0" allowfullscreen></iframe></center>Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-41705312479250802542014-05-23T08:59:00.000-07:002016-07-13T13:56:28.209-07:00New release SemanticMerge 1.0.65 is out<p>This is just a minor release after the changes released in <a href="http://blog.semanticmerge.com/2014/05/skip-format-conflicts-with-new.html">1.0.64</a> and solves a few customer requests.</p>
<p>There are 3 new tasks being merged in 1.0.65 which are:</p>
<a name='more'></a>
<ul>
<li>New feature: Semantic diff now allows you to modify the destination file. This closes <a href="http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/5677495-edit" target="_blank">this UserVoice request</a></li>
<li>New feature: the diff viewer inside SemanticMerge is now updated automatically when selecting different changes. This closes <a href="http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/5824281-option-to-update-diff-window-automatically-when-se" target="_blank">this UserVoice request</a>.</li>
<li>We've improved the parser for the C language to detect correctly the end text of the container declarations with different end of lines.</li>
</ul>Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-75718457459398920882014-05-16T00:50:00.002-07:002016-07-13T14:07:16.964-07:00Skip format conflicts with the new SemanticMerge 1.0.64<p>We switched to the latest open-source Roslyn <a href="http://blog.semanticmerge.com/2014/04/new-semanticmerge-1061-is-out.html">in the previous release</a> and now we’re adding more features based on that.</p>
<p>This new release includes 2 major features:</p>
<ol>
<li><strong>Automatic method body merge resolution</strong> with the <code>--merge-decl</code> param: so far if a method (or any declaration body) was modified by the two contributors, the user had to manually launch the external 3-way merge tool to solve the conflicts, even when the merge was automatic. Now the new param forces Semantic to try to solve every method body so now the merge is as automatic as possible.</li>
<li><strong>Skip code formatting conflicts</strong>: suppose two developer reformat the same method but only one of them introduces an actual change. It can be time consuming to figure out that the change was only a reformat and that nothing really changes before accepting the real change. This is exactly what the new feature does for C#. It solves 3 User Voice requests:
<ul>
<li><a href="http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/3986679-semantic-merge-needs-to-be-smarted-about-unimporta">http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/3986679-semantic-merge-needs-to-be-smarted-about-unimporta</a></li>
<li><a href="http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/4124571-ignore-whitespace-around-curly-braces">http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/4124571-ignore-whitespace-around-curly-braces</a></li>
<li><a href="http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/4416982-format-code-to-every-user-s-liking-and-end-the-end">http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/4416982-format-code-to-every-user-s-liking-and-end-the-end</a></li>
</ul>
</li>
</ol>
<div class="alert">
<strong>Remark:</strong> If you want the advanced feature related to the ignored format available for .net languages, you should download the Microsoft Build Tools 2013: <a href="http://www.microsoft.com/en-us/download/details.aspx?id=40760">http://www.microsoft.com/en-us/download/details.aspx?id=40760</a>
</div>
<a name='more'></a>
<h2>Automatic resolution of conflicts inside methods*</h2>
<p>(*Methods or any other declaration body).</p>
<p>Consider the following scenario:</p>>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_f6iYiYQzbjMSjW106N-0LDwLHvPcxw_r01_6HP6I4sZMdYSVB3_VceeFh_vTUjwkVJike9zoQejIjn2Cg23YsBpro53o77DF28V388ZtrwDBGUi_FcSoQXRmNt-FCv_MljV63rR2L9Q/s1600/automergedeclarations.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_f6iYiYQzbjMSjW106N-0LDwLHvPcxw_r01_6HP6I4sZMdYSVB3_VceeFh_vTUjwkVJike9zoQejIjn2Cg23YsBpro53o77DF28V388ZtrwDBGUi_FcSoQXRmNt-FCv_MljV63rR2L9Q/s1600/automergedeclarations.png" /></a>
<p>Where the method “CheckParentsFromDstMergeLink()” was:</p>
<ul>
<li>moved to a different location by the first developer and also modified (that’s why the icon is ‘c’ and ‘m’ (changed and moved)).</li>
<li>changed by the second developer.</li>
</ul>
<p>And the changes were as follows:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWUgI5siIUsiV84tjqdFdzfa2rdbNvh2RPL6cX3hI1g4zA6Ckq71ffdShe6yau-5JKAfAiWwXwCS9KSQuhc4lebmXlTxU96hpkgNDI30YiAooHu9t-DAju4kHFfRdTSpKT0BIX8uQXp04/s1600/automerge-text-merge.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWUgI5siIUsiV84tjqdFdzfa2rdbNvh2RPL6cX3hI1g4zA6Ckq71ffdShe6yau-5JKAfAiWwXwCS9KSQuhc4lebmXlTxU96hpkgNDI30YiAooHu9t-DAju4kHFfRdTSpKT0BIX8uQXp04/s1600/automerge-text-merge.png" /></a>
<p>Since the changes were made on non-colliding lines, the merge can be fully automatic.</p>
<p>Adding the new param <code>--merge-decl</code> (which stands for merge declarations) Semantic will still show up showing the method conflict as solved:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWslADjw7IbH1JSd-kKAYfZdcIgCX-i7eCev-fWud4NWk1KSaeRQLwUXHREc0p3a4sQMntsu25inIATExuT1q6V3Z2r22PZXRdL35INhjigizxsqTGa-DxSvSMg5cLvXvASGVzrfJuXgQ/s1600/mergewith--merge-dec.PNG" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWslADjw7IbH1JSd-kKAYfZdcIgCX-i7eCev-fWud4NWk1KSaeRQLwUXHREc0p3a4sQMntsu25inIATExuT1q6V3Z2r22PZXRdL35INhjigizxsqTGa-DxSvSMg5cLvXvASGVzrfJuXgQ/s1600/mergewith--merge-dec.PNG" /></a>
<p>If you also add <code>-a</code> (which stands for ‘automatic’) the GUI won’t be launched and the result file will be directly created (for files with conflicts that can be automatically solved).</p>
<h2>Skip code formatting conflicts</h2>
<p>This is the most important feature we have introduced in the last months: it really takes advantage of ‘understanding’ the underlying code structure to automatically solve as many conflicts as possible.</p>
<p>Suppose you’ve a method like this one:</p>>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8d8by2n73OIDRKwYmfx7ttm6CR6V__f9dxcnXt0mA3D3gbDEopFkgcQdG0OJcTNQgDthLdHxQscuE3XdLvoEprp3S-z6JzRaOvLzpKv3CNvJ1NER05KlOO47wqYAYI_ENKiLR6tVl0jg/s1600/format-aware-basecode.PNG" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8d8by2n73OIDRKwYmfx7ttm6CR6V__f9dxcnXt0mA3D3gbDEopFkgcQdG0OJcTNQgDthLdHxQscuE3XdLvoEprp3S-z6JzRaOvLzpKv3CNvJ1NER05KlOO47wqYAYI_ENKiLR6tVl0jg/s1600/format-aware-basecode.PNG" /></a>
<p>Then one of the developers starts working and moves the method to a different location within the class (like in the previous example). But he also makes some changes to the code:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWpTD7otjNUyDoOV2QZ7fcm_aQY0Ev-gddXaWUN09jYTDoFGeja_YeeCiiECqmsG7ZWvgSmwVp3K-TvBw6Xaj72JbddVuZrzCmSmJGy4nF1lGxf3Ww3406qCRl4P-PZQ1q5r-sAcANMYk/s1600/format-aware-srccode-final.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWpTD7otjNUyDoOV2QZ7fcm_aQY0Ev-gddXaWUN09jYTDoFGeja_YeeCiiECqmsG7ZWvgSmwVp3K-TvBw6Xaj72JbddVuZrzCmSmJGy4nF1lGxf3Ww3406qCRl4P-PZQ1q5r-sAcANMYk/s1600/format-aware-srccode-final.png" /></a>
<p>Meanwhile a second developer makes some changes to the same method too:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUYb0oOIrzKqjkL4uF4oDSONI1AaCtulqI5ELmErBmZWZxlNXiN_uZ6Q_Cx1s4OSAR4795l0BvDBQpKVh0O8hIo2CtLOmcOS_qL8UVaET-lgyxfiP04sUeDJnndw-GkFXMbmtAtenzsJ8/s1600/format-aware-dstcode-final.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUYb0oOIrzKqjkL4uF4oDSONI1AaCtulqI5ELmErBmZWZxlNXiN_uZ6Q_Cx1s4OSAR4795l0BvDBQpKVh0O8hIo2CtLOmcOS_qL8UVaET-lgyxfiP04sUeDJnndw-GkFXMbmtAtenzsJ8/s1600/format-aware-dstcode-final.png" /></a>
<p>As you can see they both made a non-colliding change which is adding more log on different locations, but then there’s a colliding change: the two modified the method declaration: one added a new param while the other reformatted it. While easy to handle for a human, every 3-way merge tool will end up with a conflict because it can’t decide what to do:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf0FjQsZEAoqMrBVdWBF4Yayjh6mmwuwa0WzGOmKd6uXUrS0DrtQsYn2eccJIgXefeiFLo7GMr4d6TKCG7SOSzqfyhTa5dP2lRyXgwnd7AevujYSvya_VvrzAxWOx8AiVrIDXPUZxFadk/s1600/text-conflict.PNG" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf0FjQsZEAoqMrBVdWBF4Yayjh6mmwuwa0WzGOmKd6uXUrS0DrtQsYn2eccJIgXefeiFLo7GMr4d6TKCG7SOSzqfyhTa5dP2lRyXgwnd7AevujYSvya_VvrzAxWOx8AiVrIDXPUZxFadk/s1600/text-conflict.PNG" /></a>
<p>But Semantic, with the --merge-decl argument is able to automatically solve the conflict as follows:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjUdezIft8ODskoIue9c5Ul2n-vK3hh5Wv_C1ECGE3GFbH9BeP5zOH0ygpCzyS3D_f8M62KwVvxgPkhOU2muMzK_jhXri5g6bgq8Xd8k6DlAUmljMtIUFaN8zJQMBSnmrCohGvyDpCdEM/s1600/auto-resolution.PNG" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjUdezIft8ODskoIue9c5Ul2n-vK3hh5Wv_C1ECGE3GFbH9BeP5zOH0ygpCzyS3D_f8M62KwVvxgPkhOU2muMzK_jhXri5g6bgq8Xd8k6DlAUmljMtIUFaN8zJQMBSnmrCohGvyDpCdEM/s1600/auto-resolution.PNG" /></a>
<p>Semantic basically knows the ‘reformat’ change can be discarded and then re-runs the text merge.</p>
<h2>Next steps – improving ‘ignore reformat heuristics’</h2>
<p>Well, ignoring format changes during merge (or diff) can greatly help saving precious time without being distracted by trivial changes.</p>
<p>That being said, code formatting is crucial for readability, so there will be many situations where you’ll want to preserve the formatting.</p>
<p>In the case above Semantic made a decision: since undoing a format change avoids a time consuming (ok, not so time consuming this time, but you get the point) conflict resolution, Semantic will just undo the change to simplify the merge.</p>
<p>Our goal is to make Semantic smart enough to avoid only the minimum number of reformats, so that the code preserves the preferences of the author.</p>
<p>While it is still definitely work in progress, we’re happy to say that Semantic is able to do things beyond what any other diff or merge tool can!</p>
<p>Enjoy!</p>
<br />
<a href="http://www.plasticscm.com/company/team.html">The SemanticMerge team</a><br />
<br />Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-12543197657770299762014-04-25T01:18:00.000-07:002016-07-13T14:08:48.856-07:00New SemanticMerge 1.0.61 is out<p>We have just released a new version of SemanticMerge, full of interesting improvements.</p>
<p>The two main ones are:</p>
<ul>
<li>Semantic is now based in the newest Roslyn (<a href="http://roslyn.codeplex.com">the new open sourced version Microsoft just released</a>) which means: Semantic now supports C# 5! :-) Also, Semantic now requires .NET 4.5 to run on Windows. The added C# 5 support closes one of the <a href="http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/4318628-c-5-support">top UserVoice requests</a>.</li>
<li>Now Semantic is able to skip differences where only EOLs and indentation changed. Look at the following example:</li>
</ul>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjldoSEFjJuhkvsysKGxpYqOI1v-k4HDfLrMuJ3ecBVuTum6ZFiBnBbU7n9dQe71mc2U8mG_4G_9gex6QQy6Z_wFjvN5GLRQfad_6yTsOFp6OtEi4QZAvo6k4NG6VEHAiO85joda9IBBYE/s1600/ignoreeolsandindentations.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjldoSEFjJuhkvsysKGxpYqOI1v-k4HDfLrMuJ3ecBVuTum6ZFiBnBbU7n9dQe71mc2U8mG_4G_9gex6QQy6Z_wFjvN5GLRQfad_6yTsOFp6OtEi4QZAvo6k4NG6VEHAiO85joda9IBBYE/s1600/ignoreeolsandindentations.PNG" /></a>
<a name='more'></a>
<p>While indentation was modified, no other real changes were made, so Semantic will ignore the change. This will happen by default unless the user specifies the --include-format-change argument.</p>
<p>We also closed another top User Voice request: <a href="http://plasticscm.uservoice.com/forums/196398--mergebegins/suggestions/3911755-ignore-blank-lines">ignore blank lines between methods</a>. Together with the EOL and indentation we can also skip the blank lines between methods now.</p>
<h2>Additionally</h2>
<p>A few more changes included in 1.0.61:</p>
<ul>
<li>Bug fixed: now the log file is placed at ~/.semanticmerge when running on Linux. Previously the user didn't have write access to the directory where SemanticMerge was trying to place the log file.</li>
<li>Bug fixed: Fix crash when running SemanticMerge without arguments under Debian/Ubuntu.</li>
<li>New: C language is now supported on OpenSuSE, Debian >= 7 and Ubuntu distributions.</li>
</ul>
<p>Enjoy!</p>
<p>The SemanticMerge Team - <a href="http://www.plasticscm.com/company/team.html">http://www.plasticscm.com/company/team.html</a></p>
Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-69117775628011578872014-03-24T08:29:00.000-07:002016-07-13T14:09:44.229-07:00Dissecting SemanticMerge, Part 4: Cocoa 101 for WinForms/WPF developers<p>Ever thought about writing a Mac GUI in C#?</p>
<p>You’re probably used to Buttons, Panels, Dialogs and the like, but how do they map to the Mac counterparts?</p>
<p>Well, this is what we try to cover in this post: a Cocoa 101 for WinForms developers.</p>
<a name='more'></a>
<h2>Background</h2>
<p>Mac development is a new world for a Windows developer. New tools, new subsystems, new OS, new languages...</p>
<p>We wanted to develop a Mac native UI for SemanticMerge and then we faced some decisions: stay in C#? Move to Objective-C? Get used to the Interface Builder or ignore it?</p>
<p>Since other teams might be facing a similar situation we thought it would be good to dissect our SemanticMerge GUI and use it to explain some Mac GUI development essentials.</p>
<p>Before entering the Cocoa 101 we had to decide whether we should go for <a href="http://blog.semanticmerge.com/2014/03/learning-mac-devel-in-c-by-dissecting.html">Objective-C or not and whether we should go for a native UI or try something like Qt</a>.</p>
<p>In a previous post we also covered <a href="http://blog.semanticmerge.com/2014/03/dissecting-semanticmerge-part-2-enter.html">some MonoMac basics</a> and then one interesting topic: should you use the <a href="http://blog.semanticmerge.com/2014/03/gui-development-design-or-code-imperative.html">Interface Builder or go hard-core and code the entire GUI</a>?</p>
<h2>Welcome to Cocoa</h2>
<p>You start and write your first “hello world” in Xamarin Studio but then you’ve to figure out how to really structure your app. And then is when worlds collide.</p>
<p>As Windows developers we were used to Buttons, Forms, Panels, Splitters and all but… that’s not the same thing when you get to Xamarin.Mac. You’ve to get used to the Cocoa and a new set of controls.</p>
<p>As I mentioned first, this is what I’m going to do by dissecting our SemanticMerge application. And for the sake of simplicity, I’ll start with a simple dialog, the start up window:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJN3gN3nTXVmT-sBlbo5EqLGsvEsrgpVQ14RAvPZzE3hyphenhypheneI8qKCGi6C0W15QdupxSsL58HZCNySsMzB56yM_maN9sCirBhCiceyQF1AiCFDsNTkwafJ4RD7ojmUiSY_HPRb645nW_m3K0/s1600/semanticmerge-launcher.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJN3gN3nTXVmT-sBlbo5EqLGsvEsrgpVQ14RAvPZzE3hyphenhypheneI8qKCGi6C0W15QdupxSsL58HZCNySsMzB56yM_maN9sCirBhCiceyQF1AiCFDsNTkwafJ4RD7ojmUiSY_HPRb645nW_m3K0/s1600/semanticmerge-launcher.png" /></a>
<p>And let’s now go and dissect it:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJwuFLrnOy2R0V-XnhhWmrK38slnDqWlqOdS_VtbnjF8x7SPFn_TJ7biPkAUOVc4cT2UtrptsHqgKzIz2U0fui0VhJ4UPM-awFUwiWlK3mswCnHZGc-1syJlPRUJHtzPXqusJNJWEdC90/s1600/launcher-dissected.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJwuFLrnOy2R0V-XnhhWmrK38slnDqWlqOdS_VtbnjF8x7SPFn_TJ7biPkAUOVc4cT2UtrptsHqgKzIz2U0fui0VhJ4UPM-awFUwiWlK3mswCnHZGc-1syJlPRUJHtzPXqusJNJWEdC90/s1600/launcher-dissected.png" /></a>
<p>The picture shows all the controls we use in this simple dialog and I think it is a good way to get familiar with Cocoa if you come from a Windows background.</p>
<p>Let me share thoughts on the picture above:</p>
<ul>
<li>The Window has a ContentView which is the one you’ll use to place more controls inside. The ContentView is an NSView.</li>
<li>The NSBoxes are somehow similar to Panels in WinForms. You can use them to contain other controls.</li>
<li>Buttons: all buttons in Cocoa will be of type NSButton, but then you’ll set properties to it depending on the style of the button you want to use.</li>
<li>Something similar happens with NSTextField: you can use a TextField as a WinForms TextBox, but you can also configure it to be like a Label. In the picture I defined the ‘edit boxes’ as NSTextFields with “Editable = true” and “Bordered = true”.</li>
</ul>
<h2>Alignment with Constraints</h2>
<p>Once you meet a few controls is time to know how to align them. You can always just place them in the Window ContentView with global coordinates, but it won’t help if you need your NSBoxes to grow with the window, or your buttons to keep aligned to the right.</p>
<p>While we were all familiar with Anchors in WinForms, to code UIs in Mac we need to learn the Constraints.</p>
<p>Constraints are the set of rules you use to define where each control is located, aligned and so on.</p>
<p>The ‘language’ to define constrains can be intimidating at first, but it is really easy to learn and very powerful.</p>
<p>I’ll first explain how constraints are defined and later I’ll cover how to code it in C#.</p>
<p>Let’s start with a very simple scenario: just a window with two buttons as the figure shows:</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjet-tI0YR-OQdwRdUwD1ewMSyVZCiPNMqacoKwKN8c3ygMh-T3fSoDvP1K7jx_Xt3LA21kZB6kyQsDnM6ZhsdklYKZdxF9W6LO8FTv3f6AvnmClUO9QxhsGRxWiWQAYHjkbdbMrUn3mLE/s1600/constraints-scenario.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjet-tI0YR-OQdwRdUwD1ewMSyVZCiPNMqacoKwKN8c3ygMh-T3fSoDvP1K7jx_Xt3LA21kZB6kyQsDnM6ZhsdklYKZdxF9W6LO8FTv3f6AvnmClUO9QxhsGRxWiWQAYHjkbdbMrUn3mLE/s1600/constraints-scenario.png" /></a></div>
<p>If we don’t set the constraints correctly (step 2) then when the window grows the buttons will stay on the same position, losing the correct relative position “anchored” to the bottom right of the window.</p>
<p>In step 3 the constraints are correctly set and the buttons keep the relative position to the bottom right.</p>
<p>How do we achieve this? With the ‘magic of Mac constraint rules’.</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrUcr-O9TZCEjdsEP-v7Cin8EF9q3hKEVZOKJi8czmarQ6jYbjzjCY2zePBfHtE_1VbXVAZ_duFs_RLXLEh2D215c2B1xnVm0QijNA5cEUWY6ZPRq1yDa6GQKLcYBo64hw_wNQlnuhC10/s1600/vertical-constraints-sample.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrUcr-O9TZCEjdsEP-v7Cin8EF9q3hKEVZOKJi8czmarQ6jYbjzjCY2zePBfHtE_1VbXVAZ_duFs_RLXLEh2D215c2B1xnVm0QijNA5cEUWY6ZPRq1yDa6GQKLcYBo64hw_wNQlnuhC10/s1600/vertical-constraints-sample.png" /></a></div>
<p>The rule to specify the horizontal alignment is very simple:</p>
<ul>
<li>H: stands for horizontal rule.</li>
<li>[cancel(150)] refers to the “cancel” button (later I’ll explain how do you tell the system that the button will be named ‘cancel’ when specifying contraints.
<li>-10- means you’re separating the two buttons with a “10 size” separation.
<li>[ok(150)] gives a 150 size to the “ok” button.
<li>-10- is another separator.
<li>| the last vertical bar on a horizontal constraint rule refers to the right border of the window. It is the piece of the constraint saying “keep everything aligned to the right”.
</ul>
<p>The language is easy to remember and very powerful as you can see.</p>
<p>Since we’re only specifying the “right border” it means everything will be relative to the right.</p>
<p>Notice I didn’t set a “left bar” which means the buttons will be ‘anchored’ to the right.</p>
<p>What if I edit the rule and modify it in the following way:</p>
<p><b>“H: |-10-[cancel(150)]-10-[ok]-10-|”</b></p>
<p>I have added a “left border” so basically I’m saying:</p>
<ul>
<li>The “cancel” button should be linked to the left border with a 10 points margin.</li>
<li>Then there will be another “10” separator between the buttons.</li>
<li>And the “ok” button will grow as much as it needs in order to keep a right margin of 10 with the right border.</li>
</ul>
<p>The result will be something like:</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGNAiCJtANkCGUN6pDEfTmLRkOK6-urp7LnovF0ItMyvwP0DtQCv8_uclYfY8__j3kyYWYcc4xMbLKP-xsAg5835OeOHBQnoJXoCeoGWMrUVNYBS6cQlSAup-10GjCww21CjbE4jp7Lrs/s1600/horizontalconstraints-sample2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGNAiCJtANkCGUN6pDEfTmLRkOK6-urp7LnovF0ItMyvwP0DtQCv8_uclYfY8__j3kyYWYcc4xMbLKP-xsAg5835OeOHBQnoJXoCeoGWMrUVNYBS6cQlSAup-10GjCww21CjbE4jp7Lrs/s1600/horizontalconstraints-sample2.png" /></a></div>
<p>Now that we know how to set up the horizontal constraints, the vertical ones will be really easy to figure out:</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiIPreGdZjryw2sqQ4E5RW8sn6GGBu9V36PqEyYhc8RYRVW4LMx4B6kE4TC5zYWzjpgHtcn3CULXe2EqwohnaaxWFIJF5t89LQux3w8RL9EX4Wv-t6xQutcqYoGL5JXmyk-bmCFhErUwQ/s1600/vertical-constraints-example.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiIPreGdZjryw2sqQ4E5RW8sn6GGBu9V36PqEyYhc8RYRVW4LMx4B6kE4TC5zYWzjpgHtcn3CULXe2EqwohnaaxWFIJF5t89LQux3w8RL9EX4Wv-t6xQutcqYoGL5JXmyk-bmCFhErUwQ/s1600/vertical-constraints-example.png" /></a></div>
<p>We specify 2 different rules where we set the vertical margin between the buttons and the bottom border of the window, and also the button height (or vertical size).</p>
<p>Now that we “master” the constraints, it is not hard to figure out the layout of the SemanticMerge launch window:</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgslyoaxVZxe8O-iJv73LMimIC9ETxIsm0acStyrIhTADocBWwzFGINE6Zd6lfNV6HDlamywEFN1aJ9HlPzdFSgVgKj0Iz3WpcaXOUF7eMPkII6q4vpaZ8MjMTb-e1ZyFgZZ-URzGeXB3M/s1600/contraints-launcherDialog.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgslyoaxVZxe8O-iJv73LMimIC9ETxIsm0acStyrIhTADocBWwzFGINE6Zd6lfNV6HDlamywEFN1aJ9HlPzdFSgVgKj0Iz3WpcaXOUF7eMPkII6q4vpaZ8MjMTb-e1ZyFgZZ-URzGeXB3M/s1600/contraints-launcherDialog.png" /></a></div>
<p><b>Remark</b>: you ALWAYS have to specify both the vertical and horizontal constraints. Otherwise nothing will be rendered. It happened to us :-)</p>
<h2>Defining constraints in C# and MonoMac</h2>
<p>Now that the constraint language is crystal clear ;-): how is this set on a MonoMac application?</p>
<p>Look at the following code listing which is able to create a Window like the following:</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-JOIBljHliDQTKlKpv0R-kuDEJbEstjS1lyu0DcjyXBK397dzLE-64c209PpXRNFedS_BrIzxlOzFtVItRFCuX09Cr-LuEkw4176o5t1SfAV_JHKuN3bv5CsGJ73vR800tjYZAGfVhqM/s1600/clickmesample.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-JOIBljHliDQTKlKpv0R-kuDEJbEstjS1lyu0DcjyXBK397dzLE-64c209PpXRNFedS_BrIzxlOzFtVItRFCuX09Cr-LuEkw4176o5t1SfAV_JHKuN3bv5CsGJ73vR800tjYZAGfVhqM/s1600/clickmesample.png" /></a></div>
<p></p>
<pre>
public override void AwakeFromNib ()
{
base.AwakeFromNib ();
// button created programatically
NSButton button = new NSButton();
button.Title = "Click Me";
// button added to the window
NSView contentView = Window.ContentView;
contentView.AddSubview(button);
// now we set the constraints
// nothing works if you do not specify this!!
button.TranslatesAutoresizingMaskIntoConstraints = false;
// now let's add the names of the controls
// to the constraints system so we can
// reference the controls by name in the
// constraints rules
var views = new NSMutableDictionary();
var constraints = new List<NSLayoutConstraint>();
views.Add(new NSString("button"), button);
// and here go the constraints
constraints.AddRange(
NSLayoutConstraint.FromVisualFormat(
"H:[button(150)]-10-|", 0 , null, views));
constraints.AddRange(
NSLayoutConstraint.FromVisualFormat(
"V:[button(23)]-10-|", 0, null, views));
contentView.AddConstraints(constraints.ToArray());
}
</pre>
<p>Setting the constraints in code is straightforward as you see, but simply don’t forget to:</p>
<ul>
<li>Specify horizontal and vertical constraints.</li>
<li>Set the “TranslatesAutoresizingMaskIntoConstraints” to false!</li>
</ul>
<h2>Wrapping up</h2>
<p>We’ve discussed about whether going native or use multi-platform UI toolkits, then we went through the ‘imperative vs designer based’ UI implementation alternatives and later we introduced some very common Cocoa controls.</p>
<p>Finally we dissected the “launcher dialog” in SemanticMerge to explain how constraints work.</p>
<p>Hope you find this post useful and happy Mac C# hacking.</p>
Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-18970931642987320212014-03-23T06:24:00.000-07:002016-07-13T14:10:41.851-07:00GUI development: should you design it or code it - Dissecting SemanticMerge, Part 3<p>Our question here was: "should we use the designer or code an imperative UI?</p>
<p>As <a href="http://blog.semanticmerge.com/2014/03/dissecting-semanticmerge-part-2-enter.html">you have just seen</a> using the Interface Builder is really simple, just drag and drop, getting used to the new controls and the UI of the designer and so on.</p>
<p>Xamarin Studio doesn't provide its own designer it simply relies on invoking Interface Builder, which is not bad since they’re not reinventing the wheel.</p>
<p>But, there are some concerns in my opinion:</p>
<a name='more'></a>
<p>Each time the Interface Builder modifies one of the .xib files (files containing XML defining the interfaces) Xamarin Studio gets notified and rebuilds whatever linked code it needs. It always worked for us with pet projects but I wouldn’t really like to be in the situation, 6 months after starting the project, with tons of code written, to find some sort of ‘conversion error’ when linking the .h files populated by Interface Builder with the Xamarin code. I hope I’m wrong here, but simply I don’t want to be in that situation.</p>
<p>Now, more about UI designer vs plain code: recently I read this <a href="http://blog.xamarin.com/creating-imperative-uis-in-c">blog post about creating “imperative UIs” with C#</a> in the Xamarin blog. When I found this post we already had finished the SemanticMerge UI programming in “imperative mode”.</p>
<p>There were various reasons why we went the ‘imperative way’ and we coded our entire interface completely avoiding the Interface Builder:</p>
<ul>
<li>First we wanted to avoid any potential issue with the ‘automatic conversion’ as I mentioned.</li>
<li>Prior to starting with Mac we developed a GTK# UI for SemanticMerge, to give it native look and feel on Linux. We used MonoDevelop 4 there, which is great, but its interface designer is… well, far from looking solid. So we went the ‘hardcore’ way and created the entire UI with code. It can sound like an overkill (it *did* sound crazy to me years ago) but read the next bullet point first.</li>
<li>We’ve been developing Plastic SCM (www.plasticscm.com) with a WinForms UI for almost 9 years now. We always used the Visual Studio designer and… you know what? I hate it. It looks great for a toy application, you just go and drag and drop your controls and everything looks fine. But use it for a decade and you’ll find out:</li>
<ul>
<li>That the infamous .resx will break or simply won’t get correctly updated and you will lose alignments or some event handlers from time to time. Time wasted.</li>
<li>At least the WinForms designer doesn’t enforce good practices: I hate when I find auto-generated names in controls such as Form1 or Label1 and so on. Of course you can ask your team to… not do it this way, but the tool *helps* doing it wrong.</li>
<li>Suppose you redesign a Form and then you need to move part of the UI inside a new panel and then add more things to the form… well, you’ll need to play with the “anchors”, cut and paste… and pray. BTW the entirely regenerated automatic code will be a nice thing to merge...</li>
<li>Since it is very easy to just “throw controls on the window” then probably many unneeded ones will hang around, like panels inside panels and other beauties.</li>
<li>Keep the right margin for buttons and controls in all forms… looks easy, but someone will have to hand write the margin space again and again… wouldn't a constant help?</li>
</ul>
</ul>
<p>As counter-intuitive as it might sound (tell it to my younger self coding a MFC UI and missing Delphi), for long running projects I truly believe it is better to go and code the UI: you can refactor code to make it more readable, you’ll think twice before adding a control, you’ll name everything correctly, you’ll just have to slightly modify the code to change the hierarchy of objects inside a window… and you won’t have to depend on error prone UI designers.</p>Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-90887323498019764442014-03-19T14:16:00.001-07:002016-07-13T14:11:55.484-07:00Dissecting SemanticMerge, Part 2: Enter MonoMac<p>Note: this is the second part in the Dissecting SemanticMerge series. <a href="http://blog.semanticmerge.com/2014/03/learning-mac-devel-in-c-by-dissecting.html">Part I is How we develop for Mac using C# and MonoMac</a>.
<p>So, if you’re going to write a C# “native looking” app for Mac the choice is <a href="http://www.mono-project.com/MonoMac">MonoMac</a> a.k.a. <a href="http://macapi.xamarin.com/">Xamarin.Mac</a>. It is pretty well documented and it looks solid.</p>
<p>The first thing you’ll have to do is to go and grab a <a href="http://xamarin.com/download">Xamarin Studio installer</a> and you can play with it for free before you decide to go commercial.</p>
<p>Installing is easy and then you’ll be on a very familiar environment since it feels like Visual Studio (it is the famous MonoDevelop now in Xamarin disguise, pretty polished. We’ve been using it for months and it is pretty good. Of course, MonoDevelop 4 is also solid on Linux. Having used all versions since their first release, version 4 is really a plus).</p>
<a name='more'></a>
<h2>The .xib files and the Interface Builder</h2>
<p>I strongly recommend that you go and complete one of the basic <a href="http://docs.xamarin.com/guides/mac/getting_started/hello,_mac/">Xamarin.Mac tutorials</a>. You’ll start getting familiar with objects starting with NS (NSApplicationDelegate, NSObject and many more) and then with the Interface Builder.</p>
<p>The Interface Builder is the Xcode (the native Mac IDE to develop Objective-C, developed by Apple) interface to design user interfaces.</p>
<p>Interface Builder is the typical interface designer, similar to what you’d expect as a WinForms or WPF developer.</p>
<p>You can go and drag a button (a “Push Button” in Mac jargon) to the window area and you have created your first button. You can edit its properties and change the title:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9oCJhB7Uv61zd-g6A8OSgr2GcGZZd9AvDbMjwkL4SmGKzPyhwSPGvGQi-SuFP_l81Vi1DXmt2DmQggaQKBaHxlqHQku60-UaW-3EdQTU3d06HRw6NZfK_20SVrYzSKtT44967k_9pito/s1600/interfacebuilder.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9oCJhB7Uv61zd-g6A8OSgr2GcGZZd9AvDbMjwkL4SmGKzPyhwSPGvGQi-SuFP_l81Vi1DXmt2DmQggaQKBaHxlqHQku60-UaW-3EdQTU3d06HRw6NZfK_20SVrYzSKtT44967k_9pito/s1600/interfacebuilder.PNG" /></a>
<p>Then you can drag the button to the MainWindowController.h to create an outlet or an action. This is the way in which the code will discover the button (or any other control) you have just created.</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjBtjcSCww_FF7mUfGlWfZg7bbPH9kMOGNSqI81ukq-mRNd3ImvALN4qdaooIcMI-KxUVSc_Hi8DtmI04lKYyeBJGtituvdMxeVdkomMOcsmE9t9z-AmqPOA793OReyIhevizF0eb1KAo/s1600/interfacebuilder-linking-code.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjBtjcSCww_FF7mUfGlWfZg7bbPH9kMOGNSqI81ukq-mRNd3ImvALN4qdaooIcMI-KxUVSc_Hi8DtmI04lKYyeBJGtituvdMxeVdkomMOcsmE9t9z-AmqPOA793OReyIhevizF0eb1KAo/s1600/interfacebuilder-linking-code.PNG" /></a>
<p>Once you’re done with this, you’ll be able to add an event to your code as follows:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQu_R-4tjS6fNVEmvY5SWwNBoiGNt3hZwt3gbodRjIiHpniHGD6kbXVOPLKL7BVdUlmKo9akH6w-6mOnyidwbJu3BTWm_xBhjTze0GFt6FB3msmtWuEjyVSdesIVwrDHHqaTa-DLg0nnI/s1600/awakefromnib.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQu_R-4tjS6fNVEmvY5SWwNBoiGNt3hZwt3gbodRjIiHpniHGD6kbXVOPLKL7BVdUlmKo9akH6w-6mOnyidwbJu3BTWm_xBhjTze0GFt6FB3msmtWuEjyVSdesIVwrDHHqaTa-DLg0nnI/s1600/awakefromnib.PNG" /></a>
<p>Just notice I’m overriding the AwakeFromNib method which is like the “Load” method in WinForms applications. It is invoked just when the window is activated.</p>
<p>You can learn more about this following the Xamarin tutorials, so I’ll just continue focusing on what’s not in the tutorials :-)</p>
Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-55654804776857961742014-03-18T06:48:00.000-07:002016-07-13T14:13:35.305-07:00Dissecting SemanticMerge, Part 1: how we develop for Mac using C# and MonoMac<p>Objective-C is the language of choice when you go for Mac (and iPhone) but thanks to <a href="www.xamarin.com">Xamarin</a> now more than half a million C# developers are able to code for Apple platforms in their language of choice. And this is something good if you’re a Windows developer who need to develop a new app on Mac.</p>
<p>I’m going to share the things we learned while developing <a href="http://www.semanticmerge.com">SemanticMerge</a> for Mac using C# and MonoMac, and I’d like these posts to be the sort of writing I wish we had when we started our journey :-). This is the part one of a series of posts dissecting SemanticMerge to explain how we develop with C# and Mac</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-uSt9Y3QRA3sP3posEj-8tXKrb2IunAFbHKnU5mAa8Q1Bb-iSGLLuziarcjlxTH6pHqQvaEmLUSyKDn2vLcnI7dxwb1-wJh61MoH_MEQt2qvYxK964NVawm8gnCVQJ5yrQ50Zv2qScew/s1600/macos-02-semanticwindow.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-uSt9Y3QRA3sP3posEj-8tXKrb2IunAFbHKnU5mAa8Q1Bb-iSGLLuziarcjlxTH6pHqQvaEmLUSyKDn2vLcnI7dxwb1-wJh61MoH_MEQt2qvYxK964NVawm8gnCVQJ5yrQ50Zv2qScew/s1600/macos-02-semanticwindow.PNG" /></a>
<a name='more'></a>
<h2>To Objective-C or not to Objective-C</h2>
<p>The obvious choice when going to develop a Mac app is going for Objective-C. It is the native language so there’s no better choice.</p>
<p>That being said, there are some situations when you might consider sticking to C#:</p>
<ul>
<li>Your app will be based on an extensive codebase written in C#. When that’s the case, rewriting in Objective-C or making it interop somehow can be time consuming.</li>
<li>The deadlines are tight (aren’t they always? :P) and getting proficient with Objective-C is not an option.</li>
</ul>
<p>While I think the first reason is pretty acceptable, I’m afraid the second one can be a dangerous excuse for a real world application. Let me elaborate a little bit further: you’ll need to learn the foundations of the Mac environment in order to develop a professional app (I mean, anything that is not just a demo).</p>
<ul>
<li>You’ll have to read Objective-C code since it is the main source of documentation and unfortunately there’s not so much info in C#.</li>
<li>You’ll have to get familiar with the Cocoa objects to build your app anyway.</li>
</ul>
<p>I hope we can help reducing the learning curve with these posts :-)</p>
<h2>Native toolkits</h2>
<p>Once you’ve decided C# is the right choice (otherwise you’d be reading Objective-C guides already :P) you’ll probably wonder if you should go for a native ‘window toolkit’ or not.</p>
<p>Let me explain it in detail: “wouldn’t it be awesome to have some sort of UI toolkit where you can write your app once and run it everywhere? I mean, this is the sort of thing Mono does for .NET programs, isn’t it?” – Someone would say.</p>
<p>Well, yes and no. We’ve developed WinForms apps (<a href="http://www.plasticscm.com/gallery.html">check the Mac and Linux screenshots in our gallery</a>) for years and we have run them on Linux, Windows and Mac. You think you save time at the beginning because you have a “write once run everywhere” sort of thing. You don’t. The app looks great on Windows, but it looks alien on Mac and Linux. And users will notice immediately, specially the Mac ones.</p>
<p>So, no, don’t go for a “one size fits all” here. You’ll have to spend time writing a MonoMac app even if you already have a wonderful WPF or WinForms one.</p>
<p>“What about things like Qt then?” – I hear someone crying – Well, yes, Qt is cool if you’re a C++ developer, but the C# wrappers, while they’ve been around for ages, seem to lack solid documentation and evolution.</p>
<h2>Conclusion</h2>
<p>We decided to go with C# and MonoMac because we were very familiar with the language (we love C#, we’d love C# for system programming even more :P) and we had to reuse most of our codebase.</p>
<p>We also used the development of Semantic in C# and MonoMac as an experiment (or pilot project if you prefer) before porting the entire Plastic SCM GUI to Mac.</p>Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com1tag:blogger.com,1999:blog-5381144043654452808.post-19659972177113882602014-02-19T10:11:00.000-08:002016-07-13T14:14:44.060-07:00SemanticMerge for Mac is here<p>Finally! We are ready to share the Mac version with you!</p>
<p>If you’re eager to put your hands on it, <a href="http://www.semanticmerge.com/merge-diff-tool-mac.html">sign up here</a> and we’ll contact you ASAP. The beta is not yet 100% public, that’s why we’re asking you to sign up, so we can create a group of people willing to send us valuable usability feedback (among other).</p>
<p>Check how the new version looks like here:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNY-lSDjh3wT4N6ekG-jheKQOYLACOSWmp3TLTMKzrnIGvkH50_Jlpq8aEswkGWke-69qJDq1XyQ_NdOxXoGGwh7JxCX52GXFHZlA70vPfMj6FT7OQPyiCEHpp4eNU7V2WGPsqL_ZjnAg/s1600/macos-03-visualdiff.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNY-lSDjh3wT4N6ekG-jheKQOYLACOSWmp3TLTMKzrnIGvkH50_Jlpq8aEswkGWke-69qJDq1XyQ_NdOxXoGGwh7JxCX52GXFHZlA70vPfMj6FT7OQPyiCEHpp4eNU7V2WGPsqL_ZjnAg/s1600/macos-03-visualdiff.PNG" /></a>
<p></p>
<p>As you can see the Mac version includes the “visual merge” which is the piece which really simplifies understanding the complex merges.</p>
<a name='more'></a>
<h2>Supported languages - .Net, Java and C</h2>
<p>The Mac version supports semantic merging for C# and Vb.net, Java and also C, which is the new language we have just added to the list.</p>
<p>The C language support took a while since there are many situations where it is not trivial to parse the code without considering the include files. We tried to avoid using the include files because it would make the configuration of the tool more complex and time consuming and project dependent. We don’t discard adding this configuration capabilities in the near future but so far we were able to correctly parse good amounts of code without extra config needs (99.32% of the Linux kernel code).</p>
<p>We rely on the libclang library to do the parsing and it is the same library we will be using for Objective-C and hopefully C++.</p>
<h2>Supported platforms</h2>
<p>Now we support Windows, Linux and Mac.</p>
<h2>Starting up the tool</h2>
<p>Once you get the binaries (sign up first - (http://www.semanticmerge.com/merge-diff-tool-mac.html)) you’ll install it as a regular Mac application. Remember to unzip it first.</p>
<p>Then you’ll be able to start the app from Finder and by default you’ll see something as follows:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNGRxaQmhqhfyCFogozf4IFehLrzHlPtvZZDiuRNVlpbw9DTeDncsaOttRLHBHgElu2s2-N3Vv9WoA48-xZqnfTdC6aWqvKZ9NtyUMubHyCWi5wV9qX14k8AJ2aHXCK5quDQMz995WDRQ/s1600/macos-00-mainscreen.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNGRxaQmhqhfyCFogozf4IFehLrzHlPtvZZDiuRNVlpbw9DTeDncsaOttRLHBHgElu2s2-N3Vv9WoA48-xZqnfTdC6aWqvKZ9NtyUMubHyCWi5wV9qX14k8AJ2aHXCK5quDQMz995WDRQ/s1600/macos-00-mainscreen.PNG" /></a>
<p>From this window you can launch a merge choosing the contributors or explore the examples to get more familiar with the tool. Here you have a screenshot of the examples browser:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaPwBkWAzzdHolfytPjKKvCiZI24oAvOIyfNCBki6xZOfcmxv2z-dJFCuOy7o7hyckfu-yR1CXSrxSa0EY8fDNzR7P1iHc2DvgQCJokqigzcNPGCJuUWWq46z5gnqcdPim_9X_QcEsyjU/s1600/macos-01-samples.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaPwBkWAzzdHolfytPjKKvCiZI24oAvOIyfNCBki6xZOfcmxv2z-dJFCuOy7o7hyckfu-yR1CXSrxSa0EY8fDNzR7P1iHc2DvgQCJokqigzcNPGCJuUWWq46z5gnqcdPim_9X_QcEsyjU/s1600/macos-01-samples.PNG" /></a>
<p>My favorite is the”Socket_Deeper” simple in C# and Java, but we’ve added more samples in C.</p>
<p>This way of launching Semantic won’t be the usual one as soon as you integrate it with your favorite version control: normally you’ll invoke it from the command line, in fact, it will be invoked by your version control to resolve a given conflict. Notes on how to set it up on different <a href="http://www.semanticmerge.com/sm-guides/main.shtml">version controls here</a>.</p>
<h2>Up and running</h2>
<p>Here is the aspect of the Mac version running:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIUNYlECzuH3AZzFjkf9JGtAxDWFpk7BphMg8yuHXYVqVP1V7WEwmmdfPzWqAD-dr17MV4_xWrzwEH06ZTMXZSdeIJBTNz5cG-3nHB-Q4-GyQ7gaE7IW3KFWQWbpOfF8f9R-JOCT7yx98/s1600/macos-02-semanticwindow.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIUNYlECzuH3AZzFjkf9JGtAxDWFpk7BphMg8yuHXYVqVP1V7WEwmmdfPzWqAD-dr17MV4_xWrzwEH06ZTMXZSdeIJBTNz5cG-3nHB-Q4-GyQ7gaE7IW3KFWQWbpOfF8f9R-JOCT7yx98/s1600/macos-02-semanticwindow.PNG" /></a>
<p>And now here goes the “Socket_Deeper” simple, rendered by “visual merge” in Mac :-) As you can see the “Listen()” method has been refactored and moved and modified concurrently to two different subclasses… something crazy for other tools but easy for Semantic.</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNY-lSDjh3wT4N6ekG-jheKQOYLACOSWmp3TLTMKzrnIGvkH50_Jlpq8aEswkGWke-69qJDq1XyQ_NdOxXoGGwh7JxCX52GXFHZlA70vPfMj6FT7OQPyiCEHpp4eNU7V2WGPsqL_ZjnAg/s1600/macos-03-visualdiff.PNG" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNY-lSDjh3wT4N6ekG-jheKQOYLACOSWmp3TLTMKzrnIGvkH50_Jlpq8aEswkGWke-69qJDq1XyQ_NdOxXoGGwh7JxCX52GXFHZlA70vPfMj6FT7OQPyiCEHpp4eNU7V2WGPsqL_ZjnAg/s1600/macos-03-visualdiff.PNG" /></a>
<h2>Configuring an external diff tool</h2>
<p>SemanticMerge i sable to solve conflicts by parsing the code. But when a given method conflicts you have to merge the bodies of the methods and Semantic relies on an external 3-way text-based merge tool. On Windows we include our <a href="http://www.plasticscm.com/features/xmerge.aspx">own Xmerge tool</a> but on Mac we still don’t have a native one, so you’ll have to setup your current diff tool to deal with the conflicts within text blocks.</p>
<p>In my case I’ll be configuring Kdiff3. In order to do that I’ll create a $HOME/.semanticmerge/semanticmergetool.conf with the following content:</p>
<pre>
-edt=/Applications/kdiff3.app/Contents/MacOS/kdiff3 \
"#sourcefile" "#destinationfile""
-emt=/Applications/kdiff3.app/Contents/MacOS/kdiff3 \
-b "#basefile" "#sourcefile" "#destinationfile" \
--L1 "#basesymbolic" --L2 "#sourcesymbolic" \
--L3 "#destinationsymbolic" -o "#output"
</pre>
<p><b>Note:</b>I split the lines for readability but remember everything should go on two lines, one for -emt, one for -edt, and removing the \ I used to split lines.</p>
<p>And now you’ll have support to merge method body conflicts with KDiff3. <a href="http://www.semanticmerge.com/sm-guides/main.shtml">Check the user guide</a> to find more help (like how to configure KDiff3 to solve 2-way merge conflicts inside semantic blocks) or to configure other tools.</p>
<h2>What is next?</h2>
<p>Well, we’ve a lot of work to do:</p>
<ul>
<li>Develop the diff tool (right now only merge tool, which is like the difficult part but SemanticDiff is very useful too, like the one we have for Windows).</li>
<li>Objective-C support – which is like a must for Mac coders.</li>
<li>Improve usability and “mac flavor” – by listening to you! SO please send us all the feedback to sm@codicesoftware.com.</li>
</ul>
<p>Please <a href="http://www.semanticmerge.com/merge-diff-tool-mac.html">do not forget to sign up</a> and thanks for your help!</p>Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0tag:blogger.com,1999:blog-5381144043654452808.post-60353239254323147792014-02-06T06:50:00.001-08:002016-07-13T14:15:13.503-07:00What most developers don't know about refactoring<p>Say “refactor” to a corporate executive and he will say, “talk to me about business”. What he doesn’t realize is that refactoring is more about business than it is about code. It is all about keeping the cost of change low, being able to react fast to customer requests, being able to focus on adding value to the product... Put it this way and you’ll catch the exec’s attention.</p>
<a name='more'></a>
<h2>Refactor and the cost of change</h2>
<p>“Make a change in the software during the production phase and it will cost you a fortune compared to a change made during the analysis or design phases”. Ever heard that? Boehm wrote it in Software Economics back in the 80’s. Heavily tied to the “waterfall lifecycle” way of thinking it was the mantra used to train generations of software engineers all around the globe.</p>
<p>When you blindly believe this you feel fine when things go wrong later in the lifecycle and believe it to not be your fault.</p>
<p>“They should have asked for it before” Sound familiar?</p>
<p>“Unfortunately” Kent Beck and the entire “agile movement” is all about changing the infamous curve: take care of your code and you will not only be a clean coder, you won’t spend hours blaming the codebase... and the cost of introducing new changes won’t grow exponentially.</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4o8XIEzM0TXfVO-q_bduBuibjpcnghUTHqWtjVUB4q-Kqr_G4Jm0hZPR6wmp8el1aUa8VOisU4_QTfJJDhojB0_uD5bGcPVjL73xoaKFNQRUGFbABzIVQmsKxkSUJ4XmO3476fawIB_U/s1600/costofchange-boehmvsbeck.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4o8XIEzM0TXfVO-q_bduBuibjpcnghUTHqWtjVUB4q-Kqr_G4Jm0hZPR6wmp8el1aUa8VOisU4_QTfJJDhojB0_uD5bGcPVjL73xoaKFNQRUGFbABzIVQmsKxkSUJ4XmO3476fawIB_U/s1600/costofchange-boehmvsbeck.png" /></a>
<p>The “silver bullet” behind the “agile cost of change curve” is keeping the code clean, simple, well written, easy to read, easy to extend, easy to modify… thereby making it easy to introduce changes. If you can’t prevent change… well, embrace it. Obviously it doesn’t happen by chance. You won’t arrive one day to the office and find the big mess ironed out and ready to be effortlessly modified. It takes time, it takes effort and the technique known to achieve it is known as “refactoring”.</p>
<p>"Refactoring" is defined as the operations you perform to improve your code without affecting its functionality. Rewrite a piece of code making it simpler and more readable… after that the new features will simply flow.</p>
<p>When you spend time refactoring you’re not adding ‘value’ to the product but rather ‘paying the technical debt’. Spending time doing correctly what you didn’t previously have time to do.</p>
<h2>Excuses to avoid refactors</h2>
<p>Despite all that I wrote above, Mr. Anti-refactor will probably say “well, yes, refactoring sounds cool for code katas and having a good time but, you know, our team is big, we’ve got a lot of things to do and stopping to refactors would simply put us out of business”, the bad news is that he’s probably right to some extent.</p>
<p>Refactoring means changing the structure of the code and, on a real project of a certain size, it will mean making changes on parts of the code that are being concurrently modified by other developers. You know the rule: 80% of the changes happen on 20% of the files, at most. So if you do concurrent/parallel development it means one of two things:</p>
<ul>
<li>You stop development while you clean up the code – which is probably excuse number one not to pay the technical debt.</li>
<li>Or you simply go ahead and… well, you’ll create a nightmare of a merge later on...</li>
</ul>
<h2>21st century version control</h2>
<p>But we are in the 21st century, aren’t we? Back in 2005 distributed version control (DVCS) arrived and teams stopped to think about version control as a ‘commodity’ (it doesn’t matter which one you have, they all do the same) to find out that advanced ones (like Git, Mercurial and our own Plastic SCM) allowed them to do things that were simply unthinkable before. Working distributed? Doing good branching? Merging anyone? It all changed.</p>
<p>Now, almost a decade later, DVCS is not just the new toy for cool kids, big teams are using it, enterprises are throwing away their old irons and jumping to the now-mature distributed version control systems.</p>
<p>So, don’t they bring a better way to handle refactors?</p>
<p>The answer is no, they don’t. At the end of the day brand new version controls still depend on arcane merge tools to perform the file-per-file merges.</p>
<p>Let me explain in more detail. Suppose you have a class like the following (I’ll just focus on the class structure and not the actual code for the sake of simplicity and focus on the refactor operation):</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh864JlSBxT1d01ytMjbdIOfL2zMt82ODwgzoFfICZ5Dp1R646Q5mbr_crqGzv5FYqpJ-7LljrO9k1QrxgGQnKSYJIDcjNEEy23HcfO5yDCMSbyQBPRvM9SpO0nGEbHvE8yZjjec9fRlOg/s1600/00refactor-step.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh864JlSBxT1d01ytMjbdIOfL2zMt82ODwgzoFfICZ5Dp1R646Q5mbr_crqGzv5FYqpJ-7LljrO9k1QrxgGQnKSYJIDcjNEEy23HcfO5yDCMSbyQBPRvM9SpO0nGEbHvE8yZjjec9fRlOg/s1600/00refactor-step.png" /></a>
<p>The class looks like a small mess: Which is the main interface method on the class? Sending bytes (possibly through a socket)? Or as the name says, retrieving some sort of stats from a remote machine?</p>
<p>To start the process first sort the methods in a more ‘expressive’ way:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilZRIokLZcaIDPbzZA-lT5Zjhps1ysWbQeoNOBZ2pzpMWzn7SxxeJDXwmedUtO17z3o7qWeOtbjloyjowAWvAui9lDN4YGWlla61o9s-2PnefzenAumtRmWvUYrPoC3jM6aNQ4s8tyrlE/s1600/01refactor-step.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilZRIokLZcaIDPbzZA-lT5Zjhps1ysWbQeoNOBZ2pzpMWzn7SxxeJDXwmedUtO17z3o7qWeOtbjloyjowAWvAui9lDN4YGWlla61o9s-2PnefzenAumtRmWvUYrPoC3jM6aNQ4s8tyrlE/s1600/01refactor-step.png" /></a>
<p>Now it is a little clearer that the “interface” method with the outside world is the GetStats method which probably initializes the class with data from a remote host.</p>
<p>The “Send()” method is no longer public and the methods have been sorted trying to “explain” what the class does: the interface method, then the methods handling the ‘comm protocol’ and finally 4 methods that look too low level to belong to the same class… (Obviously the example is a little bit forced in order to go straight to the point).</p>
<p>So, you still go further and create a subclass to isolate the “pure network” methods as follows:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgetM86ZDYWZatHEEsS4zHCScGZBzB6zRhlpxvKioiVoYL7YLJXv9vGsoGm7ICMPR8ASG75dYf8OAaMOeqkBskXS7eqfIJ92nEte5ItjcCBydMiWguuGRsQyjx0YNdOorKh3IM3vTKHzE4/s1600/02refactor-step.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgetM86ZDYWZatHEEsS4zHCScGZBzB6zRhlpxvKioiVoYL7YLJXv9vGsoGm7ICMPR8ASG75dYf8OAaMOeqkBskXS7eqfIJ92nEte5ItjcCBydMiWguuGRsQyjx0YNdOorKh3IM3vTKHzE4/s1600/02refactor-step.png" /></a>
<p>Much cleaner. Still far from perfect but it is a good step forward.</p>
<p>Now, since you’re not alone in your project, what would happen if your colleague ‘john’ made a modification to the “GetStats()” method while you were refactoring??</p>
<p>Well, from a “human” point of view you know that you just rearranged the code to make it more readable, but a traditional merge tool doesn’t know how to compare your version and John’s so it will try to match the code line by line… and as you can see below, it won’t be doable since it won’t follow the arrows between the methods as my graphic does:</p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHWONdG51PaXB-BgXg5zDeebGKcfLs4PRWlfSUk_TUCgRmvEFBAgFH3SO_8n8eLo4B4cArl92hYo1gS0sZzij_6mz9BoaAd8eJK1Tj6OxNXwWySnpg6-1Cat5vMHkzqekuGzMJhLKuljA/s1600/03refactor-step.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHWONdG51PaXB-BgXg5zDeebGKcfLs4PRWlfSUk_TUCgRmvEFBAgFH3SO_8n8eLo4B4cArl92hYo1gS0sZzij_6mz9BoaAd8eJK1Tj6OxNXwWySnpg6-1Cat5vMHkzqekuGzMJhLKuljA/s1600/03refactor-step.png" /></a>
<p>Once you suffer that you probably won’t think about going through this again.</p>
<h2>How using a semantic merge helps?</h2>
<p>But, what if the diff and merge tool was actually able to understand the code? What if it knew that all you did was rearrange the code? Then it would be possible for it to “understand” that it should just take the change made by John at GetStats() and simply put it wherever the method is now located on your version of the file, wouldn’t it?</p>
<p>This is exactly what SemanticMerge is all about and this is what we explain, step by step and using actual code in the following 20 minute webinar!</p>
<iframe src="//fast.wistia.net/embed/iframe/c6anvn5gs9" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="840" height="630"></iframe>
<p>In the middle of the version control DVCS age we are no longer limited to unified diffs, 2-way merges, and at best 3-way text based diff and merge tools which show diffs side by side without understanding the underlying programming code structure at all.</p>
<p>SemanticMerge is what comes to the mind of every programmer facing the scenario I just described above... and fortunately we took the time to implement.</p>
<p>Enjoy!</p>
Pablo Santoshttp://www.blogger.com/profile/08083682682597484025noreply@blogger.com0