<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sude Kılıç on Medium]]></title>
        <description><![CDATA[Stories by Sude Kılıç on Medium]]></description>
        <link>https://medium.com/@sudekilic?source=rss-37cfc7a3eed6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8vym-pUA8xatniWZoHQArw.png</url>
            <title>Stories by Sude Kılıç on Medium</title>
            <link>https://medium.com/@sudekilic?source=rss-37cfc7a3eed6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:52:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sudekilic/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Socket.IO with Node.Js + Express]]></title>
            <link>https://medium.com/kocfinanstech/socket-io-with-node-js-express-5cc75aa67cae?source=rss-37cfc7a3eed6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5cc75aa67cae</guid>
            <category><![CDATA[socketio]]></category>
            <category><![CDATA[sockets]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[express]]></category>
            <dc:creator><![CDATA[Sude Kılıç]]></dc:creator>
            <pubDate>Thu, 16 Dec 2021 08:19:51 GMT</pubDate>
            <atom:updated>2021-12-16T13:37:05.393Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LXMQ6NojZj6uJSgMCBBdxQ.png" /></figure><p>Nowadays, most web developers want to develop real-time web applications or customize their existing applications to become real-time in order to increase user satisfaction. Therefore, Websockets are becoming very common in the modern web development environment. Especially in areas like Chat Applications and Push Notifications, this need has become even more prominent.</p><h4>What is WebSocket?</h4><blockquote><a href="https://en.wikipedia.org/wiki/WebSocket#:~:text=WebSocket%20is%20a%20computer%20communications,WebSocket%20is%20distinct%20from%20HTTP.">WebSocket</a> is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.</blockquote><p>WebSocket promotes real-time communication between the Client and the Web Server. It has the significant advantage of providing full-duplex communication over an HTTP connection. WebSocket also increases the accuracy and efficiency of stream events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Z60UCXgOmbENe6CXpX5ug.png" /></figure><h4>What is Socket.io?</h4><blockquote><a href="https://socket.io/">Socket.IO</a> enables real-time, bidirectional and event-based communication. It works on every platform, browser or device, focusing equally on reliability and speed.</blockquote><p>Socket.IO is a JavaScript library for real-time web applications. It has two parts: a client-side library that runs in the browser, and a server-side library for Node.js. Socket.IO automatically upgrades the requirement to WebSocket if needed.</p><h4>Difference Between WebSocket and Socket.io</h4><p>It’s important to note that Socket.IO is not a WebSocket implementation. The authors state that:</p><blockquote>“Socket.IO indeed uses WebSocket as a transport when possible, but a WebSocket client will not be able to connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a WebSocket server”.</blockquote><p>Here are some of the key differences between WebSocket and Socket.io</p><ol><li>WebSocket is the protocol that is established over the TCP connection, Socket.io is the library to work with WebSocket.</li><li>WebSocket provides full-duplex communication on TCP connections, Socket.io provides the event-based communication between browser and server.</li><li>WebSocket does not support Proxy and load balancer, with Socket.io a connection can be established in the presence of proxies and load balancers.</li><li>WebSocket doesn’t support broadcasting, Socket.io supports broadcasting.</li><li>WebSocket doesn’t have a fallback option, Socket.io supports fallback options.</li></ol><h4>Integrating Socket.io</h4><p>You will need Node and npm installed before you can start creating apps with Socket.IO. You can run the following lines in your terminal to confirm that node and npm are installed.</p><pre>node --version<br>npm --version</pre><p>After making sure that Node and npm are downloaded, create a new file and set up the npm package to create a package.json configuration file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YlTzSDCbEzPMJ0l-Q7bsiA.png" /></figure><p>Now we are ready to install Express and Socket.io</p><pre>npm i --save express socket.io</pre><p>Instead of using the node command, you can use <strong>nodemon</strong> to avoid restarting the server whenever a file changes.</p><pre>npm i -g nodemon</pre><p>If all these steps are done, let’s create a simple file called <strong>server.js</strong>.</p><pre>const app = require(&#39;express&#39;)();<br>const server = require(&#39;http&#39;).createServer(app);<br>const io = require(&#39;socket.io&#39;)(server);</pre><pre>const port = process.env.PORT || 8080;</pre><pre>app.get(&#39;/&#39;, function(req, res) {<br>  res.sendfile(&#39;index.html&#39;);<br>});</pre><pre>server.listen(port, function() {<br>  console.log(`Listening on port ${port}`);<br>});</pre><p>And, we need an <strong>index.html</strong> file.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>   &lt;head&gt;<br>      &lt;title&gt;Hello!&lt;/title&gt;<br>   &lt;/head&gt;<br>   &lt;body&gt;Integrating Socket.io with Node.js and Express&lt;/body&gt;<br>&lt;/html&gt;</pre><p>You can test it by running the <strong>nodemon </strong>command, this command will run the server on localhost:8080. If you go to your browser and enter localhost:8080, you can see that the application is running. Now, let’s continue with socket.io.</p><pre>io.on(&#39;connection&#39;, (socket) =&gt; {<br>    socket.emit(&#39;connect&#39;, {message: &#39;a new client connected&#39;})<br>})</pre><p>The critical parts of this code block are the<strong> io.on</strong> and <strong>socket.emit</strong> functions.</p><p>The io.on function triggers a sequence of actions when a connection arrives. The codes in this function will only work if the connection is received. This event handler uses the socket object to handle connection, disconnection, events, and more.</p><p>The Socket.IO API is inspired by the Node.js <a href="https://nodejs.org/docs/latest/api/events.html#events_events">EventEmitter</a>, which means you can emit events on one side and register listeners on the other. The socket.emit function takes an emit name as its first argument. You can specify this name and listen to it on the client-side according to this name. The second argument should be the data you want to send.</p><p>For example, you may add features like broadcasting a message to the entire chat group. In other words, a message can be sent to all users who are currently connected to the socket port.</p><pre>socket.on(&#39;chat&#39;, message =&gt; {<br>    // console.log(&#39;From client: &#39;, message)<br>    io.emit(&#39;chat&#39;, message)<br> })</pre><p>Of course, the client has to listen to the event emitted by the server.</p><pre>socket.on(&#39;chat&#39;, message =&gt; {<br>  console.log(&#39;From server: &#39;, message)})</pre><p>For now, let’s move on with logging to see if it works properly. The final version of server.js is as follows.</p><pre>const app = require(&#39;express&#39;)();<br>const server = require(&#39;http&#39;).createServer(app);<br>const io = require(&#39;socket.io&#39;)(server);<br>const port = process.env.PORT || 8080;</pre><pre>app.get(&#39;/&#39;, function(req, res) {<br>   res.sendfile(&#39;index.html&#39;);<br>});</pre><pre>io.on(&#39;connection&#39;, (socket) =&gt; {<br>  console.log(&#39;user connected&#39;);</pre><pre>  socket.on(&#39;disconnect&#39;, function () {<br>    console.log(&#39;user disconnected&#39;);<br>  });<br>})</pre><pre>server.listen(port, function() {<br>  console.log(`Listening on port ${port}`);<br>});</pre><p>After logging messages on connections and disconnections, the client script must be included to initialize the socket object so that clients can create connections as needed. io server serves the script at <strong>‘/socket.io/socket.io.js’</strong>.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>   &lt;head&gt;<br>      &lt;title&gt;Hello!&lt;/title&gt;<br>   &lt;/head&gt;<br>   &lt;script src = &quot;/socket.io/socket.io.js&quot;&gt;&lt;/script&gt;<br>   &lt;script&gt;<br>      const socket = io();<br>   &lt;/script&gt;<br>   &lt;body&gt;Integrating Socket.io with Node.js and Express&lt;/body&gt;<br>&lt;/html&gt;</pre><p>All set! If you go to your browser and enter localhost:8080, you can see that the server logs the message ‘user connected’. Each time you refresh your browser, it will first disconnect the socket connection(‘user disconnected’) and then recreate a new one (‘user connected’).</p><p>It’s that easy to connect to Socket.io with Node.js and Express. The Socket.io also offers different features that you can use according to your own needs such as a few examples below.</p><p><strong>socket.to($client-id):</strong> sending a message from a client to just one client <br><strong>io.sockets:</strong> sending messages to all clients connected to the server with Socket.io<br><strong>socket.brodcast:</strong> communicating with other clients from a client with Socket.io.</p><p>You can find more detailed information in the <a href="https://socket.io/docs/v4/">documentation</a>.</p><p>Thanks to the features and methods in Socket.IO, real-time applications can be developed easily. However, when there is a problem on the server and client-side, it will be beneficial to take good action without reflecting this problem on the user.</p><p>Take care!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cc75aa67cae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kocfinanstech/socket-io-with-node-js-express-5cc75aa67cae">Socket.IO with Node.Js + Express</a> was originally published in <a href="https://medium.com/kocfinanstech">Koçfinans Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code II: React]]></title>
            <link>https://medium.com/kocfinanstech/clean-code-ii-react-fb7a56d6a0a4?source=rss-37cfc7a3eed6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb7a56d6a0a4</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Sude Kılıç]]></dc:creator>
            <pubDate>Fri, 02 Apr 2021 08:43:09 GMT</pubDate>
            <atom:updated>2021-04-02T08:43:42.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*5u9xzoJLggfuPXZkhbNirg.png" /></figure><p>Hello everyone, it’s me again! This post can be thought of as a continuation of the previous one. So, without further ado, let’s return to our subject.</p><p>I love removing dead codes and writing as simple as possible. It satisfies me as a developer and also provides convenience in many ways. For this reason, I wanted to share with you a few suggestions that made my React development life easier and cleaner. However, I must warn you that some suggestions are not the best scenario for every situation. Therefore, there will be several points open to interpretation.</p><h3>1.Conditional Rendering: One Condition</h3><p>In programming we always need conditions but if we only need one for conditional rendering, then it is better to use &amp;&amp; operator instead of the ternary operators.</p><pre>isGreetingVisible ? &quot;Hello!&quot; : null   -- Bad</pre><pre>isGreetingVisible &amp;&amp; &quot;Hello!&quot;   <strong>-- Good</strong></pre><p><em>Warning: This also appears to be a controversial issue because falsy values need more attention.</em></p><h3>2.Conditional Rendering: Either Condition</h3><p>If you have one condition and you want to render different things due to its satisfaction, then it is better to use a ternary operator instead of the&amp;&amp; operator. Also, by splitting these out into two separate conditionals using the &amp;&amp; operator, it obfuscates the fact that the two pieces of UI are related and that they are opposites of each other.</p><pre>isConditionSatisfied &amp;&amp; &quot;Yes!&quot;   <strong><br></strong>!isConditionSatisfied &amp;&amp; &quot;No!&quot;   <strong>-- Bad</strong></pre><pre>isConditionSatisfied ? &quot;Yes!&quot; : &quot;No!&quot;   <strong>-- Good</strong></pre><h3>3. Props: Boolean</h3><p>If you need a boolean props parameter and its value is true then there is no need to write its value.</p><pre>&lt;TurkishMessage isTurkish={true} /&gt;  <strong>-- Bad</strong></pre><pre>&lt;TurkishMessage isTurkish /&gt;   <strong>-- Good</strong></pre><h3>4. Props: String</h3><p>If you need a string props parameter then you don’t need to use curly braces or backticks. Double quotes will be enough.</p><pre>&lt;GreetingMessage name={&quot;Sude&quot;} /&gt;  <strong>-- Bad<br></strong>&lt;GreetingMessage name={&#39;Sude&#39;} /&gt;  <strong>-- Bad<br></strong>&lt;GreetingMessage name={`Sude`} /&gt;  <strong>-- Bad</strong></pre><pre>&lt;GreetingMessage name=&quot;Sude&quot;/&gt;   <strong>-- Good</strong></pre><h3>5. Props: Event Handler Functions</h3><p>If you need an event handler that needs a single argument for the Event, then you don’t need to wrap the function.</p><pre>&lt;NameInput onChange={e =&gt; handleChange(e)} /&gt;  <strong>-- Bad</strong></pre><pre>&lt;NameInput onChange={handleChange} /&gt;   <strong>-- Good</strong></pre><h3>6. Props: Component</h3><p>If you need to pass a component as a props to another component and it is the only props, then you don’t need to wrap the passed component.</p><pre>&lt;ComponentWithOtherComponent OtherComponent={Other} /&gt;  <strong>-- Bad</strong></pre><pre>&lt;ComponentWithOtherComponent OtherComponent={() =&gt; &lt;Other/&gt;}/&gt; -<strong>Good</strong></pre><h3>7. Setting state that depends on the previous state</h3><p>In React, state updates can be batch processed. Therefore, if the new state is dependent on the previous state, then set state as a function of the previous state.</p><pre>const [isDisabled, setIsDisabled] = useState(false)</pre><pre>const disableButton = () =&gt; setIsDisabled(!isDisabled) <strong>--Bad</strong><br>const disableButton = () =&gt; setIsDisabled(isDisabled =&gt; !isDisabled) <strong>--Good</strong></pre><h3>8. Fragment Shortcut</h3><pre>&lt;React.Fragment&gt;&lt;/React.Fragment&gt;  <strong>--Long</strong><br>&lt;&gt;&lt;/&gt;   <strong>--Short</strong></pre><h3><strong>9. super() in Constructor</strong></h3><p>You can safely remove your super() from your constructor if you’re not doing anything with your props in it.</p><p><em>Warning: However, pay attention to the derived state warnings.</em></p><h3>10. Functional Components</h3><p>This is definitely something that most developers won’t like but this is like a trick. If you have functional components, then you can call them like functions.</p><pre>&lt;SomeComponent/&gt; =&gt; SomeComponent()</pre><h3>11. Assigning Keys to Children</h3><p>In React, when creating a list of elements key is necessary to identify them, but you can also use React.Children.toArray()which has a built-in method that automatically assigns the keys.</p><pre>{someData.map(element =&gt; &lt;div key={element.id}&gt;Hello!&lt;/div&gt;)}</pre><pre>{React.Children.toArray(someData.map(element =&gt; &lt;div&gt;Hello!&lt;/div&gt;)}</pre><p><em>Warning: </em><em>map() index not recommended.</em></p><h3>12. Code Format: Prettier</h3><p><a href="https://prettier.io/">Prettier</a> is a tool that makes it easier for you and your team to maintain code formatting consistency. It also enforces clean code practices, which you can customize based on your opinion.</p><p>This <a href="https://medium.com/free-code-camp/these-tools-will-help-you-write-clean-code-da4b5401f68e">gif of Adeel Imran </a>pretty much explains the context:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*SqRZTC9JRX4l20upOl5Jfw.gif" /></figure><h3>13. Order Imports</h3><p>Although ordering varies from person to person, it will also be beneficial to standardize it. Order can also be decided within the team, but generally, preferred ordering is as follows:</p><ol><li>React import</li><li>Library imports</li><li>Absolute imports from the project</li><li>Relative imports</li><li>import * as</li><li>import &#39;./somefile.ext&#39;</li></ol><p>That’s all, I really hope you have enjoyed reading it. Please feel free to share some of your tips and tricks with me :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb7a56d6a0a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kocfinanstech/clean-code-ii-react-fb7a56d6a0a4">Clean Code II: React</a> was originally published in <a href="https://medium.com/kocfinanstech">Koçfinans Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code: Write better, simple and cleaner]]></title>
            <link>https://medium.com/kocfinanstech/clean-code-write-better-simple-and-cleaner-aadd51f7cd93?source=rss-37cfc7a3eed6------2</link>
            <guid isPermaLink="false">https://medium.com/p/aadd51f7cd93</guid>
            <category><![CDATA[uncle-bob]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Sude Kılıç]]></dc:creator>
            <pubDate>Fri, 02 Apr 2021 08:40:53 GMT</pubDate>
            <atom:updated>2021-04-02T08:42:09.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rz_RXNYHw_Zs0G9y_L1KdA.png" /></figure><p>Some books change the way we code, one of the best examples for me (and probably many developers) is “Clean Code” by Robert C. Martin.</p><p>You may think that technical debt should be left but I believe messy code tends to get messier and it becomes hard to clean. Decreasing repetitive codes and preferring understandable/extensible code principles will speed up the decision process. The clean code principles will not only give you personal satisfaction but also your teammates and future self will thank you.</p><blockquote>Code is not how you tell the computer what to do; it is how you tell another programmer what you want the computer to do.</blockquote><p>In this article, I’ll discuss a few issues that are also addressed in the “Clean Code” Bible. Although most of us have mastered these rules, I wrote this article because I believe it would be good to remember and remind each other from time to time. I hope you enjoy reading!</p><h3>1. Meaningful Names</h3><blockquote><em>There are only two hard things in Computer Science: cache invalidation and naming things.</em><strong><em> — </em>Phil Karlton</strong></blockquote><p>You have probably heard of Phil Karlton’s famous phrase. Although it is difficult to find meaningful names, it is one of the most important elements underlying the clean code principles. The name of a variable, function or class should tell why it exists, what it does, and how it is used. If a name requires a comment, the name has not been selected properly.</p><p>Let’s look at some examples.</p><p><strong><em>Variable names should have meaning and should be </em>easily pronounceable<em>:</em></strong></p><blockquote><em>“You should name a variable using the same care with which you name a first-born child.” — Robert C. Martin, </em><strong><em>Clean Code: A Handbook of Agile Software Craftsmanship</em></strong></blockquote><pre>int x = products.size();  <strong>-- Wrong</strong></pre><pre>int prdctSize = products.size();  <strong>-- Wrong</strong></pre><pre>int productSize = products.size(); -- <strong>Right</strong></pre><p><strong><em>Singular and Plural:</em></strong></p><pre>List&lt;String&gt; name = Arrays.asList(&quot;Sude&quot;,&quot;Selen&quot;,&quot;Mert&quot;,&quot;Kerim&quot;);<br>String name1 = name.get(0);  <strong>-- Wrong</strong></pre><pre>List&lt;String&gt; names = Arrays.asList(&quot;Sude&quot;,&quot;Selen&quot;,&quot;Mert&quot;,&quot;Kerim&quot;);<br>String name = names.get(0);  <strong>-- Right</strong></pre><p><strong><em>Functions should be verbs, classes should be nouns: </em></strong>Use a verb as the first word in the method and use a noun for class. Use camelCase for variables and function names. Classes should start with a capital letter.</p><pre>function price()  <strong>-- Wrong</strong></pre><pre>function calculatePrice()  <strong>-- Right</strong></pre><pre>class CalculatePrice  <strong>-- Wrong</strong></pre><pre>class Price   <strong>-- Right</strong></pre><p><strong><em>Booleans are “to be are not be”:</em></strong></p><pre>boolean nameValid = !StringUtils.<em>isBlank(name);</em>   <strong>-- Wrong</strong></pre><pre>boolean isNameValid = !StringUtils.<em>isBlank(name);</em> -- <strong>Right</strong></pre><p><strong><em>Consistency: </em></strong>Chose similar words for similar functions. If you used “get” in one class, do not use “fetch” in another.</p><h3>2. Testing</h3><blockquote><em>If it is not tested, it is broken</em></blockquote><p>Write a lot of tests and make sure you have enough to cover your core business functionality. Writing clean code will automatically make writing unit tests faster and easier.</p><p>In addition, there are a few points mentioned in the book.</p><blockquote>Dirty tests are worse than no tests!</blockquote><p>They will be more difficult to understand and it takes more time to fix it. I don’t think we should stick to the “one assertion per test” rule dogmatically but as the name implies it is “unit” testing.</p><p>Good tests should be readable and follow to <a href="https://dzone.com/articles/writing-your-first-unit-tests#:~:text=Fast%3A%20Tests%20should%20be%20fast,be%20discouraged%20from%20using%20them.&amp;text=This%20allows%20you%20to%20run,see%20what%20is%20going%20wrong.">FIRST</a> rules:</p><p><strong>Fast</strong>: Tests should be fast enough that you won’t be discouraged from using them.</p><p><strong>Independent</strong>: Tests should not depend on each other, when needed you should be able to run each test separately.</p><p><strong>Repeatable</strong>: Tests should be repeatable in any environment without varying results.</p><p><strong>Self-Validating: </strong>Each test will have a single pass/fail boolean output. It should not be your responsibility to check whether the method’s output is correct every time the test is run.</p><p><strong>Timely</strong>: Unit tests should be written right before the production code that makes the test pass. This is something you would do if you were doing TDD (Test Driven Development), but it may not be applicable in other cases.</p><h3>3. Separation of Concerns (Single Responsibility Principle)</h3><blockquote><em>The Single Responsibility Principle (SRP) is a computer programming principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.</em></blockquote><p>Basically, keep it simple! Classes and functions should be small and do one thing(one purpose). Surely, if an error occurs, it will be easier to find.</p><p>Robert C. Martin in <em>Clean Code</em> provides a parallel definition about this subject:</p><blockquote>The Single Responsibility Principle (SRP) states that each software module should have one and only one reason to change.Gather together the things that change for the same reasons. Separate those things that change for different reasons.</blockquote><p>It’s critical to divide responsibilities into different functions, classes, and modules because code smells like Fragility and Viscosity can result from misplaced responsibilities. There are multiple techniques to achieve this separation. In this context, the reason for the change and whose responsibility it is are important. Uncle Bob comments on this situation as follows: <em>“The code is not responsible for bug fixes or refactoring. Those things are the responsibility of the programmer, not of the program.”</em></p><h3>4. Reusable Codes instead of Duplication</h3><blockquote>Duplicate code is the root of all evil in software design. When a system is littered with many snippets of indentical, or nearly identical code, it is indicative of sloppiness, carelessness, and sheer unprofessionalism. It is the guilt-edged responsibility of all software developers to root out and eliminate duplication whenever they find it.<strong> <em>— Robert C. Martin</em></strong></blockquote><p>Removing code duplications keeps your code clean and allows you to provide faster feature support and new updates. It simplifies the code structure and also improves the code’s maintainability while reducing technical debt over time. It helps to reduce the number of security vulnerabilities.</p><p>You can see some of the treatments in the following:</p><p><strong><em>If the same code appears in two or more methods in the same class: </em></strong>Use the Extract Method and call the new method from both locations.</p><p><strong><em>If the same code appears in two subclasses of the same level:</em></strong> Use the Extract Method for both classes and Pull it Up.</p><p><strong><em>If the same code appears in two different classes: </em></strong>If the classes don’t belong to a hierarchy, use Extract Superclass; if creating a superclass is impossible, use Extract Class in one class and use the new component in the other.</p><p><strong><em>Do not hardcode: </em></strong>Instead of hardcoding values define constants or use variables. Using variables will not only make the code more readable, but it will also make it easy to modify if it is being used at multiple places.</p><p>Also an important point, have you ever heard of <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> principles?</p><p><em>“It basically aims to reduce the repetition of software patterns by replacing them with abstractions or using data normalization to avoid redundancy.”</em></p><p>Although it is one of the most valuable principles of common development wisdom, it can often be misunderstood. Even if two pieces of code appear to be identical, they may represent different concepts and different abstractions. In such examples, duplication may be a more logical choice.</p><blockquote>Duplication is far cheaper than the wrong abstraction<em> </em><strong><em>– Sandi Metz</em></strong></blockquote><h3>5. Design Decisions</h3><blockquote>The hardest part of design … is keeping features out.<strong> — Donald A. Norman</strong></blockquote><p><strong><em>Keep Configurable Data at High Levels: </em></strong>If you have a constant such as a default or configuration value that is known and expected at a high level of abstraction, do not bury it in a low-level function. Expose it as an argument to that low-level function called from the high-level function.</p><p><strong><em>A class should know only its direct dependencies: </em></strong>Follow<strong> <em>Law of Demeter.</em></strong></p><p><strong><em>Use dependency injection:</em> </strong>Dependency injection makes it possible to eliminate unnecessary dependencies and makes it easier to reuse in a different context. It reduces dependency carrying and increases testability. Inversion of Control supports the SPR.</p><p><strong><em>Functions should have no side effects.</em></strong></p><p><strong><em>Prefer to use as few parameters as possible and no flag arguments.</em></strong></p><p><strong><em>Prefer polymorphism to if/else or switch/case: </em></strong>Switch statements are commonly used because they are the most obvious brute force solution, not because they are the best solution. That is why this heuristic exists to remind us to consider polymorphism before using a switch. In addition, cases, where functions are more unpredictable than types, are uncommon. Therefore, any switch statement should be regarded as suspicious.</p><h3>6. Code Smells</h3><p>We all know what code smells means but I still wanted to share its definition on <a href="https://en.wikipedia.org/wiki/Code_smell#:~:text=In%20computer%20programming%2C%20a%20code,%2C%20developer%2C%20and%20development%20methodology.&amp;text=It%20is%20also%20a%20term%20used%20by%20agile%20programmers.">Wikipedia</a>:</p><p><em>“In computer programming, a code smell is any characteristic in the source code of a program that possibly indicates a deeper problem. Code smells are usually not bugs; they are not technically incorrect and do not prevent the program from functioning.”</em></p><p>We all are familiar with the concept and most part of this post is related to or covers this topic. But, since the book specifically mentions it, I wanted to quote a few points here.</p><p><strong>Rigidity: </strong><em>The software is difficult to change. A small change causes a cascade of subsequent changes.</em></p><p><strong>Fragility</strong>: <em>The software breaks in many places due to a single change.</em></p><p><strong>Immobility: </strong>Y<em>ou cannot reuse parts of the code in other projects because of involved risks and high effort.</em></p><p><strong>Opacity: </strong><em>The code is hard to understand.</em></p><p>Thank you for reading, let’s take our corona days as a warning and always pay attention to cleanliness :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aadd51f7cd93" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kocfinanstech/clean-code-write-better-simple-and-cleaner-aadd51f7cd93">Clean Code: Write better, simple and cleaner</a> was originally published in <a href="https://medium.com/kocfinanstech">Koçfinans Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Benefits of Using GraphQL]]></title>
            <link>https://medium.com/kocfinanstech/benefits-of-using-graphql-11d6c8a0104a?source=rss-37cfc7a3eed6------2</link>
            <guid isPermaLink="false">https://medium.com/p/11d6c8a0104a</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Sude Kılıç]]></dc:creator>
            <pubDate>Mon, 30 Nov 2020 07:59:01 GMT</pubDate>
            <atom:updated>2020-12-14T11:51:04.294Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to my first post, I hope you enjoy reading!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCUWYBzuz3FriZ2vNBw_4w.jpeg" /></figure><p>Are you building an API? Have you ever wasted your time and energy to decide how to structure URLs? If your answer is yes, I would like to share my experiences and opinions about GraphQL, which is seen as the next big thing in API architecture.</p><p>GraphQL is basically a query language which provides a query in the form of a string that is sent to a server. The server interprets the query and then returns the result in JSON format to the client.</p><p>In the following you can see the factors that make GraphQL so powerful and the advantages I have experienced when using it at Koçfinans.</p><blockquote><strong>No Over-Fetching or Under-Fetching</strong></blockquote><p>One of the key advantages of GraphQL has over REST is, GraphQL’s ability to fetch only what is required. Developer defines the exact fields that they want to fetch and it fetches the data of only these fields.</p><blockquote><strong>Strongly-typed Schema Definition</strong></blockquote><p>All the types (Boolean, String, Int, Float, ID, Scalar) supported by the APIs are specified in the schema in GraphQL Schema Definition Language (SDL).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*0MXJhtAuedE31ZcJ-P8hQA.png" /></figure><p>Validations can be added by specifying the mandatory status of the fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*fap9FsKoXfgxpL3Tr1tyEA.png" /><figcaption>totalPrice: mandatory ~ promotionAmount: non-mandatory</figcaption></figure><blockquote><strong>Good Choice for Microservices</strong></blockquote><p>Multiple systems can be integrated behind GraphQL API. It unifies them, conceals their complexity and helps to manage communication between multiple services by combining them into one GraphQL schema.</p><blockquote><strong>Speed of Development</strong></blockquote><p>GraphQL is much faster than other communication APIs, because it allows developer to select only the specific fields which they want to query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*d52f4xVPE0rrV2OxisVabw.png" /></figure><p>It is no longer necessary<em> </em>to specify data requirements on the server side such as which fields need to be fetched and exposed.</p><p>As the <a href="https://graphql.org/">official website of GraphQL</a> puts it,</p><pre>&quot;Describe your data, ask for what you want, get predictable results.&quot;</pre><blockquote><strong>Code Sharing</strong></blockquote><p>Higher component level can be used for repetitive fields in different queries to increase reusability. This feature is referred as fragments and it allows to get different data while retaining the same schema field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*gAQDtmO6HSKqgPpgjlnmrg.png" /></figure><blockquote><strong>Explore With Postman</strong></blockquote><p>Even though Postman is mostly known as an advanced REST client, it is a more comprehensive tool that handles any calls sent over HTTP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l3MixhRyLNoCbOxSibQljQ.png" /></figure><p>As the official website of Postman describes it,</p><pre>&quot;Postman provides a separate interface to author GraphQL variables. After defining your GraphQL query in the <strong>Query</strong> editor, you can author and edit <strong>GraphQL variables</strong> in the adjacent variables editor.&quot;</pre><p>This is the end of my first post and I really hope you have enjoyed reading it. Rather than providing technical information about GraphQL, I wanted to talk about what kind of benefits and easiness I experienced while using it. I hope our paths cross in many more posts. Happy developments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11d6c8a0104a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kocfinanstech/benefits-of-using-graphql-11d6c8a0104a">Benefits of Using GraphQL</a> was originally published in <a href="https://medium.com/kocfinanstech">Koçfinans Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>