<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Julian Konchunas on Medium]]></title>
        <description><![CDATA[Stories by Julian Konchunas on Medium]]></description>
        <link>https://medium.com/@konchunas?source=rss-e01718c1f5ed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QRHSkUtrjFLkztJe.jpg</url>
            <title>Stories by Julian Konchunas on Medium</title>
            <link>https://medium.com/@konchunas?source=rss-e01718c1f5ed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 05 Jun 2026 19:35:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@konchunas/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Sol2Ligo foreign calls update]]></title>
            <link>https://medium.com/madfish-solutions/sol2ligo-foreign-calls-update-a634faab7d0c?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/a634faab7d0c</guid>
            <category><![CDATA[tezos]]></category>
            <category><![CDATA[translation]]></category>
            <category><![CDATA[compilation]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 13:02:50 GMT</pubDate>
            <atom:updated>2020-09-08T13:02:50.432Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This is an update to our Solidity to LIGO transpiler. Refer to our </em><a href="https://medium.com/coinmonks/solidity-to-ligo-transpiler-981ac35a7297"><em>introductory post</em></a><em> if you want to know more.</em></p><p>Last week we came up with an idea which might be rather useful for the Solidity to Ligo translation process. Since we already have a main contract detection mechanism we can differentiate between local and foreign calls. Solidity calls to foreign contracts are very similar to the local calls and their gas cost is calculated as a single chunk. In Tezos, however, every call to another contract should be formed as a separate transaction. To aid users with that we go through code while translating and try to convert all foreign calls to transactions. Thanks to the Babylonnet Tezos protocol <a href="https://blog.nomadic-labs.com/michelson-updates-in-005.html">upgrade</a>, you can make a call to a contract by its arguments, knowing only part of its interface. It brings more versatility to implementing token interactions and lets us save a bit of gas. We take advantage of this capability by creating a transaction call dummies. This might reduce migration cost for systems consisting of several separate contracts in Solidity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ipG0CO_ORNVUuPXOKAz3SA.png" /><figcaption>The most logical way to translate Solidity foreign calls to LIGO</figcaption></figure><p>Another great milestone for us personally is now we are able to translate MakerDAO SAI contracts without errors! It surely doesn’t mean that this project can be magically migrated to Tezos in a few clicks. But it definitely means that our Solidity features coverage is quite large so it can swallow proven contracts with real-world usage.</p><p>As a small and nice-to-have change, we have added the “Default state” tab in our <a href="https://madfish-solutions.github.io/sol2ligo/">web version</a>, so now you are able to get your contract Tezos origination params right in your browser! And now we have the <a href="https://github.com/madfish-solutions/sol2ligo/wiki">main page</a> in our Github wiki, which is aimed to guiding you when getting started.</p><p>If you want to stay tuned for more updates subscribe to our <a href="https://twitter.com/madfishofficial">Twitter</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a634faab7d0c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/madfish-solutions/sol2ligo-foreign-calls-update-a634faab7d0c">Sol2Ligo foreign calls update</a> was originally published in <a href="https://medium.com/madfish-solutions">Madfish Solutions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity to LIGO transpiler. Folder mode.]]></title>
            <link>https://medium.com/madfish-solutions/solidity-to-ligo-transpiler-folder-mode-762eeafe194f?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/762eeafe194f</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ligo]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[tezos]]></category>
            <category><![CDATA[xtz]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Fri, 21 Aug 2020 15:57:58 GMT</pubDate>
            <atom:updated>2020-08-21T15:57:58.528Z</atom:updated>
            <content:encoded><![CDATA[<p>In the last update, we implemented what we call a “directory translation mode”. It makes translation easier for you if your contract stretches across multiple files. Take a look at Maker DAO for example. It has a bunch of contracts placed into a tree-like structure in the filesystem. Previously, you would need to specify an exact file, so sol2ligo could automatically get download and resolve every import into one big Solidity Abstract Syntax Tree. Later on, this AST gets transformed and translated so you get a single output. If an original contract is on the larger side, this could lead to producing one large hard-to-read several-thousand-lines-of-code file. But now we have a special mode for this exact case called Directory mode. You specify a whole folder and the transpiler recursively translates every file in it one by one by placing #include statements whenever appropriate. This way resulting LIGO folder structure will be rather similar to what was there in Solidity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*KQh_m6bxxuwd7ICekIT_uA.png" /><figcaption>SAI Solidity contract directory structure</figcaption></figure><p>We have also worked on fixing numerous issues with our default state generator. The default state is a LIGO structure representing the initial state of a contract needed for its origination in Tezos. This mechanism is needed because in Ethereum contract is first deployed and then initiated by constructor call. Whereas in Tezos contract is deployed and initiated with some default storage parameters at the same time. Thus default parameters have to be somehow be extracted and prepared. This feature is not yet available in the web version, but you can pass the output file name via--outfile flag transpiler will produce a special .storage.ligo file alongside the main one. Also, this feature is enabled by default if you are translating using the aforementioned directory mode via --dirCLI flag.</p><p>Don&#39;t forget to give us star on GitHub 😊😊😊</p><p><a href="https://github.com/madfish-solutions/sol2ligo">madfish-solutions/sol2ligo</a></p><h4>Try <strong>Sol2Ligo here</strong>: <a href="https://madfish-solutions.github.io/sol2ligo/">https://madfish-solutions.github.io/sol2ligo/</a></h4><p>If you want to stay tuned for more subscribe to our <a href="https://twitter.com/madfishofficial">Twitter</a><br>Our Website: <a href="https://www.madfish.solutions/">madfish.solutions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=762eeafe194f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/madfish-solutions/solidity-to-ligo-transpiler-folder-mode-762eeafe194f">Solidity to LIGO transpiler. Folder mode.</a> was originally published in <a href="https://medium.com/madfish-solutions">Madfish Solutions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improving library and using keywords on Sol2Ligo transpiler]]></title>
            <link>https://medium.com/madfish-solutions/improving-library-and-using-keywords-on-sol2ligo-transpiler-8aee48926a5b?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aee48926a5b</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[tezos]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Tue, 28 Jul 2020 12:15:57 GMT</pubDate>
            <atom:updated>2020-07-28T12:15:57.317Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzlUXA9NJgJuueNThE8SYA.png" /><figcaption>Web version of transpiler with new compilation options in the bottom left corner</figcaption></figure><p>Our team at MadFish continues working on Sol2Ligo transpiler — a utility aimed at helping Ethereum developers migrate to Tezos by transpiling Solidity into LIGO smart contract programming language.</p><p>In this update, we fixed and improved Solidity using keyword translation. Now if your underlying type is applying library methods for all its operations in LIGO you will get them too. Even if you use a library broadly as using Foo for * we can translate that as well. Some less prominent bugs in library translation were fixed in the process. For example this.prop() and super.fn() now come out as expected.</p><p>As per request, we have improved nested arrays and mapping access. Now your multi-dimensional arrays access like arr[1][2][3] will be split into multiple lines to mitigate LIGO limitation.</p><p>Another good news is that we have ported compilation flags previously available only in the CLI version to our web version.</p><p>Finally, we have cleaned up our warnings and put links to documentation where the additional explanation was needed. We plan to improve our documentation even further to make Solidity to Ligo transition even smoother.</p><h3>Feedback</h3><p>You may try our transpiler with all these new features online here: <a href="https://madfish-solutions.github.io/sol2ligo/">sol2ligo</a></p><p>Feel free to provide your feedback in our Github Issues should you run in any trouble:</p><p><a href="https://github.com/madfish-solutions/sol2ligo/issues">madfish-solutions/sol2ligo</a></p><p>Subscribe to our Twitter to stay tuned: <a href="https://twitter.com/madfishofficial">@madfishofficial</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aee48926a5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/madfish-solutions/improving-library-and-using-keywords-on-sol2ligo-transpiler-8aee48926a5b">Improving library and using keywords on Sol2Ligo transpiler</a> was originally published in <a href="https://medium.com/madfish-solutions">Madfish Solutions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Annotations in Tezos and Michelson]]></title>
            <link>https://medium.com/madfish-solutions/annotations-in-tezos-and-michelson-a24017983990?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/a24017983990</guid>
            <category><![CDATA[annotations]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[tezos]]></category>
            <category><![CDATA[ligo]]></category>
            <category><![CDATA[michelson]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Wed, 08 Jul 2020 13:37:44 GMT</pubDate>
            <atom:updated>2020-07-08T13:37:44.265Z</atom:updated>
            <content:encoded><![CDATA[<p>When we were trying to optimize our contract’s gas usage, we got a tip on tezos-dev channel to strip out annotations from our contract. We weren’t quite sure what annotations are and how they affect our smart contract. But seems we have figured it out and would like to share this knowledge with you.</p><p>For this example, we have created two nearly identical LIGO contracts based on the better-known increment-decrement contract boilerplate.<br>Those contracts are pretty simple and the main idea of both is to have a single entrypoint, but with a little twist. The first one accepts a structure and the second one expects a tuple as a parameter. Both of them should also have the same argument types in the same order.</p><p>Here is a comparison of these two contracts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W2ROkgWka6VVG-mKodIaYg.png" /><figcaption>LIGO contract accepting record argument on the left. Tuple argument on the right</figcaption></figure><p>When compiled to Michelson differences between these two are even more minor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLiElYuJrw0fBSv7KxdcVQ.png" /><figcaption>The annotated contract has argument names auxiliary to the input argument</figcaption></figure><p>That is what is called annotations: additional information about data that is carried around to assist you in debugging and development. Annotations also make contracts in a block explorer more understandable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*Szjx1mIibLEjZu-mRYY8tQ.png" /><figcaption>Annotations on the left in Block explorer. Notice that arguments types are in the same order</figcaption></figure><p>But the trickiest part comes when you compile your parameters to Michelson to perform an actual call.</p><pre>&gt; ligo compile-parameter ./contracts/Annotated.ligo main “Increment(record [ first = 5; second = 3n])”<br>(Pair 5 3)<br>&gt; ligo compile-parameter ./contracts/Tuple.ligo main “Increment(5, 3n)”<br>(Pair 5 3) </pre><p>As you can see, input parameters are compiled to the same Michelson code. Therefore, you can perform calls to a contract either by record convention or by tuple convention without any difference. You should just ensure proper types and their order. As for the “gas cost” part we didn’t immediately have any definitive answer, but we configured a mockup Tezos chain to test this out. We passed this argument to both of our contract and got the following results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uXFzzdPkKpYchohQMp0bfA.png" /><figcaption>Gas usage difference between annotated and non-annotated input parameters</figcaption></figure><p>The result is non-annotated contract uses 228 less gas. And that is only by stripping two arguments. This might or might not be a lot in your case. I would recommend trying this on your own contract to see the real-world results. Though you may miss some of those sweet names which make working with your contract a bit more pleasurable.</p><h3>Links</h3><p>We are grantees of Tezos Foundation developing multiple projects for Tezos ecosystem. Check out our website: <a href="https://www.madfish.solutions/">madfish.solutions</a></p><p>Our Twitter: <a href="https://twitter.com/madfishofficial">madfishofficial</a></p><p>Our Github: <a href="https://github.com/madfish-solutions/">madfish.solutions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a24017983990" width="1" height="1" alt=""><hr><p><a href="https://medium.com/madfish-solutions/annotations-in-tezos-and-michelson-a24017983990">Annotations in Tezos and Michelson</a> was originally published in <a href="https://medium.com/madfish-solutions">Madfish Solutions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sol2ligo update #4]]></title>
            <link>https://medium.com/madfish-solutions/sol2ligo-update-4-5b72d85ec7eb?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b72d85ec7eb</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[erc20]]></category>
            <category><![CDATA[tezos]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Fri, 03 Jul 2020 10:04:10 GMT</pubDate>
            <atom:updated>2020-07-03T11:20:05.629Z</atom:updated>
            <content:encoded><![CDATA[<h3>Solidity to LIGO token conversion update</h3><p>Though the pandemic is ongoing, we are keeping nose to the grindstone on our Solidity to LIGO transpiler.</p><p>We have planned a lot of new and useful features; that’s why we have to drastically rework our the project for its better maintainability in the future. Now our architecture is reorganized according to the modern standards of compiler development. This new architecture will allow us to improve code analysis for implementing more complex features and polishing contract interoperability support.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Qd6UgJh1XcF53DNb2bJLw.jpeg" /></figure><p>We have laid the foundation for ERC20 and ERC721 interfaces conversion. This means transpiler will now detect if your Solidity contract uses either of these two interfaces. Thereafter, the transplier will try to replace them to a corresponding <a href="https://gitlab.com/tzip/tzip/blob/master/proposals/tzip-7/tzip-7.md">FA1.2</a> and <a href="https://gitlab.com/tzip/tzip/-/blob/master/proposals/tzip-12/tzip-12.md">FA2</a> code respectively. For example, if you want to migrate your Dex contract which works with ERC-20 tokens, you will get a code which theoretically does the same with FA1.2 tokens on Tezos. Since Tezos and Ethereum contracts have different mechanisms of interoperability, this will require some manual intervention. But as of now, it feels extra convenient to have at least a template for things that can’t be translated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QFGmWqluRrsG0-yIhlMVKg.png" /><figcaption>The example of ERC-20 conversion to FA1.2</figcaption></figure><p>Another thing we worked on was a runtime execution tests. From the very start of this project, we were a bit worried issues could appear at runtime, even when the transpiled code looks valid. To eliminate this risk, we have developed a bunch of tests which compare execution results of a translated code. We have decided to limit ourselves to plain types and maps. But now we at least can be sure that Solidity adding to map is, in fact the same as LIGO&#39;s Map.add.</p><p>In the process we have improved our static analysis methods along with incorporating some new and more concise LIGO syntax. Now resulting code better detects external functions and returns operation list when appropriate. We are also planning to implement a similar approach to pure functions detection and such.</p><p>You can play around with our transpiler online <a href="https://madfish-solutions.github.io/sol2ligo/">here</a>. Try these new features and tell us what you think! And don’t hesitate to reach out to us if you run into any difficulties. We are open to suggestions — the more users trying out our utility, the better we become.</p><h3>Links</h3><p>Try it online: <a href="https://madfish-solutions.github.io/sol2ligo/">sol2ligo</a></p><p>Feel free to provide your feedback in our Github Issues section:</p><p><a href="https://github.com/madfish-solutions/sol2ligo/issues">madfish-solutions/sol2ligo</a></p><p>Subscribe to our twitter for updates on this and other our projects: <a href="https://twitter.com/madfishofficial"><em>@madfishofficial</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b72d85ec7eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/madfish-solutions/sol2ligo-update-4-5b72d85ec7eb">Sol2ligo update #4</a> was originally published in <a href="https://medium.com/madfish-solutions">Madfish Solutions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Microsoft got right about power users, but not quite]]></title>
            <link>https://medium.com/@konchunas/what-microsoft-got-right-about-power-users-but-not-quite-8efa8de59408?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/8efa8de59408</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[wsl]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Fri, 22 May 2020 12:17:32 GMT</pubDate>
            <atom:updated>2020-05-27T21:26:43.853Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently Windows team made a few stunning announcements, which seem to try to win over Linux and OSX developer bunch. Their main target is power users since this group is traditionally overlooked by official Microsoft. Now Windows has entered a battle for developers with their new and shiny tools that mimic a proper development workflow. I’m talking about the following:</p><ul><li>Official <a href="https://devblogs.microsoft.com/commandline/windows-package-manager-preview/">Windows Package Manager</a> similar to apt in Ubuntu or brew in OSX</li><li>DirectX <a href="https://devblogs.microsoft.com/directx/directx-heart-linux/">support</a> for WSL. Which may allow Windows to take a crown of Ubuntu being the most used platform for Machine Learning. As a nice side effect it may provide us with Linux GUI apps in Windows.</li><li><a href="https://devblogs.microsoft.com/commandline/windows-terminal-1-0/">Windows Terminal 1.0</a> release. That should have been done decades ago</li><li><a href="https://github.com/microsoft/PowerToys">PowerToys</a> — a bunch of utilities inspired by PowerToys for Windows 95 which include Spotlight-like launcher and window-switcher, key remapper and, some more.</li></ul><p>So I decided to boot into Windows to check them all out. And they are nice and useful until you include user experience into consideration. And let me spoiler it for you — it just sucks.</p><blockquote><em>Want to read this story later? Save it in </em><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=blog&amp;utm_campaign=noteworthy&amp;utm_content=eid7"><em>Journal</em></a><em>.</em></blockquote><h4>Terminal and WSL 2</h4><p>Let me start with the Windows Terminal experience. Overall, it works fine. You can do your development work in a neat Linux environment. But the first launch of the Linux subsystem after system reboot is unbelievably slow. Apparently it needs to initialize a hypervisor once, and then WSL launches fine subsequently. My XFCE Terminal starts almost instantly on the same machine. And it doesn’t matter if I launch it the first or tenth time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fes74ew&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fes74ew&amp;image=https%3A%2F%2Fcdn-b-east.streamable.com%2Fimage%2Fes74ew.jpg%3Ftoken%3D3EklHFCFN8KhKNWOkGaPmg%26expires%3D1590157200&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="1204" height="772" frameborder="0" scrolling="no"><a href="https://medium.com/media/b71a5ffd64d69811dea8e3bb65638397/href">https://medium.com/media/b71a5ffd64d69811dea8e3bb65638397/href</a></iframe><p>Not to mention that wsl$ folder is inaccessible in File Explorer before the first launch of the terminal. You basically cannot skim through your Linux files without enduring this wait.</p><p>The next thing in Windows Terminal that really bugs me is the menu. Why is it animated? Or, even if it is, why is animation so slow? I want any dropdown menus to be fast, at least not slower than the speed of thought. And it is not like animated menus are common across in Windows software. To me it seems like this one was specifically tailored for edgy teenagers to boast about their cool new terminal application. Not for professionals.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fze4pk9&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fze4pk9&amp;image=https%3A%2F%2Fcdn-b-east.streamable.com%2Fimage%2Fze4pk9.jpg%3Ftoken%3DCh-xw1-R6cddyLQgiGITjw%26expires%3D1590105060&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="1224" height="772" frameborder="0" scrolling="no"><a href="https://medium.com/media/204fbe38a6b713519f0bb5a571b0fc44/href">https://medium.com/media/204fbe38a6b713519f0bb5a571b0fc44/href</a></iframe><p>My next concern is the settings editor. Being a Linux user I’m used to editing text configs. But, really, Microsoft? You choose Notepad as a default editor for settings stored in JSON? It doesn’t have no syntax highlighting, nor indentation editing, which is quite necessary for editing JSON. But altering your settings manually using your favorite text editor is not an easy task either since documentation is outdated on their official Github page and points to the wrong file path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dlicjq_ltGdQii_FgfrE0A.png" /><figcaption>Editing JSON settings in Notepad is just pathetic</figcaption></figure><h4>PowerToys</h4><p>I haven’t evaluated all utilities of PowerToys. I’m particularly interested in “PowerToys Run” to fire apps quickly since I use similar functionality on other platforms. But once again it is just impossible to work with. It visibly lags and blinks when I type. My laptop fan starts to rotate loudly while I am at it. And it sits in tray. I still don’t get why every windows application feels obliged to sit in a tray.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Ft4oso7&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Ft4oso7&amp;image=https%3A%2F%2Fcdn-b-east.streamable.com%2Fimage%2Ft4oso7.jpg%3Ftoken%3DRXeYOjHV_bv_sr1VcMwBDA%26expires%3D1590105300&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="862" height="454" frameborder="0" scrolling="no"><a href="https://medium.com/media/902ca80264a3b63c136f0dc926887748/href">https://medium.com/media/902ca80264a3b63c136f0dc926887748/href</a></iframe><p>Moreover it doesn’t index newly installed applications. I guess we’d say it is an early release and hope for a later fix. Notably it has 23k Stars on Github at a time of writing. I don’t think there is any other alpha software given that much love.</p><p>But it made worse by the fact that even default windows search lags and blinks all the time. It generally searches better, but not by much. And lacks window switch functionality. If you try to search by part of the name it may not even work. I thought <a href="https://github.com/junegunn/fzf">fuzzy searching</a> was a solved problem, huh, Microsoft? You’ve done it right in VS Code, can you borrow that one employee to help for this specific task?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fpd9een&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fpd9een&amp;image=https%3A%2F%2Fcdn-b-east.streamable.com%2Fimage%2Fpd9een.jpg%3Ftoken%3D3qcNHSusfstaKAG58ykeBw%26expires%3D1590105600&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="1002" height="744" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce478895046e4c8b3061cca5d663c6ca/href">https://medium.com/media/ce478895046e4c8b3061cca5d663c6ca/href</a></iframe><h4>General windows experience</h4><p>And now for my favorite part of using Windows. Open or save file Dialog is just the worst in all regards. I don’t know how this happens, but it is super jerky when appearing. My guess is some kind of compositing problem overlapping with an attempt to draw widgets asynchronously. And it is not like you can replace it with a third-party utility of some sort.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fxn49x5&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fxn49x5&amp;image=https%3A%2F%2Fcdn-b-east.streamable.com%2Fimage%2Fxn49x5.jpg%3Ftoken%3DSwx7lYoTX4E6d6Hbe8Un_Q%26expires%3D1590100140&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="984" height="646" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4b518b0cce4d1336cbb91257b6a33eb/href">https://medium.com/media/a4b518b0cce4d1336cbb91257b6a33eb/href</a></iframe><p>The right-click context menu is another favorite annoyance of mine. I don’t get why the context menu should contain all the actions available for this file type. Especially insignificant ones like “Print” or “Edit with Paint 3D”. This oddity is worsened by the fact that sometimes the system needs to load these context menu items and makes me wait, effectively interrupting my thoughts and irritating me.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fo1eq9e&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fo1eq9e&amp;image=https%3A%2F%2Fcdn-b-east.streamable.com%2Fimage%2Fo1eq9e.jpg%3Ftoken%3Ddst4hYbCmEEq3QsmFvZfLw%26expires%3D1590104040&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="968" height="792" frameborder="0" scrolling="no"><a href="https://medium.com/media/8375fafa98d725896c46dcc75bb8c2f5/href">https://medium.com/media/8375fafa98d725896c46dcc75bb8c2f5/href</a></iframe><p>The context menu itself looks amateurish. Some items have icons some don’t and I haven’t found any way to get rid of all of the unnecessary ones. All I want as a user is a few important generalized actions like “Open with” and “Properties”. And maybe a submenu for specialized ones. I don’t care about “Print” or “Give access to” since these operations are perfectly doable using other means.</p><h3>Conclusion</h3><p>I’m not sure if rendering lags are my hardware fault. I have a reasonably powerful laptop: Intel i7 6500U running on full performance, SATA 3 Solid-state drive, DDR4 RAM. Rendering is done on Intel HD520 GPU which is decent enough for the modern desktop. My OS isn’t cluttered, it is only stuffed with a minimal amount of software necessary for development work. Linux UI runs fluidly on this hardware even with a bit heavier Desktops like GNOME3. I’m pretty sure if I install Windows XP right now it will be as fast as any Linux desktop.</p><p>But even if it is my hardware fault, why would terminal emulator loading take any noticeable time? A system-wide search should not be as sluggish and unreliable. Guys at Microsoft are going in the right direction, but I don’t think performance is their concern yet (or ever, for that matter). And it is not surprising: with the rise of heavyweight JS applications everything not-Electron is recognized as fast nowadays. People rely on “better hardware is coming” for fixing software performance issues.</p><p>It is tempting to implement new and shiny features and tell about it in a development blog. But as you cut corners here and there, the overall user experience is lacking. And this is especially important for power users who need to get their work done fast and not break the flow of thought in the process.</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=blog&amp;utm_campaign=noteworthy&amp;utm_content=eid8"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ArLSH4tuI2v4pF0giI3-OQ.png" /></a></figure><p>📝 Save this story in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-tech/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_text">Read the Noteworthy in Tech newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8efa8de59408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity to LIGO translation challenges (sol2ligo update #2)]]></title>
            <link>https://medium.com/madfish-solutions/solidity-to-ligo-translation-challenges-sol2ligo-update-2-b13bd82212fa?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/b13bd82212fa</guid>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Sat, 22 Feb 2020 22:44:38 GMT</pubDate>
            <atom:updated>2020-02-22T22:44:38.150Z</atom:updated>
            <content:encoded><![CDATA[<p>We had a rough time building this system for the last month. LIGO is vastly different from Solidity, so we are slowly, but steadily converging them. As our goal is to get a few popular contracts transpiled in a meaningful way, we are prioritizing some features over another. One of the main pieces we have been working on is called <em>Router</em>.</p><p><em>A router</em> is a system in Michelson (low-level language for LIGO) that allows to pass arguments and make a call to any method specified in the contract. In Solidity, It is quite easy to call a single method of contract from outside. Just get the name from ABI, properly arrange arguments and you are good to go. However, in LIGO you can only call the main method. To work around the problem smart guys have came up with a <em>router</em>, namely: a special structure that allows users to pass the method name and its arguments straight into the main method. It will take care of the branching, make a specified call and return its value. Usually, developers of the contract do it manually, deciding which methods are accessible from the main entrypoint.</p><p>However, we believe it is crucial for our transpiler to remove this burden from the developer’s shoulders and let the machine do its work (so to speak). Sol2ligo analyzes input code, finds all declared methods and determines if a function should be added to the router. We analyze Solidity modifiers like public, internal, pure, view to detect the most suitable way to include the method. We have also improved our state extraction code which picks methods that should accept and return a contract state depending on pure/view modifiers in Solidity input code.</p><p>Let’s take a look at how we translate a simple Solidity method declaration into a LIGO function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*t1rE6F1BH-NHZbkeDTg4Yw.png" /><figcaption>Translation from Solidity into LIGO</figcaption></figure><p>As you can see, even the simplest methods have to be augmented with opList and state variables to achieve the same logic as they have in Solidity.</p><p>But if you want to call a method from outside it gets more complex since you have to provide a router, so, practically, every method is being translated into the following piece:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*dYYAjRQCgpSFntEAZxd44Q.png" /><figcaption>Notice how `arg` gets tossed into three different places</figcaption></figure><p>This one is much more complex. Initially, record named &lt;funcname&gt;_args containing all arguments is formed for every method. Then, a composite type variant enclosing this record is generated and put into router_enum. Later, according to LIGO requirements, a method declaration is translated and modified to return both an operation list and a record for keeping state. Finally, the main function is created and it performs matching of input params with router_enum for calling a specific action. To better understand why all these complications are necessary, you may refer to the <a href="https://ligolang.org/docs/next/advanced/entrypoints-contracts/#entrypoints">Entrypoints</a> section of LIGO documentation.</p><h4>Conversion highlights</h4><p>One may wonder how we translate such different languages and, to be fair, that’s not an easy task. We want to share some highlights and clever hacks we have had to apply to get the best-looking result. I’m not sure if they’d settle since every the smallest detail raises heated debates inside our team of how to provide the best result for an end-user. Thereby, I’ve collected a few interesting cases to look at.</p><p><strong>Array declaration</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*6ejUVhvTAdZ4G0UtnfcxDw.png" /></figure><p>It’s implemented this way because LIGO doesn’t have any array support and map with an unsigned integer key is well suited for this job. Notice how we lose array size in the process - it doesn’t make sense to have a fixed length for a map</p><p><strong>Map access</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*QXxxN6Je7njsUoHOvWQIkg.png" /></figure><p>In Solidity, maps will return a default value if no value is found under the specified key. In LIGO we have to emulate this behavior by using one neat trick —case is an expression! It enables us to use its results anywhere in the code, even on the right-hand side.</p><p><strong>C-like for loop</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*c5IcEGhd5hQSTQv3t6qPDA.png" /></figure><p>This is the exact case of for loop translation I have described in our <a href="https://medium.com/madfish-solutions/what-is-a-transpiler-47beac592848">previous story</a>. Solidity doesn’t support for3, so we have had to transform it into a while loop. You can also notice that LIGO doesn’t have += operator, so this one has to be emulated as well.</p><h4>Changelog</h4><p>It was a fruitful month, so here are some key things we have been working on:</p><ul><li>Types and their default values: numbers, strings, bytes. Aliases for bytes&lt;num&gt; and int&lt;num&gt;</li><li>Modifiers inlining, basic libraries unrolling, improved handling for pure functions</li><li>Comparisons, bitwise math, negations, pow</li><li>Cryptographic functions conversion</li><li>Stubs for event and emit, more warnings and more explanations</li><li>Improved type inference for number types and arrays</li><li>Better tuples support</li><li>require and assert (shout out to LIGO team for helping out)</li><li>Basic support for address methods like (send, transfer)</li><li>enum and struct declarations and definitions</li><li>Tests for all of that</li></ul><h4>Work in progress</h4><p>Lots of things are being changed, fixed and broken in the process. We change API and output trying to balance out readability and correctness. If you want to try it out be aware that’s an unventured territory, since no real-world testing has been done yet.</p><p>Check out repo at <a href="https://github.com/madfish-solutions/sol2ligo">https://github.com/madfish-solutions/sol2ligo</a></p><p>Show us your support by leaving a star!</p><h4>Subscribe for updates</h4><p><a href="https://www.facebook.com/madfishofficial/">Facebook</a> and <a href="https://twitter.com/madfishofficial">Twitter</a></p><p><a href="https://tezos.org.ua/">https://tezos.org.ua/</a> — Tezos Ukraine community website<a href="https://twitter.com/UkraineTezos"><br>https://twitter.com/UkraineTezos</a> — Tezos Ukraine twitter</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b13bd82212fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/madfish-solutions/solidity-to-ligo-translation-challenges-sol2ligo-update-2-b13bd82212fa">Solidity to LIGO translation challenges (sol2ligo update #2)</a> was originally published in <a href="https://medium.com/madfish-solutions">Madfish Solutions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is a transpiler?]]></title>
            <link>https://medium.com/madfish-solutions/what-is-a-transpiler-47beac592848?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/47beac592848</guid>
            <category><![CDATA[ligo]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[compilers]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Sat, 08 Feb 2020 12:21:07 GMT</pubDate>
            <atom:updated>2020-02-09T11:07:12.216Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>A little journey into how one programming language gets translated into another on the example of our Solidity to LIGO transpiler</blockquote><p>“Transpilation” unlike “compilation” is a process of translating a code from one language into another, given that they are on the same level of abstraction. Take assembly, for instance. It is a low-level language and its instructions practically correspond to commands issued directly on the processor. Rust and C, on the other hand, operate on abstract mathematical entities such as variables and functions. Only later these entities are being compiled (hence the name) into processor instructions. But if you translate C to Rust this process is called “transpilation”, since they are both high-level languages.</p><h4>How it is done</h4><p>The process of translation is pretty similar to the one of compilation. In a nutshell, the idea is to parse the source language and generate target language output. In between there is a medium of translation called Abstract Syntax Tree, or AST for short. You may think of AST as of a tree-like JSON structure, containing every word and instruction of the language. And since it is a tree, every language unit is aware its own properties and also stores pointers to its parents and siblings. For example, this code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*Fi1GCgYChe5bUUJn-AnEcA.png" /></figure><p>Would be roughly represented as the following AST:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ZsCYvXNpJWFeToU6laDhqQ.png" /></figure><h4>In detail</h4><p>Transpiling a language generally involves a few stages: <em>parsing</em>, <em>transformation</em>, <em>type</em> <em>inference</em>, and <em>translation</em></p><p>The very first stage required is<strong> Parsing. </strong>Parser takes the input language and splits it into syntactic units to create aforementioned AST. To our luck, Solidity compiler solc is able to produce such AST in JSON format out of the box. Parsing language is a complex task with hundreds of articles on this topic existing already. So let’s just continue to interesting parts and assume we have our input language neatly parsed into AST structure.</p><p>Next one is<strong> Transformation</strong> — a process of modifying a syntax tree for the purpose of getting data better suited for the target language. The stage is aimed at adapting the semantics of the language, since even seemingly<br>equivalent statements may require a special treatment. For example, in Solidity we can write widely used C-like for loop with 3 expressions like this:<br>for (init; condition; step)</p><p>LIGO doesn’t support such a statement, but as you may have guessed, it is possible to convert any for loop into a while loop like so:</p><pre>init;<br>while (condition) {<br> …<br> step;<br>}</pre><p>And that’s exactly where the transformer fits. It removes a for3 node from AST and creates a logically equivalent while statement to replace it. Keep in mind, it is operating on the syntax tree and not on the actual language text yet. Transformer is what accepts AST and outputs modified AST by recursively traversing nodes. You can take a look at our for3 transformer for sol2ligo <a href="https://github.com/madfish-solutions/sol2ligo/blob/master/src/ast_transform.coffee#L166">here</a> for a better understanding.</p><p>Sure thing quite a bit more transformers are necessary for different cases of ranging complexity in sol2ligo. They perform a wide range of operations: generating router, emulating state, inlining modifiers, unrolling libraries, taking care of inheritance and so forth.</p><p><strong>Type inference</strong> — is a special step required to perform better informed decisions on types translation. Since LIGO compiler can’t do a type inference on its own, we kindly lend our helping hand here. Let’s consider returning from a function as an often occurring case. If you want to use the returned value you are ought to declare a variable like this:</p><pre>const v : &lt;type&gt; = func()</pre><p>Basically type inferrer’s task is to analyze all function declarations beforehand and remember their returned types for every function call. The same thing happens when we deal with variable declarations. In case we need to translate assignment operation we just peek to the right side of expression and infer the type based on what’s going on there.</p><p>Sometimes it is not easy to infer a type based on the data of the node’s closest siblings. That is why our type inference is divided into two stages. Roughly speaking, the first one identifies type from AST node and its neighbors and the second one may perform line traversal to fetch type info from farther away. Sometimes even this may not be enough, since statements like var x = 0; simply do not provide enough information about the type. Solidity assumes x of some ambiguous number type and we have to seek later operations to understand if this was intended to be int or nat.</p><p>If we got you interested, our type inference module can be found <a href="https://github.com/madfish-solutions/sol2ligo/blob/master/src/type_inference.coffee">here</a>.</p><p>Finally,<strong> the Translation</strong> stage (sometimes called “generation”) is what produces actual code from a syntax tree. You pass the an AST as an input and it outputs a valid LIGO code and does formatting, knowing how to interpret each node of the tree. It understands where to put brackets and what statements should be grouped into blocks. It recursively enters every leaf thus monstrosity like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*9yQzLF9PgZGqYCOdzKQ0nw.png" /></figure><p>Effectively gets translated into neat little function like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*FmrN7mWSip17VFhtINozaw.png" /></figure><p>That is basically how your Solidity contract gets translated into LIGO contract. It is a simple enough process, but it requires careful thinking. We always keep in mind that similarly looking code may not work properly and even introduce subtle vulnerabilities, which did not exist in the original source code.</p><p>You may take a look at our project here: <a href="https://github.com/madfish-solutions/sol2ligo">Github — sol2ligo</a>. Give us a star to show your support!</p><p><em>This is a followup to the our story on Solidity to LIGO transpiler funded by Tezos Foundation. Check out our introduction story </em><a href="https://medium.com/@madfishsolutions/solidity-to-ligo-transpiler-981ac35a7297"><em>here</em></a><em> if you want to learn more.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47beac592848" width="1" height="1" alt=""><hr><p><a href="https://medium.com/madfish-solutions/what-is-a-transpiler-47beac592848">What is a transpiler?</a> was originally published in <a href="https://medium.com/madfish-solutions">Madfish Solutions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Telegram file sharing from command line]]></title>
            <link>https://medium.com/@konchunas/telegram-file-sharing-from-command-line-9a3f593bcf4e?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a3f593bcf4e</guid>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Sat, 20 Jul 2019 18:09:12 GMT</pubDate>
            <atom:updated>2019-07-20T22:50:54.019Z</atom:updated>
            <content:encoded><![CDATA[<p>Apparently there are Share menus everywhere on modern systems: OS X, Windows, Android, iOS. Everywhere, but not on Linux.</p><p>I often send different documents via Telegram and proper Share menu would be super handy. But since I couldn’t find any graphical way to do that I decided to write my own script for this very purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*XQAAuJqwJ6PZF97owmv-NQ.png" /><figcaption>That’s how Telegram looks when you try to send file via this command</figcaption></figure><p>To achieve that I have created a script, which accepts only one argument — a file path. Executing this script brings up Telegram window in “Choose recipient…” mode, where you can immediately type desired receiver name. A file will be sent as soon as Enter is pressed. No more Alt+Tab and drag and dropping. No more clunky file chooser navigation.</p><h3>How to</h3><p>You may need to install wmctrl as prerequisite. On Debian-based system it can be done using sudo apt install wmctrl</p><p>Now create the following two-line script</p><pre>#!/bin/sh<br>telegram-desktop -sendpath &quot;$(readlink -f &quot;$1&quot;)&quot;<br>wmctrl -x -a Telegram.TelegramDesktop</pre><p>First statement resolves any provided path to an absolute path using readlink utility and then invokes Telegram passing a special flag. Second line asks your window manager to focus and activate Telegram window so you can immediately start typing recipient name.</p><p>Save this script to file at your favorite scripts location and apply chmod +x to it. Then to execute this script use</p><p>./tg-share-file.sh file-to-send.jpg</p><p>For convenience you may want to add it to your aliases by the name of, for example, tgsend</p><pre>alias tgsend=/home/user/scripts/tg-share-file.sh</pre><p>And invoke it anywhere like so:</p><pre>tgsend vacation-photo.jpg</pre><p>I would also advice considering integration into your favorite File manager if you need to send files or photos often. One handy shortcut may save you a lot of time otherwise spent dragging and dropping files. Just find a way to pass selected file path as argument to this script and you are good to go! But because there are myriads of file managers out there I leave this as an exercise for the reader :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a3f593bcf4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MonkeyType: type inference for transpiling Python to Rust]]></title>
            <link>https://medium.com/@konchunas/monkeytype-type-inference-for-transpiling-python-to-rust-64fa5a9eb966?source=rss-e01718c1f5ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/64fa5a9eb966</guid>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Julian Konchunas]]></dc:creator>
            <pubDate>Fri, 15 Feb 2019 22:25:31 GMT</pubDate>
            <atom:updated>2019-02-15T22:25:31.687Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*WtQD8r7X-cBq7-KWouwUSA.jpeg" /></figure><p>In my previous <a href="https://medium.com/@konchunas/transpiling-python-to-rust-766459b6ab8f">post</a> about Python to Rust transpiler I’ve said, that one of the biggest problems is absence of types in python and inability to infer them for functions. But it turns out there is a solution to this problem. Guys from Instagram have developed an incredible tool for runtime type inference called <a href="https://github.com/Instagram/MonkeyType">MonkeyType</a>. It monitors what types functions accept and return while running a program. This approach works quite nicely so I want to share with you how it’s done.</p><p>Let’s take a look at the following totally practical example for determining if there is an even number in a list:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74d4d906406741addae5b560e534a1e0/href">https://medium.com/media/74d4d906406741addae5b560e534a1e0/href</a></iframe><p>After transpiling to Rust you get:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95e6fc8d923c03f1d7db1fe8793a3ea9/href">https://medium.com/media/95e6fc8d923c03f1d7db1fe8793a3ea9/href</a></iframe><p>This code can’t be compiled by rustc because only we know that argument is a vector, but not the compiler:</p><pre>2 |     for num in numbers {<br>  |                ^^^^^^^ `T0` is not an iterator</pre><p>And return type RT is not bool, for sure</p><pre>4 |     return true;<br>  |            ^^^^ expected type parameter, found bool</pre><p>But now let’s run our python code using monkeytype run __init__.py and then apply collected results by monkeytype apply main</p><p>And whoosh! We have List[int] type automatically derived for numbers argument and bool for a return type</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/102856bd8b98febb549c869ee4b4765d/href">https://medium.com/media/102856bd8b98febb549c869ee4b4765d/href</a></iframe><p>Now the transpiled result will successfully compile by rustc because enough type information is known</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aed02bd11a7f33c611ee0abe9c8ba354/href">https://medium.com/media/aed02bd11a7f33c611ee0abe9c8ba354/href</a></iframe><p>This MonkeyType utility is quite powerful, so I ran it through <a href="https://github.com/pandoraboxchain/prometheus-python">our consensus prototype project</a> and implemented translation for most frequently encountered types:</p><ul><li>List[T]will become Vec&lt;T&gt;</li><li>Dict[T,S] will be HashMap&lt;T,S&gt;</li><li>Optional[T] translates to Option&lt;T&gt;</li><li>Tuple[T,S] is going to be (T,S)</li></ul><p>But there are also types like Any and Union which cannot be easily translated to Rust type system due to their dynamic nature. And they suggest architectural problems in the code which have to be addressed.</p><p>In addition I’ve also implemented support for variable type annotations in translator, so you can write x:int = 1 in python and it will translate to let x: i32 = 1; Though it must be noted MonkeyType does not generate such annotations at all.</p><h4>Porting guide</h4><p>So, If you are like me and have found yourself in need to port a Python project to Rust I highly recommend you using MonkeyType before converting any code. First thing to do is to make sure you have Python 3.7, because typing support has much improved since its introduction in version 3.5. Then install MonkeyType using: pip install MonkeyType</p><p>Now launch your main file like this monkeytype run main.py. Since this utility infers types as it runs, you want to make sure you execute as much code as possible. If you have user interaction run all possible branching paths. If you have high test coverage you could run tests using monkeytype run `which pytest`. As you finished collecting symbols you can put all modules into file with monkeytype list-modules &gt; module_list.txt. Edit that file and remove all external modules. Now use while read p; do monkeytype apply $p; done &lt;module_list.txt to apply type annotations to all project modules from that file. In the process you may encounter python errors. Here are my errors and suggested solutions:</p><ul><li>Cyclic dependencies, which I resolved by creating forward declaration or simply removing both import and types referenced by them</li><li>Methods returning Self. Python doesn’t support this in 3.7, so you may want to add from __future__ import annotations to the very beginning of file where function returns its class instance.</li></ul><p>Because process of adding types stops on errors, you should fix them, remove corresponding file from module_list.txt and then reapply everything again. Repeat this steps until you got no errors. After that you can invoke <a href="https://github.com/konchunas/pyrs">pyrs</a> on your folder to convert whole project to Rust. Viola! Both your Python and Rust methods now have types. I also worked a bit on struct definition generation lately, so your class fields will guess their types based on that as well.</p><h4>Conclusion</h4><p>Big props to guys at Instagram for creating and open sourcing such an amazing tool. It adds some performance burden and requires code to be evaluated to infer types, but works well and makes idea of converting Python to Rust a bit more practical. It may save some time when migrating languages, but don’t expect your code to compile out-of-the-box, because Rust’s borrow checker exists for a reason.</p><p><em>Check out the </em><em>monkeytype in </em><em>examples folder of </em><a href="https://github.com/konchunas/pyrs"><em>pyrs</em></a><em> repository to try it for yourself.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64fa5a9eb966" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>