<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hans Ulrich Wyss</title>
	<atom:link href="http://www.huwyss.com/feed" rel="self" type="application/rss+xml" />
	<link>https://www.huwyss.com</link>
	<description>Professional Software Development and Continuous Learning</description>
	<lastBuildDate>Fri, 18 Jan 2019 21:14:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.8</generator>
	<item>
		<title>Resolutions 2019 and Review 2018</title>
		<link>https://www.huwyss.com/petprojects/resolutions-2019-and-review-2018</link>
					<comments>https://www.huwyss.com/petprojects/resolutions-2019-and-review-2018#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Fri, 18 Jan 2019 21:14:59 +0000</pubDate>
				<category><![CDATA[petprojects]]></category>
		<category><![CDATA[android game]]></category>
		<category><![CDATA[level it]]></category>
		<category><![CDATA[Manta Chess Engine]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=938</guid>

					<description><![CDATA[<p>During the last year I had to take care of a personal issue that consumed most of my time and energy. So I fell short of several of my goals in 2018. &#160; Review Goals 2018 &#160; 1. Read 3 technical Books I read Uncle Bobs &#8220;Clean Architecture&#8221;. &#160; 2. Improve the Chess Engine I <a class="more-link" href="https://www.huwyss.com/petprojects/resolutions-2019-and-review-2018">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/petprojects/resolutions-2019-and-review-2018">Resolutions 2019 and Review 2018</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>During the last year I had to take care of a personal issue that consumed most of my time and energy. So I fell short of several of my goals in 2018.</p>
<p>&nbsp;</p>
<h4>Review Goals 2018</h4>
<p>&nbsp;</p>
<h5>1. Read 3 technical Books</h5>
<p>I read Uncle Bobs &#8220;Clean Architecture&#8221;.<br />
&nbsp;</p>
<h5>2. Improve the Chess Engine</h5>
<p>I implemented the minor promotion (pawn to queen) <a href="https://reversephonelookuponline.com/phone/6155448550">615-544-8550</a> , improved the code quality and added many unit tests. It however doesn&#8217;t beat me yet.<br />
&nbsp;</p>
<h5>3. Certification C#</h5>
<p>not done.<br />
&nbsp;</p>
<h5>4. JavaScript or TypeScript Application</h5>
<p>not done.<br />
&nbsp;</p>
<h5>5. Learn ASP.NET MVC</h5>
<p>I read &#8220;ASP.NET MVC 5 Pro&#8221; by Adam Freeman and implemented a web application using the technology.<br />
&nbsp;<br />
&nbsp;</p>
<h4>Coding Resolutions 2019</h4>
<p>&nbsp;</p>
<h5>1. Read 3 Technical Books</h5>
<p>&#8220;Code Complete&#8221; by Steve McConnell, &#8220;Pattern of Enterprise Application Architecture&#8221; by Martin Fowlers, and one more that isn&#8217;t selected yet.<br />
&nbsp;</p>
<h5>2. Improve Chess Engine</h5>
<p>a) I improve the search algorithm (currently brute force min max is implemented), and (b) the engine needs to connect to a standard GUI.<br />
&nbsp;</p>
<h5>3. Improve the Android Game &#8220;Levels It!&#8221;</h5>
<p>I want to implement 20 new Levels and a new world.</p><p>The post <a href="https://www.huwyss.com/petprojects/resolutions-2019-and-review-2018">Resolutions 2019 and Review 2018</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/petprojects/resolutions-2019-and-review-2018/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Intro on How to Write a Chess Engine</title>
		<link>https://www.huwyss.com/petprojects/intro-on-how-to-write-a-chess-engine</link>
					<comments>https://www.huwyss.com/petprojects/intro-on-how-to-write-a-chess-engine#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Sat, 17 Mar 2018 23:16:13 +0000</pubDate>
				<category><![CDATA[petprojects]]></category>
		<category><![CDATA[chess]]></category>
		<category><![CDATA[chess computer]]></category>
		<category><![CDATA[chess engine]]></category>
		<category><![CDATA[mantachessengine]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=928</guid>

					<description><![CDATA[<p>I am interested in chess and always wanted to write my own chess engine. About a year ago I started to code my own engine MantaChessEngine in C#. The goal is that the engine beats me. As I&#8217;m not a strong player that should not be much of a problem. Today my engine can actually <a class="more-link" href="https://www.huwyss.com/petprojects/intro-on-how-to-write-a-chess-engine">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/petprojects/intro-on-how-to-write-a-chess-engine">Intro on How to Write a Chess Engine</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I am interested in chess and always wanted to write my own chess engine. About a year ago I started to code my own engine MantaChessEngine in C#. The goal is that the engine beats me. As I&#8217;m not a strong player that should not be much of a problem. Today my engine can actually play. Last time I played I won and since then I haven&#8217;t significantly improved its strength. So obviously I&#8217;m  not yet done. If you are interested you can watch the engine progress on Github&#8230;</p>
<p>In this article I give a short introduction on how to code a chess engine. If you are interested have a look at the code of my <a href="https://github.com/huwyss/MantaChessEngine" rel="noopener" target="_blank">chess engine on Github: MantaChessEngine</a>.</p>
<p>&nbsp;</p>
<h4>Chess Engine Framework</h4>
<p>The framework itself is very simple. It holds references to all the parts of the engine and lets the client access the methods required to play a game of chess. It also holds a reference to the board with its pieces.</p>
<p>I wanted to be able to let one instance of the engine play versus another instance of the engine with the same or with a different configuration. That way one could see how a certain search or evaluation strategy would do versus another.</p>
<p>And of course the engine needs to be easily testable!</p>
<p>Here is an overview of the main classes and interfaces used:</p>
<p><a href="https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngineUML.jpg"><img fetchpriority="high" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngineUML-1024x436.jpg" alt="20180317 - ChessEngineUML" width="730" height="311" class="alignnone size-large wp-image-930" srcset="https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngineUML-1024x436.jpg 1024w, https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngineUML-300x128.jpg 300w, https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngineUML.jpg 1048w" sizes="(max-width: 730px) 100vw, 730px" /></a></p>
<h4>Board Representation</h4>
<p>The board holds an array of chess pieces. It can get and set pieces and it can execute moves and take moves back. It knows the state of the board: it knows which player still has the right to do one of the castlings and it knows which pawn has the right to do en passant capture. The board holds a reference to the History object that contains a list of the previously executed moves and board states.</p>
<p>&nbsp;</p>
<h4>Searching for the Best Move</h4>
<p>A chess engine needs to find the best move for one player. Lets say we want find the best move for white for the next 2 plies (1 ply = 1 move of one player). So first the MoveGenerator must find all possible moves for white and then for all those moves it must find all answers of black. Now the Evaluation must evaluate all the end positions. Note that all the moves are followed down to the maximum depth. Even if a queen gets lost after the first ply we still follow the moves to the maximum depth and only then evaluate at the end. The last step is to propagate the choices for each move of black and of white back to the first move. Now we have the best move or at least the best move for that particular algorithm.</p>
<p>&nbsp;</p>
<h4>Move Generator</h4>
<p>The main method of the MoveGenerator is GetAllMoves(color). I implemented my engine as a king capture engine. This means that GetAllMoves() returns a list of all pseudo legal moves for one opponent. Pseudo legal means all the normal moves are included in the list that each chess piece can do. It even includes the moves where the own king is under attack. These illegal moves must not actually be played. These moves will be filtered out later when the evaluation of the position takes place.</p>
<p>There is however one situation where the MoveGenerator returns no moves: if the player has lost its king. As the game has ended already we do not follow all moves down to the maximum depth in this situation.</p>
<p>In my first implementation of the MoveGenerator I did it all in one class. It was easy to test but became astonishingly complicated with a deep nesting of ifs and switches. Then I refactored out the chess pieces Pawn <a href="https://reversephonelookuponline.com/phone/6155445451">615-544-5451</a> , Bishop, Knight, Rook, Queen and King. They all know how they are allowed to move on the board.</p>
<p>&nbsp;</p>
<h4>Evaluation</h4>
<p>The Evaluation calculates the score of the board. If the score is positive then white has the better position, if the score is negative black is better.</p>
<p>My simplest Evaluation was to just add up points for all pieces, positive for white, negative for black: Pawn 1, knight 3, bishop 3, rook 5, queen 9. If the king is missing it returns the score for a lost game.</p>
<p>My next Evaluation includes some position info of the piece. Pawns for instance get 1.2 points if they are in the center or the knight gets 1 point in the middle of the board and 0.95 at the border. The player with two bishops gets a bonus of 0.5 points.</p>
<p>I guess there could be more useful special cases like check gives extra points or a rook on open file which I have not tested yet.</p>
<p>&nbsp;</p>
<h4>Minimax Search</h4>
<p>Lets have a look at the minimax algorithm that I used to search the best move (see image). In this example we search to the maximum depth of 2 plies. At “start” white can do two different moves: w1 and w2. As response to w1 black can do move b1 or b2, to answer w2 black can do b3 or b4. The Evaluation calculates the score of each end position. After move b1 it calculates the score 1, after b2 it calculates -1, and so on.</p>
<p>Let black choose its move. Black wants to have a score as low as possible, white wants as large as possible. In black&#8217;s move of course black can choose. From b1 or b2 it chooses b2 because the score is lower, from b3 or b4 black chooses b3 (circle in the image).</p>
<p>The chosen scores propagate back so that white can choose from. White knows its move w1 will score -1 and w2 will score 2. 2 is greater so white chooses w2.</p>
<p><a href="https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngine_searchminimax.jpg"><img decoding="async" src="https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngine_searchminimax.jpg" alt="20180317 - ChessEngine_searchminimax" width="538" height="366" class="alignnone size-full wp-image-934" srcset="https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngine_searchminimax.jpg 538w, https://www.huwyss.com/wp-content/uploads/2018/03/20180317-ChessEngine_searchminimax-300x204.jpg 300w" sizes="(max-width: 538px) 100vw, 538px" /></a></p>
<p>I hope this short intro gave you an overview on how to code a chess engine and made you curious to have a look at the code of <a href="https://github.com/huwyss/MantaChessEngine" rel="noopener" target="_blank">MantaChessEngine on github</a> or even to start your own engine.</p><p>The post <a href="https://www.huwyss.com/petprojects/intro-on-how-to-write-a-chess-engine">Intro on How to Write a Chess Engine</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/petprojects/intro-on-how-to-write-a-chess-engine/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>The 3 Most Important Ideas from The 10X Rule by Grant Cardone</title>
		<link>https://www.huwyss.com/success/the-3-most-important-ideas-from-the-10x-rule-by-grant-cardone</link>
					<comments>https://www.huwyss.com/success/the-3-most-important-ideas-from-the-10x-rule-by-grant-cardone#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Fri, 02 Mar 2018 23:36:34 +0000</pubDate>
				<category><![CDATA[success]]></category>
		<category><![CDATA[10X rule]]></category>
		<category><![CDATA[Grant Cardone]]></category>
		<category><![CDATA[massive action]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=923</guid>

					<description><![CDATA[<p>Recently I read this great book by Grant Cardone. To help myself and others to actually use the content I write down the three ideas that stood out the most for me. Here they are: &#160; 10X Goals and 10X Action For some reason we humans underestimate the actions required to achieve a goal. It <a class="more-link" href="https://www.huwyss.com/success/the-3-most-important-ideas-from-the-10x-rule-by-grant-cardone">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/success/the-3-most-important-ideas-from-the-10x-rule-by-grant-cardone">The 3 Most Important Ideas from The 10X Rule by Grant Cardone</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><iframe style="float:right; width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&#038;OneJS=1&#038;Operation=GetAdHtml&#038;MarketPlace=DE&#038;source=ac&#038;ref=tf_til&#038;ad_type=product_link&#038;tracking_id=frauenverst08-21&#038;marketplace=amazon&#038;region=DE&#038;placement=0470627603&#038;asins=0470627603&#038;linkId=d30d0d805919271562ca7925953162c8&#038;show_border=true&#038;link_opens_in_new_window=true&#038;price_color=000099&#038;title_color=000099&#038;bg_color=ffffff"><br />
</iframe></p>
<p>Recently I read this great book by Grant Cardone. To help myself and others to actually use the content I write down the three ideas that stood out the most for me. Here they are:</p>
<p>&nbsp;</p>
<h4>10X Goals and 10X Action</h4>
<p>For some reason we humans underestimate the actions required to achieve a goal. It always takes longer and there are always more problems and obstacles than expected. In software development this is true for sure.</p>
<p>So what happens if you set a normal goal? You underestimate the actions required, you take some action and run into more trouble than you thought and you fall short of the goal. But it wasn&#8217;t a giant goal, it was just a normal one! The normal goal did not motivate you to take massive action.</p>
<p>That is why the 10X rule says that you should set goals for yourself that are 10 times bigger than what you would normally and you need to take 10 times the action that you originally thought you would need to achieve your goals.</p>
<p>The giant goal is supposed to motivate you to take massive action!</p>
<p>&nbsp;</p>
<h4>Fear tells you where to go and when</h4>
<p>Fear is like a fire. Time is like oxygen. If you add oxygen to a fire it will burn stronger, if you remove the oxygen the fire extinguishes. Fear behaves very similar. If you fear and then wait and think about the fear will grow. If you act fast the fear loses its power over you. The fear does not need to go away. Fear is not a signal to stop. It is the signal to act.</p>
<p>Grant Cardone has this great saying that you should commit first and figure out the rest later. You should commit 100% first without knowing all the details. While working on it and taking massive action your creativity will kick in and help you in ways you didn&#8217;t think possible before.</p>
<p>Fear is an indicator in which direction to go and when to go.</p>
<p>&nbsp;</p>
<h4>Success</h4>
<p>Success is important. You must never reduce success in your mind or in a conversation to something that does not matter. Anyone who minimizes the importance of success to your future has given up on his own chances of accomplishment. Success is vital!</p>
<p>Success must be approached from an ethical viewpoint. Success is your duty <a href="https://reversephonelookuponline.com/phone/6155449656">615-544-9656</a> , obligation and responsibility! No one else is responsible for your success. You are! Success doesn&#8217;t happen to you, it happens because of you.</p>
<p>No one needs to fail if someone succeeds. Success is not a scarce resource. Success can be created without limit. There is no shortage of success.</p><p>The post <a href="https://www.huwyss.com/success/the-3-most-important-ideas-from-the-10x-rule-by-grant-cardone">The 3 Most Important Ideas from The 10X Rule by Grant Cardone</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/success/the-3-most-important-ideas-from-the-10x-rule-by-grant-cardone/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Code Fizzbuzz Without If-Statements or Loops</title>
		<link>https://www.huwyss.com/fundamentals/fizzbuzz-without-if-or-loop</link>
					<comments>https://www.huwyss.com/fundamentals/fizzbuzz-without-if-or-loop#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Fri, 16 Feb 2018 23:11:12 +0000</pubDate>
				<category><![CDATA[fundamentals]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[chain of responsibility]]></category>
		<category><![CDATA[coding without if]]></category>
		<category><![CDATA[fizzbuzz]]></category>
		<category><![CDATA[kata]]></category>
		<category><![CDATA[pattern]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=905</guid>

					<description><![CDATA[<p>A while ago I was attending the Global day of Coderetreat in Zurich. It is a day long coding practice event. Attendees work together in groups of two. In each session we coded the kata &#8220;game of life&#8221; from scratch puttygen , each time with different constraints. The constraint I found very interesting was this: <a class="more-link" href="https://www.huwyss.com/fundamentals/fizzbuzz-without-if-or-loop">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/fundamentals/fizzbuzz-without-if-or-loop">How to Code Fizzbuzz Without If-Statements or Loops</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>A while ago I was attending the <a href="http://zurich.codersonly.org/events/code-retreat/" rel="noopener" target="_blank">Global day of Coderetreat in Zurich</a>. It is a day long coding practice event. Attendees work together in groups of two. In each session we coded the <a href="https://www.huwyss.com/petprojects/the-first-5-coding-katas" rel="noopener" target="_blank">kata &#8220;game of life&#8221;</a> from scratch <a href="https://www.puttygen.net/">puttygen</a> , each time with different constraints. The constraint I found very interesting was this: Code game of life without if-statement or loop. In one of the sessions we tried to implement the the solution using a rules based approach. The sessions were not long enough to totally finish the code. It was more to see how a particular approach work. By the way it was amazing how many ways there are to code this simple program. Anyway I was fascinated by this rules based approach so later I tried this approach on the kata Fizzbuzz.</p>
<p>&nbsp;</p>
<h4>Fizzbuzz</h4>
<p>Fizzbuzz is simple: Write a method that prints the number you put in except print &#8220;fizz&#8221; if the number is dividable by 3, and &#8220;buzz&#8221; if it is dividable by 5, and &#8220;fizzbuzz&#8221; if it is dividable by 3 and 5.</p>
<p>&nbsp;</p>
<h4>Simple Solution</h4>
<p>The first solution that comes to mind would probably be something like this:</p>
<pre class="brush: csharp; title: ; notranslate">
public class FizzBuzzer
{
    public static string Evaluate(int number)
    {
        if (number % 15 == 0)
        {
            return &quot;fizzbuzz&quot;;
        }
        else if (number % 3 == 0)
        {
            return &quot;fizz&quot;;
        }
        else if (number % 5 == 0)
        {
            return &quot;buzz&quot;;
        }
        else
        {
            return number.ToString();
        }
    }
}
</pre>
<p>For this simple requirement this solution is completely fine. However what would you do if you wanted to be able to add new rules to the program without having to modify places where the exiting rules are coded?</p>
<p>&nbsp;</p>
<h4>Rule Interface: IRule</h4>
<p>One could hide the behavior of a rule behind an interface. DoesApply() tells if the rule applies. Apply() applies the rule and executes it.</p>
<pre class="brush: csharp; title: ; notranslate">
public interface IRule
{
    string Apply(int number);
    bool DoesApply(int number);
}
</pre>
<p>The implementation of this interface for the Fizz-rule looks like this:</p>
<pre class="brush: csharp; title: ; notranslate">
public class FizzRule : IRule
{
    public bool DoesApply(int number)
    {
        return number % 3 == 0;
    }

    public string Apply(int number)
    {
        return &quot;fizz&quot;;
    }
}
</pre>
<p>Basically the if part of the first solution has moved to DoesApply() and the &#8220;calculation&#8221; has moved to Apply().</p>
<p>&nbsp;</p>
<h4>How to Use the Rules</h4>
<p>Now we could create a list with all the rules and apply the rules in a foreach loop.</p>
<pre class="brush: csharp; title: ; notranslate">
public class FizzBuzzer
{
    private List&lt;IRule&gt; _rules;
    
    public FizzBuzzer()
    {
        _rules = new List&lt;IRule&gt;();
        _rules.Add(new FizzBuzzRule());
        _rules.Add(new FizzRule());
        _rules.Add(new BuzzRule());
        _rules.Add(new CatchAllRule());
    }

    public string Evaluate(int number)
    {
        foreach (var rule in _rules)
        {
            if (rule.DoesApply(number))
            {
                return rule.Apply(number);
            }
        }
 
        return null;        
 }
</pre>
<p>&nbsp;</p>
<h4>Chain of Responsibility Pattern</h4>
<p>However the constraint says no if and no loop. Lets use the Chain of Responsibility pattern to get rid of the loop.</p>
<p>SetNextHandler() is used to create the chain of concrete handlers and HandleRequest() uses the methods in IRules interface to either handle the request directly or pass it to the next handler.</p>
<pre class="brush: csharp; title: ; notranslate">
public abstract class Handler : IRule
{
    Handler _nextHandler;

    public void SetNextHandler(Handler nextHandler)
    {
        _nextHandler = nextHandler;
    }

    public string HandleRequest(int number)
    {
        return DoesApply(number) ? Apply(number) : _nextHandler.HandleRequest(number);
    }

    // IRules interface
    public abstract string Apply(int number);
    public abstract bool DoesApply(int number);
}
</pre>
<p>Because the class hierarchy changed a bit the rules are renamed to handlers and derive from Handler. Here&#8217;s the FizzHandler as example.</p>
<pre class="brush: csharp; title: ; notranslate">
public class FizzHandler : Handler
{
    public override bool DoesApply(int number)
    {
        return number % 3 == 0;
    }

    public override string Apply(int number)
    {
        return &quot;fizz&quot;;
    }
}
</pre>
<p>Now we need to construct the objects which is done in the class FizzBuzzer. Here it is:</p>
<pre class="brush: csharp; title: ; notranslate">
public class FizzBuzzer
{
    private Handler _firstHandler = null;

    public FizzBuzzer()
    {
        AddHandler(new CatchAllHandler());
        AddHandler(new BuzzHandler());
        AddHandler(new FizzHandler());
        AddHandler(new FizzBuzzHandler());
    }

    private void AddHandler(Handler previousHandler)
    {
        previousHandler.SetNextHandler(_firstHandler);
        _firstHandler = previousHandler;
    }

    public string Evaluate(int number)
    {
        return _firstHandler.HandleRequest(number);
    }
}
</pre>
<p>You can find the complete <a href="https://github.com/huwyss/KataCatalog/tree/master/KataFizzButt_NoIf" rel="noopener" target="_blank">FizzBuzz solution on Github</a>. <a href="https://whocallmenow.com/phone/6155446650">615-544-6650</a> </p><p>The post <a href="https://www.huwyss.com/fundamentals/fizzbuzz-without-if-or-loop">How to Code Fizzbuzz Without If-Statements or Loops</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/fundamentals/fizzbuzz-without-if-or-loop/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Win Friends and Influence People &#8211; Dale Carnegie</title>
		<link>https://www.huwyss.com/peopleskills/how-to-win-friends-and-influence-people-dale-carnegie</link>
					<comments>https://www.huwyss.com/peopleskills/how-to-win-friends-and-influence-people-dale-carnegie#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Sat, 03 Feb 2018 16:07:23 +0000</pubDate>
				<category><![CDATA[peopleskills]]></category>
		<category><![CDATA[dale carnegie]]></category>
		<category><![CDATA[how to win friends and influence people]]></category>
		<category><![CDATA[people skills]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=897</guid>

					<description><![CDATA[<p>Recently I have seen several recommendations for the book &#8220;How to Win Friends and Influence People&#8221; by Dale Carnegie so I went to the local library and picked it up. It was a great read with real practical advice and lots of examples. The title sounds somewhat cheesy and manipulative but it&#8217;s not at all. <a class="more-link" href="https://www.huwyss.com/peopleskills/how-to-win-friends-and-influence-people-dale-carnegie">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/peopleskills/how-to-win-friends-and-influence-people-dale-carnegie">How to Win Friends and Influence People – Dale Carnegie</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><iframe style="float:right;width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&#038;OneJS=1&#038;Operation=GetAdHtml&#038;MarketPlace=DE&#038;source=ac&#038;ref=tf_til&#038;ad_type=product_link&#038;tracking_id=frauenverst08-21&#038;marketplace=amazon&#038;region=DE&#038;placement=1439199191&#038;asins=1439199191&#038;linkId=98d1f3a2758029605f0c376ef627848f&#038;show_border=true&#038;link_opens_in_new_window=true&#038;price_color=000099&#038;title_color=000099&#038;bg_color=FFFFFF"></iframe><br />
Recently I have seen several recommendations for the book &#8220;How to Win Friends and Influence People&#8221; by Dale Carnegie so I went to the local library and picked it up. It was a great read with real practical advice and lots of examples. The title sounds somewhat cheesy and manipulative but it&#8217;s not at all. Basically it&#8217;s about how to find out what people want and then give it to them. In the book there is a nice summary of all the points and you find them easily on the internet. Just search for the book title. Therefore I&#8217;m not reciting them here. I want to point out a few that I think are very important:<br />
&nbsp;</p>
<h5>Don&#8217;t criticize <a href="https://phonenumberlookuponline.com/phone/6155440810">615-544-0810</a>  <a href="http://aiw-roi.com/phone/area/800.html">Telephone Area 800</a>  <a href="https://phonelookupbase.com/region/Michigan-989"> Michigan region phone </a> , condemn or complain!</h5>
<p>Criticism is futile because it puts a person on the defensive and usually makes them strive to justify themselves. This is very true. You can easily observe how your mental reaction is to someone criticizing you. Do you feel good? Do you feel motivated to do better? Do you like the other person criticizing you? Try to observe others if you criticize them. How do they react? How is the mood of your conversation afterwards? In my experience citicism does not really lead to what you intended. Try it out yourself and observe!<br />
&nbsp;</p>
<h5>Give honest and sincere appreciation!</h5>
<p>This is exactly the opposite of the point above. Some time ago I had a boss who compliented me on my good work often. I cannot objectivly tell if my work was that good. However the result of the compliments was that I felt motivated to do even better. I wanted to conform and to keep conforming to my bosses top notch opinion of me. Have you experienced something similar? Instead of criticizing others try to appreciate the thing they did good and observe what happens.<br />
&nbsp;</p>
<h5>Become genuinely interested in other people!</h5>
<p>Be a good listener! Encourage others to talk about themselves! Let the other person talk about her/his favorite person &#8211; herself/himself. I remember a situation when I was talking about something I&#8217;m interested in and the other person was listening closely, asking a few questions here and there but not talking much &#8211; just listening. The result? It made me feel totally understood and appreciated. It made me like the other person! Have you experienced this? Try to be interested in other people and try to learn stuff from them and observe what happens.<br />
&nbsp;<br />
Check out the book! It has lots of great insights!</p><p>The post <a href="https://www.huwyss.com/peopleskills/how-to-win-friends-and-influence-people-dale-carnegie">How to Win Friends and Influence People – Dale Carnegie</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/peopleskills/how-to-win-friends-and-influence-people-dale-carnegie/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Localization TextManager for Unity3d</title>
		<link>https://www.huwyss.com/level-it/localization-textmanager-for-unity3d</link>
					<comments>https://www.huwyss.com/level-it/localization-textmanager-for-unity3d#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Fri, 19 Jan 2018 21:12:22 +0000</pubDate>
				<category><![CDATA[Level It!]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[Resource manager]]></category>
		<category><![CDATA[text manager]]></category>
		<category><![CDATA[unity]]></category>
		<category><![CDATA[unity3d]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=880</guid>

					<description><![CDATA[<p>When trying to add localization to my mobile game Level It! for Android I wanted to use the .net resource manager but unfortunately got a weird error message from Visual Studio. Apparently this is not supported with Unity3d. This post describes a simple text manager to do the localization with Unity 3d. My starting point <a class="more-link" href="https://www.huwyss.com/level-it/localization-textmanager-for-unity3d">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/level-it/localization-textmanager-for-unity3d">Localization TextManager for Unity3d</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>When trying to add localization to my <a href="https://www.huwyss.com/levelit" rel="noopener" target="_blank">mobile game Level It! for Android</a> I wanted to use the .net resource manager but unfortunately got a weird error message from Visual Studio. Apparently this is not supported with Unity3d. This post describes a simple text manager to do the localization with Unity 3d.</p>
<p>My starting point was <a href="https://forum.unity.com/threads/textmanager-localization-script.35617/" rel="noopener" target="_blank">this solution</a> from the unity forum which I adapted to my needs. Thanks for the code. Hopefully the improvement in this post is helpful for someone. </p>
<p>The basic idea is to have a language file for each language. A language file consists of keys and contents. The language files need to be stored in the Unity solution (in Unity Editor) in a folder called Resources. To configure the Unity game with a language the script loads the textfile from the resources, parses it and stores the texts and keys in a dictionary. To retrieve a localized text call <code>GetText(key)</code>.</p>
<p>&nbsp;</p>
<h5>TextManager Class Definition</h5>
<pre class="brush: csharp; title: ; notranslate">
using UnityEngine;
using System.IO;
using System.Collections.Generic;
using System;
using Assets.Scripts;

public class TextManager : MonoBehaviour
{
    private static readonly IDictionary&lt;string, string&gt; TextTable = new Dictionary&lt;string, string&gt;();
    private static TextAsset _language;
</pre>
<p>&nbsp;</p>
<h5>Singleton Constructor</h5>
<p>TextManager is a singleton. I wanted to make sure there is only one TextManager in the system and the resource file should only be read once. Note the private constructor and the method instance. <code>DontDestroyOnLoad()</code> makes sure the object is not destroyed when a new scene is loaded.</p>
<pre class="brush: csharp; title: ; notranslate">
    private TextManager() { }

    private static TextManager _instance;
    public static TextManager instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = GameObject.FindObjectOfType&lt;TextManager&gt;();

                // Tell unity not to destroy this object when loading a new scene!
                DontDestroyOnLoad(_instance.gameObject);
            }

            return _instance;
        }
    }
</pre>
<p>&nbsp;</p>
<h5>Awake to Destroy Additional Instances</h5>
<p>When during the game you switch from a scene that does not have TextManager in its GameObjects list to a scene with TextManager then a new GameObject is created and the <code>Awake()</code> method is called on it. So if you use <code>DontDestroyOnLoad()</code> you would add another TextManager to the currently instanciated GameObjects. To make sure we only have one TextManager the implementation of <code>Awake()</code> destroys all additional TextManagers.</p>
<pre class="brush: csharp; title: ; notranslate">
    void Awake()
    {
        if (_instance == null)
        {
            // If I am the first instance &lt;a href=&quot;https://phonelookupbase.ca&quot;&gt;Phone Number Trace&lt;/a&gt; , make me the Singleton
            _instance = this;
            DontDestroyOnLoad(this);
            SetDefaultLanguage();
        }
        else
        {
            // If a Singleton already exists and you find
            // another reference in scene, destroy it!
            if (this != _instance)
                Destroy(this.gameObject);
        }
    }
</pre>
<p>&nbsp;</p>
<h5>Set the Default Language</h5>
<p><code>Persistence.GetLanguage()</code> returns the name of the language that the player has configured. It just reads a value from the <code>PlayerPrefs</code>. If the code is running for the first time we try to set the language that is set in the operating system. Definitions.GermanName, Definitions.EnglishName and Definitions.DefaultLanguages are constant strings. <code>Persistence.SetLanguage()</code> sets a value in the <code>PlayerPrefs</code>.</p>
<pre class="brush: csharp; title: ; notranslate">
public static void SetDefaultLanguage()
    {
        string language = Persistence.GetLanguage();
        if (language == &quot;&quot;)
        {
            var osLanguage = Application.systemLanguage;
            if (osLanguage == SystemLanguage.German)
            {
                language = Definitions.GermanName;
            }
            else if (osLanguage == SystemLanguage.English)
            {
                language = Definitions.EnglishName;
            }
            else
            {
                language = Definitions.DefaultLanguage;
            }
            
            Persistence.SetLanguage(language);
        }

        SetLanguage(language);
    }
</pre>
<p>&nbsp;</p>
<h5>Load the Text File from the Resources</h5>
<p>The method <code>SetLanguage()</code> loads the language text file in memory and calls <code>LoadLanguage()</code>.</p>
<pre class="brush: csharp; title: ; notranslate">

    public static void SetLanguage(string langFilename)
    {
        // Load a asset by its AssetName.
        // The text file must be located within 'Resources' subfolder in Unity ('Assets/Resources' in Visual Studio).
        TextAsset newLanguage = Resources.Load(langFilename) as TextAsset;
        if (newLanguage == null)
        {
            Debug.LogError(String.Format(&quot;No valid asset file.&quot;));
        }
        else
        {
            LoadLanguage(newLanguage);
            _language = newLanguage;
        }
    }

</pre>
<p>&nbsp;</p>
<h5>Parse the Text File to Create the Dictionary</h5>
<p><code>LoadLanguage()</code> parses the language text file and stores all entries in a dictionary. For the expected file format see below.</p>
<pre class="brush: csharp; title: ; notranslate">
    
    private static void LoadLanguage(TextAsset asset)
    {
        TextTable.Clear();

        var lineNumber = 1;
        using (var reader = new StringReader(asset.text))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                int firstSpaceIndex = line.IndexOf('=');
                if (firstSpaceIndex &amp;gt; 0)
                { 
                    var key = line.Substring(0 &lt;a href=&quot;https://whocallmenow.com/phone/6155445221&quot;&gt;615-544-5221&lt;/a&gt;  &lt;a href=&quot;http://aiw-roi.com/phone/area/900.html&quot;&gt;Telephone Area 900&lt;/a&gt; , firstSpaceIndex);
                    var val = line.Substring(firstSpaceIndex + 1);

                    if (key != null &amp;amp;&amp;amp; val != null)
                    {
                        var loweredKey = key.ToLower();
                        if (TextTable.ContainsKey(loweredKey))
                        {
                            Debug.LogWarning(String.Format(
                                     &amp;quot;Duplicate key '{1}' in language file '{0}' detected.&amp;quot;, asset.text, key));
                        }
                        TextTable.Add(loweredKey, val);
                    }
                }
                else
                {
                    Debug.LogWarning(String.Format(
                         &amp;quot;Format error in language file '{0}' on line {1}. Each line must be of format: key=value&amp;quot;,
                          asset.text, lineNumber));
                }

                lineNumber++;
            }
        }
    }

</pre>
<p>&nbsp;</p>
<h5>Retrieve the Localized Text</h5>
<p>This is the implementation that retrieves the localized text from the dictionary.</p>
<pre class="brush: csharp; title: ; notranslate">

    public string GetText(string key)
    {
        string result = &quot;&quot;;
        var loweredKey = key.ToLower();

        if (TextTable.ContainsKey(loweredKey))
        {
            result = TextTable&#x5B;loweredKey];
        }
        else
        {
            Debug.LogWarning(String.Format(&quot;Couldn't find key '{0}' in dictionary.&quot;, key));
        }

        return result;
    }
}
</pre>
<p>&nbsp;</p>
<h5>Text File Format</h5>
<p>The language files are expected to have this format:<br />
English.txt:</p>
<pre class="brush: plain; title: ; notranslate">
firstkey=first english text
key2=another english text
</pre>
<p>German.txt:</p>
<pre class="brush: plain; title: ; notranslate">
firstkey=erster deutscher Text
key2=Noch ein deutscher Text
</pre>
<p>The keys need to be the same in all language files.</p>
<p>German Umlauts<br />
To make sure the german umlauts (äöü) are properly displayed I set the encoding of the text file to UTF-8. For instance use Notepad++ and you find the Encoding in the menu.</p>
<p>&nbsp;</p>
<h4>Unity 3d</h4>
<p>Add the TextManager to the list of GameObjects in Unity. You only need to add it to the scene that is loaded first. The way we defined the constructor and the Awake() method the TextManager will always be there and exactly once.</p>
<p>To get localized text use this line of code:</p>
<pre class="brush: csharp; title: ; notranslate">
TextManager.instance.GetText(&quot;key&quot;);
</pre>
<p>So that&#8217;s it. Happy coding! 🙂</p><p>The post <a href="https://www.huwyss.com/level-it/localization-textmanager-for-unity3d">Localization TextManager for Unity3d</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/level-it/localization-textmanager-for-unity3d/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Review 2017 and Resolutions 2018</title>
		<link>https://www.huwyss.com/fundamentals/review-2017-and-resolutions-2018</link>
					<comments>https://www.huwyss.com/fundamentals/review-2017-and-resolutions-2018#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Sat, 06 Jan 2018 21:32:06 +0000</pubDate>
				<category><![CDATA[fundamentals]]></category>
		<category><![CDATA[new year's resolutions]]></category>
		<category><![CDATA[programming skills]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=871</guid>

					<description><![CDATA[<p>Review 2017 Here&#8217;s a quick review of the goals of 2017: Deploy and maintain &#8220;Level It!&#8221;. It is deployed and I developed the second release with several improvements. See Level It! page Chess engine that beats me. I developed the engine however it does not beat me yet. See Manta Chess Engine on Github Read <a class="more-link" href="https://www.huwyss.com/fundamentals/review-2017-and-resolutions-2018">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/fundamentals/review-2017-and-resolutions-2018">Review 2017 and Resolutions 2018</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<h4>Review 2017</h4>
<p>Here&#8217;s a quick review of the goals of 2017:</p>
<ol>
<li>Deploy and maintain &#8220;Level It!&#8221;. It is deployed and I developed the second release with several improvements. See <a href="https://www.huwyss.com/levelit" rel="noopener" target="_blank">Level It!</a><br />
 page</li>
<li>Chess engine that beats me. I developed the engine however it does not beat me yet. See <a href="https://github.com/huwyss/MantaChessEngine" rel="noopener" target="_blank">Manta Chess Engine</a> on Github</li>
<li>Read &#8220;Pattern of Enterprise Application Architecture&#8221;. I did not read it.</li>
<li>Run a coding dojo. Over the past year I ran five dojos.</li>
<li>Bonus: Implement another mobile game. I did not start this.</li>
</ol>
<p>&nbsp;</p>
<h4>My Programming Skills Goals 2018</h4>
<h5>1. Read 3 technical Books</h5>
<p>Probably those are going to be: Uncle Bobs &#8220;Clean Architecture&#8221; <a href="https://phonelookupbase.ca">https://phonelookupbase.ca</a> , &#8220;Code Complete&#8221;, Martin Fowlers &#8220;Pattern of Enterprise Application Architecture&#8221;.</p>
<h5>2. Improve my chess engine</h5>
<p>(a) Implement promotion (pawn to queen), (b) improve the search algorithm (currently brute force min max is implemented), and (c) it needs to connect to a standard GUI.</p>
<h5>3. Certification C#</h5>
<p>I have to check whether this certificate is still available and if it really makes sense. But I sharpen my C sharp skills this year. It could also be done via Pluralsight courses or something similar.</p>
<h5>4. JavaScript or TypeScript Application</h5>
<p>Recently I decided that I want to learn more about web development. An important piece of this is JavaScript. So my goal is to write a small game in JavaScript.</p>
<h5>5. Learn ASP.NET MVC</h5>
<p>As Part of the web development idea I want to learn ASP.NET MVC. This includes the Book &#8220;ASP.NET MVC 5 Pro&#8221; by Adam Freeman and implementing a web application using the technology.</p>
<p>So these are my programming skills tasks for this year&#8217;s free time. To get this done I intend to get up earlier so I can get an hour of activities done before work.</p>
<p> <a href="https://www.puttygen.net/">puttygen download windows</a>  <a href="https://phonenumberlookuponline.com/phone/6155445148">615-544-5148</a> </p><p>The post <a href="https://www.huwyss.com/fundamentals/review-2017-and-resolutions-2018">Review 2017 and Resolutions 2018</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/fundamentals/review-2017-and-resolutions-2018/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Regex Jumpstart Tutorial</title>
		<link>https://www.huwyss.com/fundamentals/regex-jumpstart-tutorial</link>
					<comments>https://www.huwyss.com/fundamentals/regex-jumpstart-tutorial#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Wed, 13 Dec 2017 21:49:40 +0000</pubDate>
				<category><![CDATA[fundamentals]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regex tutorial]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[regular expressions tutorial]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=835</guid>

					<description><![CDATA[<p>Several times in a project I had to use regular expressions to match some pattern in a string. I started reading several tutorials but the regexes looked just too cryptic to me. Fortunately I always found the answer on Stackoverflow that either did exactly what I wanted or something similar that could be adapted easily. <a class="more-link" href="https://www.huwyss.com/fundamentals/regex-jumpstart-tutorial">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/fundamentals/regex-jumpstart-tutorial">Regex Jumpstart Tutorial</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Several times in a project I had to use regular expressions to match some pattern in a string. I started reading several tutorials but the regexes looked just too cryptic to me. Fortunately I always found the answer on Stackoverflow that either did exactly what I wanted or something similar that could be adapted easily. However last week again I had to use regular expressions and I needed many. It was time to get my feet wet and actually learn how to use them. I don&#8217;t know all the exceptions and details of every regex dialect. That is not what this article is about. It&#8217;s about the basics. Hopefully it is helpful for those who haven&#8217;t really started yet. So here it is…</p>
<h3>Introduction</h3>
<p>With a regular expression you can find patterns in a string. For instance you can find certain keywords in a text or you can find specific formatted pattern (like email addresses, phone numbers, or hex numbers) in a text.</p>
<p>A regular expression represents a state machine which is used to parse a text to find matches. For most programming languages there are regex engines that are able to use regular expressions and find matches in a text.</p>
<h3>Developing and Testing Regexes</h3>
<p>When I develop a regular expression I find it very helpful to draw the state machine of the regex. Check out this Website which does exactly that. By the way all regex statemachine diagrams below were generated by <a href="https://regexper.com/" rel="noopener" target="_blank">this regex tool</a>.</p>
<p>To test a regex I use this very helpful <a href="https://regex101.com/" rel="noopener" target="_blank">regex test tool</a>. You can enter the regex and the text and see immediately while you type where the matches are.</p>
<h3>Literal Characters</h3>
<p>Lets say the regex is &#8220;ca&#8221; and the text is &#8220;dog, car, cat&#8221;. The engine starts at the &#8220;d&#8221; of &#8220;dog&#8221; of the text to try to match the &#8220;ca&#8221; of the regex. It finds the first match at the &#8220;ca&#8221; of &#8220;car&#8221;. As the regex is finished it starts over and tries to match again the &#8220;ca&#8221; of the regex in the text continuing at the next character in the text. After the space it finds the next match at &#8220;ca&#8221; of &#8220;cat&#8221;. This was the last match so we are done having found 2 matches.</p>
<p>The state machine is very simple. It only has one state.</p>
<h3>Escaping</h3>
<p>In the previous regex the characters we wanted to match &#8220;normal&#8221; letters. Lets consider we want to find &#8220;(&#8221; in a text. As &#8220;(&#8221; has a special meaning in regexes we need to escape it. So the regex is &#8220;\(&#8220;.</p>
<h3>Quantifiers</h3>
<p>There are symbols that define how many times the previous character (or group) must occur. * means the previous character must occur 0 or more times. For instance the regex &#8220;a*&#8221; matches &#8220;&#8221;, &#8220;a&#8221;, &#8220;aa&#8221;, …<br />
The quantifier refers to the previous characcter (or group). &#8220;abc*&#8221; matches &#8220;ab&#8221;, &#8220;abc&#8221;, &#8220;abcc&#8221; …</p>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Regex</th>
<th class="col-md-4">Statemachine</th>
<th class="col-md-6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
            &#8220;abc*&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/abc_star.jpg"><img decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/abc_star.jpg" alt="abc_star" width="199" height="85" class="alignnone size-full wp-image-845" /></a>
        </td>
<td>
            0 or more times
        </td>
</tr>
</tbody>
</table>
<p>Another quantifier is &#8220;+&#8221;. It means 1 or more times, ie. &#8220;abc+&#8221; matches &#8220;abc&#8221;, &#8220;abcc&#8221;, &#8220;abccc&#8221;, it does not match &#8220;ab&#8221;.</p>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Regex</th>
<th class="col-md-4">Statemachine</th>
<th class="col-md-6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
            &#8220;abc+&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/abc_plus.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/abc_plus.jpg" alt="abc_plus" width="201" height="72" class="alignnone size-full wp-image-843" /></a>
        </td>
<td>
            1 or more times
        </td>
</tr>
</tbody>
</table>
<p>&#8220;?&#8221; means 0 or 1 time, ie. &#8220;abc?&#8221; matches &#8220;ab&#8221; and &#8220;abc&#8221;.</p>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Regex</th>
<th class="col-md-4">Statemachine</th>
<th class="col-md-6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
            &#8220;abc?&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/abc_Question.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/abc_Question.jpg" alt="abc_Question" width="217" height="70" class="alignnone size-full wp-image-844" /></a>
        </td>
<td>
            0 or 1 times
        </td>
</tr>
</tbody>
</table>
<p>&#8220;{}&#8221; indicates a minimum and maximum occurrence of the preceding character. &#8220;abc{3}&#8221; matches &#8220;abccc&#8221;<br />
&#8220;abc{2,3}&#8221; matches &#8220;abcc&#8221; and &#8220;abccc&#8221;.</p>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Regex</th>
<th class="col-md-4">Statemachine</th>
<th class="col-md-6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
            &#8220;abc{2,3}&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/abc_curly.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/abc_curly.jpg" alt="abc_curly" width="215" height="86" class="alignnone size-full wp-image-842" /></a>
        </td>
<td>
            Min 2, max 3 times
        </td>
</tr>
</tbody>
</table>
<h3>Character Groups</h3>
<p>Character groups are written in square brakets []. The text matches to any of the characters in the group, ie. &#8220;[abc]&#8221; matches &#8220;a&#8221; or &#8220;b&#8221; or &#8220;c&#8221;.</p>
<p>The regex elements can be combined, see some examples in the table below.</p>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Regex</th>
<th class="col-md-4">Statemachine</th>
<th class="col-md-6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
            &#8220;a[bc]+&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/ab_or_c.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/ab_or_c.jpg" alt="ab_or_c" width="228" height="134" class="alignnone size-full wp-image-841" /></a>
        </td>
<td>
            matches &#8220;ab&#8221;, &#8220;ac&#8221;, &#8220;abb&#8221;, &#8220;abc&#8221;, &#8220;acc&#8221;, &#8220;acb&#8221;,… &#8220;abbbcccbbc&#8221; …
        </td>
</tr>
<tr>
<td>
            &#8220;[a-f]&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/a-f.jpb_.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/a-f.jpb_.jpg" alt="a-f.jpb" width="190" height="80" class="alignnone size-full wp-image-852" /></a>
        </td>
<td>
            Character range matches &#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;, &#8220;d&#8221;, &#8220;e&#8221; or &#8220;f&#8221;.
        </td>
</tr>
<tr>
<td>
            &#8220;[^a]&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/nona.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/nona.jpg" alt="nona" width="165" height="79" class="alignnone size-full wp-image-853" /></a>
        </td>
<td>
            Negation matches any character but &#8220;a&#8221;.
        </td>
</tr>
</tbody>
</table>
<h3>Grouping</h3>
<p>In (…) you can group parts of characters together, see table below.</p>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Regex</th>
<th class="col-md-4">Statemachine</th>
<th class="col-md-6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
            &#8220;(ab)*&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/ab_group.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/ab_group.jpg" alt="ab_group" width="200" height="123" class="alignnone size-full wp-image-838" /></a>
        </td>
<td>
            matches &#8220;&#8221;, &#8220;ab&#8221;, &#8220;abab&#8221;, ..
        </td>
</tr>
<tr>
<td>
            &#8220;(ab)|(1)&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/ab_or_1.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/ab_or_1.jpg" alt="ab_or_1" width="224" height="168" class="alignnone size-full wp-image-839" /></a>
        </td>
<td>
            matches to &#8220;ab&#8221; or &#8220;1&#8221;.
        </td>
</tr>
<tr>
<td>
            &#8220;(ab)+|(1)&#8221;
        </td>
<td>
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/ab_or_1_2.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/ab_or_1_2.jpg" alt="ab_or_1_2" width="250" height="180" class="alignnone size-full wp-image-840" /></a>
        </td>
<td>
            The grouping combined with quantifier. Example matches with &#8220;ab&#8221; <a href="https://reversephonelookuponline.com/phone/6155445408">615-544-5408</a> , &#8220;abab&#8221;, &#8220;ababab&#8221;, &#8220;1&#8221;.
        </td>
</tr>
</tbody>
</table>
<h3>Word Boundary</h3>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Regex</th>
<th class="col-md-4">Name</th>
<th class="col-md-6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
            &#8220;\b&#8221;
        </td>
<td>
Wordboundary
        </td>
<td>
            Regex: &#8220;\bworld\b&#8221;, text: &#8220;hello world, helloworld&#8221;. Matches the word &#8220;world&#8221; but does not match &#8220;helloworld&#8221;.
        </td>
</tr>
</tbody>
</table>
<h3>Example with Statemachine</h3>
<p>Let the regex be &#8220;\b0x[0-9a-f]+\b&#8221; and the text &#8220;add(0x1ff0, var)&#8221;. The regex engine take the first part of the regex &#8220;\b&#8221; and starts to try to find a match in the text. At the beginning we have a word boundary so the match starts. The next part of the regex is &#8220;0x&#8221;. The text continues with &#8220;a&#8221; of &#8220;add&#8221; which is no match. So we are looking for a word boundary again. It finds the match after the braket. Here is a word boundary and it finds a match for the &#8220;0x&#8221;. It goes to the next character in the text &#8220;1&#8221; and the next part of the regex &#8220;[0-9a-f]&#8221; and checks if they match. They do. The next character in the text is &#8220;f&#8221;. The next part of the regex is a word boundary or another &#8220;[0-9a-f]&#8221;. The engine tries to find the longest match possible. The &#8220;f&#8221; matches. This goes on until there is a word boundary at the &#8220;,&#8221;. The regex ends. So the engine found &#8220;0x1ff0&#8221; and after that no other matches are found.<br />
<a href="https://www.huwyss.com/wp-content/uploads/2017/12/hex.jpg"><img loading="lazy" decoding="async" src="https://www.huwyss.com/wp-content/uploads/2017/12/hex-300x71.jpg" alt="hex" width="300" height="71" class="alignnone size-medium wp-image-863" srcset="https://www.huwyss.com/wp-content/uploads/2017/12/hex-300x71.jpg 300w, https://www.huwyss.com/wp-content/uploads/2017/12/hex.jpg 534w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>The point is the engine is processing the regex starting at the beginning of the regex then walks character by character through the text. If it finds a match it goes to the next character of the regex. If this regex-character does not match the text then the engine starts again at the beginning of the regex and continues at the place in the text where it left off.</p>
<h3>Anchor</h3>
<p>The regex &#8220;^abc&#8221; anchors the match to the start of the text. In other words: to match the text must start with &#8220;abc&#8221;.<br />
The regex &#8220;abc$&#8221; anchors the match to the end of the text. In other words: to match the text must end with &#8220;abc&#8221;.<br />
 </p>
<h3>Shortcodes</h3>
<p>Here are some often used shortcodes:</p>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Shortcode</th>
<th class="col-md-4">Explicit From</th>
<th class="col-md-6">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#8220;\s&#8221;</td>
<td>&#8220;[\t\f\n\r ]&#8221;</td>
<td>whitespace</td>
</tr>
<tr>
<td>&#8220;\d&#8221;</td>
<td>&#8220;[0-9]&#8221;</td>
<td>digit</td>
</tr>
<tr>
<td>&#8220;\w&#8221;</td>
<td>&#8220;[AZ-a-z0-9_]&#8221;</td>
<td>wordcharacters</td>
</tr>
<tr>
<td>&#8220;\D&#8221;</td>
<td>&#8220;[^0-9]&#8221;</td>
<td>Anything but a digit (negation)</td>
<tr>
<td>&#8220;\W&#8221;</td>
<td>&#8220;[^A-Za-z0-9_]&#8221;</td>
<td>Anything but a wordcharacter (negation)</td>
<tr>
<td>&#8220;\S&#8221;</td>
<td>&#8220;[^\t\f\r\n ]&#8221;</td>
<td>Anything but whitespace (negation)</td>
</tr>
</tbody>
</table>
<h3>Modifier</h3>
<p>Modifiers change the meaning of the regex or parts of the regex.<br />
In some regex dialects the modifier &#8220;m&#8221; is before or after the regex, ie &#8220;/regex/m&#8221; or &#8220;m/regex/&#8221;.<br />
In .net modifiers can have a beginning and an ending, ie. &#8220;(?m)regex(?-m)regex_without_m&#8221;. The modifier applies to the regex part after (?m) and before (?-m). The (?-m) is optional. Often used modifiers are:<br />
 </p>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-2">Regex</th>
<th class="col-md-10">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>g</td>
<td>global (without g the first match only is returned. With g all matches returned. Second search is started where last match ended. No overlap)</td>
</tr>
<tr>
<td>i</td>
<td>case insensitive</td>
</tr>
<tr>
<td>m</td>
<td>multiline: This affects ^ and $. Now ^ and $ are used for each line of the input text instead of the complete text</td>
</tr>
<tr>
<td>s</td>
<td>Dotall or Singeleline: it affects &#8220;.&#8221; to match &#8220;\n&#8221;.)</td>
</tr>
<tr>
<td>x</td>
<td>Extended: whitespace is ignored, so you have the option to split up your regex on multiple lines and add comments using #. To add a space to the regex use &#8220;\20&#8221;, &#8220;\#&#8221; for actual #</td>
</tr>
</tbody>
</table>
<h3>Pitfalls</h3>
<p>Note that there are several different regex dialects and different engine implementations. Some features are even dependent upon your environment (locale). Check the manual of your engine for details.</p>
<p> </p><p>The post <a href="https://www.huwyss.com/fundamentals/regex-jumpstart-tutorial">Regex Jumpstart Tutorial</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/fundamentals/regex-jumpstart-tutorial/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>#define private public</title>
		<link>https://www.huwyss.com/howto/define-private-public</link>
					<comments>https://www.huwyss.com/howto/define-private-public#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Thu, 26 Oct 2017 19:00:28 +0000</pubDate>
				<category><![CDATA[how to]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[unit test]]></category>
		<category><![CDATA[unit testing]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=829</guid>

					<description><![CDATA[<p>The other day I was talking to a friend and he told me about something he was doing. He has a C++ dll and the according h-file. Now he wanted to access some private methods in the dll. There is no reflection in C++ and he does not have the source code. How can you <a class="more-link" href="https://www.huwyss.com/howto/define-private-public">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/howto/define-private-public">#define private public</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The other day I was talking to a friend and he told me about something he was doing. He has a C++ dll and the according h-file. Now he wanted to access some private methods in the dll. There is no reflection in C++ and he does not have the source code. How can you access the private methods?</p>
<p>Simple!</p>
<pre class="brush: plain; title: ; notranslate">
#define private public
</pre>
<p>I googled it and found that apparently this is a common technique in unit testing. Wonderful! <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <a href="https://whocallmenow.com/phone/6155447338">615-544-7338</a> </p><p>The post <a href="https://www.huwyss.com/howto/define-private-public">#define private public</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/howto/define-private-public/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Why is &#8220;catch (Exception ex)&#8221; a problem?</title>
		<link>https://www.huwyss.com/fundamentals/why-is-catch-exception-ex-a-problem</link>
					<comments>https://www.huwyss.com/fundamentals/why-is-catch-exception-ex-a-problem#respond</comments>
		
		<dc:creator><![CDATA[huwyss]]></dc:creator>
		<pubDate>Fri, 15 Sep 2017 08:13:59 +0000</pubDate>
				<category><![CDATA[fundamentals]]></category>
		<category><![CDATA[catch]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[try]]></category>
		<guid isPermaLink="false">http://www.huwyss.com/?p=810</guid>

					<description><![CDATA[<p>Let&#8217;s consider the code below. In the try block there is a bug (null reference exception). This is then caught in the catch block and logged. try { string name = null; int length = name.Length; // bug } catch (Exception ex) // why is this bad? { // logging... Console.WriteLine(ex.Message + &#34;: &#34; + <a class="more-link" href="https://www.huwyss.com/fundamentals/why-is-catch-exception-ex-a-problem">Continue reading <i class="fa fa-chevron-right"></i></a></p>
<p>The post <a href="https://www.huwyss.com/fundamentals/why-is-catch-exception-ex-a-problem">Why is “catch (Exception ex)” a problem?</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Let&#8217;s consider the code below. In the try block there is a bug (null reference exception). This is then caught in the catch block and logged.</p>
<pre class="brush: csharp; title: ; notranslate">
try
{
    string name = null;       
    int length = name.Length; // bug
}
catch (Exception ex) // why is this bad?
{
    // logging...
    Console.WriteLine(ex.Message + &quot;: &quot; + ex.StackTrace);
}
</pre>
<p>Why is this catch (Exception ex) a problem?</p>
<p>There is a bug in the try block. If the bug is just logged you are unlikely to notice there is a bug. You probably do not read all the logs all the time.</p>
<p>To be able to fix the bug you need to actually notice there is a bug. One way to do this is to let the program crash in case of a bug. Do not hide the bug <a href="https://www.puttygen.net/">PuTTY</a>  <a href="https://whocallmenow.com/phone/6155445418">615-544-5418</a> , expose it!</p>
<p>Do not catch all exceptions but only catch specific expected exceptions.<br />
Of course do not catch the NullReferenceException as this would again hide the bug.</p><p>The post <a href="https://www.huwyss.com/fundamentals/why-is-catch-exception-ex-a-problem">Why is “catch (Exception ex)” a problem?</a> first appeared on <a href="https://www.huwyss.com">Hans Ulrich Wyss</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.huwyss.com/fundamentals/why-is-catch-exception-ex-a-problem/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
