<?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 Cengizhan Pasaoglu on Medium]]></title>
        <description><![CDATA[Stories by Cengizhan Pasaoglu on Medium]]></description>
        <link>https://medium.com/@cngzhnp?source=rss-d32196d9a373------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Y9d_0SOGBvpUxXSgSDAPOQ@2x.jpeg</url>
            <title>Stories by Cengizhan Pasaoglu on Medium</title>
            <link>https://medium.com/@cngzhnp?source=rss-d32196d9a373------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:55:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cngzhnp/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[When Your Codebase Starts Carrying the World: Untangling Atlas Architecture ️]]></title>
            <link>https://cngzhnp.medium.com/when-your-codebase-starts-carrying-the-world-untangling-atlas-architecture-%EF%B8%8F-2c6aba2e889e?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c6aba2e889e</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[agile-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Mon, 01 Sep 2025 15:07:39 GMT</pubDate>
            <atom:updated>2025-09-01T15:07:39.606Z</atom:updated>
            <content:encoded><![CDATA[<p><em>“Our company is like a family.”</em></p><p>Ah yes, that famous line. It always sounds warm and fuzzy — until you realize that sometimes, it’s the <em>dysfunctional</em> kind of family. Every engineering team has been there.<br>You open a seemingly harmless file, planning to change one little constant… and suddenly, five pipelines turn red, three microservices scream in silence, and Jenkins looks at you with quiet disappointment.</p><p>At that moment, you realize something bigger is wrong. Your codebase isn’t just complex. It’s <strong>entangled</strong>.</p><p>In psychology, there’s a concept called <strong>enmeshment</strong> — when boundaries blur, roles overlap, and individuals lose their autonomy because everything is too interconnected. Don’t worry, I am not here to trivialize psychology or trauma. Borrowing the metaphor to make sense of why our codebases sometimes behave like teenagers slamming doors. And in software, even entire organizations — suffer from <strong>architectural enmeshment</strong>: components and teams are so deeply intertwined that <strong>no single part can move without shaking the whole system</strong>.</p><p>This isn’t just a technical problem. It’s a cultural one, too. And sometimes, Agile — when misunderstood — unintentionally accelerates the chaos.</p><h3>When Dependencies Turn Into Invisible Chains ⛓️</h3><p>Dependencies are like oxygen — you can’t build without them. But when left unchecked, they quietly grow into <strong>invisible chains</strong> that bind your architecture:</p><ul><li>You want to fix a single typo → but 12 services suddenly fail tests.</li><li>You try to optimize one API → and discover three other teams are using it… without telling you.</li><li>You rename a variable → and somewhere, a legacy service from 2015 silently dies.</li></ul><p>At this point, your dependency graph looks less like a neat tree and more like someone dropped a bowl of spaghetti on your whiteboard.</p><p>This is the first sign of <strong>enmeshment in architecture</strong>:</p><ul><li>Everything depends on everything.</li><li>Nothing can move independently.</li><li>Every release feels like playing Jenga… blindfolded.</li></ul><h3>The Atlas Personality of Codebases 🦸‍♀️</h3><p>In psychology, <strong>Atlas personality</strong> refers to someone who carries too much responsibility — solving everyone’s problems, holding everything together, until burnout hits.</p><p>In software, enmeshment creates <strong>Atlas roles</strong> — both in code and in people:</p><h3>1. The Atlas Object</h3><p>That one <strong>god object</strong> everyone depends on:</p><ul><li>Stores configs, business logic, and database access.</li><li>Touches everything and everything touches it back.</li><li>If you touch it in a wrong way, half the system collapses or not recovered.</li></ul><p>Here, enmeshment makes the object <strong>too central to fail</strong>, locking progress and forcing every change to pass through a fragile bottleneck.</p><h3>2. The Atlas Engineer</h3><p>10x senior engineer who holds all the undocumented knowledge and gets pinged 200 times a day.</p><ul><li>They know every hidden dependency.</li><li>They’ve memorized where the skeletons are buried.</li><li>Without them, production freezes.</li></ul><p>Enmeshment here becomes organizational: knowledge, responsibilities, and authority cluster around a single person.</p><p>The cost? <strong>Burnout, fragility, and single points of failure</strong>. When Atlas goes on vacation, the entire system starts sweating.</p><h3>Misreading Agile: When Speed Creates Chaos 🚦</h3><p>Agile promised us freedom, focus, and faster delivery. But when misunderstood, Agile often <strong>magnifies enmeshment</strong>:</p><ul><li><strong>Daily stand-ups</strong> turn into status reporting instead of solving real blockers.</li><li><strong>Sprint planning</strong> drags on because nobody knows who owns what.</li><li><strong>Retrospectives</strong> become therapy sessions without follow-up action.</li></ul><p>The trap comes from confusing <strong>Agile</strong> with <strong>boundaryless freedom</strong>:</p><ul><li>Agile isn’t “everyone touches everything.”</li><li>Agile isn’t “ship now, fix later.”</li><li>Agile isn’t “move fast and break each other.”</li></ul><p>Healthy Agile is the opposite of enmeshment:</p><ul><li>Clear ownership of components.</li><li>Independent, decoupled teams.</li><li>Short feedback loops to detect risks early.</li></ul><p>When done right, Agile <strong>reduces enmeshment</strong>. When done wrong, it amplifies it. When everyone’s involved in everything, <strong>nothing moves fast</strong>. It feels like trying to drive a car while ten people argue about which radio station to pick.</p><h3>The Cost of Enmeshment Nobody Talks About 💸</h3><p>The more tangled your architecture and teams become, the more expensive everything gets:</p><ul><li><strong>Longer onboarding</strong> → New engineers spend weeks decoding “tribal knowledge.”</li><li><strong>Slower releases</strong> → A one-line change requires four team approvals.</li><li><strong>Fragile systems</strong> → Every deployment feels like disarming a bomb.</li><li><strong>Atlas burnout</strong> → The same people are always firefighting, never building.</li></ul><p>This isn’t just technical debt. It’s <strong>organizational debt</strong> caused by enmeshment:</p><p>Every time we “just patch it for now,” we make the knot tighter — until one day, <strong>future us can’t move without breaking something critical</strong>.</p><h3>Escaping the Atlas Trap 🧭</h3><p>Untangling enmeshed systems is painful, but it’s possible. The key is <strong>boundaries</strong> — in code, in teams, and in culture.</p><h3>1. Map the Knots</h3><ul><li>Draw your dependency graphs — visually, painfully, honestly. Not just of services, but <em>decisions</em>.</li><li>Identify hotspots where multiple teams or services collide. Find the places where “just one more thing” piled up over years.</li><li>Prioritize the biggest bottlenecks first.</li></ul><h3>2. Distribute Responsibility</h3><ul><li>No more <strong>god objects</strong>. Break them into smaller, focused components.</li><li>Stop relying on a single “Atlas engineer.” Share knowledge proactively.</li><li>Rotate ownership so no one person or team is a bottleneck. Avoid “hero patterns” — they create systemic fragility.</li></ul><h3>3. Redesign Agile Around Clarity</h3><ul><li>Define <strong>team boundaries</strong> like APIs: clear inputs, clear outputs.</li><li>Keep stand-ups short and focused on blockers, not extended small talks.</li><li>Use retros to design better processes — and follow up on them.</li></ul><h3>4. Automate Understanding</h3><ul><li>Build living documentation, diagrams, and dashboards.</li><li>Invest in tooling that makes dependencies visible in real-time.</li><li>Empower teams to see the whole system without waking Atlas at 2 a.m.</li></ul><h3>Closing Thought 🌿</h3><p>Healthy systems — and healthy organizations — aren’t built on heroics. They’re built on <strong>clarity, boundaries, and trust</strong>.</p><p>The goal isn’t to eliminate dependencies. That’s impossible. The goal is to <strong>untangle enmeshment</strong> and make dependencies <strong>explicit, manageable, and intentional</strong>. Dependencies aren’t evil. Interdependence is natural — in families, in teams, in code. But there’s a fine line between <strong>healthy collaboration</strong> and <strong>hidden enmeshment</strong>.</p><p>Great architecture, like great organizations, has <strong>breathing room</strong>. Boundaries aren’t walls; they’re membranes. They let ideas flow without letting chaos in.</p><p>Because when your architecture stops carrying the world on its shoulders, your teams finally get to focus on what really matters: <strong>building, learning, and growing without breaking each other</strong>.</p><p>And finally, I’d like to thank my colleague <strong>Thomas</strong>, who planted the seed of this metaphor in my mind during one of our discussions. Sometimes, the best insights come from unexpected conversations — and this was one of them.</p><p>A little disclaimer: family enmeshment is a serious psychological concept. Borrowing the metaphor here only to shine a light on how codebases and organizations sometimes get tangled. The goal isn’t to trivialize real-life struggles, but to find a playful lens that helps us see complexity more clearly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c6aba2e889e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How does software architect help me to choose software patterns?]]></title>
            <link>https://medium.com/codex/how-does-software-architect-help-me-to-choose-software-patterns-be20dda7169a?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/be20dda7169a</guid>
            <category><![CDATA[software-architect]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Sun, 13 Feb 2022 13:24:29 GMT</pubDate>
            <atom:updated>2022-02-13T16:06:39.992Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey, it’s me again here to ask a question to software architects. In my stories, mostly, I choose questions as a title. To emphasize my writing would be enough as an answer. Oh wait, is it also a pattern that I apply? :)</p><p>Story title shows itself that we’ve already decided to use a pattern in our software project. Do we exactly know what design pattern means? How do we decide to use the selected XYZ pattern? How can we describe this as a design pattern? For example, could <a href="https://en.wikipedia.org/wiki/Merge_sort">merge sort</a> be considered as a design pattern? Let’s find out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*dBV0btXdrCZ4mybD.jpg" /><figcaption>As an example of Merge sort (A few steps)</figcaption></figure><p>Before going deep down into this topic, we need to find the answer to this question, what is the pattern? <em>It presents a useful solution for a recurring design problem. </em>Do you realize what we need more? Perfect, you are good at that, a design problem. Let’s start with <strong>identifying the design problem.</strong></p><p>Before applying the selected XYZ pattern, we might want to get advice from a good software architect. Probably asks, “Hey X, before applying this pattern imprudently, did you analyze exactly what needs to be resolved? Of which scope and from which domain? Did you consider constraints of the requirement? What will be the consequences of this solution?”.</p><p>As you realize, a good software architect needs a lot of answers during even the identification step. For example, if the scope is not explained well, the software architect might suggest a software design pattern instead of an <a href="https://en.wikipedia.org/wiki/Architectural_pattern">architectural pattern</a> or vice versa. Of course, it is not a final decision, could be revocable. A good software architect should ask after the identification step: “How do we decide to use that XYZ pattern? Do we have any other options?”. A new chapter is online now: <strong>Checking for available patterns.</strong></p><p>First thing first, if anyone does not know about XYZ pattern in pattern universe, congratulations you have a new problem! Unknown patterns or the thing which was thought of as a pattern bring risks to the table. In such cases, software architects must always stay on guard. To mitigate an issue, the right question should be asked, “<em>Have you already checked for available patterns?</em>”.</p><p>You recognize that XYZ pattern is actually as known as XYZ sort algorithm. So, what is the difference? Is it still useful as a pattern? <em>No, please do not do.</em> An algorithm gives a recipe for how to solve the problem step by step by performing small instructions. A design pattern is like a blueprint: a structured collection of objects and associations and actions to accomplish some goal.</p><p>There are many different patterns, but only a few of them could fit your problem. Therefore, it is mandatory to narrow down the pattern space into useful patterns that address the problem. There are many different books that could help us to choose the right pattern, for example <a href="https://en.wikipedia.org/wiki/Design_Patterns">GoF design patterns</a> or <a href="https://en.wikipedia.org/wiki/Pattern-Oriented_Software_Architecture">POSA series.</a></p><p>However, if we cannot find any feasible pattern for a specific problem, what should we do? <em>Do not force yourself to suggest a design pattern for every problem. If there is no available pattern, just provide the solution without the pattern. </em><strong>Otherwise, we are ready for analyzing the consequences.</strong></p><p>Now, we have a decision for a pattern and we know that resolving the right problem in the right way. However, this is still not a final step for choosing a pattern. In software architecture, there might be some trade-offs between quality attributes. Only you have to do is, analyze requirements and constraints, apply the right design tactics and find the enough - <em>not must be the best</em> -solution. If the price to pay for the selected pattern does not outweigh its benefits, we might say that we are on the right track. For example, developers might not be familiar with exceptional design patterns. Furthermore, it may cost a few days to understand the pattern and apply it. In this case, you should suggest the simplest solution as much as possible. Using a rare pattern does not make us a genius or legend! Perfect, now we are <strong>implementing the selected pattern</strong> stage. By the way, <em>again if it does not fit your problem, do not push other people to use design patterns.</em></p><p>A good architect does not implement the selected design pattern, or does he? It could be another story title for me but now we must focus on implementation. As a software architect, you should guide developers on integrating the pattern into legacy design. Be sure that with a new pattern, everything works fine as expected by extending test scenarios. However, team realize that XYZ pattern would not be enough and you might need another pattern as known as ABC. Perfect, their maturity level is high and they start implementing it immediately. Keep up the good work! Oh, wait… Implementing two different patterns at the same time is safe?</p><p>The problem might require multiple patterns but <em>each pattern must be applied individually. </em>Prioritize design problems from the most important to the least. Afterwards, do it same thing in each iteration until all subproblems are addressed to the selected patterns in the right way. Combining the patterns deserves to be written a separate story for itself.</p><p>During the implementation phase, developers might start complaining about a potential solution that does not fit best. To prevent such an issue, you should consider it “<em>Patterns are not constant things</em>”. It means you can do tailoring on it and adapt the selected pattern for your needs.</p><p>All things are done and we should be happy. Do we have to follow any other steps? Of course, the final step is “<strong>Reviewing and refactoring if necessary</strong>”.</p><p>Until now, we describe a lot of steps to select the right pattern. Even though we follow the all rules or guidelines, do not forget that we are human beings. We can be wrong or might give wrong decisions. We must be aware of how can we mitigate wrong decisions. Reviewing and refactoring. If the most suitable pattern does not fit in our architecture, it misleads us in the development phase. You are not late for own your funeral, we have a room for a review and refactoring. Then please go back to step “<strong>Checking for available patterns” </strong>and find an alternative pattern for your problem. Go through each step again and tailor it if necessary.</p><p>As a result, there are many steps we have to follow for selecting the right pattern for our problem. In this journey, software architects should understand why you need a design pattern for your problem, consider alternative patterns, suggest architectural patterns if necessary, make sure patterns fit the context and requirements, keep eye on integrating design pattern during the implementation phase, and refactoring it if necessary. Do not forget a design pattern is just a tool not a silver bullet that needs to be applied with care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be20dda7169a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/how-does-software-architect-help-me-to-choose-software-patterns-be20dda7169a">How does software architect help me to choose software patterns?</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use a dynamic library generated by Zig-lang in C++ codebase]]></title>
            <link>https://medium.com/codex/how-to-use-a-dynamic-library-generated-by-zig-lang-in-c-codebase-f83790520e03?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/f83790520e03</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[zig]]></category>
            <category><![CDATA[dynamic-library]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Sat, 22 Jan 2022 23:03:11 GMT</pubDate>
            <atom:updated>2022-01-23T01:31:21.094Z</atom:updated>
            <content:encoded><![CDATA[<p>In the past, I wrote a <a href="https://cngzhnp.medium.com/c-dilinde-yaz%C4%B1lan-bir-kodu-python-dilinde-nas%C4%B1l-kullan%C4%B1r%C4%B1z-74a6303dbefb">similar story</a> about using a dynamic library with C++ and Python but it was in Turkish. Please write a comment or do not hesitate to contact me on any social media account if you want to make me translate it. Today, we will try to produce a dynamic library by using Zig programming language afterwards use it in C++ code. Let’s begin!</p><p>Before explaining an implementation detail of this codebase, maybe I should introduce my new favorite programming language <a href="https://ziglang.org/">Zig</a>. Zig is a freshly-started programming language that encourages you to write metaprogramming style based on compile-time code. Its syntax is similar to Go language at least for me but it has many many unique and significant feature sets that I can explain in another story such as comptime, independent from Glibc, zero dependency, drop-in C/C++ compiler support and so on. Currently, it supports cross-platform compilation and could be installed from many different package managers that you can find them <a href="https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager">here</a>.</p><p>In Zig, there are many different options and you can list them simply by writing “Zig” in the terminal. If you want to create an executable project from scratch you may want to use “<strong>zig init-exe</strong>”. On the other hand, if you want to create a library project, you can directly use “<strong>zig init-lib</strong>” command as you can see screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*PtlmoLejKwIVqAgMe8S2iw.png" /><figcaption>Zig list all options/commands on the terminal</figcaption></figure><p>If you choose &amp; run “<strong>zig init-lib</strong>” command above, Zig will generate <em>build.zig</em> file in the current directory and newly created “<strong>src</strong>” folder inside with <em>main.zig</em> file. In this simple example, we do not have any interaction with <em>build.zig</em> file which is mostly related to compiling, linking and testing configurations. We should go inside <em>main.zig</em> file and try to understand what is written by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*IPU-HS9z_C_pm-YhlbVeKw.png" /><figcaption>Default main.zig file created by Zig itself</figcaption></figure><p>By default, you will see this content in the <em>main.zig</em> file and I will try to explain line by line. The first line, reminds you what? Oh, same for me. It is like <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive">using</a> directive of C# or a combination of <a href="https://en.cppreference.com/w/cpp/language/namespace">using</a> directive and <a href="https://en.cppreference.com/w/cpp/preprocessor/include">include</a> preprocessor of C++. The second line is a great example of alias usage. It simplifies the usage of testing functionality which is supported by language standards.</p><p>Afterwards, you can guess that it is a function call that takes two <em>i32 </em>type parameters and return the sum of them in the same type. “<em>fn</em>” is a keyword for representing a function (or could be an abbreviation), and afterwards “<em>add</em>” is its name. Then parameter syntax is given like “<em>parameter name-colon-type</em>” and <em>i32 </em>equivalent of <em>int32_t</em> C type. The return type is located after these parameters as Go language does. If you are familiar with Golang, you might say that <a href="https://go.dev/tour/basics/4">they are almost similar</a> except for colons of parameters and keyword name choice for functions.</p><p>Test is another key feature of Zig language, you can directly use it in the source code. “<em>test</em>” keyword is standing for test case and afterwards you can give a name for the case. If you are familiar with unit test frameworks like <a href="https://github.com/google/googletest">GTest</a> or <a href="https://github.com/catchorg/Catch2">Catch2</a> from C++, the next line is simply understandable, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/0*ccdK-6iCJfwzs8n-.jpg" /><figcaption>Expectation vs Reality on testing</figcaption></figure><p>In-depth explanation, you might realize that one thing I did not mention yet intentionally. Oh right, “<em>export</em>” keyword. With the new example below, I will explain it in more detail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*3skHjDcJtoz_YHQbKbsw8w.png" /><figcaption>Export keyword usage in Zig</figcaption></figure><p>Let’s assume that there are almost similar two function calls named “<em>add_internal</em>” and “<em>add_external</em>”. The second function has another keyword “<a href="https://ziglang.org/documentation/0.9.0/#Exporting-a-C-Library"><em>export</em></a>” which makes it publicly available. Let’s compile this code block and generate a dynamic library.</p><p>To generate a dynamic library from a file, you have to give “<em>-dynamic</em>” option explicitly because Zig generates a <strong>static </strong>library <strong>by default</strong>. So, after running the “<em>zig build-lib -dynamic {filename}</em>” command, we will have a dynamic library. Let’s check that our function call is located in the symbol table of the dynamic library. As seen in the screenshot below, “<em>add_external</em>” is located in the symbol table but “<em>add_internal</em>” is not, as we expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*Zq8HLOAVDgLDWdixYmjeFg.png" /><figcaption>“add_external” in the symbol table</figcaption></figure><p>Now, we are ready to use it in C++ code. Let’s write a simple C++ code to use function immediately which was written in Zig. Here is the simple a few line C++ code to compile &amp; run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*bgqlVtw2Qc2hC6xPpodPvw.png" /><figcaption>Simple C++ code to use Zig-based function</figcaption></figure><p>Now, everything is OK, right? Oops, compile stage seems OK but linkage we have a problem here. Why?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*u5ww3TxWw2BaligI8tM57Q.png" /><figcaption>Linkage error for add_internal function.</figcaption></figure><p>A few minutes later… Oh, right <a href="https://en.wikipedia.org/wiki/Name_mangling">mangling</a>! Compile stage was OK because there is no conflict at all for function names. However, “<em>ld</em>” could not find the implementation details of this function because the function name was mangled. Then, the next question is how we can disable mangling for this function? Hello, “<em>extern C</em>” <a href="https://www.youtube.com/watch?v=NAEppFUWLfc">my old friend</a>. Let’s modify our function signature by adding this keyword in front of it like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*LYeaDfFJL1mvd7lwQgM25A.png" /><figcaption>After adding extern keyword to function signature</figcaption></figure><p>Now, we know that our function signature will not be mangled anymore and we can use it as it is. Let’s compile &amp; run it again without any error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*IWoRq-ljycCXE5OhIPAAKA.png" /><figcaption>Printed output after successful compilation</figcaption></figure><p>Perfect! Now, we are ready to use our implementation in C++ code base. I hope that you also enjoy from this journey. In next story, I will try to explain more attractive functionality from Zig language. Please share your thoughts about this story here or any place where you can find me!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f83790520e03" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/how-to-use-a-dynamic-library-generated-by-zig-lang-in-c-codebase-f83790520e03">How to use a dynamic library generated by Zig-lang in C++ codebase</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why do software architects learn the business language?]]></title>
            <link>https://medium.com/codex/why-do-software-architects-learn-the-business-language-292f958979b0?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/292f958979b0</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[business-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[requirements-engineering]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Sat, 28 Aug 2021 16:14:40 GMT</pubDate>
            <atom:updated>2021-09-01T11:27:25.891Z</atom:updated>
            <content:encoded><![CDATA[<p>As an architect, from time to time you might wonder why software architects must learn a business language and also why business people do not learn technical things more. The first question starts with this; <em>What should software architects understand about business aspects?</em></p><p>There are many right answers for this but I would like to keep them short. When I start to do something in my daily job, I always ask <strong>why</strong>. It makes me analyze, evaluate and solve problems in a business-oriented way. It helps you to save your time, effort, and focus. “<a href="https://en.wikipedia.org/wiki/Five_whys#:~:text=Five%20whys%20(or%205%20whys,basis%20of%20the%20next%20question.">Five whys</a>” is one of the most popular techniques to understand the root cause of your problem clearly. However, where you can use this technique in your work life as an architect? The answer is <strong>requirements</strong>. On the other hand, do you know that who is doing best in daily life? Bingo, kids! :)</p><p>Requests are a type of unsaturated requirement that comes from customers, business goals, standards, or even regulations. However, we cannot say that all the requests should be considered as requirements. This is another story but writing good requirements is really difficult than you expected. In this scenario, we might assume that our requirements have good characteristics. Also, do not think that they must be handled <strong>not only once</strong> in the project life cycle.</p><p>They must be <em>continuously </em>elicitated, consolidated, analyzed, validated, and verified if necessary and you might be involved in every step as an architect to support other people. And yes, without defining the requirement engineering process, every project has a risk on budget and time.</p><p>As an architect, you have a key role to understand stakeholder requirements and trace them into system or subsystem requirements whether feasible or not in a technical way. In this manner, it would be easy to address verification of the system with the question “Are we developing the <em>product right</em>?”. Agile culture allows you to ask this question to yourself in every sprint. And use it for traceability.</p><p>Requirements traceability is one of the required skills from software architects to describe and follow the life of a requirement at different levels. In V-Model architecture, there is two way of tracing; horizontal and vertical.</p><p><strong>Horizontal tracing</strong> is a bidirectional connection between requirement and its implementation via test cases.</p><p><strong>Vertical tracing</strong> connects outputs bidirectionally to their successors.</p><figure><img alt="Taken from https://www.javatpoint.com/software-engineering-v-model" src="https://cdn-images-1.medium.com/max/500/0*INtOhXhfJ72qUIE2.png" /><figcaption>V Model</figcaption></figure><p>For the reasons above, you might think that software architects might need a checklist for requirements to trace. Let’s iterate them over one by one.</p><p>Requirements must be defined simply and clearly in terms of <strong>quantity and quality</strong> manner for every stakeholder. If not, “<em>right product</em>” question might be replied to stakeholders as a failure at the end of your project.</p><p>Requirements must be <strong>prioritized </strong>by the product owner/manager in terms of business impact. If not, please clarify during the design phase of your architecture. Otherwise, you might come with unintended solutions and face unsatisfied customers.</p><p>Ask or discuss the technical or architectural <strong>risks </strong>of the requirement. Clarify that if customer really needs it. If not, convince your management to reject them with proper arguments.</p><p>Always wonder that is there any <strong>relation </strong>between requirements and the business case. If not, ask for clarification from management. No business case, no development.</p><p><strong>Count them how many</strong> requirements you need to handle. If too much, discuss with management all of them must be fulfilled or not. Try to convince management for restructuring them to mitigate the risk. Too many requirements bring with risks.</p><p><strong>Review </strong>the requirement if necessary for redundancy or make them correct for every stakeholder. Also do not forget that you are<em> not the owner</em> of the requirement, you are only supporting them on this journey. However, all you need is communication.</p><p>As a result, as a software architect, you might need to understand, clarify, analyze, and have to do many other things for requirements. To succeed in all of these, you have a powerful tool that we called “<em>communication</em>”. For this reason, you need to learn which language is management spoken. Otherwise, if you cannot understand what they need, you cannot translate what they say to your team. So, be supportive on both the technical and management sides if you want to survive as an architect!</p><p>Please leave your thoughts and experiences via comments or anywhere else you can!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=292f958979b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/why-do-software-architects-learn-the-business-language-292f958979b0">Why do software architects learn the business language?</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What does Software Architect at choosing OSS?]]></title>
            <link>https://cngzhnp.medium.com/what-does-software-architect-at-choosing-oss-d0ebe3ec5598?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0ebe3ec5598</guid>
            <category><![CDATA[architectural-design]]></category>
            <category><![CDATA[software-architect]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[open-source-software]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Sat, 01 May 2021 13:27:24 GMT</pubDate>
            <atom:updated>2021-05-01T13:44:58.140Z</atom:updated>
            <content:encoded><![CDATA[<p>At this time, I decided to write my article in a different language. Maybe later on I may translate it into my native language. Today I will try to explain if there is a software architect on your project, which steps s/he could follow choosing open-source software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*PGsoNalaL-htFtOG1raf8w.png" /><figcaption>Thoughtful Software Architect</figcaption></figure><p>Let’s start with the definition of software architecture. <a href="https://en.wikipedia.org/wiki/Grady_Booch">Grady Booch</a> states that “Architecture represents the <strong>significant </strong>design decisions that shape a system, where <strong>significant is measured by the cost of change</strong>.” On this long journey, the software architect is capable of understanding the business domain and requirements from all stakeholders clearly to translate this information to the team in a technical way. Do not forget that we are not trying to find a solution!</p><p>After the team fully have a command of the requirements and constraints about the product that they start building it immediately. However, frequently this development process might take longer than we expected due to unseen implementation details. Mostly when we build a large software, it may consist of many different subcomponents or subsystems. During the development phase or before that, software architects could give an <strong>important </strong>decision whether build or buy these subcomponents or subsystems. This is mostly known as the “<em>build-vs-buy</em>” or “<em>make-vs-buy</em>” decision. Why does the software architect need to take this decision? Or how such a decision must be taken? <strong>Also, why the software architect has to make this decision, the team could not decide that by themselves?</strong></p><p>Of course, the team could give this decision by themselves but it brings an extra responsibility to all of them. In this case, the <a href="https://en.wikipedia.org/wiki/Bystander_effect">Bystander effect</a> might be happened on if something goes wrong on the project. However, SWA is responsible to understand the business domain and its context. This knowledge forces you to design and track the software architecture of your product and its content.</p><p>So, SWA should be aware of which parts of the software must be focused on by team members. If they focus on parsing XML files or lost their way of handling mouse click event delegation in UI instead of implementing business logic, maybe it&#39;s time to guide them.</p><p>In this case, you could offer them two solutions; the team could finish their tasks with the current implementation that they developed until now. Afterward, they might have time to extend their implementation for covering business cases with well-designed unit tests or integration tests. On the other hand, could we use open-source software instead of implementing it? First or latter which one is correct?</p><p>There is <strong>no absolutely correct or right solution</strong> for all cases, this is the most important lesson that every software architect has to take, at least it was for me. So, if we choose to use open-source software, what should we do? There are some questions that we need to answer by asking ourselves or discussing with the team members. How can we ensure that the quality attributes of a software project are fulfilled by OSS? Does suggested OSS conflict with our business aspects or domains? What are the pros and cons of using this OSS?</p><p>SWA is responsible for identifying technical risks of the project and knows how to mitigate them. It should be analyzed if one of the OSS is chosen for the project, what kind of risks may be risen and their solution tactics. For example, if OSS is not actively supported anymore, still do we choose it? What kind of risks might be occurred bugs, defects? Could we solve them by ourselves?</p><p>One of the responsibilities of SWA is being aware of which quality attributes are important for the project and how to map them with architectural significant requirements. For example, performance is an important quality attribute for your project but this OSS does not guarantee that fulfill your ASR related to performance. Is this OSS conflicting with them? Is there any quality metric that we can check? <strong>Every OSS is good for us?</strong></p><p>There are always <em>cons and pros</em> for choosing almost everything. The same rule could be applied in software contexts as well. Let’s take a look at what could be good at OSS for the software projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*ogi5H5YaFx1c1zOXw32BsQ.jpeg" /><figcaption>Startup Speed</figcaption></figure><p>The first good point that we could say about OSS is increasing the <strong>startup speed</strong> of your project strongly. In the project, we might not want to spend too much time on tasks like parsing XML files. It does not mean that we can write such a small parser that you can work but there are many things we have to think of. <em>Is it extensible? Is it quite tested enough? Is there any measured quantity that we can see?</em> All these efforts would be spent on these tasks if we do not choose to use OSS. So, it <strong>reduces our effort and time</strong> on different tasks that we need to care about. If the product is time-critical on the market, a <a href="https://wiki.c2.com/?WalkingSkeleton">walking skeleton</a> of the product will be ready probably faster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*9bnPttnOGKfuecCTCWudAg.jpeg" /><figcaption>Be Visible!</figcaption></figure><p>On the other hand, SWA might want to check the motivation of the team members during the development phase. OSS could be a part of this motivation for the team members but how? People, at least some of them, might want to be more visible or forefront on the group, it is quite natural. OSS projects offer a nice opportunity, to contribute. If there is a possibility, supporting these people not only to use OSS but also contribute it, could be a great start line for the motivation.</p><p>Oh, bad things might also happen, right Cinderella?</p><p>Let’s assume there are two OSS that have the same effect on our project in a technical way. Which criteria makes us consider one of them is just better than the other one? Maybe, the first criteria we need to check, is OSS well-documented? Without the guidance of authors that wrote OSS, how we ensure the correctness of our implementation? Is the function that we used in the project, thread-safe or not? Well-documented OSS helps us to implement fast and secure projects with <strong>trust</strong>.</p><p>Another thing we need to consider as SWA, legal implications of the OSS we will use. Probably, this is the most annoying part of deciding that which OSS could be used or modified on the project. Almost every OSS defines a license that is known by others or defined own their license type. In this case, if there is an expert about OSS usage on the company, SWA might need to get a consult from him/her. Otherwise, he must investigate a little bit more deeply with help of <a href="https://choosealicense.com/appendix/">this website</a> for instance.</p><p>During the development phase, the team might encounter such issues or bugs caused by OSS on the project. The main focus of the team is not solving such bugs for OSS and in this case, they can get help from OSS contributors. However, contributors might contribute to OSS without any “free” expectation and on-demand support is not always available for projects. This might cause “<strong>time and development</strong> <strong>effort</strong>” in a negative way for the team. Maybe it is time to mention here as a countermeasure argument for this, OSS does not <em>have to be free</em>. As a company, you might want to open source code but on-demand support could be contracted. In this case, the effort may be reduced again but not free.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*NFja8Ety2KDs-blGvh2aBQ.png" /><figcaption>Clearance steps that SWA should involve</figcaption></figure><p>We might consider that there are four steps that SWA needs to involve in choosing OSS. The first step as evaluation, ensure that OSS could fulfill the quality attributes and requirements of the project. Secondly, OSS might have some effects on architecture and design. SWA consider which risks might occur and integration could be done smoothly or not. At last, SWA could verify the OSS by checking test results and quality measures are fulfilled or not. The clearing part could be optional and depends on the company. Responsibility for this stage might be taken by SWA with the team or experts on the company.</p><p>Consequently, there are many things we need to consider as SWA to decide OSS that fits our project. Hope that it will encourage other software architects to consider twice before choosing OSS. Please do not forget to share your thoughts and experiences!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0ebe3ec5598" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C++ Başlık Dosyaları ve Ön Bildirim Kullanımı]]></title>
            <link>https://cngzhnp.medium.com/c-ba%C5%9Fl%C4%B1k-dosyalar%C4%B1-ve-%C3%B6n-bildirim-kullan%C4%B1m%C4%B1-bc6b9204ceaa?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc6b9204ceaa</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[forward-declaration]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Sun, 17 May 2020 14:15:15 GMT</pubDate>
            <atom:updated>2020-05-17T14:26:24.402Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KLyJAOBn_aIscoEb.png" /></figure><p>Uzun süredir bu konu hakkında bir şeyler yazmak isterken sanırım anca yılın bu zamanında kendime vakit ayırabildim. Bu yazıda başlık dosyaları ve ön bildirimlerin C++ içerisinde nasıl kullanıldığını ele aldım. Bu yazıda başlık dosyası (<em>include file</em>) ve ön bildirim yapmanın (<a href="https://wiki.c2.com/?ForwardDeclaration"><em>forward declaration</em></a>) C++ uygulaması geliştirirken ne gibi bir önemi olduğunu bildiğim kadarıyla anlatmaya çalışacağım.</p><p>C++ ile uygulama geliştirmeye başladığımızda “Hello World!” yazısını ekranda görmek için, yazdığımız kodun ilk satırlarından birisi, <strong>#include&lt;iostream&gt;</strong> ön direktifi oluyor. Böyle olması çok normal, çünkü yazılan ilk örneğin ekran çıktısını görmek için standart kütüphaneden gerekli fonksiyon çağrılarının ve nesnelerin getirilmesi gerekiyor. Peki neden bunu eklemek zorunda kalıyoruz örnekler üzerinden ilerleyelim.</p><p>Her zaman olduğu gibi, çözüm sunmadan önce problemin ne olduğunu belirlememiz ve bunu neden yaptığımızı kendimize sormamız gerekiyor. Bu anlamak için de, öncelikle şu soruya yanıt bulmalıyız: Neden başlık dosyası ekliyoruz? Bildiğiniz üzere, programlama dillerini kullanırken bize dili geliştirilenler tarafından sağlanan kural setine bağlı kalmak zorundayız. Bu kural setinin tarafımızca düzgün kullanılıp kullanılmadığını da arka planda kontrol eden başka mekanizmalar, araçlar haliyle mevcut.</p><p>Bu araçlar, C++ dilinde yazılan kodların doğru bir biçimde derlenebilmesi için, sizin yazdığınız kodun, dilin gramer kurallarına uygunluğunu kontrol eder. Örneğin; verilen değişken adları, fonksiyon tanımlamaları gibi. Bu aşamada bizim odaklandığımız kısım ise isim araması(<a href="https://en.cppreference.com/w/cpp/language/lookup"><em>name lookup</em></a>) olarak bilinen adım. İsim araması, kod yazan kişi tarafından oluşturulan bir nesnenin türü ya da fonksiyonsa parametreleri, dönüş değeri gibi bilgilerin arandığı bir süreç aslında. İsim araması da kendi içerisinde pek çok farklı alana ayrılıyor olsa da, bizim bu makalede odaklanmamız gereken en önemli kısım tip tanımlanması (<em>type definition</em>). Bu yazıda template kullanımındaki tip tanımlanmasını anlatmayacağım, onu başka bir yazıda ele alalım.</p><p>Tamamlanmamış tipler(<a href="https://docs.microsoft.com/en-us/cpp/c-language/incomplete-types?view=vs-2019">incomplete type</a>) ise aslında bu yazının temel taşını oluşturuyor. Az çok ne olduğunu anlatmaya çalışırsak, boyutunu tam olarak bilmediğimiz tiplerin bu kategoriye dahil olduğunu düşünebiliriz. Örneğin; pointer, reference, boyutları belli olmayan diziler. Aslında derleyici bu tiplerin ne kadar boyut kapladığından gayet haberdar, çünkü pointer ya da reference gibi tiplerin boyutu işlemci tipine bağlı olarak 4 ya da 8 byte yer kaplar. Hadi biraz daha örnek üzerinden gidelim:</p><p>Yakın zamanda <a href="https://github.com/TileDB-Inc/TileDB">TileDB</a> projesinin bir kısmına destek vermiştim. Bu projedeki başlık dosyalarını incelediğimde gözüme ilk çarpan şeylerden birisi fazla sayıda başlık dosyası eklenmiş bir başlık dosyasının olmasıydı.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*DkKFqMYFqh7C2dXNzmNaaw.png" /><figcaption>ArraySchema Sınıf Nesnesi Bildirimi</figcaption></figure><p>TileDB projesinde <a href="https://github.com/TileDB-Inc/TileDB/pull/1463/files#diff-649a32ecddf8b9e368c5615087367dc4">ArraySchema</a> adında bir sınıf bildirimi görüyorsunuz. Projenin kaynak kodlarını ilk incelediğimde, dikkatimi çeken şeylerin başında bu başlık dosyasında eklenmiş fazla sayıda başlık dosyası olmasıydı (Kırmızıyla işaretlenen alan önceki kullanımı gösteriyor). Ancak, bu kullanım bize bu durumun yanlış olduğunu değil, aksine geliştirmeye açık bir alan olduğunu görmemizi sağlıyor.</p><p>Peki, bunun nasıl bir önemi var? Başlık dosyasında bunu bilmek bize nasıl bir avantaj sağlayacak sorusu akıllara gelebilir. Başlık dosyası hazırlarken, en çok rastlanan alışkanlarımızdan biri, bir nesne tanımlandığında ona ait olan başlık dosyasını “include” etmektir. Ancak, bu durum proje büyüdükçe size büyük yükler getirmeye başlayacaktır. Örneğin; bir başlık dosyasında değişiklik yaptınız ve neredeyse tüm implementasyon dosyalarınız yeniden derlenmeye başladı. Halbuki, siz sadece bir başlık dosyası değiştirmiştiniz? Bu durumun temel sebebi, iç içe geçmiş başlık eklemelerinin “nested inclusions” yarattığı karmaşık dosya yapısıdır.</p><p>Ön işlemci komutu olan “include” aslında sizin dosyanızı okuyup, çağırdığınız dosya içerisine içeriğini yapıştırıyor. Bu da demek oluyor ki, siz eklediğiniz başlık dosyasında değişiklik yaptığınızda, onu eklediğiniz her dosya bundan etkileniyor. Bunun önüne geçip, aslında gerekli olan dosyalarda değişiklik yapmanın bir yolu ön bildirim tanımı yani “<a href="https://en.cppreference.com/w/cpp/language/class#Forward_declaration">forward declaration</a>” dır.</p><p>Ön bildirim tanımını kullanmak için ise, yukarıda bahsettiğim tamamlanmamış tipleri öğrenmiş olmak gerekiyor. Hadi bir örnekle, neyden bahsettiğimizi anlatmaya çalışalım:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*kFRtiOg2Jkga8LtTNfkGkA.png" /><figcaption>GZip Sınıf Tanımı</figcaption></figure><p>Yukarıdaki örnekte, başlangıç olarak compress fonksiyonunu ele alalım. Bu fonksiyon “<a href="https://github.com/TileDB-Inc/TileDB/blob/dev/tiledb/sm/buffer/const_buffer.h"><em>ConstBuffer</em></a>” ve “<a href="https://github.com/TileDB-Inc/TileDB/blob/dev/tiledb/sm/buffer/buffer.h"><em>Buffer</em></a>” adlı iki sınıfa ait “<em>pointer</em>” ları parametre olarak almış. İlk dikkat edilmesi gereken nokta, <em>ConstBuffer</em> sınıfının bizim tarafımızdan yazılıp yazılmadığını kontrol etmek. Açık kaynak kodlu ya da değil, bizzat yazmadığınız bir kütüphane sınıfı kullanıyorsanız dökümantasyonunu okumadan <strong>ön bildirim kullanmaya karar vermeyin</strong>. Bu kullanımı, daha çok kendi yazdığınız kodlarda kullanmak sizi güvenli bölgede tutar.</p><p><em>ConstBuffer</em> sınıfının bize ait olduğunu biliyorsak ve başlık dosyası içerisinde herhangi bir yerde bu sınıfın “<em>complete type</em>” olarak tanımlanmadığına da emin olduysak, artık ön bildirim kullanımı yapabiliriz. Ekran görüntüsünde dikkatinizi çekmek istediğim bir diğer nokta ise, ön bildirim yapılan yerin <em>namespace</em> içerisinde olması. Eğer kullandığınız tip, bir <em>namespace</em> içerisindeyse bunu başlık dosyasında belirtmeniz gerekiyor, aksi takdirde name lookup esnasında ilgili tipi derleyici bulamayacaktır.</p><p>Ön bildirim yaptıktan sonra ise, artık bu sınıflara ait olan başlık dosyalarını eklememize gerek kalmadı. Bu da demek oluyor ki, <em>ConstBuffer</em> sınıfında yapacağım herhangi bir değişiklik artık <a href="https://github.com/TileDB-Inc/TileDB/blob/dev/tiledb/sm/compressors/gzip_compressor.h"><em>GzipCompressor.h</em></a> dosyasını ve bu dosyayı ekleyen diğer dosyaları da etkilemeyecek. Bu iki dosyayı aslında birbirinden bağımsız hale getirmiş oldum. Peki bu dosyadan sildiğim başlık dosyaları kullanılmayacak mı? Elbette kullanılacak, ancak bu dosyalar artık başlık dosyalarına değil kaynak dosyalarına eklenecek çünkü “complete type” olarak kullanılan tipler artık burada.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*_sCBDwoYOEcUDydAaXGv4g.png" /><figcaption>Gzip Sınıfına Ait Kaynak Kod Parçası</figcaption></figure><p>Bu akıllara şu soruyu da getirebilir, başlık dosyası içerisinde implementasyon yapmak ne kadar doğru? Aslında, bunun için geçerli bir sebebiniz varsa ve dil buna izin veriyorsa neden olmasın. Ancak, bunu yaptığınızda başlık dosyalarınızdaki pek çok tipin “<em>complete type</em>” olarak yer alacağını ve sınıflar arasında bağımlılık yaratacağını da hesaba katmalısınız.</p><p>Başka bir önemli detay ise <strong><em>&lt;iostream&gt;</em></strong> başlık dosyasının başlık dosyaları içine eklenmesi pek önerilmez, sebebi kendisinin oldukça büyük bir kütüphane eklentisi olmasından ötürüdür. Bu sebeple buna ihtiyacınız varsa, ve başlık dosyası içerisinde bu kütüphaneye ait bir “<em>complete type</em>” yoksa, önerilen <strong><em>&lt;iosfwd&gt;</em></strong> kütüphanesidir. Çünkü bu başlık dosyası I/O ile ilgili dosyalara ait ön bildirim tanımlamaları içerir ve daha az yer kaplar.</p><p>Umarım, <em>forward declaration</em> hakkında akıllara gelen soruları cevaplayabilmişimdir. Eğer, eksik gördüğünüz ya da yanlış olduğunu düşündüğünüz kısımlar varsa, benimle iletişime geçebilirsiniz.</p><p>Bu projeye ait <em>forward declaration</em> değişikliklerimi içeren Pull Request listesine de <a href="https://github.com/TileDB-Inc/TileDB/pulls?q=is%3Apr+is%3Aclosed+author%3Acngzhnp">burdan</a> ulaşabilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc6b9204ceaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C++ dilinde yazılan bir kodu Python dilinde nasıl kullanırız?]]></title>
            <link>https://cngzhnp.medium.com/c-dilinde-yaz%C4%B1lan-bir-kodu-python-dilinde-nas%C4%B1l-kullan%C4%B1r%C4%B1z-74a6303dbefb?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/74a6303dbefb</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[cplusplus]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[swig]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Tue, 10 Mar 2020 18:22:41 GMT</pubDate>
            <atom:updated>2020-03-11T08:02:04.438Z</atom:updated>
            <content:encoded><![CDATA[<p>Bu yazıya da günümüzde oldukça popüler bir konu haline dönüşen Python — C++ ile devam edelim istedim.</p><p>Şu sıralar akademik alanda yapılan çalışmalardan, şirketlerin vizyonlarına kadar çok yaygın kullanılan bir kaç terim var: Yapay zeka, veri madenciliği, büyük veri gibi. Bu teknolojiler gelişirken, hali hazırda en çok kullanılan programlama dillerinin başında da <a href="https://www.python.org/">Python</a> geliyor. Kullanım kolaylığının yanı sıra, herkes tarafından sevilen ve pek çok alanda çok iyi işler çıkarmasına karşın performans açısından isteneni veremediği durumlar ortaya çıkabiliyor. Ya da daha önce başka bir dille yazılmış olan yapıyı kullanmak istiyor olabilirsiniz. Bu gibi durumlarda da akıllara şu soru geliyor; performansı arttırabilecek bir dille kombine edilebilir mi? Cevap evet tabi, yoksa bu yazıda işiniz ne :]</p><p><a href="https://www.python.org/"><em>Python</em></a> programlama dili temelinde <em>C</em> ile yazıldığı için, bu dilde yazılmış bir kod parçasının <em>Python</em> dilinde yorumlanması çok da yadırganmaz diye düşünüyorum. Ancak burada başka bir problem daha ortaya çıkıyor; <em>C++</em> dilinde yazılan bir kod parçasının <em>C</em> diline dönüşümü yapılarak (sarmalayan fonksiyonlar ile) ancak <em>Python</em> tarafından çağrılması mümkün. Bunu bir sonraki yazıda ele alabiliriz. Bugün daha farklı bir araç <em>SWIG</em> ‘ten bahsedeceğim.</p><p><a href="http://www.swig.org/">SWIG</a> kendi web sayfasında bahsettiği gibi <em>C</em> ve <em>C++</em> dilleri kullanılarak oluşturulmuş, daha önce yazılmış bir implementasyonu üst seviye başka bir dile bağlayan bir araçtır. <em>Python</em>, <em>R</em>, <em>C#</em> gibi yüksek seviyeli dillerle kullanılmasına olanak sağlar.</p><p>Hadi bir örnekle başlayalım. Öncelikle <em>SWIG</em> uygulamasını ve <em>Python3</em> için gerekli olan geliştirme kütüphanelerini <em>Ubuntu</em> için aşağıdaki gibi indirmemiz gerekiyor.</p><p>Benim sanal makinem üzerinde <a href="http://releases.ubuntu.com/19.10/"><em>Ubuntu 19.10</em></a> yer alıyor. Eğer kullandığınız versiyona uzaktan başka bir kaynak(<em>repository</em>) eklemediyseniz, varsayılan olarak <em>SWIG 3.0</em> geliyor. Ancak websitesinden indirip kendiniz <a href="http://www.swig.org/download.html">4.0</a> kurabilirsiniz.</p><p>Bunun yanı sıra, <em>Python3</em> için gerekli olan <em>python3-dev</em> kütüphanesini de indirmeniz gerekiyor. Aşağıdaki komutları bunun için kullanabilirsiniz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*LestniHsTerIRTZrJ62eoA.png" /><figcaption>Yüklenmesi zorunlu kütüphane ve uygulamalar</figcaption></figure><p>Hadi başlayalım. Örnek olması açısından çok basit bir sınıf örneği yazdım. Başlık dosyasını beraber inceleyelim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*LBdxOaJUZGeIp-kVIRTZRA.png" /><figcaption>Örnek için oluşturulmuş basit Date sınıfı</figcaption></figure><p>Örnekte görüldüğü üzere <em>Date</em> sınıfımızın dış dünyaya açılan tek özel olmayan fonksiyonu <em>calculateNextDecade()</em> olarak gözüküyor. Bu noktada parantez açmak gerekirse, aslında <em>public</em> anahtar kelimesi altında yer alan diğer fonksiyonlar da dış dünya tarafından kullanılabilir tabi ancak onlar daha çok sınıfa ait özel fonksiyonlar olarak düşünülmelidir.</p><p>Hadi bir de implementasyona bakalım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*xNXHrf559pJnXILA9CiFYw.png" /><figcaption>Date sınıfı uygulama kısmı</figcaption></figure><p>Gerekli olan fonksiyonların iç kısımlarına kendi düşündüğümüz mantıkta yerleştirdiğimizden de eminsek bu çağrıları nasıl kullanacağımızı düşünelim. Burada en dikkat edilmesi gereken noktalardan birisi oluşturacağımız yapının görüldüğü üzere herhangi bir main çağrısı(<em>main function</em>) tarafından kullanılmıyor oluşu. Çünkü yapmak istediğimiz şey, bir uygulama yazmak değil kütüphane oluşturmak. Bu nedenle <em>shared library</em> dediğimiz paylaşımlı kütüphane dosyasını oluşturup <em>Python3</em> ile kullanacağız.</p><p>SWIG nerede dediğiniz duyar gibiyim, şimdi mikrofon SWIG’ te. Şimdi onun için gerekli olan arayüz(<em>interface</em>) dosyasını hazırlayalım. SWIG aracının asıl görevi sizin vermiş olduğunuz girdileri kullanarak anlamlı çıktılar üretmek. Ürettiği bu çıktıları da sizin kullanacağınız <em>Python3</em> modülü için kullanacağız.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*P74SZTodvC7GoerGQd-AYw.png" /><figcaption>SWIG arayüz dosyası</figcaption></figure><p>Buradaki söz-dizimi alışkın olduğunuzdan biraz daha farklı olabilir, kendine has bir söz-dizimine sahip SWIG için kullandığımız iki anahtar kelime var; <em>module </em>ve <em>include</em>.</p><p><em>Module </em>anahtar kelimesi içerisinde yer alan kısım, <em>SWIG </em>tarafından oluşturulacak olan <em>wrapper</em> dosyasını derlememiz için gerekli olan eklemelerin yapılması gereken yer. Oluşturduğumuz sınıf <em>date.h</em> dosyasında bulunuyor ve bu sınıf <em>Cengo</em> isim uzayında yer almakta. Bu yüzden modül içerisine bu bilgileri ekliyoruz.</p><p>Bunun dışında yer alan <em>include </em>anahtar kelimesi ise <em>Python3</em> için kullanacağımız kısımda nelere erişebileceğimizi gösteren bir arayüz aslında. Yazdığımız sınıfta kullandığımız erişim belirteçleri (<a href="https://en.cppreference.com/w/cpp/language/access"><em>access specifier</em></a>) otomatik olarak bunu yapıyor. Ancak burada bile isterseniz başlık dosyasının tamamını değil, arayüz olarak vermek istediğiniz sınıfların ya da fonksiyonların bildirimlerini yazabilirsiniz. Bu kadar laf yeter, nasıl çalışıyor bakalım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*zsMIyCP3-dlED_PT8edZfg.png" /><figcaption>SWIG komut dosyası</figcaption></figure><ul><li><strong>-Wall</strong> bayrağı aslında C++ kullanıcıları için çok yabancı gelmeyebilir ama yine de açıklamak gerekirse, arayüz dosyasını derlerken karşılaşılan yanlış kullanımlar için bizi uyaran bir <em>flag</em>.</li><li>Hangi dili seçtiğini söylediğiniz başka bir argüman <strong>-c++</strong> da bizim için önemli.</li><li>Eklediğiniz ya da tanımını vermiş olduğunuz fonksiyonların yerini belirtmek için ise yine alışkın olduğumuz bir sözdizimi olan <strong>-I</strong> belirlenmiş. Bu sayede SWIG kullanmak istediğiniz başlık dosyalarını çözümlemiş oluyor.</li><li>Arayüz dosyanızı vermeden önce de hangi dile dönüştürülmesini isterseniz onu argüman olarak gösteriyorsunuz. Bu yazıda Python incelediğimiz için <strong>-python</strong> dedik.</li></ul><p>Bu aşamada SWIG sizin için iki tane dosyayı otomatik olarak üretiyor. Bunlardan birincisi <em>{modulename}_wrap.cxx</em> dosyası. <em>Python3</em> <a href="https://pyobjc.readthedocs.io/en/latest/">nesne yapısı</a>nı sizin için sarmalayarak kullanabileceğiniz bir yapı haline getiriyor. Üretilmiş karmaşık bir yapıya sahip <em>C++</em> dosyası sizi yeterince korkuttuysa dosyayı kapatabilirsiniz :)</p><p>Diğer dosya ise <em>{modulename}.py</em>, sizin günün sonunda oluşturmuş olduğunuz paylaşımlı kütüphane dosyasını Python dosyasına yükleyerek(load işlemi) size sadece bu dosyayı import etmek kalıyor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HC-OUGIEtZIxklcjhIj1zQ.png" /><figcaption>Derlenme aşaması</figcaption></figure><p>Artık SWIG tarafından üretilen dosya ve kendimize ait dosyaları derleyip nesne dosyaları ürettirebiliriz. Buradaki önemli noktalar ise şöyle:</p><ul><li>Eğer oluşturacağımız dosya paylaşımlı kütüphane ise <a href="https://www.rapidtables.com/code/linux/gcc/gcc-fpic.html"><strong>-fPIC</strong></a> bayrağını kullanmamız gerekiyor.</li><li><strong>-c</strong> argümanı ile sadece dosyaları derleyeceğimizi onları birbirine bağlamayacağımızı belirtiyoruz. Eğer bunu unutursanız varsayılan olarak obje dosyaları birbirine bağlanmaya çalışacak ancak nesneler arasında main fonksiyonu olmadığı için hata alacaksınız, bu yüzden önemli.</li><li>Bir diğer nokta ise indirdiğimiz Python geliştirme ortamına ait başlık dosyasının yer aldığı dizini göstermek. Bu sayede <em>Python.h</em> adlı başlık dosyasını kullanabiliyoruz.</li></ul><p>Sıra geldi elimizdeki nesneleri <a href="https://linux.die.net/man/1/ld">linker</a> ile bağlayıp bir paylaşımlı kütüphane ortaya çıkarmaya. Bunu <em>ld</em> komutu kullanarak da yapabiliriz ama ben yine <em>g++</em> kullanarak ilerlemek istiyorum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0aH1UK-c_zTEjMVZKvLAQ.png" /><figcaption>Paylaşımlı kütüphane oluşturma komutu</figcaption></figure><blockquote>Sonlara doğru gelirken belki en önemli detay olarak burayı göstermem gerekiyor diye düşünüyorum çünkü dökümanda dikkat edilmesi gereken bir nokta olarak gösterilmemiş. Oluşturacağınız dosyasının adı alt çizgi ile başlamalı ve modüle tanımlamış olduğunuz isimle birebir aynı olmalı.</blockquote><p>Hazırsak artık yazdığımız <em>Python</em> kod örneğini paylaşalım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*MAZTRQk6kgS-RqSl5fj1Zw.png" /><figcaption>Python örneği</figcaption></figure><p><em>C++</em> sınıfında yazmış olduğumuz algoritmayı hatırlarsak, eğer istenen tarih 1900 ve 2200 arasında değilse fonksiyonun bize -1 dönmesini bekliyoruz. Bakalım sonuç ne oldu?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*tYCLmSF_PAROcEkJfRONIA.png" /><figcaption>Python çıktısı</figcaption></figure><p>Görüldüğü üzere yazmış olduğumuz <em>C++</em> sınıfı, <em>SWIG</em> sponsorluğunda <em>Python</em> tarafından yorumlanıp kullanılabilir hale geldi. Yorumlarınızı ve düşüncelerinizi bana istediğiniz adresten ulaştırabilirsiniz!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74a6303dbefb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Struct Veri Tipi İçin Alignment]]></title>
            <link>https://cngzhnp.medium.com/struct-yap%C4%B1s%C4%B1-i%CC%87%C3%A7in-alignment-22d60026c23a?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/22d60026c23a</guid>
            <category><![CDATA[alignment]]></category>
            <category><![CDATA[struct]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Sat, 23 Nov 2019 00:27:08 GMT</pubDate>
            <atom:updated>2019-11-24T12:21:53.363Z</atom:updated>
            <content:encoded><![CDATA[<p>Uzun zamandır yazmayı planladığım seriye yaklaşık 3.5 yıl sonra dönüş yapmam biraz değişik hissettirdi açıkçası. <a href="https://medium.com/@cngzhnp/c-programlama-dilinde-struct-yap%C4%B1s%C4%B1-1bfea688e112">Önceki yazımda</a>, struct yapısının işlemci için nasıl adreslendiği ve işlemcinin erişmesi için derleyicinin sağlamış olduğu padding işleminden bahsetmiştim.</p><p>Peki işlemci her zaman bu şekilde mi erişiyor yoksa struct yapısı için yapılabilecek farklı yöntemler de var mı? Sorunun cevabı evet.</p><p>Şimdi bir struct veri tipi örneğini inceleyelim. <a href="https://medium.com/@cngzhnp/c-programlama-dilinde-struct-yap%C4%B1s%C4%B1-1bfea688e112">Önceki yazımı</a> okuduysanız, aşağıdaki struct yapısının ne kadar yer kapladığı konusunda 2 farklı cevabınız olmalı:</p><figure><img alt="Örnek bir struct veri tipi" src="https://cdn-images-1.medium.com/max/243/1*uDso8Kcr9IsUs_NZ8RhBHg.png" /></figure><p>İşlemcinin ne tür bir mimaride olduğunu öğrenmek için Linux da <em>lscpu</em> komutunu kullanılabilir. Bu durumda, <a href="https://gist.github.com/cngzhnp/557dccc0e534fea5859778e2c4f7bd30">verilen kod parçasındaki</a> çıktının 64-bit işlemcisi olan bir makinede çıktısı aşağıdaki gibi olmalı:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*oIm5R7OBy16FqCzisgficg.png" /></figure><p>32-bit işlemciyle çalışan bir sistem için ise, doğru cevap 24 olmalıydı. Bu sistem için padding aşağıdaki ekran görüntüsündeki gibi oluşturulur.</p><figure><img alt="32-bit makinede alignment yapılmış hali" src="https://cdn-images-1.medium.com/max/364/1*kkxcC0SisN9Q2z8iKeIIJg.png" /></figure><p>Peki sürekli align olmuş bir veri tipi mi kullanabiliriz? Neden ayrı ayrı elemanların veri tiplerinin topladıkları alan kadar yer kaplamıyor?</p><p>Bunun için kullanılan 2 yöntemden bahsedeceğim; öntanımlı işlemci direktifi olan #pragma ve __attribute__ yapısı.</p><p>Pragma önişlemci direktifi ile başlayacak olursak, belirtilen struct veri tipini yukarıda istenen bir yapıya dönüştürmek için şöyle tanımlanmalıdır.</p><figure><img alt="Pragma kullanılarak tanımlanmış struct veri tipi" src="https://cdn-images-1.medium.com/max/254/1*phGWbg7PF3iHFn7bVAjYyw.png" /></figure><p>Peki bu yapıyı kullanıyoruz ancak neden 1 dediğimizi merak ediyor olabilirsiniz. Burada push sonrası belirtilen sayı, struct veri tipinin kaç byte align edileceğini gösteriyor. Alignment bu şekilde yapıldığında, işlemcinin araya bir padding koymasına gerek kalmıyor çünkü zaten erişebilecek en küçük boyuta indirilmiş durumda. Yani, padding uygulanmayacağı için aslında bu veri tipinin toplam boyutu içerisindeki elemanların tek tek boyutlarının toplamını vermektedir. Linkteki kodu tekrar bu şekilde derlediğimizde aşağıdaki sonucu alırız:</p><figure><img alt="Pragma pack direktifi kullanılan struct veri tipinin boyutu" src="https://cdn-images-1.medium.com/max/478/1*n7Oe32x0RXe1nEkjNu4SRA.png" /></figure><p>Peki align olacak byte sayısını 2 yaparsak durum nasıl değişir? Öncelikle 2-byte alignment yapıldığında ilk eleman için herhangi bir padding yapılmayacak, çünkü toplamda 10 byte boyuta sahip. İkinci elemanın da boyutu 8 byte olduğu için(64-bit sistem için) yine 2 byte in katı olduğu için alignment uygulanmayacaktır. Son eleman da 1 byte olarak alignment a ihtiyaç duyacağı için toplamda <strong>20</strong> byte yer kaplayacaktır.</p><p>Akla gelebilecek bir diğer soru ise, n sayısının 3, 5 ya da 2 nin katı olmayacak şekilde verildiğinde derleyicinin buna ne yanıt vereceği olabilir. Aşağıdaki ekran görüntüsü bununla ilgili size bir fikir verecektir diye düşünüyorum.</p><figure><img alt="Alignment yapılacak olan byte sayısını 2 nin katı olmadığı durum" src="https://cdn-images-1.medium.com/max/960/1*RCW2GP_4qXo6ZO37V2oVPA.png" /></figure><p>Peki ekran görüntüsünü gördüğünüz üzere, çıktı sadece <em>GCC</em> derleyicisine özel diyebilir miyiz? Hadi aynı kod parçasını clang derleyicisiyle derlemeye çalışalım. Bakalım farklı bir davranış sergileyecek mi?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*a2Gbht_aVTxZ8ukgrb9fDA.png" /></figure><p>Görüldüğü gibi aslında benzer uyarıları farklı cümlelerle bize açıklıyorlar. Bu durumda doğru alignment değeri kullanıldığında sonuçların da aynı olmasını bekliyoruz. Öte yandan dipnot olarak kullanılan direktif başka derleyicilerde tanımlı olmayabilir, bu durumda verdiğiniz struct tipinde size <strong>aynı çıktıyı vermeyebilir.</strong></p><p>Şimdi de bir diğer yöntem olan <em>__attribute__ </em>a biraz yakından bakalım. Yine aynı struct üzerinde kullanmak istersek aşağıdaki ekran çıktısına benzer yapıda olmasını öngörüyoruz.</p><figure><img alt="Attribute ile struct veri tipinin align edilmesi" src="https://cdn-images-1.medium.com/max/339/1*6t9FKrcbFr8hbCLqCmEd2A.png" /></figure><p>Aslında önişlemci direktifiyle arasındaki benzerliği fark etmiş olmalısınız. Align edilmek istenen kaç byte ise <em>aligned </em>anahtar kelimesinin içerisine yazmalı ve <em>packed </em>anahtar kelimesiyle birlikte kullanılmalıdır. Bu durumda da önişlemci örneğindeki gibi aynı çıktıyı, 19 byte, olarak vermelidir.</p><p>Peki 2 nin katı olmayan boyutta align etmediğimizde nasıl bir sonuç alıyoruz? Önişlemci direktifiyle arasındaki farkı görelim. Yukarıdaki örnekte align edilen değeri 3 olarak değiştirdiğimizde aşağıdaki gibi bir çıktı ile karşılaşıyoruz.</p><figure><img alt="Beklenmedik align boyutu verildiğinde GCC derleyicisinin ürettiği hata" src="https://cdn-images-1.medium.com/max/652/1*gpT9GDysa94WmK99bNFgvg.png" /></figure><p><em>GCC </em>derleyicisi align edilen değerin, 2 nin pozitif bir katı olup olmadığını kontrol edip, hata üretiyor. Öncekinden farklı olarak kodu derlemeyip hata üretiyor. Bir önceki örnekte kodun derlediğini gözden kaçırmayın. Eğer böyle bir durumda önceliğiniz hatayı derleyici zamanında yakalamak ise belki de bunu kullanmak avantajınıza olabilir. Hadi gelin bir de clang derleyicisine bakalım.</p><figure><img alt="Beklenmedik align boyutu verildiğinde Clang derleyicisinin ürettiği hata" src="https://cdn-images-1.medium.com/max/623/1*9WHjjNnN58LoYuqT9d3rkg.png" /></figure><p>Görüldüğü gibi, <em>clang </em>derleyicisi de <em>GCC </em>gibi aynı durumda kodu derlemeyip, hata üretiyor.</p><p>Sonuç olarak, struct veri tipini sadece alignment edilmiş şekilde değil, farklı direktifler kullanarak istenilen kadar boyutta align edilerek de kullanılabileceğini görmüş olduk.</p><p>Peki bazı veri tipleri farklı sistemlerde farklı boyutlarda tutulabildiğine göre nasıl bir yöntem izlenebilir sorusunun cevabı ise, <strong>stdint.h</strong> kütüphanesinin içinde gizli. Eğer kullanılmak istenen verinin en düşük ve en yüksek alabileceği değerler biliniyor ya da tahmin edilebiliyorsa, hangi sabit boyutlu veri tipinin uygun olduğuna karar verebilirsiniz. Örneğin; bir banka uygulamasında sıra numarası veren makine için değer atamak gerekiyorsa, sıra numarasının 0&#39;dan küçük olmaması ve tahminen 65535&#39;ten küçük olması gerektiği düşünülebilir. Bu durumda bu sayıyı tutmak için sabit boyutlu olan <em>uint16_t</em> veri tipi uygun olacaktır.</p><p>Yukarıda anlatılanların ne zaman ve neden kullanılacağı şöyle açıklanabilir; farklı sistemler, makineler vb. arasında gönderilen verinin doğruluğundan emin olmak istediğiniz durumlarda kullanılabilir. Daha genel olmak gerekirse; bu senaryoların tamamen ihtiyaçlar doğrultusunda gerçekleşeceğini unutulmamalı.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22d60026c23a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C++11 bana göre güzel ama İngiliççe]]></title>
            <link>https://cngzhnp.medium.com/c-11-ile-gelen-yeni-%C3%B6zellikler-db5a9f5d2fe5?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/db5a9f5d2fe5</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Sat, 11 Apr 2015 12:00:10 GMT</pubDate>
            <atom:updated>2015-04-11T12:19:00.360Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>1-)auto keyword</em></strong></p><p>C ya da C++ dilinde en çok kafa karıştıran şey çoğunlukla pointer yapısıdır. Özellikle de linked list,stack ya da queue gibi veri yapıları yazmaya çalışıyorsanız başlangıçta oldukça zorlanacağınız aşikar. Peki yok mu bir kısa yolu falan diyorsanız STL kütüphaneleri sizin yol göstericiniz olacaktır. Programlamayı kolaylaştırılan bu kütüphaneler bile zaman zaman zorluklar çıkarabiliyor. Hadi aşağıdaki örneği inceleyelim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dd107eac796aea706f96576aee45ad6/href">https://medium.com/media/0dd107eac796aea706f96576aee45ad6/href</a></iframe><p>Kodu incelediğimizde özellikle iterasyon yapılan yerlerde işlem yapmak zor ve hataya oldukça elverişli. Peki C++11 işimizi kolaylaştırmak için neler geliştirmiş bakalım. İşte aşağıdaki örneğin C++11 de derlenebilir hali. auto keyword sayesinde iterasyon yapmak artık daha basit. Nested STL değişkenlerinin iterator leri arasında boğulmak yerine C++11 size auto keyword ünü sunuyor. Böylece kendisi run-time esnasında onun hangi iterator olduğuna karar verip işlem yapıyor. Bakalım auto kullanarak nasıl yazılıyor?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eab386c4241b4a7304a1dcee546999f4/href">https://medium.com/media/eab386c4241b4a7304a1dcee546999f4/href</a></iframe><p>Ancak hala end(),begin() gibi fonksiyonlar kullanıyoruz yeterince C++11 syntax ı gibi durmuyor.</p><p><strong><em>2-)for loop</em></strong></p><p>Önceki örneğimizden devam edersek hala yeterince basitleştiremediğimizi görüyorum. Hala end,begin gibi yapılar hoş durmuyor. Hadi bu kodu biraz daha C++11 syntax ına uygun hale getirelim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65e8126d106b9481d44ffd76567d2914/href">https://medium.com/media/65e8126d106b9481d44ffd76567d2914/href</a></iframe><p>Yukarıdaki kodu incelediğimizde ne kadar kolay hale geldiğini görebiliyoruz. Aslında for_each döngüsüne benzer bu yapıda döngüye nereden ne döndüreceğini söylememiz yeterli. Kendisi bize bir önceki örnekle aynı çıktıyı verecektir. Gelelim memory management kısmına. Sadece auto x kullanarak her nesnenin bir kopyasını oluşturacağımız için bundan kaçınılmalı ve nesnenin kendisiyle çalışmalıyız. (Tabi eğer böyle gerekiyorsa.). Bu durumda auto &amp;x kullanarak işlem yapmamız gerekiyor. Hatta sadece bir arkadaşa bakıp çıkayım herhangi bir işlem yapmayayım derseniz de auto const&amp; kullanmak her zaman için daha iyidir. Görüyorum ki hala C++11 syntax ına yakışmayan şeyler var yukarıdaki kodda. Örneğin başlangıç değerleri atamak gibi.</p><p><strong><em>3-)initialization</em></strong></p><p>İlk örnekte map STL inde tutulan değişkene eleman eklemek için yine insert fonksiyonu içerisinde pair oluşturularak eleman eklemek vs. çok yorucu. Neden int a = 5 gibi kolayca başlangıç değeri atayamıyoruz? İşte C++11 de bize bu kolaylığı da sağlıyor. Şu koda bir göz gezdirelim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de385c78c5c0ecd80e74a2d4f9c8b44c/href">https://medium.com/media/de385c78c5c0ecd80e74a2d4f9c8b44c/href</a></iframe><p>Önceki uzun ve “ugly” kodun yerine daha sade ve daha şık bir syntax e sahip bir kod geldi. Peki sadece STL kütüphaneleriyle mi sınırlı tabiki değil. Bana kalırsa en çok yararlı olacak şeylerin başında class içerisindeki elemanların başlangıç değerlerinin atanması geliyor. Elimizde çok sayıda eleman barındıran bir class olduğunda başlangıç değerlerini aşağıdaki gibi atamak zorunda kalıyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37d7d7318f64fc1cd0d8b0a8dc894bf9/href">https://medium.com/media/37d7d7318f64fc1cd0d8b0a8dc894bf9/href</a></iframe><p>Değişkenlerin başlangıç değerlerini constructor da atamak yerine onları tanımlarken atamak kodu daha okunaklı hale getiriyor. Artık aşağıdaki kod örneği gibi C++11 kullanırken class yapısı içerisindeki elemanları initialize etmek daha kolay. Böylece public bir constructor yaratıp elemanlara değer atamak gibi ekstra bir iş de yapmamış oluyorsunuz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cf0f61ab0d8c68e6ee5f3ae821a9e51/href">https://medium.com/media/5cf0f61ab0d8c68e6ee5f3ae821a9e51/href</a></iframe><p>Eğer değişkenlerin değerlerini default olarak atamak isterseniz her değişkenin sonuna “{}” koymanız yeterli. Böylece variable ne olursa olsun sizi <strong>memset</strong>(variable,0,sizeof(variable)) gibi fonksiyon yazımından kurtarıyor.</p><p><strong><em>4-)lambda expressions</em></strong></p><p>STL kütüphanelerinin bir diğer güzel yanı da size fonksiyon template ı sunmasıdır. “algorithm” kütüphanesi kullanılarak belli fonksiyon templatelerini kullanıp eleman bulmak,sıralamak daha kolay hale geliyor. Şimdi, [a,b] arasında kaç tane sayı olduğunu bulan programı inceleyelim tabiki a ve b sayıları kullanıcıdan alınıyor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed06e77dd2462507ad153e02c3fa3302/href">https://medium.com/media/ed06e77dd2462507ad153e02c3fa3302/href</a></iframe><p>Yukarıda görüldüğü gibi count_if algoritmasını kullanmak için operator overloading yapan bir class ımız ve bu class a parametre gönderdiğimiz için gerekli olan 2 class elemanı ve 1 de constructor var. Görüldüğü gibi sadece 1 operator overloading için gerektiğinden fazla işlem yaptık. Class oluştur onu doldur derken asıl işlemden çok şey yazdık. Halbuki ihtiyacımız olan şey sadece overloading işleminin yaptığı satır. Tam da bunu karşılayacak yapı lambda expression lar. Lambda expression sayesinde anonymous yazılan fonksiyonlar yukarıdakiyle aynı işlemi yapıyor. Hadi bir göz atalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3c40783b625c8a5d4f70cf6e646e2fa/href">https://medium.com/media/f3c40783b625c8a5d4f70cf6e646e2fa/href</a></iframe><p>Süslü parantezin içi aynı operator overloading için yazdığımız fonksiyon gibi tek farkı ise syntax ı. Parantez içerisindeki değer lambda fonksiyonuna göndereceğimiz parametre. Yani normal fonksiyondan herhangi bir farkı yok ancak onun yanında köşeli parantez içerisinde başka bir yapı daha var. Bunlara da <strong>Capture </strong>adı veriliyor. Fonksiyon içerisine yollandıktan sonra fonksiyondan geri alınması istenen değerler burada belirtiliyor. Yine belirtmekte fayda var ki, eğer bu elemanları fonksiyon içerisinde değiştirip daha sonra doğru bir şekilde almak isterseniz, referans olarak göndermeniz gerekecek. Aksi takdirde değerini koruyacaktır. Peki ya elimde göndermem gereken 5–6 tane böyle parametre var hepsini tek tek yazacak mıyım? Tabiki hayır.<strong> [&amp;] </strong>şeklinde<strong> </strong>belirttiğinizde lambda fonksiyon içerisinde tanımlanmayan tüm değerlerin referansını tutacaktır. Aynı şekilde değer gönderirken de <strong>[=] </strong>diyerek tüm değerleri value by olarak gönderebilirsiniz.</p><p>Bu arada yazının sonuna gelirken nasıl derleyeceğiniz hakkında şu detayı da vereyim. Command line üzerinden normal derlemeye çalışırsanız sen ne konuşuyosun lan değişik demesi muhtemel. O yüzden oluşturduğunuz Makefile içerisine <strong>-std=c++11</strong> eklemeyi unutmayın. Aynı zamanda GCC versiyonunuzun da güncel olmasına dikkat edin.</p><p>Pek yeni özellik eklenmeye de devam ediyor. C den gelenler için oldukça garipleşen C++11 ilk başta biraz soğuk gibi geliyor ama girince alışıyor insan ☺ Bu yazıda bazı kısımlarına değinebildim daha değinmediğim <strong>nullptr, decltype,rvalue </strong>gibi yapıları da var. Umarım ileriki zamanlarda bunlar hakkında da birkaç şey karalayabilirim.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db5a9f5d2fe5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Struct Yapısı İçin Padding]]></title>
            <link>https://cngzhnp.medium.com/c-programlama-dilinde-struct-yap%C4%B1s%C4%B1-1bfea688e112?source=rss-d32196d9a373------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bfea688e112</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Cengizhan Pasaoglu]]></dc:creator>
            <pubDate>Sun, 08 Mar 2015 21:42:06 GMT</pubDate>
            <atom:updated>2019-11-23T07:14:30.829Z</atom:updated>
            <content:encoded><![CDATA[<p>Bu yazıda C ve C++ dilinde oldukça yaygın olarak kullandığımız <em>struct</em> yapısıyla alakalı enteresan bir konuya değinmek istiyorum. Bu yazıyı okuyacakların C ve C++ diliyle ilgili adresleme ve pointer gibi kavramlara aşina olması ve CPU mimarisi konusunda az da olsa bilgi sahibi olması önemlidir. Hemen başlayalım o halde, nedir bu <em>struct</em>?</p><p>Struct bilindiği üzere farklı veri tiplerini bir araya getirmek için kullandığımız bir tanımlama aslında. Hep verilen bir örnek üzerinden gitmek gerekirse; elimizde bir bilgisayarın özelliklerini tutan farklı veriler olduğunu düşünelim. Bu bilgisayarın markası, modeli, işlemci tipi, hızı, kaç GB RAM e sahip olduğu gibi bilgileri farklı veri tiplerinde ayrı ayrı tutmaktansa, struct tipinde ve adının PC olduğu bir değişken tanımlayıp içini doldurmak kod yazmayı daha basit ve yazılan kodu anlaşılır kılar. Peki hiç <em>struct </em>yapısı içinde tutulan değişkenlerin yerlerinin önemli olabileceğini düşünmüş müydünüz?</p><p>Biliyoruz ki, günümüzde yaygın olarak kullanılan 64-bit işlemciler gelmeden önce çoğu bilgisayar 32-bit belki de 16-bitti. Peki ne anlama geliyor bir bilgisayarın 16, 32 ya da 64-bit olması? İşlemcilerin bu tipleri, aslında ne kadar çok adresleme yapabildiklerini gösteriyor. Yani 32-bit işlemciye sahip bir makine aslında 2^32 farklı bit kombinasyonunu adresleyebildiğinden 4 GB’a kadar olan datayı adresleyebiliyor. Peki bu değişkenler bellekte ne kadar yer kaplıyor? <em>Char</em> tipinde değişkeni 1 byte, <em>short integer</em> tipinde bir değişken 2 byte, <em>integer</em> tipinde değişken ise 4 byte yer kaplar ancak işlemcinin 32-bit olduğu durumda. Peki ya pointer lar? Pointer lar adres gösterdikleri için aslında işlemcinin mimarisinin 32-bit ya da 64-bit olmasına göre 4 byte ya da 8 byte yer kaplayabilir. Peki ya <em>struct </em>ne kadar yer kaplar?</p><p>Hadi aşağıda yer alan <em>struct </em>yapısını biraz inceleyelim:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*qpJ1MR88oIiyLBVYVrbvPQ.png" /><figcaption>Alignment for Struct</figcaption></figure><p>Eğer <em>struct </em>yapısının bellekte nasıl konumlandığı hakkında fikriniz yoksa, bu struct ın bellekte 10 byte yer kapladığını düşünmeniz gayet doğal. 64-bit işlemcilerde pointer 8 byte alan kaplar, bu durumda <em>struct </em>boyutu 14 byte gibi algılanabilir. Fakat durum sandığınız gibi değil. İşlemciler tek byte olacak şekilde adrese erişmek için tasarlanmamışlardır. Genellikle 32-bit işlemciler 4-byte <strong>self-alignment</strong> adresleme yöntemini kullanırken 64-bit işlemciler ise 8-byte adresleme yöntemini kullanırlar (1 byte = 8 bit olduğunu kabul edersek). Peki nasıl oluyor da 32-bit bir işlemci, struct yapısı içerisinde yer alan örnekteki <em>first </em>değişkenin kapladığı alan 1 byte olmasına rağmen bu alanlara erişebiliyor? Bu erişim sırasında yaptığı işleme <strong>padding </strong>adını veriyoruz. Yani işlemci aslında <em>struct </em>yapısını şöyle görüyor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*hsEbgICLw1E6A6aS-9PKKw.png" /><figcaption>Padding for struct variable.</figcaption></figure><p><em>First</em> değişkenine eriştikten sonra padding değeri olarak 3 byte ekleme yapıyor. İlk padding işlemi bu. Sonraki <em>*ptr</em> değişkeni için sıkıntı yaratan bir durum yok. Ancak <em>second</em> değişkeni için de durum aynı. İşlemci yine 3 byte padding ekleyerek adresleme yapacak. <em>Offset </em>değişkeni için de sorun yok o da self-alignment yapısına uygun. Yani struct yapısının son hali aşağıdaki gibi olmalı:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*pahouY_RAhMRe1SdJi59_w.png" /><figcaption>Last state of Struct variable.</figcaption></figure><p>Yine değinmek istediğim nokta 64-bit işlemciler için padding değerinin 8 byte a tamamlanabilir olması. Yani padding değeri 3 değil 7 olacaktı.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*ygYBQVyLu_JpfBSZs0IKeg.png" /><figcaption>Struct inside of in struct placement</figcaption></figure><p>Yine struct içerisinde tanımlanan struct değişkenleri için de yandaki gibi bir durum ortaya çıkacak yine padding işlemleri onun için de geçerli olacak. Toplamda bu struct da 24 byte yer kaplayacak.</p><p>Peki 24 byte olması normal mi? Tabi ki değil. Amacımız da zaten 24 byte dan daha az yer kaplayabileceğini düşündüğümüz bu struct içerisindeki yerleşimi değiştirmek. Eğer padding yapılan alanları azaltırsak ya da padding yapılan alanları kendimize uygun biçimde kullanabilirsek, struct için ayrılan alan daha da azalacaktır. Şimdi de aynı struct yapısını şu şekilde değiştirelim:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*vAk18roSk9GVpKa1WUn5BQ.png" /><figcaption>Aligned struct declaration</figcaption></figure><p>Yandaki struct yapısında 2-byte padding <em>last</em> değişkeninden sonra 2-byte padding de <em>second</em> değişkeninden sonra kullanılacak. Bu durumda struct boyutu 16 byte olarak değişecektir.</p><p>Padding işlemlerinden sonra struct yapısında 8 byte kadar bir azalma görüldü. Bu struct değişkeninden yüzlerce, binlerce tanımlandığında çoğunlukla gömülü sistemlerdeki sınırlı bellek alanı düşünüldüğünde alignment işleminin ne kadar önemli olduğu gözlenebilir. Peki nerede padding var nasıl gözleyebiliriz sorusuna gcc derleyicisinde yer alan <strong>Wpadded</strong> parametresiyle cevap verilebilir. Aşağıda yer alan ekran görüntüsünde satır satır nerelerde padding yapılması gerektiğini görebiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*O-FdfHzGrSjtQhbqQyiczg.png" /><figcaption>-Wpadded parameter during gcc compiling stage</figcaption></figure><p>Görüldüğü üzere <em>*ptr</em> ve <em>last</em> değişkenlerinden önce de bir padding gerektiği konusunda gcc bizi uyarıyor.</p><p>Böylece <em>struct </em>yapısında alignment işleminin önemini görmüş olduk. Yazdığım bu ufak kodu da <a href="http://pastebin.com/qUGjhWGx">şu linkte</a> bulabilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bfea688e112" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>