<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Amr Hesham</title>
    <description>The latest articles on DEV Community by Amr Hesham (@amrdeveloper).</description>
    <link>https://dev.to/amrdeveloper</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F189059%2Fe74324f8-1875-4857-adc2-f9a9cfc0827c.jpg</url>
      <title>DEV Community: Amr Hesham</title>
      <link>https://dev.to/amrdeveloper</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amrdeveloper"/>
    <language>en</language>
    <item>
      <title>How i created a query language for .git files (GQL)</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Thu, 08 Jun 2023 15:48:15 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/how-i-created-a-query-language-for-git-files-gql-47mo</link>
      <guid>https://dev.to/amrdeveloper/how-i-created-a-query-language-for-git-files-gql-47mo</guid>
      <description>&lt;p&gt;Hello everyone. Last month I got interested in Rust programming language and want to discover more about it. So I started to learn the basics and started to see the open source projects written in Rust. I also created one PR in the rust analyzer project; it does not depend on my knowledge of rust but on my general knowledge of Compilers and Static analysis. As usual, I love to learn new things by creating new projects with ideas that I am interested in.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea
&lt;/h2&gt;

&lt;p&gt;I started to think about small ideas that I love to use, for example, a faster search CLI or some utility apps. But then I got a new cool idea.&lt;/p&gt;

&lt;p&gt;While reading the Building git book (a book about building git from scratch), I learned what each file inside the .git folder does and how git store commits, branches and other data and manage its own database. So what if we have a query language that runs on those files?&lt;/p&gt;

&lt;h2&gt;
  
  
  The Git Query Language (GQL)
&lt;/h2&gt;

&lt;p&gt;I decided to implement this query language, and I named it GQL. I was very excited to start this project because it was my first time implementing a query language. I decided to implement it from scratch, not converting .git files into an SQLite database and running normal SQL queries. And I thought it will be cool if, in the future, I can use the GQL engine as a part of a Git client or analyzer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The implementation of GQL
&lt;/h2&gt;

&lt;p&gt;The goal is to implement it into two parts. The first one is converting the GQL query into AST of nodes, then passing it to the engine to walk and execute it as an interpreter or in the future to convert this into virtual matching for GQL Byte code instructions.&lt;/p&gt;

&lt;p&gt;The engine has the functionality to deal with .git files using the rust binding for git2 library so it can perform selecting, updating and deleting tasks, also storing the selected data into a data structure so we can perform filtering or sorting.&lt;/p&gt;

&lt;p&gt;To simplify this implementation and I created a struct called GQLObject that can represent commit, branch, tag or any other object in this engine also to make it easy to perform sorting, searching, and filtering with single functions that deal with this type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;GQLObject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The GQLObject is just a map of string as a key and value, so it can be general to put the info of any type. And now features like comparisons, filtering or sorting can be implemented easily on this strings map.&lt;/p&gt;

&lt;h2&gt;
  
  
  The current state
&lt;/h2&gt;

&lt;p&gt;Over the last week, I implemented the selecting feature with conditions, filtering and sorting with optional limit and offset so you can write queries like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;commits&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;commits&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;commits&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;commits&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;contains&lt;/span&gt; &lt;span class="nv"&gt;"gmail"&lt;/span&gt; &lt;span class="k"&gt;order&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;commits&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;lower&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;"amrdeveloper"&lt;/span&gt;

&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;branches&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;branches&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;ishead&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;"true"&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;branches&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="n"&gt;ends_with&lt;/span&gt; &lt;span class="nv"&gt;"master"&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;branches&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;contains&lt;/span&gt; &lt;span class="nv"&gt;"origin"&lt;/span&gt;

&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;tags&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;tags&lt;/span&gt; &lt;span class="k"&gt;offset&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;limit&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/SNXRYOnK82g"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The next step
&lt;/h2&gt;

&lt;p&gt;Now the next step is to optimize the code and start to support more features, for example, imaging query for deleting all branches except the master.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;branches&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;"master"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or pushing all or some branches to a remote repository using a single query. Maybe grouping and analyzing how many commits for each user in this month and many other things we can do.&lt;/p&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/amrdeveloper/gql"&gt;https://github.com/amrdeveloper/gql&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am looking forward to your opinion and feedback 😋.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed my article and you can find me on&lt;/p&gt;

&lt;p&gt;You can find me on: GitHub, LinkedIn, and Twitter.&lt;/p&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>gql</category>
      <category>git</category>
      <category>sql</category>
    </item>
    <item>
      <title>I created a programming language and created games with it</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Mon, 24 Apr 2023 14:43:40 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/i-created-a-programming-language-and-created-games-with-it-a5f</link>
      <guid>https://dev.to/amrdeveloper/i-created-a-programming-language-and-created-games-with-it-a5f</guid>
      <description>&lt;p&gt;Hello everyone, today I will share with you the story about my programming language Amun, which is an open source low level general purpose language that compile to machine code using LLVM Framework.&lt;/p&gt;

&lt;p&gt;The story begins two years ago, when I am as a self taught software engineer learning the subjects of computer science and in this time, I started to learn about Compiler design for the first time from Courses and Books, I created many small programming languages some of them are for specific goals like creating bots, drawing shapes …etc&lt;/p&gt;

&lt;p&gt;I really loved the career of Compiler engineer and started to learn more about it, reading source code, try to design new features, watching live streams about compilers.&lt;/p&gt;

&lt;p&gt;In the last year, I got the idea to design a high performance language that should be fast as C/C++ but to be very simple and easy to learn, also to give you some features to create good libraries and DSL (Domain specific Languages).&lt;/p&gt;

&lt;p&gt;I already created a design for a small language with some features and concepts inspired by other languages such as C/C++, Go, Rust, Jai, Swift, Kotlin, and I started to simplify this design and named it Jot.&lt;/p&gt;

&lt;p&gt;What I want is a language that is simple as C and Go, no preprocessor, no garbage collection (remember I need a high performance language).&lt;/p&gt;

&lt;p&gt;It also has such as Type inference and Generic Programming support, Compile time stuff, lambda expression, operator overloading, infix, prefix and postfix functions inspired by Swift, and some cool other features for examples.&lt;/p&gt;

&lt;p&gt;Lambda expression with the ability to move lambda moved out of parentheses in function call and constructor&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var lambda = { printf("Hello from lambda!\n"); };

fun let(value *void, callback *() void) {
    if (value != null) {  callback(); }
}

fun main() {
   let(null) { 
       printf("Will never printed");
   }; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, to come up with an easy way to iterate over arrays and strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for array { printf("array[%d] = %d\n", it_index, it); } 
for item : array { printf("array[%d] = %d\n", it_index, item); }
for item, index : array { printf("array[%d] = %d\n", index, item); }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tuples so you can create a collection of different type values and use it to make a function that return more than one type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var tuple = (1, 2, "Hello", 3, 4, "World");

fun max_min(x int64, y int64) (int64, int64) {
   return if (x &amp;gt; y) (x, y) else (y, x);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One of the most important goals is to have a cool and helpful compiler like rust, it should tell you messages that help you yo not only fix the bug but also understand more about problem and the language.&lt;/p&gt;

&lt;p&gt;After some research, I found that the easiest way to create a high performance low level language is to use the LLVM Framework as a backend for the compiler so it can optimize and generate machine code for most of platforms. So I started to learn more about LLVM from Books and created a few projects with it.&lt;/p&gt;

&lt;p&gt;In June 2022 I started to work on the compiler, and I decided to create it using C++ for many reasons such as high performance and LLVM is also created using C++ so I can easily found samples written in C++, also because I have some experience using it.&lt;/p&gt;

&lt;p&gt;In Jan 2023 the language had most of the features that can help you to provide any programs that you can create in C but without Macros and i started to create simple programs and link with libraries such as OpenGL and Raylib to create simple GUI Applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---QDEmJi4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rowehsdbe1wrnyb6ice.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---QDEmJi4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rowehsdbe1wrnyb6ice.PNG" alt="Image description" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then I started to work on features that can make creating libraries and applications easier, such as tuples, operator overloading, lambda, type alias, directives and also improve the compiler error message, I can’t covering all features in this article but I will write about them latter with cool samples.&lt;/p&gt;

&lt;p&gt;After testing the features i ported a Pong game written using C++ and Raylib in my language and this is the result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=lQt4s0haPGw"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--28bLDOL9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.youtube.com/vi/lQt4s0haPGw/0.jpg" alt="Pong with Amun and Raylib" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Until this step, the language name was Jot, but I was surprised that there is already a language with the same name, so I searched for a new name, and I named it Amun. The name is inspired by Ancient Egyptian mythology when Amun was the chief deity of the Egyptian Empire.&lt;/p&gt;

&lt;p&gt;The language is now still in development and everyone is most welcome to contribute to it. You can help with documentation, compiler, samples …etc.&lt;/p&gt;

&lt;p&gt;You can follow the development on the GitHub repository, and there are more than 200 samples to over all language features, so feel free to star the project if you loved it.&lt;/p&gt;

&lt;p&gt;Github Repo: &lt;a href="https://github.com/AmrDeveloper/amun"&gt;https://github.com/AmrDeveloper/amun&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enjoy Programming and creating cool stuff 😇&lt;/p&gt;

</description>
      <category>amun</category>
      <category>compiler</category>
      <category>llvm</category>
      <category>programming</category>
    </item>
    <item>
      <title>Short circuit evaluation and why it’s important</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Fri, 03 Feb 2023 20:22:23 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/short-circuit-evaluation-and-why-its-important-4mab</link>
      <guid>https://dev.to/amrdeveloper/short-circuit-evaluation-and-why-its-important-4mab</guid>
      <description>&lt;p&gt;Hello everyone. In this article, I want to talk about a concept that is used in many programming languages and how to take advantage of it. It has many names like McCarthy evaluation or minimal evaluation, but the most popular name is Short circuit evaluation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Short circuit evaluation?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we answer this question, let’s first think of two situations,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code snippet, if the first condition is evaluated as false, does the value of the second one matter to check if it should evaluate the if body or not? or what if the first condition is evaluated as true and the operator is Or (||) not and does we need to evaluate the second?&lt;/p&gt;

&lt;p&gt;The answer for both questions is no because in And (&amp;amp;&amp;amp;) expression, if one of the values is false, that means the condition will be evaluated as false; no matter the other value is true or false, and in Or (||) expression if the first one is true no need to check the second value, in all cases it will return true&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;   &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;  &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;    &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;   &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In most programming languages, the process of evaluating the second argument depending on the first one is automatically handled for you and it called Short-circuit evaluation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can you take advantage of Short circuit evaluation?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have a validation function that depends on more than one condition, for example, you check that a user password has a length of more than 8 characters and then match it with the Regex pattern, the performance of this validation function can be different depending on the order of the conditions.&lt;/p&gt;

&lt;p&gt;You can have two options to order those conditions like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;lengthFirst&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;matcher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;matches&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;regexFirst&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;matcher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;matches&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we pass a valid password, the two functions will be the same, but what if we pass the wrong one? which one can be faster, and how fast can it be comparing to the other one? let’s check!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"one"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;lenStart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nanoTime&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;lengthFirst&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;lenEnd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nanoTime&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;lenStart&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lenEnd&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;regexStart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nanoTime&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;regexFirst&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;regexEnd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;nanoTime&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;regexStart&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;regexEnd&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet will print the time of executing each validation function, the output on my machine is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6800
773900
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That means the first function is about 113 times faster, but why?&lt;/p&gt;

&lt;p&gt;This difference is because checking string length is much faster than matching it with regex, try to compare them and check the differences you will get almost the same result.&lt;/p&gt;

&lt;p&gt;That means to take advantage of Short circuit evaluation, you need to think carefully about the order of your conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to order conditions to get more performance?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you write expressions with multi conditions, you should think about how you can avoid evaluating the big conditions or, in other words, try to evaluate the small conditions first so if they return false, you can avoid the others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
Short circuit evaluation, like many other useful programming concepts, is not hard and gives you much more performance&lt;/p&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>How Code formatter implemented in Turtle Graphics</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Thu, 03 Nov 2022 17:35:21 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/how-code-formatter-implemented-in-turtle-graphics-51bi</link>
      <guid>https://dev.to/amrdeveloper/how-code-formatter-implemented-in-turtle-graphics-51bi</guid>
      <description>&lt;p&gt;Hello everyone, in the last article I introduced the Turtle Graphics Android App project with implementation details and resources about the scripting language, editor, generating documentation…etc, after I published the app and got more than 2000 downloads a few times and good ratings and feedback, I decided to add support for code formatting and in this article, I will talk in detail how simple code formatter work and how I implemented in Turtle Graphics app&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AFHQ2x6jwQK0Pqj6ZTKPyow.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AFHQ2x6jwQK0Pqj6ZTKPyow.gif" alt="Code formatter"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As programmers Code formatter are an essential tool in our day-to-day jobs, They make it more easier to read the code if it is formatted, but did you ask yourself how it works?&lt;/p&gt;

&lt;p&gt;Before talking about Code formatter, lets first talk about how Compilers represent your code from text to data structure to do the process on it such as type checking.&lt;/p&gt;

&lt;p&gt;Lets start our story from your file that contains a simple hello world example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {
   print("Hello, World!")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first step is to read this text file and convert it into a list of tokens, A token is a class that represents keyword, number, bracket, string, …etc with this position in the source code for example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class Token (
   val kind : TokenKind,
   val literal : String,
   val line : Int,
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also saved the file name, column start and end so when we want to report error we can provide useful info about the position for example&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Error in File Main Line 10: Missing semicolon :D&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This step called scanner, lexer or tokenizer and at the end we will end up with List of tokens for example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ FUN_KEYWORD, "fun", 1 }
{ IDENTIFIER, "main", 1 }
{ LEFT_PAREN, "(", 1 }
{ RRIGHT_PAREN, ")", 1 }
{ LEFT_BRACE, "{", 1 }
{ IDENTIFIER, "print", 2 }
{ LEFT_PAREN, "(", 2 }
{ STRING, "Hello, World!", 2 }
{ RRIGHT_PAREN, ")", 2 }
{ RIGHT_BRACE, "}", 3 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is list of tokens&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val tokens : List&amp;lt;Token&amp;gt; = tokenizer(input)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that in this step we can check for some errors such as un terminated string or char, un supported symbols …etc&lt;/p&gt;

&lt;p&gt;After this step, you will forget your text file and deal with this list of tokens, and now we should convert some tokens into nodes depending on our language grammar for when we saw FUN_KEYWORD that means we will build a function declaration node and we expect name, paren, parameters …etc&lt;/p&gt;

&lt;p&gt;In this step, we need a data structure to represent the program in a way we can traverse and validate it later and it is called Abstract Syntax Tree (AST), each node in AST represent statement such as If, While, Function declaration, var declaration …etc or expressions such as assignments, unary …etc, each node store required information to use them later in the next steps for example&lt;/p&gt;

&lt;p&gt;Function Declaration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class Function (
   var name : String,
   var arguments : List&amp;lt;Argument&amp;gt;,
   var body : List&amp;lt;Statement&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variable Declaration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class Var (
   var name : String
   var value : Expression
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This step is called parsing and we will end up with an AST object that we can use latter to traverse all nodes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var astNode = parse(tokens)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the language statically types such as Java, C, Go …etc we will go to the Type Checker step, the goal for this step is to check that the user use type correctly for example, if the use declare a variable with int type it should store only integers on it, the if condition must be a boolean type or an integer in a language like C …etc&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdqfs8pym1j6u2es0gh8u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdqfs8pym1j6u2es0gh8u.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this step, we will end up with the same AST node but now we know that it is valid and we can now compile it to any target or evalute it, But also we can do the formatting, static analysis, optimization, check code style …etc&lt;/p&gt;

&lt;p&gt;For example suppose that we want all developers to declare variables without using _ inside the name, to check that we will traverse our AST node to find all Var nodes and check them&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun checkVarDeclaration(node : Var) {
   if (node.name.contains("_") {
      reportError("Ops your variable name ${node.name} contains _")
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But now we need to format it, so how to do that? It's the same we traverse our AST and for each node, we will write it back to text but formatted for example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun formatVarDeclaration(node : Var) : String {
   var builder = StringBuilder()
   builder.append(indentation)
   builder.append("var ")
   builder.append(node.name)
   builder.append(" = ")
   builder.append(formatValue(node.value))
   builder.append("\n")   
   return builder.toString()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this simple method, we rewrite the node to string but with correct indentations and add a new line after it so now 2 variables are declared in the same line, the value also is formatted using another function you can use Visitor design pattern to make it easy to handle all nodes.&lt;/p&gt;

&lt;p&gt;At the end of this step, we end up with a string that represents the same input file but formatted and then we write it back to the file.&lt;/p&gt;

&lt;p&gt;This is the basic implementation of code formatter, a real production code formatter must handle more cases for example what if the code is not valid?, should i format only valid code? should we read the whole program every time we want to format or compile the code?&lt;/p&gt;

&lt;p&gt;Now back to Turtle graphics, In this project i already done all the required steps before and has a ready AST, so i just rewrite it with code like you saw above ^_^ i read it from the UI format it and write it back to UI in my case&lt;/p&gt;

&lt;p&gt;If you are interested and want to read more I suggest&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read at last one Compiler book such as Craftring interpreters&lt;/li&gt;
&lt;li&gt;Read about Language Server Portcol (LSP)&lt;/li&gt;
&lt;li&gt;Watch Typescript Compiler explained by the Author Anders Hejlsberg&lt;/li&gt;
&lt;li&gt;Think if you have Your program as AST what else you can do with it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you enjoyed my article and you can find me on&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/AmrDeveloper" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/amrdeveloper/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://twitter.com/AmrDeveloper" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>codeformatt</category>
      <category>java</category>
    </item>
    <item>
      <title>Turtle Graphics implementation for Android</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Fri, 15 Jul 2022 10:36:29 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/turtle-graphics-implementation-for-android-5316</link>
      <guid>https://dev.to/amrdeveloper/turtle-graphics-implementation-for-android-5316</guid>
      <description>&lt;p&gt;Hello everyone, in this article I want to introduce my last side project which is called Turtle, the project idea is totally inspired by the Turtle Graphics Project.&lt;/p&gt;

&lt;p&gt;What is the Turtle Graphics project?&lt;/p&gt;

&lt;p&gt;Today you may know Turtle graphics from the turtle implementation in the standard library in Python that allows you to control one or more turtles in a two-dimensional space, but the original one first appeared in the late 1960s as a key feature of the programming language called Logo which designed in 1967 by Wally Feurzeig, Seymour Papert, and Cynthia Solomon, you can read more information about Logo and some modern derivatives from &lt;a href="https://en.wikipedia.org/wiki/Logo_(programming_language)"&gt;wikipedia&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After I played with the turtle module in python and loved it, I searched on google play for Android Version with the same idea so I can have instructions, variables, control flow, data structures…etc, and I didn’t find any app with those features, so I decided to implement one as a side project.&lt;/p&gt;

&lt;p&gt;The first step is to have a programming language easy to write and understand the syntax so i created a small one with syntax like python and I called it Lilo (the name is from Lilo and Stitch animation and like logo), so we can have functions, if, loops, variables, constants and a set of instructions for drawing and control the colors but for now you can only control one turtle so here is one example to draw Rainbow Benzene in Python and Lilo.&lt;/p&gt;

&lt;p&gt;The Python version&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U8WOY2GR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v09v5cijofbx8ohbq580.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U8WOY2GR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v09v5cijofbx8ohbq580.png" alt="Image description" width="880" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Lilo version.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xXvsdnau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n507p2n0ktgd8c3mhwpb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xXvsdnau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n507p2n0ktgd8c3mhwpb.png" alt="Image description" width="880" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The result will be like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wsQlsWrq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/razy2t8inl2rvbr58bks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wsQlsWrq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/razy2t8inl2rvbr58bks.png" alt="Image description" width="382" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lilo also provide a clean error and warns messages with line and column numbers so you can easily correct your script.&lt;/p&gt;

&lt;p&gt;If you are interesting in a created programming language like Lilo you can start with those two amazing books&lt;/p&gt;

&lt;p&gt;1 — Crafting Interpreters by Robert Nystrom&lt;/p&gt;

&lt;p&gt;2 — Writing An Interpreter In Go by Thorsten Ball&lt;/p&gt;

&lt;p&gt;The next step after I created the programming language was to create a code editor for it and a preview screen, for the code editor I used the &lt;a href="https://github.com/AmrDeveloper/CodeView"&gt;CodeView&lt;/a&gt; library to provide highlighter, auto complete, snippets, error and warn highlighter and for the diagnostics messages, I used &lt;a href="https://github.com/AmrDeveloper/treeview"&gt;TreeView&lt;/a&gt; library so you an expand or collapse errors, warns or both easily.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--58oO2hfd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqj83felftmbptfl11hu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--58oO2hfd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqj83felftmbptfl11hu.png" alt="Image description" width="880" height="1564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;for the preview screen I have created a simple custom view that can take the Lilo executor and draw the result you can check the code from here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9yJlqyPx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mudlc3c8k0334yozdpiz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9yJlqyPx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mudlc3c8k0334yozdpiz.png" alt="Image description" width="880" height="1564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that I implemented a documentations expanding list easily by generating it using &lt;a href="https://github.com/AmrDeveloper/easyadapter"&gt;EasyAdapter&lt;/a&gt; library and also I implemented save, update, search, and delete your lilo scripts as a lilo packages with some extra meta data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V5Lqd-ir--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zoas6a54xlmhqa70f0cq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V5Lqd-ir--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zoas6a54xlmhqa70f0cq.png" alt="Image description" width="880" height="1564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Turtle Android App is available now on Google Play and the source code on Github so you are welcome to suggest features, report bugs, and contribute.&lt;/p&gt;

&lt;p&gt;Google play: &lt;a href="https://play.google.com/store/apps/details?id=com.amrdeveloper.turtle"&gt;Turtle Graphics App&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/AmrDeveloper/Turtle"&gt;AmrDeveloper/turtle&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is demo video for turtle app that convert many python examples to lilo check it from &lt;a href="https://www.youtube.com/watch?v=eWui7nFYia0"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>android</category>
      <category>java</category>
      <category>kotlin</category>
      <category>turtle</category>
    </item>
    <item>
      <title>A new Android TreeView implementation</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Thu, 07 Apr 2022 08:08:53 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/a-new-android-treeview-implementation-59gc</link>
      <guid>https://dev.to/amrdeveloper/a-new-android-treeview-implementation-59gc</guid>
      <description>&lt;p&gt;Hello everyone, at the start of 2022 I want to create a files tree as you see in any code editor or IDE that represents the project structures and you can do some operations like expanding or collapsing directories, and I have searched for many Tree View implementations in GitHub but I found that some of them are not maintained from many years and also the example project didn’t run on new Android Studio versions, other implementations create custom views from scratch and draw the tree but they didn’t work correctly with a big number of nodes and other limitations.&lt;/p&gt;

&lt;p&gt;So I started to create a list that contains a set of features from all of them, and also a set of features that were requested on the GitHub Issues to get inspiration from them so I can create a generic and useful implementation that can be easy to customize and extend by everyone and as a result of this I want to introduce This new TreeView library.&lt;/p&gt;

&lt;p&gt;The main goal is to make TreeView easy to use, customize and extend almost without limitation and to be up to date with the new android versions, so what you can do with TreeView?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H5XCNaZx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3bn8dflywdk6afy5shw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H5XCNaZx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3bn8dflywdk6afy5shw.gif" alt="Image description" width="320" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TreeView didn’t have any custom view, all you need is a normal RecyclerView so you can get the benefits of RecyclerView recycling and performance, also you can get 2D Scrolling without any custom layout, think of it like you want to make your normal RecyclerView have 2D Scrolling, TreeView has a custom RecyclerView Adapter with click and long click listeners ready to use and we can add more in the future, so each TreeNode didn’t need to have a reference for it listeners.&lt;/p&gt;

&lt;p&gt;You can have any number of roots, and also any number of list items layouts without the need to extend and override the default adapter, I have implemented using the Factory design pattern so you need to pass a TreeViewHolderFactory to the adapter constructor that maps each list item layout with it ViewHolder, so all you need is to create a View Holder for this layout and add it to the factory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--THfLsfUy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjvi7u4zoeity1y5u0ev.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--THfLsfUy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjvi7u4zoeity1y5u0ev.gif" alt="Image description" width="320" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TreeView also supports many operations like expanding and collapsing nodes and branches or by levels also has expanding and collapsing all nodes, you can also get the currently selected node and the parent for any node, all of those features implementation is encapsulated in the TreeNodeManager class so we can easily write a unit tests for them, also if you want to have different implementation you can easily create a custom TreeNodeManager and pass it to the adapter.&lt;/p&gt;

&lt;p&gt;All of the details about how to install, use and extend are written on the TreeView website with examples and if you face any problems or have any questions, please feel free to create a new issue on the Github repository so we can help you quickly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0ogYPLp_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d03ozlqnddbr66uyqv96.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0ogYPLp_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d03ozlqnddbr66uyqv96.gif" alt="Image description" width="320" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This implementation is ready to use and if you have any ideas or requirements feel free to share them or contribute and add them, also you will find all details on the website.&lt;/p&gt;

&lt;p&gt;TreeView Github: &lt;a href="https://github.com/amrdeveloper/treeview"&gt;AmrDeveloper/TreeView&lt;/a&gt;&lt;br&gt;
TreeView Website: &lt;a href="https://amrdeveloper.github.io/TreeView/"&gt;Github.io/TreeView&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find me on: GitHub, LinkedIn, Twitter.&lt;/p&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>android</category>
      <category>treeview</category>
      <category>java</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>How to create Adapters easily in 2022 as an Android Developer</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Wed, 02 Feb 2022 09:46:12 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/how-to-create-adapters-easily-in-2022-as-an-android-developer-5k7</link>
      <guid>https://dev.to/amrdeveloper/how-to-create-adapters-easily-in-2022-as-an-android-developer-5k7</guid>
      <description>&lt;p&gt;Hello everyone, in Android Development almost every project has one or more adapter classes to deal with a collection of views, also there are many different types of adapters such as RecyclerAdapter, ListAdapter, Paging2 Adapter, Paging 3 Adapter, ArrayAdapter, ExpandableListAdapter, some times you need to create a complex adapter class, but most of the times all you need is to bind your model class with a list item layout and provide some extra listeners and that's it, so why we can't automate the process of creating those adapters classes?&lt;/p&gt;

&lt;p&gt;Before talking about how we will automate it, lets first talk about what feature we want and what problems we want to avoid.&lt;/p&gt;

&lt;p&gt;So let's start with the features?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Declare how to bind data to views easily.&lt;/li&gt;
&lt;li&gt;Add listeners to any view or to the main list item layout view.&lt;/li&gt;
&lt;li&gt;Support some features like loading images with third party libraries like Picasso, Glide, COIL.&lt;/li&gt;
&lt;li&gt;Support default and custom names for the Adapter class.&lt;/li&gt;
&lt;li&gt;Provide clear error messages if we made any mistakes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And what problem we want to avoid by using this solution?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add any cost to the runtime.&lt;/li&gt;
&lt;li&gt;Writing complex code to deal with this solution.&lt;/li&gt;
&lt;li&gt;Slow build time.&lt;/li&gt;
&lt;li&gt;Hard to learn.&lt;/li&gt;
&lt;li&gt;limitation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So now what is this solution?&lt;/p&gt;

&lt;p&gt;The solution is &lt;a href="https://github.com/AmrDeveloper/EasyAdapter"&gt;EasyAdapter&lt;/a&gt; which is a new Android Annotation Processing library that can generate adapter classes based on your model class and your custom information in the compile time only.&lt;/p&gt;

&lt;p&gt;So how does it work?&lt;/p&gt;

&lt;p&gt;EasyAdapter has only 2 types of Annotations which are Adapters and Binds Annotations, the first type is used to annotate the model class to tell EasyAdapter what type of adapter you want to generate from this model and what list item you want to use for example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@ListAdapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"com.amrdeveloper.app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"list_item_model"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example tells the library that you want to generate ListAdapter for the Model class and use &lt;code&gt;R.layout.list_item_model&lt;/code&gt; as a list item, you also can change the generated name for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@ListAdapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"com.amrdeveloper.app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"list_item_model"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"ModelAdapter"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in version 1.0.0 EasyAdapter provides 6 Adapter types which are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ArrayAdapter&lt;/li&gt;
&lt;li&gt;ListAdapter&lt;/li&gt;
&lt;li&gt;RecyclerAdapter&lt;/li&gt;
&lt;li&gt;PagedListAdapter&lt;/li&gt;
&lt;li&gt;PagingDataAdapter&lt;/li&gt;
&lt;li&gt;ExpandableListAdapter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also find full documentation about them with examples on the documentation website&lt;/p&gt;

&lt;p&gt;The second annotation type is Bind Annotations and they used to bind or provide features&lt;/p&gt;

&lt;p&gt;For example to tell EasyAdapter that you want to use this string field as a text for TextView with id R.id.user_name you can use @BindText&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@BindText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"user_name"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and this code will generate a code to load the image with path imagePath inside ImageView class with id &lt;code&gt;R.id.user_avatar&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@BindImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ImageLoader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PICASSO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"user_avatar"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;imagePath&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use @BindListener annotation on the model class to generate listener for any view for example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@BindListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ListenerType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OnClick&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nd"&gt;@BindListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ListenerType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OnClick&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"call_button"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;EasyAdapter now will generate 2 on click listener the first one for the list item itself and the other for view with id R.id.call_button&lt;/p&gt;

&lt;p&gt;In Version 1.0.0 10 Bind Annotations which are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BindText&lt;/li&gt;
&lt;li&gt;BindImage&lt;/li&gt;
&lt;li&gt;BindImageRes&lt;/li&gt;
&lt;li&gt;BindBackgroundColor&lt;/li&gt;
&lt;li&gt;BindBackgroundRes&lt;/li&gt;
&lt;li&gt;BindAlpha&lt;/li&gt;
&lt;li&gt;BindGif&lt;/li&gt;
&lt;li&gt;BindVisibility&lt;/li&gt;
&lt;li&gt;BindListener&lt;/li&gt;
&lt;li&gt;BindExpandable&lt;/li&gt;
&lt;li&gt;BindExpandableMap&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also find a full documentation about them with examples on the documentation website&lt;/p&gt;

&lt;p&gt;Using EasyAdapter is not hard as you can see and you can learn it easily in minutes.&lt;/p&gt;

&lt;p&gt;But How EasyAdapter really works?&lt;/p&gt;

&lt;p&gt;EasyAdapter has support for 2 Annotation Processors Kapt (Kotlin Annotation Processing Tool) and KSP (Kotlin Symbol Processing) to walk in your source code and collect information from the annotations with simple type checking to make sure for example what @BindImage annotate string field which represent the image path, show error and warn messages if needed, and after we have all the required information we used code generators that generate the result adapter class source code using kotlinpoet library from Square then we write this source code in Adapter files inside the output directory:D. we try to make the generated code as optimized as possible for example we avoided calling mutable findViewById with the same id, Instead of that we have a ViewTable class inspired from the SymbolTable concept to manage the declared variable and reuse them again.&lt;/p&gt;

&lt;p&gt;This is just the first version, and everyone is welcome to help to improve this tool by suggesting features, reporting issues and contributing to the code base or documentation, everyone can add value.&lt;/p&gt;

&lt;p&gt;Github Repositroy: &lt;a href="https://github.com/AmrDeveloper/EasyAdapter"&gt;AmrDeveloper/EasyAdapter&lt;/a&gt;&lt;br&gt;
Website: &lt;a href="https://amrdeveloper.github.io/EasyAdapter/"&gt;EasyAdapter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>ksp</category>
      <category>adapter</category>
    </item>
    <item>
      <title>Functional Interfaces in Kotlin</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Sun, 09 Jan 2022 21:17:31 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/functional-interfaces-in-kotlin-32d0</link>
      <guid>https://dev.to/amrdeveloper/functional-interfaces-in-kotlin-32d0</guid>
      <description>&lt;p&gt;Hello everyone, almost all of us have seen code like &lt;code&gt;view.setOnClickListener { }&lt;/code&gt; or &lt;code&gt;view.setOnLongClickListener { }&lt;/code&gt; in Kotlin, and when you click on it to see the source code it will show you the Java OnClickListener interface. But have you asked yourself what is this syntax? Is it a kotlin extension? and how can you call your custom listener like this? In this small article, you will know the answer to all of those questions, so let's start 😋.&lt;/p&gt;

&lt;p&gt;This syntax is not an extension but SAM conversion, but what does SAM stand for?&lt;/p&gt;

&lt;p&gt;SAM stands for Single Abstract Method interface and it’s called also Functional interface which is an interface with only one non-default method and any number of default methods, for examples In the JDK we have Runnable class which has only one method called run and in Android SDK we have OnClickListener, OnLongClickListener …etc.&lt;/p&gt;

&lt;p&gt;How can we create a custom functional interface?&lt;/p&gt;

&lt;p&gt;To declare a Functional interface in Java it is easy you just create a normal interface with one method for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;FunInterface&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;method&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in Kotlin starting from Version 1.4 you need to declare it as a fun interface not only interface for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;FunInterface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;method&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Kotlin you can use Java or Kotlin Functional interfaces as a Lambda expression for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;learnFunInterface&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fi&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;FunInterface&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To you this function you can pass FunInterface as an anonymous object for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nf"&gt;learnFunInterface&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;object&lt;/span&gt; &lt;span class="err"&gt;: &lt;/span&gt;&lt;span class="nc"&gt;FunInterface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;method&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But because it Functional Interface you can pass it as lambda { } and this is what is called SAM conversion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nf"&gt;learnFunInterface&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;also in Kotlin if your last parameter is functional interface you can move your lambda out the brackets ( ) for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nf"&gt;learnFunInterface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can realize that setOnClickListener { } is just because this method takes functional interface which is OnClickListener as a parameter.&lt;/p&gt;

&lt;p&gt;Note that the same syntax will work on Kotlin also if your functional interface is written in Java like OnClickListener.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extra Resources:

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kotlinlang.org/docs/fun-interfaces.html"&gt;https://kotlinlang.org/docs/fun-interfaces.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kotlinlang.org/docs/java-interop.html#sam-conversions"&gt;https://kotlinlang.org/docs/java-interop.html#sam-conversions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jorgecastillo.dev/kotlin-sam-conversions"&gt;https://jorgecastillo.dev/kotlin-sam-conversions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>java</category>
      <category>programming</category>
    </item>
    <item>
      <title>Android CodeView: Auto Intending, Find and replace</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Sun, 09 Jan 2022 21:13:57 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/android-codeview-auto-intending-find-and-replace-1mhp</link>
      <guid>https://dev.to/amrdeveloper/android-codeview-auto-intending-find-and-replace-1mhp</guid>
      <description>&lt;p&gt;Hello everyone, In this article, I will talk about two features from the newest version of the CodeView library which are support auto-indentation, and adding support for finding matching and replacing keywords.&lt;/p&gt;

&lt;p&gt;Note that you can find full documentation about how to install and use CodeView in the &lt;a href="https://github.com/AmrDeveloper/CodeView"&gt;AmrDeveloper/CodeView&lt;/a&gt; official Repository.&lt;/p&gt;

&lt;p&gt;So first what is Auto Indentation?&lt;/p&gt;

&lt;p&gt;Auto indentation helps you to set the level of indentation when you type new text, indentation level will automatically increase or decrease by the tab length for example by 4 when you insert new lines in the end or in the middle of the text.&lt;/p&gt;

&lt;p&gt;For example in the modern IDE when you write java when you start writing new multi-lines block with { the indentation level will increase by tab length for example 4 and once you end this block with } the indentation will decrease.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hPB6Dppm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqoi8exa80uhgttw26pj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hPB6Dppm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqoi8exa80uhgttw26pj.png" alt="Image description" width="880" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To support this feature in CodeView you can do it only in 3 steps.&lt;/p&gt;

&lt;p&gt;Step 1: set the indentations start characters, so when the user type those characters the indentation level should increase for example &lt;code&gt;{&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Character&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;indentationStart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt; &lt;span class="n"&gt;indentationStart&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;'{'&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setIndentationStarts&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;indentationStart&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: set the indentations end characters, so when the user type those characters the indentation level should decrease for example &lt;code&gt;}&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Character&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;indentationEnds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt; &lt;span class="n"&gt;indentationEnds&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;'}'&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setIndentationEnds&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;indentationEnds&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: set the tab length and enable the auto indenting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setTabLength&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setEnableAutoIndentation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can easily change the highlighting color&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setMatchingHighlightColor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AYFp68o_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5229wr637a3in0u2sute.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AYFp68o_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5229wr637a3in0u2sute.gif" alt="Image description" width="310" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have done :D, Enjoying Auto indenting.&lt;/p&gt;

&lt;p&gt;The second feature is inspired by a Feature suggestion from a user of CodeView, which is the ability to highlight and get the matched substring and also replace it with another text easily, this feature you can also see in the modern Code Editors and IDE’s like Vs Code, Android Studio…etc.&lt;/p&gt;

&lt;p&gt;So now CodeView provide some methods to help you implement find and replace dialog.&lt;/p&gt;

&lt;p&gt;To get all the matched substrings from the text you can use findMatches.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Token&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findMatches&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;regex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To Find and highlight the next matching token, returns null if not found.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Token&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findNextMatch&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To Find and highlight the previous matching token, returns null if not found.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Token&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findPrevMatch&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To Clear all matching highlighted token.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;clearMatches&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To Replace the first string that matches regex with other string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;replaceFirstMatch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;regex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;replacement&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To Replace all strings that match regex with other string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;codeView&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;replaceAllMatches&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;regex&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;replacement&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GrDxB2FB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mf6ifnur557ad801eg5q.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GrDxB2FB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mf6ifnur557ad801eg5q.gif" alt="Image description" width="318" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example app on GitHub, you will find dialog that use this feature to support find and replacement&lt;/p&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>android</category>
      <category>java</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>Android CodeView: Create a code editor with Snippets</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Wed, 01 Dec 2021 21:11:07 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/android-codeview-create-a-code-editor-with-snippets-1eba</link>
      <guid>https://dev.to/amrdeveloper/android-codeview-create-a-code-editor-with-snippets-1eba</guid>
      <description>&lt;p&gt;Hello everyone, I am Amr Hesham a Software Engineer, I am interested in Android Development and Compiler Design, in the last few articles I showed you some cool features on how to use the CodeView library to create your own code editor for your custom language or data format with syntax highlighter, autocomplete, error and warn highlighter, highlight search result …etc. and in this article I will show you how to implement code snippets in your editor easily using CodeView 1.1.0.&lt;/p&gt;

&lt;p&gt;Snippets or Live Templates are very useful features and you can find them in most of the modern Code editors and IDE’s like Visual Studio Code and all of JetBrains IDE’s such as Android Studio, IntelliJ IDEA because it helps us to write repeating code patterns easily with few characters and help you write code faster, and this feature will be very needed in your Code Editor App to make the user write fast on the Mobile Device, when you type for and the IDE write for loop for you that’s what is called snippets.&lt;/p&gt;

&lt;p&gt;Starting from version 1.1.0, CodeView help you to support snippets easily with few lines of code, Let’s start by implementing our example, in this example, we want to help our Java Developers users to start writing code fast, so our goal is when the user clicks on snippet with prefix ‘main’ we will insert the Hello World code for them.&lt;/p&gt;

&lt;p&gt;To learn how to add CodeView in your project and how to create a highlighter for Java please check this Article and the official repository, so we can focus on the Code Snippets feature.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Github Repository: &lt;a href="https://github.com/AmrDeveloper/codeview"&gt;AmrDeveloper/codeview&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After you implement Java Highlighter it’s time to add your keyword and snippets.&lt;/p&gt;

&lt;p&gt;In the CodeView library keywords and snippets are classes that implementing the Code interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Code&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getCodeTitle&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getCodePrefix&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getCodeBody&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class has three attributes title, prefix and body, It’s important to know the difference between them&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The title is that text that you see on the autocomplete dropdown menu so it can be for example “Keyword Package”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The prefix is that text that we use it for filtering in the autocomplete adapter for example “package”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The body is what we inserted in the code when the user types a string that is a subset of the prefix and then he clicks on the title for example “package main;”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You will understand the different Cleary when we write some examples, so lets start by the first example.&lt;/p&gt;

&lt;p&gt;First, you need to create a list that contains all your keywords and snippets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;mainPackageTitle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="nc"&gt;Code&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;mainPacakgePrefx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;mainPackageBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;main&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;npublic&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
 &lt;span class="err"&gt;“\&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;tpublic&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
 &lt;span class="err"&gt;“\&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;tSystem&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;\”&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;World&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="err"&gt;\”&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;codes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class="n"&gt;codes&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Snippet&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mainPackageTitle&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mainPacakgePrefx&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mainPackageBody&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you need to create CodeViewAdapter and set it to CodeView object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;CodeViewAdapter&lt;/span&gt; &lt;span class="n"&gt;codeAdapter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CodeViewAdapter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;codes&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;codeview&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setAdapter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;codeAdapter&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we created our snippet with prefix ‘main’ so once the user input is a subset of ‘main’ the user will see “Main Code” option in the AutoComplete dropdown menu and once he chooses it the hello world example will be inserted in Code View editor and the final result will be like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EWPwa9LX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3ql0kbe41pj0ju7nt75.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EWPwa9LX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3ql0kbe41pj0ju7nt75.gif" alt="CodeView Snippets demo" width="446" height="811"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can add as many snippets as you want, but what if you want the autocomplete drop down menu to show snippets and keywords together, That’s easy because both classes are Code type soo you can add both of them to the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;codes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class="n"&gt;codes&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Keyword&lt;/span&gt;&lt;span class="o"&gt;(..,&lt;/span&gt; &lt;span class="o"&gt;..,&lt;/span&gt; &lt;span class="o"&gt;..));&lt;/span&gt;
&lt;span class="n"&gt;codes&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Snippet&lt;/span&gt;&lt;span class="o"&gt;(..,&lt;/span&gt; &lt;span class="o"&gt;..,&lt;/span&gt; &lt;span class="o"&gt;..));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s easy and you can extend this example so you can give the user the power to define his keyword and snippets! and your work is just inserted them on the list and pass it to the CodeViewAdapter.&lt;/p&gt;

&lt;p&gt;For users of Versions before 1.1.0, you still have the old option to create autocomplete feature with an array of strings using the normal ArrayAdapter, so your old code will not break.&lt;/p&gt;

&lt;p&gt;In the end I hope that you loved this feature, you can check the full documentation and example of CodeView in the GitHub repository, if you love it give it a star and you are most welcome to suggest features, report bugs, write articles, contribute to the code.&lt;/p&gt;

&lt;p&gt;You can find me on: &lt;a href="https://github.com/AmrDeveloper"&gt;GitHub&lt;/a&gt;, &lt;a href="https://www.linkedin.com/in/amrdeveloper"&gt;LinkedIn&lt;/a&gt;, &lt;a href="https://twitter.com/amrdeveloper"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy CodeView and Programming 😋&lt;/p&gt;

</description>
      <category>android</category>
      <category>java</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>Regex Named Groups and Backreferences</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Mon, 29 Nov 2021 07:12:38 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/regex-named-groups-and-backreferences-5dni</link>
      <guid>https://dev.to/amrdeveloper/regex-named-groups-and-backreferences-5dni</guid>
      <description>&lt;p&gt;Hi, I am Amr Hesham a Software Engineer, I am interested in Android Development and Compiler Design, In this article, I will talk about very good and useful feature which is Regex Named group and Backreferences with examples,&lt;/p&gt;

&lt;p&gt;Regex Named group and Backreferences introduced first time in Python re module then Microsoft developers supported it in .NET with different syntax, and Java supported it from JDK 7, Now it supported in most of the modern programming languages like Ruby, PHP, R …etc,&lt;/p&gt;

&lt;p&gt;This feature helps you to group your regular expressions with name and reference to those groups later in the regex, to learn more about the history of this feature and more details I recommend checking regular-expressions.info tutorials written by Jan Goyvaerts.&lt;/p&gt;

&lt;p&gt;Let’s start with examples about how to define a named group and get group by name and by index, I will use Kotlin programming language, the concepts are the same, bug as i said before but some non JVM languages have different syntax for the same feature.&lt;/p&gt;

&lt;p&gt;Suppose we want to parse color attributes in our Android project color.xml file and print each color name and value, for example here we have 3 colors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;color name="black"&amp;gt;#000000&amp;lt;/color&amp;gt;
&amp;lt;color name="white"&amp;gt;#ffffff&amp;lt;/color&amp;gt;
&amp;lt;color name="grey"&amp;gt;#cccccc&amp;lt;/color&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we want to print&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;black #000000
white #ffffff
grey #cccccc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can do this task using many different techniques, but I will show you how to do it using regex named groups easily.&lt;/p&gt;

&lt;p&gt;First, we need to create a regex that matches each attribute normally, each attribute contains type, name and value like this&lt;/p&gt;

&lt;p&gt;value&lt;/p&gt;

&lt;p&gt;So the normal regex will be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;\\w+ name=\"\\w+\"&amp;gt;.+&amp;lt;/\\w+&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use &lt;a href="https://regex101.com/"&gt;Regex101.com&lt;/a&gt; to test your regex easily and understand it, but make sure you use selected Java 8 flavor.&lt;/p&gt;

&lt;p&gt;Now after we created our regex we need to group the information that we need to get them,&lt;/p&gt;

&lt;p&gt;What we need is attribute name and value, so just put their regex inside ( ) like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;\\w+ name=\"(\\w+)\"&amp;gt;(.+)&amp;lt;/\\w+&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now attribute name will be in group number 1 because group number 0 contains the full text which is matched by our full regex and attribute value on group number 2,&lt;/p&gt;

&lt;p&gt;To get information first, We will compile this pattern&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val pattern = Pattern.compile(attributePattern)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we will get every substring that matches our pattern, and get the 2 groups 1 and 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val matcher = pattern.matcher(text) 
while (matcher.find()) {
    val attributeName = matcher.group(1)
    val attributeValue = matcher.group(2)
    println("$attributeName $attributeValue")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it!! and the output will be exactly what we want.&lt;/p&gt;

&lt;p&gt;To use grouping by name all you need is to add a name for each group, just add ? inside your group for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;\\w+ name=\"(?&amp;lt;KEY&amp;gt;\\w+)\"&amp;gt;(?&amp;lt;VALUE&amp;gt;.+)&amp;lt;/\\w+&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Group name must be an alphanumeric sequence starting with a letter and you can’t name two groups with the same name.&lt;/p&gt;

&lt;p&gt;Now instead of getting group by index like 1, 2 we will use KEY and VALUE,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (matcher.find()) {
    val attributeName = matcher.group("KEY")
    val attributeValue = matcher.group("VALUE")
    println("$attributeName $attributeValue")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you will get the same output :D.&lt;/p&gt;

&lt;p&gt;Now after we learned about what is named groups and how we can use it, it’s time for Backreferences.&lt;/p&gt;

&lt;p&gt;Basically Backreferences used to match the same text as previously matched by a group, for example suppose we want to check if a number contain only one repeated digit like 1, 22, 333, 444 so how we can do this using Regex,&lt;/p&gt;

&lt;p&gt;To use Backreferences first we need to define a group and our group in this case will be one digit (?\d), so this will match the first digit right, then we will use Backreferences to check if all other digits are the same as the matched text for our first one, to do this you can use ‘\k’ or by index like ‘\1’.&lt;/p&gt;

&lt;p&gt;Our full regex will be “(?\d)\k&lt;em&gt;” or “(\d)\1&lt;/em&gt;” this means we expect one digit with a group DIGIT and zero or more of the same digit that matched by this group, full code will be like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun main() {     
    val repeatedDigitRegex = "(?&amp;lt;DIGIT&amp;gt;\\d)\\k&amp;lt;DIGIT&amp;gt;*"
    val pattern = Pattern.compile(repeatedDigitRegex) 
    println(pattern.matcher("1").matches())
    println(pattern.matcher("22").matches())
    println(pattern.matcher("333").matches())
    println(pattern.matcher("4444").matches())
    println(pattern.matcher("10").matches())
    println(pattern.matcher("21").matches())
    println(pattern.matcher("101").matches())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And output will be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;true true true true false false false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are many ideas that can be created using this feature for example check if HTML start and closed by the same tag, check if anything is repeated …etc&lt;/p&gt;

&lt;p&gt;There is another useful method called replaceAll from matcher class, it can replace the current matched substring with any string or with group matched text using references, for example in the last example if we want to replace all the repeated digits with only one of them, so we need to replace the regex with just the first group of it.&lt;/p&gt;

&lt;p&gt;So instead of using matches we will use replaceAll and pass the group reference by a number which is $1, code will be like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;println(pattern.matcher("2222").replaceAll("$1"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and printed output will be 2&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this article and if you want to learn more about this topic there are some useful resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.regular-expressions.info/"&gt;regular-expressions.info&lt;/a&gt; website for many good Tutorial and information&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.regular-expressions.info/books.html"&gt;regular-expressions.info/books&lt;/a&gt; regex books reviews from Jan Goyvaerts&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=c9HbsUSWilw"&gt;Regular Expressions&lt;/a&gt;: Capturing Groups from The Coding Train channel&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enjoy Programming 😋.&lt;/p&gt;

</description>
      <category>java</category>
      <category>kotlin</category>
      <category>regex</category>
      <category>android</category>
    </item>
    <item>
      <title>Create a simple bot creator in 33 lines of code</title>
      <dc:creator>Amr Hesham</dc:creator>
      <pubDate>Wed, 19 May 2021 09:39:30 +0000</pubDate>
      <link>https://dev.to/amrdeveloper/create-a-simple-bot-creator-in-33-lines-of-code-25b9</link>
      <guid>https://dev.to/amrdeveloper/create-a-simple-bot-creator-in-33-lines-of-code-25b9</guid>
      <description>&lt;p&gt;Hi, I am Amr Hesham and I am a software engineer who interested in android development and compiler design, and I love to play some RPG games, but some of those games have designed to make your stay on the game as much as possible, So they give you some repeated and boring tasks to do and it’s maybe every day, for example, collect several items …etc, so I have searched for a bot creator to use it and automate those tasks.&lt;/p&gt;

&lt;p&gt;I have found a good one with many features like control mouse, keyboard, screen, check pixel color with some helper statements like if, loop …etc.&lt;/p&gt;

&lt;p&gt;But to create your script you need to add a list of command with the GUI that means you can write a script like any programming language and I hated this idea, So after trying this program I got one question how can I design one like this or maybe better than it ?!&lt;/p&gt;

&lt;p&gt;I started searching for how to control the mouse, screen, keyboard in Java, and after some research, I got many answers and found an amazing class in java called Robot.&lt;/p&gt;

&lt;p&gt;Robot as you can see in Oracle documentation&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“This class is used to generate native system input events for test automation, self-running demos, and other applications where control of the …”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and it has many useful methods to do exactly what I want, and in this time I have read some Compiler Design books and created many toy programming languages, and also have a good experience in JavaFX Framework, so I found that it will be amazing if I merged my experience in Compiler Design, JavaFX and Robot Class to create my amazing Bot Creator Project.&lt;/p&gt;

&lt;p&gt;I have started to create a scripting programming language with keywords for mouse, keyboard, screen then I added support for statements so I added if, while, repeat statements, after that, I want to make it easy for the user to create a complex bot so I have added support for variables, functions and builtin function, for example, I have added builtin function called pixelColor to get the current mouse position pixel value, after finishing this language, it’s time for JavaFX to start so I have created a simple editor for it with some buttons like run, stop, restart …etc. and this is the result I called it &lt;a href="https://github.com/amrdeveloper/snapmacro"&gt;SnapMacro&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lSlu2YkP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho2pmkyxtxa08uoop7oa.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lSlu2YkP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho2pmkyxtxa08uoop7oa.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After finished this project and using it in online games, I used it also to write a bot for Linkedin to add people or maybe I can use it to accept many people inventions and other things.&lt;/p&gt;

&lt;p&gt;This is the story behind SnapMacro, by the way, Snap is the name of my scripting language, but the article is not ended here and the goal is not just telling my story but it to show you how to create a simple bot creator in just 33 lines with the same concept.&lt;/p&gt;

&lt;p&gt;yes as you can see it will just 33 lines of code!&lt;/p&gt;

&lt;p&gt;We will not create a scripting language or support statements or variables, but we will create a simple bot creator that supports mouse, keyboard commands.&lt;/p&gt;

&lt;p&gt;So first what we want from our small bot creator? basically, we will support 3 types of commands and the result will be 7 commands.&lt;/p&gt;

&lt;p&gt;Mouse Commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mouse move x y
mouse press right | left
mouse release right | left
mouse wheel x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keyboard Commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;keyboard press x
keyboard release x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delay Commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;delay x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So let’s start creating our bot creator, and we will use Kotlin Programming language in this article but you can use Java too or take the concept and use your favourite programming language it doesn’t matter.&lt;/p&gt;

&lt;p&gt;First, we will use the Scanner class to read user input from the console and we will initialize an instance of Robot Class and we will user when to check what is the type of current command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;scanner&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Scanner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;`in`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;robot&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Robot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasNext&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"mouse"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
            &lt;span class="s"&gt;"keyboard"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
            &lt;span class="s"&gt;"delay"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now inside every type, we need to support some commands so let us start with the smallest one “delay” is has only one command which is delay x that take time in a millisecond as an integer and use The Robot API to make delay, so the code will be like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="s"&gt;"delay"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s move to mouse commands and it has 4 commands move, click and wheel, first “press” command and it will take right or left and we will use when to check this, then we have “release” and it exactly like “press” in the structure, then we have “move” command and it takes x and y values and moves the cursor to this position so we need to scan two integers for this command, after that we have “wheel” command and it need just one positive or negative integer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="s"&gt;"mouse"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"press"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"right"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mousePress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BUTTON3_DOWN_MASK&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="s"&gt;"left"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mousePress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BUTTON1_DOWN_MASK&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="s"&gt;"release"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"right"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mouseRelease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BUTTON3_DOWN_MASK&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="s"&gt;"left"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mouseRelease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BUTTON1_DOWN_MASK&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="s"&gt;"move"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mouseMove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="s"&gt;"wheel"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mouseWheel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now we finished the mouse command and we will go for keyboard commands, it has only two commands, “press” and “release” and they take character code, but it will not be very good to force the user to write the keycode like so we will read a character and convert it to a keycode, Robot has a good function that will do this job for use it called getExtendedKeyCodeForChar it takes char and return keycode as an integer, so the keyboard commands part will be like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="s"&gt;"keyboard"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;action&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;character&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;key&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KeyEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getExtendedKeyCodeForChar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;character&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;toInt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;"press"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keyPress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="s"&gt;"release"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keyRelease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now Congratulation, you have a simple bot creator so now you can write a script like that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mouse point 500 500
mouse press left
delay 500
mouse release left
mouse wheel 100
keyboard press A
delay 500
keyboard release A
delay 500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And it will work fine :D&lt;/p&gt;

&lt;p&gt;And this is the full code is about 33 lines of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;scanner&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Scanner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;`in`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;robot&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Robot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasNext&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"mouse"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="s"&gt;"press"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="s"&gt;"right"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mousePress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BUTTON3_DOWN_MASK&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                        &lt;span class="s"&gt;"left"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mousePress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BUTTON1_DOWN_MASK&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="s"&gt;"release"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="s"&gt;"right"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mouseRelease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BUTTON3_DOWN_MASK&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                        &lt;span class="s"&gt;"left"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mouseRelease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BUTTON1_DOWN_MASK&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="s"&gt;"move"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mouseMove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                &lt;span class="s"&gt;"wheel"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mouseWheel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="s"&gt;"keyboard"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;action&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;character&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;key&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KeyEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getExtendedKeyCodeForChar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;character&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;toInt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="s"&gt;"press"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keyPress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="s"&gt;"release"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keyRelease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="s"&gt;"delay"&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;robot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nextInt&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are interested in this type of projects you shouldn’t stop here, and try to improve it as must as you can, if you want to convert it to a scripting language I recommend to you &lt;a href="https://craftinginterpreters.com"&gt;Crafting Interpreter book&lt;/a&gt; that will teach you how to create a compiler and interpreter, you can also store the commands and support some new commands like restart, exit …etc.&lt;/p&gt;

&lt;p&gt;Thanks and Enjoy Coding 😋.&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>robot</category>
      <category>bot</category>
      <category>botcreator</category>
    </item>
  </channel>
</rss>
