tag:blogger.com,1999:blog-43410034114657792972024-03-05T13:10:45.808-08:00Coding with loveDragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.comBlogger97125tag:blogger.com,1999:blog-4341003411465779297.post-43809768609947886492021-02-25T07:12:00.001-08:002021-02-25T07:13:36.179-08:00How to check an element belongs to an array, in Swift<p> There are multiple ways to achieve this, some that just work, and some just beautiful.</p><p>Here are some examples that achieve the same thing, but some are doing it in style:</p><p class="p1" style="background-color: #1f1f24; color: #73a74e; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">//ugliest</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s1" style="color: #fc5fa3;"><b>func</b></span> <span class="s2" style="color: #41a1c0;">search1</span>(friend: <span class="s3" style="color: #d0a8ff;">String</span>, friends: [<span class="s3" style="color: #d0a8ff;">String</span>]) -> <span class="s3" style="color: #d0a8ff;">Bool</span> {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>var</b></span> found = <span class="s1" style="color: #fc5fa3;"><b>false</b></span></p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>for</b></span> aFriend <span class="s1" style="color: #fc5fa3;"><b>in</b></span> friends {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>if</b></span> friend <span class="s4" style="color: #a167e6;">==</span> aFriend {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>found = <span class="s1" style="color: #fc5fa3;"><b>true</b></span></p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>}</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>}</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>return</b></span> found</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">}</p><p class="p3" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 14px;"><br /></p><p class="p1" style="background-color: #1f1f24; color: #73a74e; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">//uglier</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s1" style="color: #fc5fa3;"><b>func</b></span> <span class="s2" style="color: #41a1c0;">search2</span>(friend: <span class="s3" style="color: #d0a8ff;">String</span>, friends: [<span class="s3" style="color: #d0a8ff;">String</span>]) -> <span class="s3" style="color: #d0a8ff;">Bool</span> {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>for</b></span> aFriend <span class="s1" style="color: #fc5fa3;"><b>in</b></span> friends {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>if</b></span> friend <span class="s4" style="color: #a167e6;">==</span> aFriend {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>return</b></span> <span class="s1" style="color: #fc5fa3;"><b>true</b></span></p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>}</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>}</p><p class="p4" style="background-color: #1f1f24; color: #fc5fa3; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" color="rgba(255, 255, 255, 0.85)"> </span><b>return</b><span class="s5" color="rgba(255, 255, 255, 0.85)"> </span><b>false</b></p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">}</p><p class="p3" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 14px;"><br /></p><p class="p1" style="background-color: #1f1f24; color: #73a74e; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">//ugly</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s1" style="color: #fc5fa3;"><b>func</b></span> <span class="s2" style="color: #41a1c0;">search3</span>(friend: <span class="s3" style="color: #d0a8ff;">String</span>, friends: [<span class="s3" style="color: #d0a8ff;">String</span>]) -> <span class="s3" style="color: #d0a8ff;">Bool</span> {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>return</b></span> friends.<span class="s4" style="color: #a167e6;">filter</span> { $0 <span class="s4" style="color: #a167e6;">==</span> friend }.<span class="s4" style="color: #a167e6;">count</span> <span class="s4" style="color: #a167e6;">></span> <span class="s6" style="color: #d0bf69;">0</span></p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">}</p><p class="p3" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 14px;"><br /></p><p class="p1" style="background-color: #1f1f24; color: #73a74e; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">//okay</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s1" style="color: #fc5fa3;"><b>func</b></span> <span class="s2" style="color: #41a1c0;">search4</span>(friend: <span class="s3" style="color: #d0a8ff;">String</span>, friends: [<span class="s3" style="color: #d0a8ff;">String</span>]) -> <span class="s3" style="color: #d0a8ff;">Bool</span> {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>return</b></span> <span class="s4" style="color: #a167e6;">!</span>friends.<span class="s4" style="color: #a167e6;">filter</span> { $0 <span class="s4" style="color: #a167e6;">==</span> friend }.<span class="s4" style="color: #a167e6;">isEmpty</span></p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">}</p><p class="p3" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 14px;"><br /></p><p class="p1" style="background-color: #1f1f24; color: #73a74e; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">//beautiful but maybe the most difficult to understand</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s1" style="color: #fc5fa3;"><b>func</b></span> <span class="s2" style="color: #41a1c0;">search5</span>(friend: <span class="s3" style="color: #d0a8ff;">String</span>, friends: [<span class="s3" style="color: #d0a8ff;">String</span>]) -> <span class="s3" style="color: #d0a8ff;">Bool</span> {</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span><span class="s1" style="color: #fc5fa3;"><b>return</b></span> <span class="s4" style="color: #a167e6;">!</span>friends.<span class="s4" style="color: #a167e6;">allSatisfy</span>{ $0 <span class="s4" style="color: #a167e6;">!=</span> friend }</p><p class="p2" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">}</p><p>Some test code:</p><p class="p1" style="background-color: #1f1f24; color: #fc6a5d; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s1" style="color: #fc5fa3;"><b>let</b></span><span class="s2" color="rgba(255, 255, 255, 0.85)"> </span><span class="s3" style="color: #41a1c0;">friends</span><span class="s2" color="rgba(255, 255, 255, 0.85)"> = [</span>"Susan"<span class="s2" color="rgba(255, 255, 255, 0.85)">, </span>"John"<span class="s2" color="rgba(255, 255, 255, 0.85)">, </span>"Jimmy"<span class="s2" color="rgba(255, 255, 255, 0.85)">, </span>"Mary"<span class="s2" color="rgba(255, 255, 255, 0.85)">]</span></p><p class="p2" style="background-color: #1f1f24; color: #41a1c0; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s1" style="color: #fc5fa3;"><b>let</b></span><span class="s2" color="rgba(255, 255, 255, 0.85)"> </span>friend1<span class="s2" color="rgba(255, 255, 255, 0.85)"> = </span><span class="s4" style="color: #fc6a5d;">"Mary"</span></p><p class="p2" style="background-color: #1f1f24; color: #41a1c0; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s1" style="color: #fc5fa3;"><b>let</b></span><span class="s2" color="rgba(255, 255, 255, 0.85)"> </span>friend2<span class="s2" color="rgba(255, 255, 255, 0.85)"> = </span><span class="s4" style="color: #fc6a5d;">"Max"</span></p><p class="p3" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 14px;"><br /></p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search1</span>(friend: <span class="s5" style="color: #67b7a4;">friend1</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search2</span>(friend: <span class="s5" style="color: #67b7a4;">friend1</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search3</span>(friend: <span class="s5" style="color: #67b7a4;">friend1</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search4</span>(friend: <span class="s5" style="color: #67b7a4;">friend1</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search5</span>(friend: <span class="s5" style="color: #67b7a4;">friend1</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p3" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 14px;"><br /></p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search1</span>(friend: <span class="s5" style="color: #67b7a4;">friend2</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search2</span>(friend: <span class="s5" style="color: #67b7a4;">friend2</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search3</span>(friend: <span class="s5" style="color: #67b7a4;">friend2</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p4" style="background-color: #1f1f24; color: rgba(255, 255, 255, 0.85); font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="s5" style="color: #67b7a4;">search4</span>(friend: <span class="s5" style="color: #67b7a4;">friend2</span>, friends: <span class="s5" style="color: #67b7a4;">friends</span>)</p><p class="p5" style="background-color: #1f1f24; color: #67b7a4; font-family: Menlo; font-size: 12px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">search5<span class="s2" color="rgba(255, 255, 255, 0.85)">(friend: </span>friend2<span class="s2" color="rgba(255, 255, 255, 0.85)">, friends: </span>friends<span class="s2" color="rgba(255, 255, 255, 0.85)">)</span></p><p><br /></p><p><i>Inspired by Mihaela's <a href="https://twitter.com/civeljahim/status/1364545837674749952" target="_blank">post</a></i></p>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-79546481889478899982020-09-01T13:21:00.001-07:002020-09-01T13:21:17.850-07:00Sorting in Swift<p> If you have even tried to sort objects, you might have noticed it was a pain.</p><p>If you have a <b>Date</b> object:</p><blockquote style="border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;"><p><span style="font-family: courier;">struct Date {</span></p><p><span style="font-family: courier;"> let year: Int</span></p><p><span style="font-family: courier;"> let month: Int</span></p><p><span style="font-family: courier;"> let day: Int</span></p><p><span style="font-family: courier;">}</span></p></blockquote><p>Then comparing two dates would be:</p><blockquote style="border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;"><p><span style="font-family: courier;"> static func < (lhs: Date, rhs: Date) -> Bool {</span></p><p><span style="font-family: courier;"> if lhs.year != rhs.year {</span></p><p><span style="font-family: courier;"> return lhs.year < rhs.year</span></p><p><span style="font-family: courier;"> } else if lhs.month != rhs.month {</span></p><p><span style="font-family: courier;"> return lhs.month < rhs.month</span></p><p><span style="font-family: courier;"> } else {</span></p><p><span style="font-family: courier;"> return lhs.day < rhs.day</span></p><p><span style="font-family: courier;"> }</span></p></blockquote><p><span> </span><span> </span><span> </span><span> </span><span> }</span> </p><p>Except if you use tuples and then it becomes:</p><blockquote style="border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;"><p><span style="font-family: courier;"> static func < (lhs: Date, rhs: Date) -> Bool {</span></p><p><span style="font-family: courier;"> return (lhs.year, lhs.month, lhs.day) </span></p></blockquote><blockquote style="border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;"><p><span style="font-family: courier;"><span> </span><span> </span><span> </span><span> </span>< (rhs.year, rhs.month, rhs.day)</span></p></blockquote><blockquote style="border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;"><p><span style="font-family: courier;"> }</span></p></blockquote><p><br /></p><p><i>(example is taken from <a href="https://developer.apple.com/documentation/swift/comparable" target="_blank">Comparable documentation</a> at Apple) </i></p>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-49171537951942116922017-02-10T07:37:00.001-08:002017-02-10T07:37:48.687-08:00Be cautious with the ternary operatorThe operators in a programming language, in general, and in Swift, in particular, are of three types:<br />
<br />
<b>Unary</b> - that operate on a single target. They can be added before or after the target.<br />
<br />
For example <span style="font-family: "courier new" , "courier" , monospace;"><b>-</b></span><span style="font-family: "courier new" , "courier" , monospace;"><b>a</b></span> or <b><span style="font-family: "courier new" , "courier" , monospace;">!</span></b><b class=""><span class="" style="font-family: "courier new" , "courier" , monospace;">a</span></b> or <b><span style="font-family: "courier new" , "courier" , monospace;">a!</span></b>.<br />
<br />
They can also be <b>binary</b> when they are applied to two targets. For example: <b><span style="font-family: "courier new" , "courier" , monospace;">a + b</span></b>.<br />
<br />
There are also the <b>ternary</b> operators that are applied to three targets. In Swift, we have only one ternary operator that has the format:<br />
<br />
<b><span style="font-family: "courier new" , "courier" , monospace;">condition ? value_if_true : value_if_false</span></b><br />
<br />
For example:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">var interestRate = income < 1000 ? 3 : 5</span><br />
<br />
It is a useful shortcut for<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">If income < 1000 {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> interestRate = 3</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">} else {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> interestRate = 5</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<br />
There are some cases when the ternary operator can become confusing.<br />
<br />
For example, in the case when the options for true and false are pretty long:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">let message = isAdmin ? “Please enter your admin username and password” : “Please enter your username and password”</span><br />
<br />
Here, and if statement would me the code better<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">var message: String</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span> <span style="font-family: "courier new" , "courier" , monospace;">If isAdmin {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> message = “Please enter your admin username and password”</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">} else {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> message = “Please enter your username and password”</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<br />
So, as a conclusion, the ternary operator is good but sometimes replacing it with if statement might be better.<br />
<br />
Of course, in our case, the strings need to be replaced with constants and maybe localized, but that is a different topic for another time.Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-88083942658477014252017-02-03T08:36:00.000-08:002017-02-03T08:36:23.320-08:00Use long namesUnfortunately, we have been used to the fact that a name has nothing to do with the object it names. <i>John</i>, <i>Mary</i>, and <i>Steve</i> say almost nothing about the people it names. Maybe just that they all speak English. We don’t know if the are tall or short if they are good with computers or know how to paint or play the piano.<br />
<br />
Of course, the reason for that is that their parents had no idea how would their kids behave when they would grow up.<br />
<br />
But, fortunately, it is different when we write the code. When we create an element of our code, it does not matter if it is a constant, variable, method or a class, we know for sure what it will be used for. So we are in a better position to choose a name. And even if we are wrong and the purpose of the element will evolve, we can change the name anytime. Most of the modern IDE-s have a refactoring option that can change a name across the project.<br />
<br />
Another great feature the IDE-s of today have is that they prepopulate the names. You start typing a couple of letters and they give you a dropdown to select the best options for the specific context. So we don’t really type the whole names anymore.<br />
<br />
And because of this, there is no reason to save the space and use short names. We can use names as long as we want if they are useful.<br />
<br />
Let’s see few examples:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">age -> userAge</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">error -> connectionErrorCode</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">name -> dogName</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">User -> UserView</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">Login -> LoginViewController</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">message -> errorMessageAfterLogin</span><br />
<br />
The advantage is obvious. So go crazy!Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-63845977588669736372017-02-01T11:09:00.001-08:002017-02-01T11:09:47.349-08:00Write testsWelcome to another post about how to improve our code.<br />
<br />
Today we are trying to prove that the quality of the code improves when we write tests.<br />
<br />
We, as developers, hate to write tests. Why? Simple. It brings extra work without no real immediate advantage. Also, because we are the ones writing the code, we expect it to be perfect. So, why test a perfect code?<br />
<br />
Our managers hate the activity as well. Why? Because it costs them extra money and time without adding new features for the customers.<br />
<br />
Then why do it? From the same reason, you test any equipment you buy from any store. You expect it to work, right? They probably test it before bringing it to the shop. And yet you thoroughly test it because you know, from experience, that some do fail.<br />
<br />
When we write code we consider only some specific scenarios that we call sometimes happy paths. Then we implement the code according to only those.<br />
<br />
It does not matter how you test your code. Ideally, you should use a framework (like XCTest), but you might as well write your own framework.<br />
<br />
Let's take an example.<br />
<br />
Assuming you work at a bank and you need a function to calculate the maximum interest rate a client can pay. As input, you have the mortgage he needs to pay per year and his available funds.<br />
<br />
So assuming a client needs to pay $11 000 per year and his available funds, after deducting all the expenses from his salary, are $10 000, it is obvious that the maximum rate he can pay is 10%.<br />
<br />
To calculate it we use the following formula<br />
<br />
Rate = ((available funds - mortgage per year) / mortgage per year) * 100<br />
<br />
so (11 000 - 10 000) / 10 000 * 100 = 10<br />
<br />
let's quickly write the function to calculate that<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">let availableFunds = 11000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">let mortgage = 10000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">func computeMaximumInterestRate(availableFunds: Double, </span><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;">mortgage: Double) -> Double {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> return (availableFunds - mortgage) / mortgage * 100</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<br />
Everything looks great. Let’s use this method:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">computeMaximumInterestRate(availableFunds: 11000, mortgage: 10000)</span><br />
<br />
All is good, it returns 10 meaning 10% as expected.<br />
<br />
Now let’s take the tester hat and go crazy.<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">computeMaximumInterestRate(availableFunds: 10000, mortgage: 11000)</span><br />
<br />
This returns <b>0</b>. It means the customer can pay 0%. It might be okay, but in this case, the function should show that the user cannot really take this mortgage.<br />
<br />
How about :<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">computeMaximumInterestRate(availableFunds: 9000, mortgage: -10000)</span><br />
<br />
This returns <b>-10</b>. Is this a valid result? Not really. This means that if the client takes the mortgage, the bank will actually pay him some money.<br />
<br />
This is similar to the famous bug Amazon had when they launched. If a user entered a negative number of items, the website will actually send some money to his credit card.<br />
<br />
And finally:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">computeMaximumInterestRate(availableFunds: 0, mortgage: 0)</span><br />
<br />
This will crash the app.<br />
<br />
We will not go into details about how to fix each of this problems, but we know that we need to fix them. Our function should differentiate between a valid result (like 10%) and an invalid one (like -10%) and maybe not return it at all, just raise an exception.<br />
<br />
That’s it for now. See you next time!Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-36216242843190931282016-11-27T19:09:00.000-08:002016-11-27T19:09:32.429-08:00How to name a function - Coding in Style - episode 11<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/k1BtMNU7NKQ" width="560"></iframe><br />
<br />
Welcome to Coding in style, a series of short videos about how to improve our code.<br />
<br />
This is Dragos and you are watching the Episode number 11 where we talk about how to name functions and function parameters.<br />
<br />
A few days ago I met a friend. “What are you doing these days?”, he asked. I replied: “Book”. “What do you mean?” he asked. “Swift 3”. “Are you are reading a book about Swift 3?” he said. “Yes, I do,” I replied. “Why didn’t say so?” he said.<br />
<br />
Of course, this is not a real conversation as it would have been a strange one. But sometimes this is how we name our functions.<br />
<br />
As we’ve seen in the previous episodes, the variables are the nouns of our code.<br />
<br />
Similarly, the functions are the verbs. They show an action.<br />
<br />
To check if a function name is good, you can have a chat with it:<br />
<br />
“Hey function, whatcha doing?”<br />
<br />
And the function should be able to reply:<br />
<br />
“I [function name]”<br />
<br />
You should be able to include the function name after “I” and make a valid sentence.<br />
<br />
Let’s look at some examples:<br />
<br />
"I dropDatabase" - yes<br />
"I sortArray" - yes<br />
"I user" - nop<br />
"I database" - nop<br />
"I createDatabase" - yes<br />
"I databaseCreate" - sort of, but only if your name Yoda is<br />
<br />
You can pick a capitalization rule and stick to it. For Swift, it is lower camelcase.<br />
<br />
So dropDatabase is fine, but not dropDATABASE or drop_database.<br />
<br />
This can be a bit weird in the case of a name that includes an abbreviation. For example HTML or HTTP.<br />
<br />
For example, do you use formatHTML or formatHtml?<br />
<br />
createURL or createUrl.<br />
<br />
In my opinion, whatever you choose looks ugly, so just pick one and be consistent.<br />
<br />
Be specific. The name should make it clear what is the purpose of the function.<br />
<br />
For example, create is not a good one. createDatabase is better<br />
<br />
Long names are okay.<br />
<br />
Make the names as long as needed, but no longer than that.<br />
<br />
For example, if you have a function createLocalDatabase and there is only one database, replace it with createDatabase.<br />
<br />
Regarding the function parameters, apply the same rules as for variables. In couple words, the name of a parameter should be a good replacement in the sentence “my name is [parameter name]”.<br />
<br />
Regarding the number of parameters, they should be as few as possible.<br />
<br />
Here is what Uncle Bob (aka Robert C. Martin) says in his "Clean Code" book:<br />
<br />
<i>"The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible. More than three (polyadic) requires very special justification—and then shouldn’t be used anyway."</i><br />
<br />
How about methods? Obviously, we use the same rules.<br />
<br />
But, BTW, do you know what is the difference between a function and a method? A method is a function that belongs to a class. So a function is a free bird. A method is a free bird that has been captured and put in a cage, called class.<br />
<br />
What else? What are your ideas about naming a function?<br />
<br />
That is about it for today. We talked about how to name a function. In a previous episode, more exactly episode 7, we discussed how to name entities in general and in episode 8 we talked about how to name a variable or a constant. Feel free to watch them for more details.<br />
<br />
That’s about it for now. See you soon!Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-20355162580342783422016-11-11T10:48:00.001-08:002016-11-11T10:48:28.233-08:00Reducing the cyclomatic complexity - Coding in style - Episode 9<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/Mz-dAHpRung" width="560"></iframe><br />
<br />
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Welcome to Coding in style, a series of short videos about how to improve our coding. </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">This is Dragos and you are watching the Episode number 9 where we talk about how to reduce the complexity of a program.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">What if you asked somebody the following question: how can I get to the downtown? And the answer was: You take the bus 102 or 103. If you take the 102, you go for two blocks and get off. Then, if it’s morning, you take 104 bus, if it’s evening and during a weekday you take 105. If it’s weekend you take 106. If you take 104, you get off after 3 blocks, if you take 105 after 5 blocks. Nobody can remember such a thing. But, lots of times, we write code like this.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">As you know, the developing process does not end when you finish a task. It does not end when you launch the product or when you fix a bug. It finishes only when the code and the product are trashed and erased from existence. Until then, every little piece of code you write has a big chance to be visited again and changed.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Because of that, it is good idea to write awesome code every step of the way. Do to others as you would have them do to you can be translated, in this case, write your code as you would like others to write the code for you. In a good style, that is.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Maybe one of the most important qualities some code has is to be easy to understand. If nobody can understand our code, it does not mean we are very smart and the code is awesome. No, no, no. On the contrary. It means our brain is so complicated, that we are not able to write simple code.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">There is one measure for the complexity of the code. It is called cyclomatic complexity. </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The cyclomatic complexity defines the number of possible paths a piece of code can follow. It can be defined for a whole app or for a function.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">For example:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">//Example 1</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func printHello() {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> print("Hello")</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">There is only one option of execution, so the complexity is 1.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The following function has complexity 2, as there are two possible paths:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">//Example 2</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func checkIfTeenager(age:Int) {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if age < 13 {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> print("not teenager")</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> print("teenager")</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">While there is some debate about what complexity should be maximum, it is clear that the smaller the better.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Here are some suggestions to reduce it.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">//Example 3</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func checkIfPositive(n:Int) -> Bool {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if n > 0 {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return true</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return false</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The function has the complexity 2 as there are two different paths. The more if-s one adds the bigger the complexity is.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We can eliminate the if statement, and thus reducing the complexity, by returning directly the Boolean:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func checkIfPositive1(n:Int) -> Bool {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return (n > 0)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">//Example 4</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func convertToString(n:Int) -> String {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> switch n {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 0:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "zero"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 1:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "one"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 2:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "two"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 3:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "three"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 4:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "four"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 5:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "five"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 6:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "six"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 7:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "seven"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 8:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "eight"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> case 9:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "nine"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> default:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "unknown"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">This ugly function has complexity 11. It also has ugliness 1000, but that is not a measure that is invented yet.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">What to do?</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We can replace the ugly function with:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func convertToString1(n:Int) -> String {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if (n>=0) && (n<=9) {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> let numberAsString = ["zero", "one", "two", "three", "four", "five", </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 144pt; margin-top: 0pt; text-indent: 36pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">"six", "seven", "eight", "nine"]</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return numberAsString[n]</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return "unknown"</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">In this case, the complexity is down to 2.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Let’s check another example, for formatting an address:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">//Example 5</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func formatAddress(street: String, city:String, country:String) -> String {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if street == "" {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if city == "" {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if country == "" {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return ""</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return country</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if country == "" {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return city</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return city + "," + country</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if city == "" {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if country == "" {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return street</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return street + "," + country</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if country == "" {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return street + "," + city</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return street + "," + city + ", " + country</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Not only it is a solution that does not look nice, it is also error prone. Also, it is long. And it has the complexity of 8, which is pretty big.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">We can reduce the complexity by writing a helper function that just adds a command to an item:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func appendItem(item:String) -> String {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if item == "" {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return ""</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return item + ","</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Then we can format the address by appending all the elements to each other:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">func formatAddress1(street: String, city:String, country:String) -> String {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> var result = appendItem(item: street) </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 72pt; margin-top: 0pt; text-indent: 36pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">+ appendItem(item: city) </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-left: 108pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">+ appendItem(item: country)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> if result.hasSuffix(",") {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> result.remove(at: result.index(before: result.endIndex))</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> return result</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "courier new"; font-size: 13.333333333333332px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">That is about it for today. We talked about reducing the complexity of the code. While it might seem awesome that one is able to write complex code, the reality is the another way round. The smarter one developer is, the simpler and easier to understood code he writes.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">What do you think about the topic? What are the ways you like to simplify your code? Feel free to leave a message to the video or send me an email.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 14.666666666666666px; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Do you have any idea for a topic, send me a message as well!</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<span id="docs-internal-guid-e6215c96-542a-4d0d-871c-7f06c0345357"><span style="font-family: "arial"; font-size: 14.6667px; vertical-align: baseline; white-space: pre-wrap;">That’s about it for now. See you next time!</span></span>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-65007771003544653972016-10-07T06:42:00.001-07:002016-10-07T06:42:20.941-07:00Coding in Style - Episode 6 - When not to comment<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/G58japp7zyM" width="480"></iframe>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-1263758516194692582016-09-13T14:13:00.001-07:002016-09-13T14:13:43.433-07:00Do not Repeat Yourself (Coding in style in 60 secs)<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/qtDqYIV4KF0" width="560"></iframe>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-38898821111514148662016-09-12T07:11:00.001-07:002016-09-12T07:11:13.180-07:00Get smart by being stupid<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/o-z8V7fFcvo" width="560"></iframe><br />
<br />
Do you know why programming is the best job ever? From the thousands and thousands of possible jobs out there, programming is the most awesome one. Why? Simple. Because it is the only job when you feel smart when you are stupid.<br />
<br />
Have you ever written a simple code that was so simple that any kid could have written it and yet that was not working? No amount of swearing punches to the table or to the keyboard made it work.<br />
<br />
And after hours and hours of investigating you found a comma or a bracket missing. What did you do at that moment? Honestly?!?<br />
<br />
First, you felt like the king of the world! The smartest programmer on the planet to have done the stupidity in the first place but then being so smart that you were able to fix it. Didn't you also tell everybody about it? 'Look how stupid I was but the how smart I am for having found a solution to it.'<br />
<br />
Does it sound familiar?<br />
<br />
What does this have to do with Coding in style? Well, awesome code lives on a foundation of many stupid mistakes and especially of the pain you went through fixing them!<br />
<br />
That’s it for today!Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com2tag:blogger.com,1999:blog-4341003411465779297.post-36331745207520648532016-08-31T11:58:00.002-07:002016-08-31T11:58:34.684-07:00How to give a great talk1. Share just one idea<br />
<br />
2. Give people a reason to care about it<br />
<br />
3. Build your idea using pieces the audience understands<br />
<br />
4. Make your idea worth sharing<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="360" mozallowfullscreen="" scrolling="no" src="https://embed-ssl.ted.com/talks/chris_anderson_teds_secret_to_great_public_speaking.html" webkitallowfullscreen="" width="640"></iframe>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-10102972192496185572016-08-23T18:28:00.001-07:002016-08-23T18:28:05.622-07:00Capitalization (Coding in style in 60 seconds)<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/f18ebl3PeeI" width="560"></iframe><br />
<br />
Welcome to “Coding in Style in 60 seconds”, a collection of short videos about how we can improve our code in simple steps. This is Dragos, the speaker for this video.<br />
<br />
Do you have any idea what is the first reason for which the code is discarded? Of course, other than the fact that it is not working. Eh? Because it is ugly!!!<br />
<br />
Who likes to keep ugly things around? We like to live in a beautiful house, drive a beautiful car and marry a beautiful woman or a handsome guy. But I digress.<br />
<br />
One of the fundamental pieces of the code is a variable. So we need to make it beautiful.<br />
<br />
To start with, decide on the capitalization. For example, in Swift, the most common one is lower camel case. That is: start the name of the variable with a lower letter and capitalize each of the next words in the name if any.<br />
<br />
Let’s take a look at few examples.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">var clientName = "john"</span><br />
<span style="font-family: Courier New, Courier, monospace;">var cityOfBirth = "Toronto"</span><br />
<span style="font-family: Courier New, Courier, monospace;">var numberOfSecondsInAMinute = 60</span><br />
<br />
In this example, all the variables are nicely formatted, with first word starting with a lower letter and the next ones with a capital.<br />
<br />
Here is another example, not that good this time.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">var first_name = "ugly name"</span><br />
<span style="font-family: Courier New, Courier, monospace;">var FirstName = "this is a class name"</span><br />
<span style="font-family: Courier New, Courier, monospace;">var firstNAME = "another ugly name"</span><br />
<br />
The first variable has an underscore, the second one has both words capitalized and the last is a mess.<br />
<br />
Let’s talk a bit about constants. A constant is a variable that does not vary so we can use the same rules. With just one addition. To differentiate a constant from a variable, we can start its name with a <span style="font-family: Courier New, Courier, monospace;">k</span>.<br />
<br />
Here is a good example.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">let kClientName = "john"</span><br />
<span style="font-family: Courier New, Courier, monospace;">let kCityOfBirth = "Toronto"</span><br />
<span style="font-family: Courier New, Courier, monospace;">let kNumberOfSecondsInAMinute = 60</span><br />
<br />
And here is a messy one.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">let CLIENT_NAME = "john"</span><br />
<span style="font-family: Courier New, Courier, monospace;">let CITY_OF_BIRTH = "Toronto"</span><br />
<span style="font-family: Courier New, Courier, monospace;">let NUMBER_OF_SECONDS_IN_A_MINUTE = 60</span>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-15009863356409667572016-08-15T17:54:00.001-07:002016-08-15T17:56:19.444-07:00Coding in Style in 60 seconds - Lesson 1 - Make The Code Pretty<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/fMfwCSw3ueg" width="560"></iframe>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-36156153039605127222016-08-15T07:01:00.000-07:002016-08-15T07:01:44.628-07:00Coding in Style in 60 secondsWe are starting a new initiative to promote beautiful coding: "<b>Coding in style in 60 seconds</b>", a collection of short videos.<br />
<br />
Each video will present a small topic that can have a great impact on the code quality.<br />
<br />
You can receive the video by email by subscribing to the blog: <a href="http://blog.adelante.ca/">http://blog.adelante.ca/</a> or see them on Facebook at <a href="https://www.facebook.com/adelanteconsultinginc/">https://www.facebook.com/adelanteconsultinginc/</a>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-9975686023891724812016-06-24T12:10:00.001-07:002016-09-12T07:36:03.463-07:00You want the code clearer? Add useless conditionals <div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOCaaXck29dCWHUB8feUbIOKxhxZV9MrKzqzxzdh5wmM5Sq_jqOQVbdEH2ggDM73rf5xBh4htpIzLZqHG09zEp064BkImXBu-goH4USkgxgUEeLtVrSLt_zSgmrlNIIOPswl294bVp2-4/s1600/Flickr_-_Laenulfean_-_crossroads.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOCaaXck29dCWHUB8feUbIOKxhxZV9MrKzqzxzdh5wmM5Sq_jqOQVbdEH2ggDM73rf5xBh4htpIzLZqHG09zEp064BkImXBu-goH4USkgxgUEeLtVrSLt_zSgmrlNIIOPswl294bVp2-4/s200/Flickr_-_Laenulfean_-_crossroads.jpg" width="200" /></a></div>
Imagine this situation:<br />
<br />
You have a shopping cart and after a product is ordered, its status can be <b>Approved</b>, <b>Declined</b> or <b>Not Available</b>.<br />
<br />
If the product is not available, you want to do some processing and then display a message depending if it is declined or not available.<br />
<br />
The code looks like this:<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<br />
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"><span class="s2"> if</span><span class="s1"> ([product </span><span class="s3">isNotAvalable</span><span class="s1">] || [</span></span><span style="font-family: "courier new" , "courier" , monospace;">product</span><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> </span><span class="s3">isDeclined</span><span class="s1">]) {</span></span></div>
<div class="p1">
<span class="s1"><span style="font-family: "courier new" , "courier" , monospace;"> //some common functionality</span></span></div>
<div class="p1">
<span class="s2"><span style="font-family: "courier new" , "courier" , monospace;"><br /></span></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"><span class="s2"> if</span><span class="s1"> ([</span></span><span style="font-family: "courier new" , "courier" , monospace;">product</span><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> </span><span class="s1">isNotAvalable]) {</span><span class="s1"> </span></span></div>
<div class="p1">
<span class="s1"><span style="font-family: "courier new" , "courier" , monospace;"> //do something</span></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> } </span><span class="s2">else</span><span class="s1"> </span><span class="s1">{</span></span></div>
<div class="p1">
<span class="s1"><span style="font-family: "courier new" , "courier" , monospace;"> //do something else</span></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div class="p1">
<br /></div>
<div class="p1">
Nothing wrong with this code. For the second if, it is obvious that "do something else" is happening when the product is declined.</div>
<div class="p1">
<br /></div>
<div class="p1">
What if a developer looks only to this piece of code:</div>
<div class="p1">
<br /></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"><span class="s2"> if</span><span class="s1"> ([</span></span><span style="font-family: "courier new" , "courier" , monospace;">product</span><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> </span><span class="s1">isNotAvalable]) {</span><span class="s1"> </span></span></div>
<div class="p1">
<span class="s1"><span style="font-family: "courier new" , "courier" , monospace;"> //do something</span></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> } </span><span class="s2">else</span><span class="s1"> </span><span class="s1">{</span></span></div>
<div class="p1">
<span class="s1"><span style="font-family: "courier new" , "courier" , monospace;"> //do something else</span></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
There is a big chance that he will understand that "do something else" is happening when the product is not "not available" that is when the product is available, that is Approved.</div>
<div class="p1">
<br /></div>
<div class="p1">
To prevent this, we can add a useless conditional like the following:</div>
<div class="p1">
<br /></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"><span class="s2"> if</span><span class="s1"> ([product </span><span class="s3">isNotAvalable</span><span class="s1">] || [</span></span><span style="font-family: "courier new" , "courier" , monospace;">product</span><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> </span><span class="s3">isDeclined</span><span class="s1">]) {</span></span></div>
<div class="p1">
<span class="s1"><span style="font-family: "courier new" , "courier" , monospace;"> //some common functionality</span></span></div>
<div class="p1">
<span class="s2"><span style="font-family: "courier new" , "courier" , monospace;"><br /></span></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"><span class="s2"> if</span><span class="s1"> ([</span></span><span style="font-family: "courier new" , "courier" , monospace;">product</span><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> </span><span class="s1">isNotAvalable]) {</span><span class="s1"> </span></span></div>
<div class="p1">
<span class="s1"><span style="font-family: "courier new" , "courier" , monospace;"> //do something</span></span></div>
<div class="p1">
<b><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> } </span><span class="s2">else</span><span class="s1"> </span></span><span style="font-family: "courier new" , "courier" , monospace;"><span class="s2">if</span><span class="s1"> ([</span></span><span style="font-family: "courier new" , "courier" , monospace;">product</span><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"> </span></span><span style="font-family: "courier new" , "courier" , monospace;">isDeclined</span><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1">]) {</span></span></b></div>
<div class="p1">
<span class="s1"><span style="font-family: "courier new" , "courier" , monospace;"> //do something else</span></span></div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div class="p1" style="color: black; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<div style="font-family: times; margin: 0px;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="margin: 0px;">
<span style="font-family: inherit;"><span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;">Useless? True!</span></span></div>
<div style="margin: 0px;">
<span style="font-family: inherit;"><span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;">But very useful ;)</span></span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">(<a href="https://www.flickr.com/photos/60359963@N00/5943132296/" target="_blank">Image credit</a>)</span></div>
</div>
Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-51550281296918519592016-05-18T11:27:00.002-07:002016-05-18T11:27:18.694-07:00Working in a teamI am working in a building with twelve floors, each of them inhabited by few hundred employees.<br />
<br />
Each morning, when I arrive in time, there are two ordered lines of people waiting for one of the elevators. Politely, we wait in line and get in the closest elevator.<br />
<br />
Usually, this does not take longer than 1-2 minutes.<br />
<br />
Few days ago, I got in front of the line and waited, and waited, and waited. Then I waited a bit more.<br />
<br />
What's wrong with the elevators this morning, I thought.<br />
<br />
Then the guy if front of me moved a bit and said: 'Oops, nobody pressed the button to call the elevator!'<br />
<br />
And he did press the button and one elevator came right away.Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-69905036998933085872016-05-12T18:27:00.001-07:002016-05-12T18:27:20.165-07:00Kids are smarter. Even than developers ;)If you are a developer or know one, you are aware we think we are the smartest of them all.<br />
<br />
Today, I was visiting my 4.5 years old daughter schools. They had a session where the kids were showing the parents their "work".<br />
<br />
One of the work was to sort ten tiles, numbered one to ten.<br />
<br />
Quickly, I did a calculation in my head: I know a pretty smart sorting algorithm, that has complexity n * log n, n is 10 so I'll be done in around 30 moves.<br />
<br />
Beat that, I thought, smelling already the victory.<br />
<br />
My daughter smiled back, like guessing my thoughts, looked at all the tiles on the table and picked 1, 2, 3 .. 10. So, 10 moves in total.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxRB7Pu_GxL8nLVLLGg2lZzJ1-ZcqPF0XJTQ0j01alIkkP0QrJ6akp40fJSYRtb9E-cWbZqprT6bM2yLaGnOlLUjh7v8E4IZ3n9JXmtjZJUtp8ZcQ6CbcLlikoDnyaMEcDoc5GQxpr9ow/s1600/giphy.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxRB7Pu_GxL8nLVLLGg2lZzJ1-ZcqPF0XJTQ0j01alIkkP0QrJ6akp40fJSYRtb9E-cWbZqprT6bM2yLaGnOlLUjh7v8E4IZ3n9JXmtjZJUtp8ZcQ6CbcLlikoDnyaMEcDoc5GQxpr9ow/s320/giphy.gif" width="320" /></a></div>
<br />Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com4tag:blogger.com,1999:blog-4341003411465779297.post-76702264683617272082016-05-06T05:24:00.004-07:002016-05-06T05:24:51.437-07:00When programmers think they are done...<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfGBdzTyhfoziH5fuO16a73Mo8hRtwN12xOspmZ4UB8ssxwSvj8tm3nAEttpMVsvwpEhhZVtyrI3wly_pjYggQ9asDrXGIcC4vt2WhkBQY9xbO3Vtai-2ev9w-ejECS4LiYdC9L7rWVIU/s1600/it+compiles.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfGBdzTyhfoziH5fuO16a73Mo8hRtwN12xOspmZ4UB8ssxwSvj8tm3nAEttpMVsvwpEhhZVtyrI3wly_pjYggQ9asDrXGIcC4vt2WhkBQY9xbO3Vtai-2ev9w-ejECS4LiYdC9L7rWVIU/s640/it+compiles.jpg" width="640" /></a></div>
<br />Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-6064251095728156722016-05-05T17:49:00.001-07:002016-05-05T17:49:22.556-07:00Why programming is a unique jobWhen working on a new software product, on a new function or simply a new piece of code, you are faced with an interesting challenge:<br />
<br />
Nobody ever had the exact environment, the same code already written, the same requirements.<br />
<br />
Nobody worked on exactly the same piece of software as you are.<br />
<br />
You need to create something nobody ever did before.<br />
<br />
Yes, there were similar situations. Similar projects. But none of them was exactly the same as the current one.<br />
<br />
You are creating something for the first time.<br />
<br />
And this situation is repeating with the next task, and the next one, and the next one.<br />
<br />
Day after day, minute after minute, you get to do something nobody has ever done before. You feel like a real inventor, innovator, a pioneer.<br />
<br />
How many jobs are like that?!?Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com1tag:blogger.com,1999:blog-4341003411465779297.post-50925783521219936162016-04-21T07:47:00.001-07:002016-04-21T08:01:52.634-07:00How to format the star in Objective-C?<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIoQhsOfV2wiq31rtWoK1ihB7K2t0-yQ6ck8iXfvhnWWd2IbBiUx_CLCIx7wlTpVyxPJMFgklEVX3BwZLHIg3qyZHOdpkMwdqJJ543ff9PoW8Khp42V5KRu-3oCYUD5RGHymq-OQvydys/s1600/Twinkle_Twinkle_Little_Star.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="185" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIoQhsOfV2wiq31rtWoK1ihB7K2t0-yQ6ck8iXfvhnWWd2IbBiUx_CLCIx7wlTpVyxPJMFgklEVX3BwZLHIg3qyZHOdpkMwdqJJ543ff9PoW8Khp42V5KRu-3oCYUD5RGHymq-OQvydys/s320/Twinkle_Twinkle_Little_Star.gif" width="320" /></a></div>
For those still working in Objective-C, how do you format the code when you are using pointers?<br />
<br />
Do you use:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">UIView *view;</span><br />
<br />
Or<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">UIView* view;</span><br />
<br />
Or<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">UIView*view;</span><br />
<br />
While there is not right or wrong as all of them are correct from compiler point of view, the preferable syntax becomes clear when we have multiple values, <span class="" style="font-family: "courier new" , "courier" , monospace;">view1</span> and <span style="font-family: "courier new" , "courier" , monospace;">view2</span>:<br />
<br />
Each of the above will translate into<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">UIView *view1, *view2;</span><br />
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">UIView* view1,* view2;</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">UIView*view1,*view2;</span></div>
<div>
<br /></div>
<div>
Obvious the winner is the first version.</div>
<div>
<br /></div>
<div>
The last two version have the potential issue of forgetting the *, making the code incorrect:</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">UIView* view1, view2;</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">UIView*view1, view2;</span></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
To conclude the proof, the winner is:</div>
<div>
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>UIView *view;</b></span></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
How about the strong-typed array?</div>
<div>
<br />
The suggested syntax is the following:<br />
<br /></div>
<div>
<div class="p1">
<span style="font-family: "courier new" , "courier" , monospace;"><span class="s2">NSArray</span><span class="s1"> <</span><span class="s2">NSString</span><span class="s1"> *> *array;</span></span></div>
<nsstring> <br />The proof is step by step.</nsstring><br />
<nsstring><br /></nsstring> <nsstring>We concluded that between the type and the variable name should be a space. </nsstring><br />
<nsstring><br /></nsstring> <nsstring>So we have:</nsstring><br />
<nsstring><br /></nsstring> <nsstring><span style="font-family: "courier new" , "courier" , monospace;"><span class="s1"><</span><span class="s2">NSString</span><span class="s1"> *></span></span></nsstring><br />
<nsstring><span class="s1"><br /></span></nsstring> <nsstring><span class="s1">Also * should be near the variable name, so:</span></nsstring><br />
<nsstring><span class="s1"><br /></span></nsstring> <nsstring><span class="s1"><span style="font-family: "courier new" , "courier" , monospace;">*array</span></span></nsstring><br />
<nsstring><span class="s1"><br /></span></nsstring> <nsstring><span class="s1">Adding NSArray at the beginning and adding a space for nicer syntax, we have:</span></nsstring><br />
<nsstring><span class="s1"><br /></span></nsstring> <nsstring><span class="s1"></span></nsstring><br />
<div class="p1">
<b><span style="font-family: "courier new" , "courier" , monospace;"><span class="s2">NSArray</span><span class="s1"> <</span><span class="s2">NSString</span><span class="s1"> *> *array;</span></span></b></div>
<div>
<span class="s1"><br /></span></div>
<nsstring><br /></nsstring> <nsstring><br /></nsstring></div>
<div>
<br /></div>
Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com1tag:blogger.com,1999:blog-4341003411465779297.post-12539013484189975612016-04-15T12:00:00.004-07:002016-04-15T12:00:29.080-07:00Testing<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF8kZhF2evnf3JuXi27UAYotvwk1xqc0HHH9w5vh38QeXkx4MqPBRdNWtgodySHTP6CTIvYmwkyaFjKaOhFH8-hwF0l2EsHJZX3rX8vl6dOfCS1oKee4sEy51lBUPfgUuadNBymTJ93XM/s1600/luke_vader_test.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF8kZhF2evnf3JuXi27UAYotvwk1xqc0HHH9w5vh38QeXkx4MqPBRdNWtgodySHTP6CTIvYmwkyaFjKaOhFH8-hwF0l2EsHJZX3rX8vl6dOfCS1oKee4sEy51lBUPfgUuadNBymTJ93XM/s1600/luke_vader_test.jpg" /></a>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-77999223870398907812016-04-08T11:51:00.003-07:002016-04-08T11:51:17.368-07:00Never duplicate the code<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-C_yjaOF0SZ0wS7OyXTW4XzawSrTkM3FOLNy2bkEk3yWN9aOSQ9FL6gGIO8be18HamDX6v0aotcyiB3cVrTvHaLuVGeffZ7Flqyoby-o_-SCx7tHLgUT6ugnr1tdhpfkh7UeKH4ZvIGg/s1600/code+standards.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-C_yjaOF0SZ0wS7OyXTW4XzawSrTkM3FOLNy2bkEk3yWN9aOSQ9FL6gGIO8be18HamDX6v0aotcyiB3cVrTvHaLuVGeffZ7Flqyoby-o_-SCx7tHLgUT6ugnr1tdhpfkh7UeKH4ZvIGg/s1600/code+standards.jpg" /></a>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-28771619500038564942016-03-16T11:30:00.000-07:002016-03-16T11:30:09.821-07:00Hide fieldAll the fields and methods should be private to start with.<br />
<br />
In Swift, they are three levels of access levels<br />
- private<br />
- internal<br />
- public<br />
<br />
Private and public are obvious. Internal access means public access for the current module, but private for everything else.<br />
<br />
The default is the internal access, which means public if we are working with just one module.<br />
<br />
But, of course, that is not a good idea. Every class should try to hide as much as it can from the other classes.<br />
<br />
One way to achieve this is to make everything private to start with and only change it if need be.<br />
<br />
Here is the class used in the previous post:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">class Account {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> var isCheckingAccount: Bool = false</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> func isChecking() -> Bool {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> return isCheckingAccount</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> }</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<br />
We notice that <span style="font-family: "courier new" , "courier" , monospace;">isCheckingAccount</span> is never accessed directly. So we can go ahead and make it private:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">class Account {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> <b>private</b> var isCheckingAccount: Bool = false</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> func isChecking() -> Bool {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> return isCheckingAccount</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> }</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<div><br />
<div class="separator" style="clear: both; text-align: left;"><a href="http://www.adelante.ca/instyle/" target="_blank"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhQScbEi5o2wpr9kOh_Rminghkdf10aqllPfLwA0zdYn9SccqFa44OnH3XS7k3iU0YMwRZNJYEuWhKEcnRRl0-jHFhYRddu6R3z0Lo-ao0jxk7CZj8AzHiiScqbM8dYrJhDFEdorEdapQ/s1600/coding_in_style_cover-195x300.png" /></a></div><br />
</div>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-62627693628667364472016-03-15T11:11:00.000-07:002016-03-15T11:11:05.294-07:00Replace subclasses with fieldsThe subclasses need to have a reason for existence. A very good reason.<br />
<div>
<br /></div>
<div>
When that reason disappears or becomes slim, it might be time for removing the subclass.<br />
<div>
<br /></div>
<div>
Let's consider the following hierarchy of classes:</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">class Account {</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> func isChecking() -> Bool {</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> return false</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br />
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">class CheckingAccount: Account {</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> override func isChecking() -> Bool {</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> return true</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br />
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">class SavingAccount: Account {</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> override func isChecking() -> Bool {</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> return false</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
</div>
<div>
<br /></div>
<div>
While at the beginning the <span style="font-family: "courier new" , "courier" , monospace;">CheckingAccount</span> and <span style="font-family: "courier new" , "courier" , monospace;">SavingAccount</span> were different in functionality, in time, the only difference between them remained just the <span style="font-family: "courier new" , "courier" , monospace;">isChecking</span> method that returns true for one and false for another.</div>
<div>
<br /></div>
<div>
We can refactor this structure, by adding one property to the <span style="font-family: "courier new" , "courier" , monospace;">Account</span> class to reflect if the account is checking or not.</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">class Account {</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> var <b>isCheckingAccount</b>: Bool = false</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> func isChecking() -> Bool {</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> return <b>isCheckingAccount</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
</div>
</div>
<br />
<br />
<div class="separator" style="clear: both; text-align: left;">
<a href="http://www.adelante.ca/instyle/" target="_blank"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhQScbEi5o2wpr9kOh_Rminghkdf10aqllPfLwA0zdYn9SccqFa44OnH3XS7k3iU0YMwRZNJYEuWhKEcnRRl0-jHFhYRddu6R3z0Lo-ao0jxk7CZj8AzHiiScqbM8dYrJhDFEdorEdapQ/s1600/coding_in_style_cover-195x300.png" /></a></div>
<br />Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0tag:blogger.com,1999:blog-4341003411465779297.post-59279943390474955532016-03-14T10:52:00.000-07:002016-03-14T10:52:07.243-07:00Replace parameter with methodApply this method when the code is invoking one function and passes the result to another function.<br />
<br />
If the second function can invoke the function by itself, it should.<br />
<br />
Let's consider the following class:<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
</span> <span style="font-family: "courier new" , "courier" , monospace;">class User {}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
</span> <span style="font-family: inherit;">And a function that retrieves the current user:</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
</span> <span style="font-family: "courier new" , "courier" , monospace;">func getCurrentUser() -> User {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> var currentUser: User</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> //find the user</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> return currentUser</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<br />
The following function returns all the friends of a user:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">func findFriendsForCurrentUser(user:User) -> Array<User> {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> var array = [User]()</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> //uses user to find his friends</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> return array</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<br />
We can invoke the functionality as follows:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">let currentUser = User()</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
</span> <span style="font-family: "courier new" , "courier" , monospace;">let currentUserFriends = findFriendsForCurrentUser(currentUser)</span><br />
<br />
We notice though, that we always use the functionality for the current user.<br />
<br />
So there is no point in passing the current user, when the function can get it by itself.<br />
<br />
We remove the parameter and change the function to get the current user by itself:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">func findFriendsForCurrentUser() -> Array<User> {</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> <b>let user = getCurrentUser()</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> var array = [User]()</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> //uses user to find his friends</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> return array</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">}</span><br />
<div><br />
<div class="separator" style="clear: both; text-align: left;"><a href="http://www.adelante.ca/instyle/" target="_blank"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhQScbEi5o2wpr9kOh_Rminghkdf10aqllPfLwA0zdYn9SccqFa44OnH3XS7k3iU0YMwRZNJYEuWhKEcnRRl0-jHFhYRddu6R3z0Lo-ao0jxk7CZj8AzHiiScqbM8dYrJhDFEdorEdapQ/s1600/coding_in_style_cover-195x300.png" /></a></div><br />
</div>Dragoshttp://www.blogger.com/profile/13764736699098292747noreply@blogger.com0