<?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 Diogo Mateus on Medium]]></title>
        <description><![CDATA[Stories by Diogo Mateus on Medium]]></description>
        <link>https://medium.com/@diogomateus?source=rss-285097eaa377------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bBDap5DT5GrafXGsX4isOw.jpeg</url>
            <title>Stories by Diogo Mateus on Medium</title>
            <link>https://medium.com/@diogomateus?source=rss-285097eaa377------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 06:05:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@diogomateus/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[Paul Atreides Is a Villain. That’s Not the Point of Dune.]]></title>
            <link>https://medium.com/@diogomateus/paul-atreides-is-a-villain-thats-not-the-point-of-dune-a1866b680a10?source=rss-285097eaa377------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1866b680a10</guid>
            <category><![CDATA[dune]]></category>
            <category><![CDATA[ethics]]></category>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[frank-herbert]]></category>
            <category><![CDATA[morality]]></category>
            <dc:creator><![CDATA[Diogo Mateus]]></dc:creator>
            <pubDate>Wed, 22 Apr 2026 16:01:42 GMT</pubDate>
            <atom:updated>2026-04-22T16:23:48.865Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HhQLDJNyJXWcto_8co9Eqg.png" /></figure><p><em>The dilemma underneath the hero-villain debate (Dune, Book One)</em></p><p>Most conversations about <em>Dune</em> come back to the same question: is Paul Atreides a hero or a villain?</p><p>By the end of the book, Paul is responsible for 61 billion deaths. He sees it coming long before it happens. He chooses it anyway: to avenge his father, to restore his house, and to protect his family. I don’t think any of that justifies 61 billion deaths. By any honest measure, he is a villain.</p><p>But I think that debate misses what the book is actually about. <em>Dune</em> isn’t really asking whether Paul is good or evil. It’s asking something more uncomfortable, because it’s something most of us have faced in smaller versions of our own lives: what do you do when you can see clearly that your choice will hurt someone else, and you choose yourself anyway?</p><p>Herbert’s move is to remove every excuse we normally use. Paul has perfect foresight, so he can’t claim he didn’t know. Paul is a genuinely good person, so we can’t write him off as a monster. The cost is billions of lives, so we can’t tell ourselves it wasn’t that bad. Once all of that is gone, what’s left is just the choice. And Herbert wants us to sit with it.</p><h3>Paul is a good person</h3><p>This part matters.</p><p>He’s thoughtful and loyal, raised by a father who governed with actual justice. He loves his family and his friends. When he meets the Fremen, he falls genuinely in love with their culture.</p><p>He also never behaves like a villain. He doesn’t torture. He doesn’t betray. He never takes pleasure in suffering. In the book, you see a decent young man trying to do his best in a situation with no good options.</p><p>Which is what makes him such a brutal version of the dilemma.</p><h3>He sees what’s coming</h3><p>From the start, Paul sees the jihad. The green and black banner carried by fanatic legions. Worlds burning in his honor.</p><p>For most of the book, he looks for some narrow path through the future that avoids the slaughter, some version of events where he gets what he wants without the cost. He can’t find one. Every path he can see leads to the jihad.</p><p>He also realises he can’t stop it. Once he becomes the messiah the Fremen are waiting for, the holy war happens with or without his consent. The legions will move in his name, whether he wants them to or not.</p><p>He crosses that point anyway, knowing exactly what comes next.</p><h3>The choice itself</h3><p>With the excuses stripped away, a good man who can see everything still chooses himself. He takes his revenge, protects his family, claims the throne that was his father’s, and convinces himself along the way that he had no other option. That last part, the story he tells himself, is probably the most human thing about him.</p><p>That’s what the book is really about, I think. Not a villain. Not a hero. Just a person placed in a situation designed to take away every comfortable story we use to make our own choices feel fine.</p><p>Herbert isn’t asking us to hate Paul. He’s asking whether, in Paul’s place, we’d actually have done anything different.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1866b680a10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CapRover + Grafana = ❤]]></title>
            <link>https://medium.com/@diogomateus/caprover-grafana-625ed7544c01?source=rss-285097eaa377------2</link>
            <guid isPermaLink="false">https://medium.com/p/625ed7544c01</guid>
            <category><![CDATA[loki]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[paas]]></category>
            <category><![CDATA[caprover]]></category>
            <category><![CDATA[saas]]></category>
            <dc:creator><![CDATA[Diogo Mateus]]></dc:creator>
            <pubDate>Mon, 09 Feb 2026 02:54:19 GMT</pubDate>
            <atom:updated>2026-02-09T03:27:16.880Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CoUNV71kjFJUc1KBLzDjtg.png" /></figure><h3>Why</h3><p>CapRover is a fantastic tool for self-hosting apps, databases and everything else. It handles all the heavy lifting of deployment, SSL, and Nginx for you. It’s a great alternative to Heroku, fly.io, and, in a way, to AWS and Google Cloud.</p><p>However, as you deploy more apps, keeping track of what is happening inside them gets difficult. CapRover’s built-in log view isn’t designed for deep troubleshooting or searching through history. I tried using Dozzle to view Docker logs, but it didn’t work well. It freezes the browser and loses logs whenever containers restart.</p><p>I also considered external observability tools like Datadog, Splunk, or New Relic. The problem is that those services get expensive very quickly.</p><p>Since you are already running your own Platform-as-a-Service, the smartest move is to self-host your logging pipeline too.</p><p>In this guide, we will set up a robust, self-hosted logging solution where:</p><ol><li><strong>Loki</strong> stores the logs.</li><li><strong>Promtail</strong> collects logs from all your containers.</li><li><strong>Grafana</strong> visualizes them.</li></ol><p>Let’s get started.</p><h3>Part 1: Deploying Loki (The Storage)</h3><p>Loki is the database that will hold all your log data. Because it needs to retain data across restarts, we must treat it as a <strong>Persistent App</strong>.</p><h4>1. Create the App</h4><ol><li>Log in to your <strong>CapRover Dashboard</strong>.</li><li>Go to <strong>Apps &gt; Create A New App</strong>.</li><li>Name it loki.</li><li>Check the box <strong>Has Persistent Data</strong>.</li><li>Click <strong>Create</strong>.</li><li>You <strong>do not</strong> need to expose this to the public web (HTTPS). Other apps within CapRover can talk to it internally using the hostname http://srv-captain--loki:3100. It is safer to keep this internal.</li></ol><h4>2. Configure Persistence</h4><p>Go to the <strong>App Configs</strong> tab and map the following Persistent Directories to ensure your logs and configs survive a restart:</p><pre><strong>Path in Container</strong>: /loki<br><strong>Label (Volume Name)</strong>: loki-data<br><strong>Purpose</strong>: Stores the actual logs and indexes.</pre><pre><strong>Path in Container</strong>: /etc/loki<br><strong>Label (Volume Name)</strong>: loki-config<br><strong>Purpose</strong>: Stores your configuration file.</pre><h4>3. Deploy the Image</h4><p>Go to the <strong>Deployment</strong> tab.</p><ol><li>Scroll to <strong>Method 6: Deploy via ImageName</strong>.</li><li>Enter: grafana/loki:latest (or a specific version like 3.0.0).</li><li>Click <strong>Deploy</strong>.</li></ol><h4>4. Configure loki.yaml</h4><p>By default, Loki starts with a basic config. We need to tweak it to handle retention (deleting old logs) and persistence correctly.</p><p>SSH into your CapRover server. We need to find where Docker stored the loki-config volume we created earlier.</p><pre>docker volume inspect captain--loki-config</pre><p>Navigate to the _data folder listed in the output.</p><p>Edit the file named loki-config.yaml in that directory. Paste the following configuration, which enables the &quot;Compactor&quot; (to delete old logs) and sets a 24-hour retention period (adjust as needed):</p><pre>auth_enabled: false</pre><pre>server:<br>  http_listen_port: 3100</pre><pre>common:<br>  path_prefix: /loki<br>  storage:<br>    filesystem:<br>      chunks_directory: /loki/chunks<br>      rules_directory: /loki/rules<br>  replication_factor: 1<br>  ring:<br>    kvstore:<br>      store: inmemory</pre><pre># 1. Enable the Compactor to handle deletion<br>compactor:<br>  working_directory: /loki/retention<br>  compaction_interval: 1h<br>  retention_enabled: true<br>  retention_delete_delay: 2h<br>  retention_delete_worker_count: 10<br>  delete_request_store: filesystem</pre><pre># 2. Set the global retention limit<br>limits_config:<br>  retention_period: 24h</pre><pre>schema_config:<br>  configs:<br>    - from: 2020-10-24<br>      store: tsdb<br>      object_store: filesystem<br>      schema: v13<br>      index:<br>        prefix: index_<br>        period: 24h</pre><p><strong>Finally, restart the Loki app</strong> in CapRover so it picks up this new configuration.</p><h3>2. Deploying Promtail (The Shipper)</h3><p>This was the most difficult part. There are many ways to ship logs (Alloy, Docker Driver, Fluentd), but ended up going with <strong>Promtail</strong> as it was the most well-documented. It sits on your server, reads the log files directly from the Docker host, and pushes them to Loki.</p><h4>1. Create the App</h4><ol><li>Go to <strong>Apps &gt; Create A New App</strong>.</li><li>Name it promtail.</li><li>Check <strong>Has Persistent Data</strong>.</li><li>Click <strong>Create</strong>.</li></ol><h4>2. The “Nuclear” Configuration</h4><p>We need a config that does three things:</p><ol><li>Scrapes logs from all Docker containers.</li><li>Drops logs older than 24 hours (so we don’t choke the server processing old history).</li><li>Tags the logs with the correct container name.</li></ol><p>Go to the <strong>Deployment</strong> tab, scroll to <strong>Method 4: Captain Definition</strong>, and paste this JSON. It uses a clever trick to write the config file <em>inside</em> the image during the build process:</p><pre>{<br> &quot;schemaVersion&quot;: 2,<br> &quot;dockerfileLines&quot;: [<br>   &quot;FROM grafana/promtail:latest&quot;,<br>   &quot;USER root&quot;,<br>   &quot;RUN mkdir -p /var/lib/promtail&quot;,<br>   &quot;RUN printf \&quot;server:\\n  http_listen_port: 9080\\n  grpc_listen_port: 0\\n\\npositions:\\n  filename: /var/lib/promtail/positions.yaml\\n\\nclients:\\n  - url: http://srv-captain--loki:3100/loki/api/v1/push\\n\\nscrape_configs:\\n  - job_name: containers\\n    static_configs:\\n    - targets:\\n        - localhost\\n      labels:\\n        job: containerlogs\\n        __path__: /var/lib/docker/containers/*/*.log\\n\\n    pipeline_stages:\\n      - json:\\n          expressions:\\n            log: log\\n            stream: stream\\n            attrs: attrs\\n      - json:\\n          expressions:\\n            tag: \\n          source: attrs\\n      - labels:\\n          stream: \\n          tag: \\n      - docker: {}\\n      - drop:\\n          older_than: 24h\\n\\n    relabel_configs:\\n      - source_labels: [__path__]\\n        regex: /var/lib/docker/containers/(.+)/.*log\\n        target_label: container_id\&quot; &gt; /etc/promtail/config.yml&quot;,<br>   &quot;CMD [\&quot;-config.file=/etc/promtail/config.yml\&quot;]&quot;<br> ]<br>}</pre><p>The command above generates the following config.yml file inside the container:</p><pre>server:<br>  http_listen_port: 9080<br>  grpc_listen_port: 0<br><br>positions:<br>  filename: /var/lib/promtail/positions.yaml<br><br>clients:<br>  - url: http://srv-captain--loki:3100/loki/api/v1/push<br><br>scrape_configs:<br>  - job_name: containers<br>    static_configs:<br>    - targets:<br>        - localhost<br>      labels:<br>        job: containerlogs<br>        __path__: /var/lib/docker/containers/*/*.log<br><br>    pipeline_stages:<br>      - json:<br>          expressions:<br>            log: log<br>            stream: stream<br>            attrs: attrs<br>      - json:<br>          expressions:<br>            tag:<br>          source: attrs<br>      - labels:<br>          stream:<br>          tag:<br>      - docker: {}<br>      - drop:<br>          older_than: 24h<br><br>    relabel_configs:<br>      - source_labels: [__path__]<br>        regex: /var/lib/docker/containers/(.+)/.*log<br>        target_label: container_id</pre><p><strong>Why do it this way?</strong></p><p>It comes down to CapRover’s “Captain Definition” deployment method.</p><p>When you deploy using this method in the UI, you can only provide instructions on <em>how</em> to build the image; you cannot easily upload separate sidecar files like a config.yml.</p><p>To get around this, we use a trick: we embed the entire contents of the configuration file inside a standard Linux command within the build instructions.</p><p>The command &quot;RUN printf \&quot;...\&quot; &gt; /etc/promtail/config.yml&quot; literally tells the system: &quot;During the build, print this text and save it into this file path.&quot;</p><p>It looks messy, but it makes the entire deployment self-contained.</p><p>Now, click <strong>Save &amp; Update</strong> to deploy. The app will start, but <strong>it won’t work yet. </strong>We need to give it access to the host.</p><h4>3. Configure Docker Socket &amp; Permissions (Crucial Step)</h4><p>Promtail needs to see the files on your host machine. Go to <strong>App Configs</strong> and add these mappings:</p><pre>Path in Container: /var/run/docker.sock<br>Path on Host: /var/run/docker.sock<br>Purpose: Allows Promtail to talk to the Docker Daemon.</pre><pre>Path in Container: /var/lib/promtail<br>Path on Host: /var/lib/promtail<br>Purpose: Stores the &quot;positions&quot; file so Promtail remembers where it left off.</pre><h4>⚠️ The “Crash Loop” Fix</h4><p>If you map /var/lib/promtail without fixing permissions, Promtail will crash immediately. This happens because the folder on the host is owned by root, but Promtail drops its privileges to user 10001 inside the container.</p><p><strong>Fix it by running this on your server terminal:</strong></p><pre># Create the directory manually<br>mkdir -p /var/lib/promtail<br><br># Set ownership to UID 10001 (Promtail&#39;s user)<br>chown -R 10001:10001 /var/lib/promtail<br><br># Ensure write permissions<br>chmod -R 775 /var/lib/promtail</pre><p>Now, restart your Promtail app. It should stay running.</p><h3>Part 4: Connect to Grafana</h3><p>If you haven’t already, deploy <strong>Grafana</strong> via the CapRover One-Click Apps list.</p><h4>1. Login</h4><ul><li><strong>Username:</strong> admin</li><li><strong>Password:</strong> admin (You will be prompted to change this immediately).</li></ul><h4>2. Add Loki as a Data Source</h4><p>Grafana is just the UI; it needs to know where Loki lives.</p><ol><li>Click <strong>Connections</strong> (or Configuration/Gear icon) &gt; <strong>Data Sources</strong>.</li><li>Click <strong>Add data source</strong>.</li><li>Select <strong>Loki</strong>.</li><li><strong>URL:</strong> http://srv-captain--loki:3100</li><li>Click <strong>Save &amp; Test</strong>.</li></ol><h4>3. Explore Your Logs</h4><p>You don’t need a fancy dashboard to verify it’s working.</p><ol><li>Click the <strong>Explore</strong> (compass icon) in the sidebar.</li><li>Paste this query {container=~&quot;captain-nginx.*”}</li><li>Click <strong>Run query</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-SKvdj5Y142gQKKx1ydXcg.png" /></figure><h3>Summary</h3><p>You now have a production-grade logging stack running entirely on your own infrastructure.</p><ul><li><strong>Loki</strong> is safely storing data with a 24h retention policy.</li><li><strong>Promtail</strong> is auto-discovering new containers and ignoring old logs to save resources.</li><li><strong>Grafana</strong> gives you a beautiful UI to query it all.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=625ed7544c01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blockchain-Based Voting: A Transparent, Secure, and Efficient Future]]></title>
            <link>https://medium.com/@diogomateus/blockchain-based-voting-a-transparent-secure-and-efficient-future-f1eb0faeb350?source=rss-285097eaa377------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1eb0faeb350</guid>
            <category><![CDATA[voting]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[elections]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[digital-democracy]]></category>
            <dc:creator><![CDATA[Diogo Mateus]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 12:11:54 GMT</pubDate>
            <atom:updated>2025-03-28T12:20:02.074Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Problems with Traditional Voting Systems</h3><p>Elections are the foundation of democracy, yet they remain expensive, inefficient, and vulnerable to fraud.</p><ul><li><strong>High Costs: </strong>Physical polling stations, election staff, printed ballots, and security make elections expensive.</li><li><strong>Lengthy Processing Times:</strong> Manual vote counting and verification lead to delays.</li><li><strong>Fraud &amp; Security Vulnerabilities: </strong>Voter impersonation, ballot tampering, cyberattacks.</li><li><strong>Lack of transparency</strong>: Voters cannot verify that their vote was counted correctly.</li></ul><p>A blockchain-based voting system can solve these problems by enabling secure, cost-efficient, and verifiable digital voting.</p><h3>How Blockchain Solves These Issues</h3><p>Blockchain provides an immutable, transparent ledger that ensures votes cannot be altered or removed. Smart contracts automate counting, and cryptographic verification prevents fraud. Key benefits include:</p><ol><li><strong>Lower Costs</strong>: No need for physical polling stations, ballot printing, or manual counting.</li><li><strong>Faster Results</strong>: Instant vote counting eliminates long delays.</li><li><strong>Security and Fraud Prevention</strong>: Votes cannot be changed or erased.</li><li><strong>Independent Verification</strong>: Any citizen can audit the vote tally as well as the smart contract’s code.</li><li><strong>Decentralization</strong>: No central authority controls the results.</li></ol><h4>1. Lower Costs</h4><p>Traditional elections require substantial investments in physical polling stations, staff, printed ballots, and security measures.</p><p>In contrast, blockchain eliminates most of these expenses by:<br>- Enabling fully digital voting<br>- Automating vote counting through smart contracts<br>- Offering <em>out-of-the-box </em>auditing functionality<br>- Relying on the blockchain instead of web servers and cloud infrastructure</p><p><strong>Estimated Costs<br></strong>Blockchain voting incurs three primary costs:</p><ol><li><strong>Mobile App Development</strong>: Authenticates users, registers votes, and displays results.<br>↦ <strong>Estimated Cost</strong>: €50,000 — €115,000</li><li><strong>Smart Contract Development</strong>: Securely processes votes on the blockchain.<br>↦ <strong>Estimated Cost</strong>: €40,000 — €92,000</li><li><strong>Blockchain Transaction Costs</strong>: Each vote is a blockchain transaction, covered by the government.<br>↦ <strong>Cost per Vote (Solana estimate)</strong>: €0.00024 — €0.00034<br>↦ <strong>Total for 10M Votes</strong>: €2,400 — €3,400</li></ol><p><strong>Total Estimated Cost<br> </strong>↦ <strong>Development (one-time)</strong>: €90,000 — €207,000<br> ↦ <strong>Blockchain Transactions (per election)</strong>: ~€3,400</p><h4>2. Faster Results</h4><p>Traditional elections often take days to count and verify votes. Blockchain allows real-time processing, reducing result delays from days to minutes.</p><h4>3. Security and Fraud Prevention</h4><p>Traditional systems are vulnerable to ballot tampering, hacking, and insider threats. Blockchain prevents fraud through:</p><ul><li><strong>Decentralization</strong>: Eliminates single points of failure. Attacks such as data breaches or DDoS attempts have little impact on a decentralized network, making large-scale election fraud virtually impossible.</li><li><strong>Immutable Records</strong>: Votes cannot be altered or removed.</li><li><strong>Public Auditability</strong>: Election integrity can be independently verified.</li><li><strong>Open-Source: </strong>Smart contracts are open source, meaning they can be reviewed, tested, and audited by independent security researchers, specialized firms, and developers worldwide.</li></ul><h4><strong>4. Independent Verification</strong></h4><p>One of the biggest challenges in elections is verifying results independently. Blockchain ensures:</p><ul><li><strong>Full Auditability</strong>: Votes are permanently recorded and can be audited at any time.</li><li><strong>Real-Time Verification</strong>: Voters can confirm that their vote was counted correctly.</li></ul><h4>5. <strong>Decentralization</strong></h4><p>Blockchain, by design, distributes control across a decentralized network of nodes, removing reliance on any single party. This has several advantages:</p><ul><li><strong>No Central Authority:</strong> Results are not controlled or influenced by any one organization or government body.</li><li><strong>Censorship Resistance:</strong> No entity can suppress votes or selectively block participation.</li></ul><h3>How does it work?</h3><h4>1. Secure Authentication via Government-Issued Credentials</h4><p>Voting begins with a mobile app that allows users to authenticate securely using government-provided authentication methods. In Portugal, for example, citizens can verify their identity using their national ID card. Other possible authentication mechanisms include:</p><ul><li><strong>Digital IDs</strong> (e.g., government-issued electronic identification)</li><li><strong>Biometric verification</strong> (e.g., fingerprint or facial recognition)</li><li><strong>Cryptographic signatures</strong> (e.g., digital certificates for secure authentication)</li></ul><p>Each voter is authenticated once and is <strong>guaranteed to cast only one vote</strong>, enforced through blockchain’s consensus mechanism.</p><h4>2. Casting a Vote on the Blockchain</h4><p>Once authenticated, voters can see a list of political parties and select their preferred option. When a vote is submitted, a request is sent to a <strong>smart contract</strong>, which securely records the vote on the blockchain.</p><p>Several key processes occur at this stage:</p><ul><li><strong>Transaction Processing Cost</strong> — Each vote is a blockchain transaction with a small associated fee. On the Solana blockchain, the average cost per transaction is <strong>$0.00025</strong>, which is <strong>covered by the government</strong>, ensuring free voting for citizens.</li><li><strong>End-to-End Encryption</strong> — The smart contract encrypts the vote before saving it to the blockchain. Only the voter and the smart contract itself can decrypt it, ensuring that votes remain private and secure.</li><li><strong>Automatic Vote Counting</strong> — The smart contract immediately updates the vote count for the selected party. However, this data remains inaccessible externally until the election ends.</li><li><strong>Voter Verification</strong> — Voters can return to the app at any time to confirm that their vote was successfully recorded. After the election ends, they can still verify their vote and show it to others as proof of participation.</li></ul><h4>3. Closing the Election and Publishing Results</h4><p>The smart contract is programmed with a predefined <strong>end date</strong> when the election is officially closed. At that moment, the following actions are triggered automatically:</p><ul><li><strong>Voting Ends</strong> — No new votes can be cast after the deadline.</li><li><strong>Results Are Published</strong> — The final tally of votes per party is made publicly available on the blockchain.</li><li><strong>Voter Anonymity Is Maintained</strong> — While the vote counts are revealed, individual voter identities remain hidden.</li></ul><p>This automated process ensures <strong>instant, tamper-proof election results</strong> without the need for manual vote counting, recounts, or human intervention.</p><h3>The Smart Contract: The Core of Blockchain Voting</h3><p>At the heart of this blockchain-based voting system is the <strong>smart contract, </strong>a self-executing program that ensures election integrity, transparency, and automation. This contract manages the entire voting process, from registration to final vote tallying.</p><p>Here is a basic implementation of a Solana blockchain voting smart contract:</p><pre>use anchor_lang::prelude::*;<br><br>#[program]<br>mod voting_smart_contract {<br>    use super::*;<br><br>    pub fn initialize(ctx: Context&lt;Initialize&gt;, end_timestamp: i64) -&gt; Result&lt;()&gt; {<br>        let election = &amp;mut ctx.accounts.election;<br>        election.end_timestamp = end_timestamp;<br>        election.total_votes = 0;<br>        Ok(())<br>    }<br><br>    pub fn cast_vote(ctx: Context&lt;CastVote&gt;, party_id: u8) -&gt; Result&lt;()&gt; {<br>        let election = &amp;mut ctx.accounts.election;<br>        let voter = &amp;ctx.accounts.voter;<br>        <br>        // Ensure voting is still open<br>        require!(Clock::get()?.unix_timestamp &lt; election.end_timestamp, VotingError::ElectionClosed);<br><br>        // Ensure voter hasn&#39;t voted before<br>        require!(!election.voters.contains(&amp;voter.key()), VotingError::AlreadyVoted);<br><br>        // Record vote<br>        election.votes[party_id as usize] += 1;<br>        election.voters.push(voter.key());<br>        election.total_votes += 1;<br>        <br>        Ok(())<br>    }<br><br>    pub fn close_election(ctx: Context&lt;CloseElection&gt;) -&gt; Result&lt;()&gt; {<br>        let election = &amp;ctx.accounts.election;<br>        require!(Clock::get()?.unix_timestamp &gt;= election.end_timestamp, VotingError::ElectionStillOpen);<br>        Ok(())<br>    }<br>}<br><br>#[derive(Accounts)]<br>pub struct Initialize&lt;&#39;info&gt; {<br>    #[account(init, payer = authority, space = 8 + 8 + 100 * 8 + 100 * 32)]<br>    pub election: Account&lt;&#39;info, Election&gt;,<br>    #[account(mut)]<br>    pub authority: Signer&lt;&#39;info&gt;,<br>    pub system_program: Program&lt;&#39;info, System&gt;,<br>}<br><br>#[derive(Accounts)]<br>pub struct CastVote&lt;&#39;info&gt; {<br>    #[account(mut)]<br>    pub election: Account&lt;&#39;info, Election&gt;,<br>    #[account(mut)]<br>    pub voter: Signer&lt;&#39;info&gt;,<br>}<br><br>#[derive(Accounts)]<br>pub struct CloseElection&lt;&#39;info&gt; {<br>    #[account(mut)]<br>    pub election: Account&lt;&#39;info, Election&gt;,<br>}<br><br>#[account]<br>pub struct Election {<br>    pub end_timestamp: i64,<br>    pub votes: [u64; 100], // Support for 100 different parties<br>    pub voters: Vec&lt;Pubkey&gt;,<br>    pub total_votes: u64,<br>}<br><br>#[error_code]<br>pub enum VotingError {<br>    #[msg(&quot;You have already voted.&quot;)]<br>    AlreadyVoted,<br>    #[msg(&quot;The election is already closed.&quot;)]<br>    ElectionClosed,<br>    #[msg(&quot;The election is still open.&quot;)]<br>    ElectionStillOpen,<br>}</pre><h3>New Possibilities for Modern Voting</h3><p>Blockchain voting isn’t just about improving existing systems. It can also introduce new capabilities such as:</p><ul><li><strong>Ranked-Choice Voting</strong>: Voters can rank their top choices, allowing more democratic outcomes.</li><li><strong>Vote Modification Until Deadline</strong>: Voters can update their selection before polls close.</li><li><strong>Voting proof</strong>: Voters can choose to disclose that they’ve voted through an official system.</li></ul><h3>A Hybrid Approach: Keeping Paper Ballots for Transition</h3><p>Blockchain voting should be introduced gradually, running alongside traditional methods to ensure accessibility. Some voters will prefer paper ballots, while others will embrace digital voting. This <strong>hybrid system</strong> maintains trust while reducing costs and logistical burdens over time.</p><h3>How to Introduce Blockchain Voting</h3><p>The transition should be gradual, with real-world testing before nationwide adoption:</p><ol><li><strong>Small-Scale Trials</strong>: Start with university elections, corporate votes, and local community decision-making.</li><li><strong>Municipal &amp; City Elections</strong>: Introduce blockchain voting for city councils and referendums.</li><li><strong>Statewide Elections</strong>: Scale up to regional votes with government oversight.</li><li><strong>National Elections (Optional Adoption)</strong>: Introduce blockchain voting as an alternative to paper ballots, with opt-in participation.</li></ol><p>To gain public trust, governments should provide in-person support at polling stations, helping citizens download and register on the blockchain voting app.</p><h3>Why Blockchain Voting Isn’t Everywhere Yet</h3><p>Despite its benefits, blockchain voting faces challenges:</p><ul><li><strong>Security Concerns</strong>: Cybersecurity experts worry about potential attack points in user devices.</li><li><strong>Legal Barriers</strong>: Many countries require paper ballots or official audit trails.</li><li><strong>Public Trust</strong>: Digital voting faces skepticism due to fears of hacking and manipulation.</li><li><strong>Scalability</strong>: Large-scale elections need robust infrastructure to handle millions of votes securely and efficiently.</li></ul><h3>The Future of Blockchain Voting</h3><p>As technology improves and trust grows, blockchain voting can become the standard for secure, transparent elections. Governments, companies, and institutions are already testing it. With the right implementation, blockchain can modernize democracy, making elections <strong>faster, cheaper, and more trustworthy</strong> than ever before.</p><h3>How You Can Help</h3><p>↦ If you have expertise, suggestions, or constructive feedback, reach out!<br>↦ If you’re interested in funding this project, let’s discuss potential collaboration.<br>↦ If you know organizations or governments looking for voting system innovations, feel free to share this.</p><p><strong>Authors</strong><br>- <a href="https://www.linkedin.com/in/diogo-mateus/">Diogo Mateus</a><br>- <a href="https://www.linkedin.com/in/mariojmateus/">Mário Mateus</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1eb0faeb350" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The brilliant Q&A’s of Arvind, the Vegan Animal Activist]]></title>
            <link>https://medium.com/@diogomateus/the-brilliant-q-as-of-arvind-the-vegan-animal-activist-d2a59b02134b?source=rss-285097eaa377------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2a59b02134b</guid>
            <category><![CDATA[vegan]]></category>
            <category><![CDATA[ethics-and-morality]]></category>
            <category><![CDATA[philosophy-and-debate]]></category>
            <category><![CDATA[plant-based]]></category>
            <category><![CDATA[animal-rights]]></category>
            <dc:creator><![CDATA[Diogo Mateus]]></dc:creator>
            <pubDate>Sat, 14 Dec 2024 15:43:57 GMT</pubDate>
            <atom:updated>2025-03-01T12:20:28.885Z</atom:updated>
            <content:encoded><![CDATA[<p>Arvind (<a href="https://www.youtube.com/channel/UCuaj1eVLt9O2aHRN-ULEXiQ">YouTube</a>, <a href="https://www.instagram.com/arvindanimalactivist/">Instagram</a>, <a href="https://www.patreon.com/ArvindAnimalActivist">Patreon</a>) became famous for his short format videos where he debates students about veganism. Students are encouraged to ask tough questions, and Arvind replies with logical and well-thought-out arguments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0RL-ZGNUOwjzV-FRRifq6A.png" /></figure><p>Arvind openly admits that his early attempts to confront people were filled with frustration and anger, and he soon realized that this only invited hostility in return. Attacking people’s beliefs didn’t open their minds, it shut them down.</p><p>Recognizing this, he decided to take a different path. He embraced a calm and non-confrontational style, focusing on debating with logic and sharing facts, all without offending others.</p><p>I really enjoy his Q&amp;A format as a more direct way of learning. Instead of just listening to someone lecture, you get to see him being challenged and responding with logical arguments.</p><p>My goal here is to share Arvind’s work as well as the arguments from his videos that I found the most interesting.</p><h3>Lions kill other animals. Why can’t we do the same?</h3><p>Using animal behavior to justify human actions is a flawed argument.</p><p>If someone were to harm their child and argue in a court of law, “Lions harm their offspring sometimes, so I should be allowed to do the same,” the court would immediately reject this defense.</p><p>Similarly, we shouldn’t use the actions of animals, like lions, to justify harming or killing animals for our own benefit.</p><p>Just as the law recognizes that humans are capable of moral reasoning and held to higher ethical standards than wild animals, we should apply the same logic to our treatment of animals.</p><p><a href="https://www.youtube.com/shorts/UFFlsY4wb3I">Source 🔗</a></p><h3>What about vitamin deficiencies on a vegan diet?</h3><p>Some people worry that switching to a vegan diet will lead to deficiencies in essential nutrients like calcium, iron, and vitamins.</p><p>Calcium is easily obtainable from plant sources like ragi millet, which contains over 300 mg of calcium per 100 grams. For iron, pair iron-rich plant-based foods with vitamin C, like a glass of orange juice, to enhance absorption. Leafy green vegetables are also excellent for a wide range of nutrients.</p><p>It is entirely possible to get all your nutrients from plant sources, except for vitamin B12. For that, you need to take a supplement.</p><p><a href="https://www.youtube.com/shorts/VeiqNiyDuwI">Source 🔗</a></p><h3>Vegans participate in the death of many insects</h3><p>Vegans acknowledge that living in a non-vegan society means participating in systems that can harm animals, such as using medications tested on animals or consuming crops grown in ways that may displace wildlife.</p><p>While these issues are real, they don’t justify avoiding efforts to reduce harm where possible.</p><p>Vegans don’t claim to have all the solutions and are open to adopting better approaches if reasonable alternatives are presented.</p><p><strong>Veganism isn’t about perfection</strong>; it’s about doing the best we can within our current system. Just because we can’t eliminate all harm doesn’t mean we shouldn’t act where we can make a difference.</p><p><a href="https://www.youtube.com/shorts/7crKsh-zFJE">Source 🔗</a></p><h3>Veganism is not healthy</h3><p>Veganism itself isn’t inherently healthy or unhealthy, it simply defines what you don’t eat, such as meat, dairy, eggs, and honey.</p><p>What matters for health is <em>what you do eat</em>. A vegan diet based on whole, nutritious foods like fruits, vegetables, nuts, seeds, and legumes, paired with good habits like exercise, can be very healthy. On the other hand, a diet of vegan junk food like fries, chips, and alcohol is still vegan but not necessarily healthy.</p><p><a href="https://www.youtube.com/watch?v=OIc1OXhIkfc">Source 🔗</a></p><h3>What happens to cows if everyone becomes vegan?</h3><p>People often argue that if everyone went vegan, cows, chickens, and goats would go extinct, because no one would take care of them.</p><p>Arvind responds by flipping the perspective:</p><blockquote>“Right now, we are not giving cows the right to live, we are torturing, enslaving, and killing them. Imagine if you had the choice to be born as a cow in this current world or not exist at all. Most of us, knowing the suffering cows endure, would choose not to exist.”</blockquote><p>He further adds:</p><blockquote>“Why feel bad about their extinction when their existence today is defined by suffering? If given the choice, every cow and chicken would say, ‘I’d rather not be born than live a life of abuse and slaughter.’ Extinction, in this case, means an end to their suffering.”</blockquote><p><a href="https://www.youtube.com/shorts/nkUq9kYI7ZQ">Source 🔗</a></p><h3>Is it scientifically proven that plants cannot think and feel?</h3><blockquote>It is impossible to prove that something does not exist</blockquote><p>In science, the burden of proof lies with the person making the claim. Just as no one can prove an invisible genie doesn’t exist, it’s impossible to prove plants don’t feel pain.</p><p>If someone asserts that plants feel pain, they must provide evidence to support it.</p><p>After years of research into plant biology, there is no peer-reviewed study demonstrating that plants experience pain or suffering. Without evidence, the claim remains baseless.</p><p><a href="https://www.youtube.com/shorts/uJrtv72QUao">Source 🔗</a></p><h3>I couldn’t find a plant-based milk that tasted similar to real milk.</h3><p>From an animal rights perspective, veganism isn’t about perfectly replicating the taste of non-vegan foods, it’s about minimizing harm to animals.</p><p>You might not find a plant-based milk that matches the exact taste of dairy in your coffee, and that’s okay. <strong>The important question is whether satisfying your taste buds outweighs the suffering of a baby cow separated from their mother for milk production</strong>.</p><p>While you can explore different vegan milks to suit your preferences, the <strong>core message of veganism is prioritizing compassion over convenience or taste</strong>.</p><p><a href="https://www.youtube.com/shorts/Hm4d6JxY18k">Source 🔗</a></p><h3>Why is it okay to eat fruits, but not milk?</h3><p>Plants produce fruits as part of a symbiotic relationship with herbivores. When animals like monkeys consume fruits, the seeds pass through their digestive systems and are deposited elsewhere, often in nutrient-rich manure. This process allows plants to spread their seeds and grow in new areas. It’s a mutually beneficial, symbiotic relationship between fruit-producing plants and herbivores.</p><p>In contrast, milk is not meant for humans or other animals, it’s specifically produced by cows for their calves.</p><p><a href="https://www.youtube.com/watch?v=sMgCu5V7okI">Source 🔗</a></p><h3>Can Religion Justify Animal Sacrifice?</h3><p>Tradition, culture and religion cannot be used as an excuse to hurt another human being or an animal.</p><p>True sacrifice means giving up something deeply meaningful to us. In the story of Ibrahim, he was prepared to sacrifice his son, as a test of faith, but God intervened and provided a goat instead. Today, purchasing and killing an animal without any emotional connection doesn’t carry the same meaning.</p><p>Arvind closes with this humorous and provoking thought:</p><blockquote>Go to sacrifice your son, if God stops you and gives you a goat, go ahead.</blockquote><p><a href="https://www.youtube.com/watch?v=7Rx4YuqCsm4">Source 🔗</a></p><h3>Taking milk does not hurt the cow. Why is it wrong?</h3><p>Even if taking milk doesn’t physically hurt a cow, it is still wrong to take something that belongs to another being without their consent. Imagine someone admiring your hair and deciding to shave it off because they liked it. Even if it didn’t hurt you, it’s still your body and your choice.</p><p>Milk, like hair, belongs to the individual who produces it. A mother cow produces milk for her calf. Taking milk that was meant for her baby is both unethical and exploitative.</p><p><a href="https://www.youtube.com/shorts/vhz3pkYUPe0">Source 🔗</a></p><p>To wrap up this post, here’s a final compelling idea:</p><h3>Why do people who exploit animals get to decide their rights?</h3><p>Arvind argues that those who harm or exploit others are not the right people to decide their rights.</p><p>For example, misogynists shouldn’t determine women’s rights because they will impose their biased, harmful views. Similarly, racists or casteists cannot fairly decide the rights of those they discriminate against.</p><p>By the same logic, those who eat animals, consume dairy, or exploit animals in any way should not be deciding what rights animals should or shouldn’t have. Their vested interests and actions reflect a mindset that prioritizes personal benefit over justice for animals.</p><p><a href="https://www.youtube.com/watch?v=PLpjc5nQQjE">Source 🔗</a></p><p>Follow Arvind on <a href="https://www.youtube.com/channel/UCuaj1eVLt9O2aHRN-ULEXiQ">YouTube</a> or <a href="https://www.instagram.com/arvindanimalactivist/">Instagram</a> to know more!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2a59b02134b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Naming tests in Golang]]></title>
            <link>https://medium.com/getground/naming-tests-in-golang-c58c188bb9a1?source=rss-285097eaa377------2</link>
            <guid isPermaLink="false">https://medium.com/p/c58c188bb9a1</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[integration-testing]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Diogo Mateus]]></dc:creator>
            <pubDate>Tue, 24 Aug 2021 10:29:22 GMT</pubDate>
            <atom:updated>2021-08-31T14:54:27.590Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Written by </em><a href="https://www.linkedin.com/in/diogo-mateus/"><em>D</em>iogo</a><em>, Senior Backend Engineer at GetGround</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*IdUnIC2tfQx5jAHkstphMQ.jpeg" /></figure><p><strong><em>GetGround’s mission is to make assets more transparent, trustworthy and accessible</em></strong><em>. We are doing this by bringing the world’s assets online, starting with residential property. We believe increased access to asset ownership will enable a fairer, more productive world.</em></p><p>We’re constantly looking for ways of improving the efficacy of our tests as it is a fundamental practice to software quality and a way to <a href="https://www.getground.co.uk/careers">pursue excellence</a>.</p><p>One of our recent topics of discussion was the test naming strategy. Even though it doesn’t directly affect the tests or the coverage, a good naming strategy brings many benefits to the table. In this blog post I’ll explore test naming strategies and why they are important. All of this will be done with a focus in Golang, our main server side language, but first let’s start with the why.</p><h4>Why do we care about effective test names?</h4><ul><li>Tests act as documentation<em>. </em>By taking a look at the implementation you’ll see <strong>how</strong> the system works, but by <strong>looking at the tests</strong> you’ll see <strong>what </strong>it does. You should be able to quickly<strong> scan through all the test names</strong> and <strong>understand the system’s requirements</strong>.</li><li>Good test names are abstracted from the implementation and <strong>resist refactorings</strong>.</li><li>A structured naming strategy will add <strong>consistency to the codebase</strong>. Developers will know exactly what to expect.</li></ul><h3>Naming tests in Go</h3><p>Golang doesn’t offer many recommendations on this topic.</p><blockquote>func TestXxx(*testing.T) — where Xxx does not start with a lowercase letter. The function name serves to identify the test routine. — <a href="https://pkg.go.dev/testing">Go’s testing documentation</a></blockquote><p>This is all you’ll find in <a href="https://pkg.go.dev/testing">Go’s testing documentation</a> when it comes to naming tests. If you couple it with the <a href="https://talks.golang.org/2013/bestpractices.slide#16">“Shorter is better”</a> practice, it will result in names like these:</p><ul><li>func TestAbs(t *testing.T)</li><li>func TestSplit(t *testing.T)</li><li>func TestAPI_AgentServices(t *testing.T)</li><li>func TestService_CreateUser(t *testing.T)</li><li>func TestService_CreateUser_Success(t *testing.T)</li><li>func TestCreateUserBadRequest(t *testing.T)</li></ul><p>There are a few issues with this approach:</p><ul><li>Many of these names refer to success, but <strong>success is ambiguous</strong>. What does it really mean? What’s actually being tested? Let’s take an example of an endpoint that creates a user. Does success mean that the user was added to the database? Does it mean that the endpoint returns the expected json response? Does it mean both?</li><li>As mentioned above, success may mean <strong>testing more than one thing</strong> at the same time, something you want to avoid when writing <strong>unit tests</strong>.</li><li>What about TestCreateUserBadRequest? Is it testing a malformed json, an empty body, a missing parameter, a wrong value type, all of them?</li><li>These approaches may also promote mindsets like: “<em>okay I tested the main scenario, this is enough, let’s move on</em>”.</li><li>Finally, it may be putting too much <strong>focus on testing functions</strong> instead of testing requirements. This creates tests that are <strong>hard to maintain</strong>: we can’t refactor easily because implementation details are exposed to tests.</li></ul><h3>Naming conventions</h3><p>Let’s take a look at some of the most established naming strategies for tests.</p><h4><a href="https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html">Roy Osherove’s naming strategy</a></h4><p>It follows the [UnitOfWork_StateUnderTest_ExpectedBehaviour] pattern where: UnitOfWork represents a single method, a class or multiple classes; StateUnderTest represents the inputs or conditions being tested and ExpectedBehaviour represents the output or result.</p><p>Let’s go back to the create user endpoint example and use this strategy to generate a Golang test name: Test_CreateUser_EmptyBody_BadRequestErrorThrown.</p><p>Because this naming strategy focus on the SUT, inputs and output, it expresses a very clear requirement.</p><blockquote><strong>Test name should be presented as a statement or fact of life that expresses workflows and outputs — </strong><a href="https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html">Naming standards for unit tests</a></blockquote><p>The main criticism against this approach is that it doesn’t resist refactors (e.g. when the UnitOfWork changes). Additionally, it may be difficult to decipher for those who aren’t used to it.</p><h4>The Plain English strategy</h4><p>This strategy is defended by Vladimir Khorikov in his blog post: <a href="https://enterprisecraftsmanship.com/posts/you-naming-tests-wrong/">You are naming your tests wrong!</a>.</p><p>It basically states that the test names should be written in plain english and shouldn’t follow any rigid policies. Our example would become something like: Create_User_With_Empty_Body_Is_Invalid or Cant_Create_User_On_Empty_Body. It benefits from being flexible, easy to read and because it doesn’t mention the SUT, it also handles refactors well.</p><p>Let’s take a look at some other examples to get a better idea of it:</p><ul><li>Delivery_With_A_Past_Date_Is_Invalid</li><li>Add_Credit_Updates_The_Customer_Balance</li><li>Purchase_Without_Funds_Is_Not_Possible</li></ul><p>My criticism against this one is that the lack of structure may allow for very different approaches within one codebase. It may also fall on the success issue I mentioned earlier where tests are named Create_User or Add_Discount, which doesn’t provide much clarity on what’s being tested.</p><h4>The Should strategy</h4><p>This strategy follows the Should_ExpectedBehaviour_When_StateUnderTest pattern. It’s similar to Roy Osherove’s naming strategy but doesn’t include the SUT in the name, which makes it more behaviour-oriented and resistant to refactors. It is also more human readable.</p><p>Example: Should_Return_BadRequest_Error_When_Body_Is_Empty</p><p>But a test should represent a fact about the SUT, not a desire, and so the word “should” has no place in it.</p><h4>The Behaviours strategy</h4><p>This one is basically the <em>Should</em> strategy without the “Should” word: ExpectedBehaviour_When_StateUnderTest</p><p>Example: Returns_BadRequest_Error_When_Body_Is_Empty. Here we aren’t manifesting a wish about the SUT but making a statement about it. It’s more direct and less verbose.</p><p>This approach is structured, descriptive and direct, but lacks the flexibility of <em>Plain English</em>.</p><h3>Structured vs Unstructured</h3><p>Vladimir Khorikov advocates for the <em>Plain English names </em>strategy, which is the most flexible approach. The names are more human readable, they describe the behaviour without constraints and may even directly reflect the story’s <em>Acceptance Criteria</em>.</p><p>On the other hand, a structured approach like the <em>Behaviours strategy</em> is less chaotic, the programmer knows exactly what to expect from it.</p><p>In the end it’s a choice between chaos vs order, human vs machine. Both have their pros and cons and are equally valid.</p><p><strong>Because I enjoy the predictability of structure</strong>, I’ll expand a little more on the <strong><em>Behaviours strategy</em></strong><em>.</em></p><h3>How to write names based on behaviours?</h3><p>Start by writing a checklist of how the SUT should behave. Using the <em>create user endpoint </em>example, the checklist could be:</p><ul><li>Returns bad request when the body is empty</li><li>Returns bad request when the json is invalid</li><li>Returns bad request when the user is invalid</li><li>Returns conflict when the user already exists</li><li>Returns success when the user is created</li></ul><p>By following this approach you’re describing what the SUT does and the test will reflect that. It will also force you to test one thing at a time as you don’t want more than one condition in the requirement.</p><p>The final step is to turn these behaviours into test names. There are a few options when it comes to naming them in Golang:</p><ul><li><strong>Test_CreateUser_Returns_BadRequest_When_The_Body_Is_Empty</strong>: this one has the SUT attached to the beginning of the name. It won’t be very resistant to refactorings but offers clarity in case there are other SUTs in the same package.</li><li><strong>Test_Returns_BadRequest_When_The_Body_Is_Empty</strong>: this approach is nicer but will require that the SUT is alone in the package. An alternative is to use <a href="https://pkg.go.dev/github.com/stretchr/testify/suite">Suites</a> from the <a href="https://github.com/stretchr/testify">testify</a> package. The suite will isolate the tests and provide helpers like setup, teardown, etc.</li><li><strong>TestReturnsBadRequestWhenTheBodyIsEmpty</strong>: for those who don’t like underscores.</li><li><a href="https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks">Subtests</a>: t.Run(&quot;returns bad request when the body is empty&quot;), func(t *Testing) { }. More elegant than the others, but because it is a subtest, it has its limitations.</li><li><a href="https://github.com/golang/go/wiki/TableDrivenTests">Table-driven tests</a> would follow a similar approach:</li></ul><pre>{<br>   name:        &quot;returns bad request when the body is empty&quot;,<br>   haveReqBody: `{}`,<br>   wantResCode: 400,<br>}</pre><h4>How to come up with the names</h4><p>When writing the test names, start by thinking about what you want as a goal. Don’t focus on implementation details that can easily change. Focus one one outcome or a consequence, preferably using business terms when possible.</p><p>It helps to <strong>start with a verb</strong> like: Creates, Returns, Throws, Converts, Updates, Calls. The rest comes naturally.</p><p>Here are a few more examples:</p><ul><li>Calls_Storage_When_Saving_User</li><li>Returns_List_Of_Users_From_Storage</li><li>Sends_Customer_Email</li><li>Lists_Sent_Messages</li></ul><p>⚠️ <em>If I’m finding it difficult to come up with a name for test, that most likely means that something is wrong: I may be trying to test more than one thing at the same time or maybe the SUT has too many responsibilities.</em></p><h4>Easy to maintain</h4><p>Once the behaviours are defined and the tests are written, the only reason to update them is when the <strong>requirements change.</strong></p><p>The developers will also be free to refactor the implementation however they like, because the tests and the implementations aren’t coupled.</p><h3>Concluding remarks</h3><p>I believe tests have potential to be the best <a href="https://www.stickyminds.com/article/tests-documentation">source of documentation</a> and that starts with the naming strategy. There are many possible approaches, each having their own pros and cons. Picking one should be a team effort.</p><p>At GetGround we are continually pushing ourselves to be better programmers and making improvements on our coding practices, either through Backend Guild meetings, <a href="https://en.wikipedia.org/wiki/Request_for_Comments">RFC’s</a>, or pairing sessions. If you think you might enjoy being part of a team like ours, connect with me on <a href="https://www.linkedin.com/in/diogo-mateus/">LinkedIn</a> as we’re hiring!</p><p><a href="https://www.linkedin.com/company/getground/mycompany/"><em>Recent news</em></a></p><p><a href="https://www.getground.co.uk/careers"><em>Careers at GetGround</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c58c188bb9a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/getground/naming-tests-in-golang-c58c188bb9a1">Naming tests in Golang</a> was originally published in <a href="https://medium.com/getground">GetGround</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Tips to Build New Habits]]></title>
            <link>https://medium.com/@diogomateus/5-practical-tips-to-create-new-habits-f7f74483bb8e?source=rss-285097eaa377------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7f74483bb8e</guid>
            <category><![CDATA[goal-setting]]></category>
            <category><![CDATA[journaling]]></category>
            <category><![CDATA[habit-building]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[planning]]></category>
            <dc:creator><![CDATA[Diogo Mateus]]></dc:creator>
            <pubDate>Mon, 01 Oct 2018 10:27:28 GMT</pubDate>
            <atom:updated>2018-10-01T15:08:35.234Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-RzXJ5hwA4nH-Vq7BUevw.jpeg" /></figure><p>Everyone heard that it takes 21 days to form a new habit, but how do you keep committed during that time?</p><p>Motivation is short lived and doesn’t lead to consistent action. In this article I’ll share 5 tips that will help you keep committed to your new habit!</p><h3>1. Write it down</h3><p>People who explicitly write down when and where their new behaviours are going to happen are much more likely to succeed.</p><p>By doing this, your goal has a time and a space to live in the real world, which triggers your behaviour instead of your motivation.</p><p>Here’s an example:</p><blockquote>Next Thursday at 18:00, I will run for at least 20 minutes in the park near my building.</blockquote><p>So start by writing what you want to do next. A notebook is more effective, but you may use a todo app on your smartphone, or specify an event on your calendar.</p><h3><strong>2. The 2 minute rule</strong></h3><p>When you start a new habit, it should take less than two minutes to do. That’s the 2 minute rule, but the idea behind it is to <strong>Start Simple</strong> — don’t try to completely change your life in one day.</p><p>Make your habits as easy as possible to start. Anyone can read 2 pages, or meditate for one minute. Once you’ve started doing the right thing, it is much easier to keep doing it.</p><h3>3. Keep track</h3><blockquote>If you can’t measure it, you can’t improve it.”</blockquote><p>This is an important quote when it comes to businesses, but it’s also helpful when forming new habits. Keeping track of your new habit constantly reminds you of them it you’ll get motivated as you see your progress.</p><p>If your goal is to read more books per year, start a <a href="https://www.goodreads.com/">Goodreads</a> <a href="https://www.goodreads.com/blog/show/1130-read-more-this-year-with-the-2018-reading-challenge">challenge</a>, if you want to start running, install <a href="https://www.strava.com/">Strava</a> on your phone. For other habits you may want to create repeating events on your calendar or alarms on your phone.</p><h3>4. Act Immediately</h3><p>At some point, during your first weeks of forming a new habit, you’ll feel like skipping it. You’ll have thoughts like:</p><blockquote><em>“Maybe it’s not as important to me as I thought.”</em></blockquote><blockquote><em>“Tomorrow I’ll definitely get back to it!”</em></blockquote><p>This moment sneaks up on you when you are feeling overconfident, but make no mistake, this is the single most important moment when forming any habit. Failing once is enough to lose the habit altogether.</p><p>At that point the answer is to <strong>stop thinking and act immediately</strong>.</p><p>If you push past it, you validate your drive to form the habit. Then, if this happens again, you’ll be able to overcome it as you did before.</p><h3>5. Journaling</h3><blockquote><em>“Writing in a journal reminds you of your goals and of your learning in life. It offers a place where you can hold a deliberate, thoughtful conversation with yourself.” — Robin S. Sharma</em></blockquote><p>Overall, journaling has been found to boost your mood, enhance your sense of well-being and improve your working memory.</p><p>Here’s how you can apply journaling to create new habits:</p><ul><li>Before going to bed, spend 5 minutes thinking of what you want to accomplish and write that down</li><li>Write down problems you are facing and questions you have and then try to find ways of overcoming them</li><li>You can also be doing this in the morning, where you’ll be planning your today</li></ul><p>This can go hand in hand with the first point.</p><p>Finally, think of which distractions are keeping you from achieving your goals and then find <strong>creative solutions</strong>. If you spend too much time on Facebook, install a <a href="https://chrome.google.com/webstore/detail/block-site-website-blocke/eiimnmioipafcokbfikbljfdeojpcgbh?hl=en">Chrome extension that blocks it</a>. If you are struggling to go to the gym, try to pack your bag the night before.</p><p>You may think of rewards for when you are on track and small punishments for when you don’t.</p><p><strong>Keep asking why</strong>, so you remember why you started in the first place and to refresh that initial motivation.</p><p>Some of these technics won’t work with you, but by trying them you’ll get to know yourself a bit better and will be able to <strong>figure out what actually works</strong>.</p><p>Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7f74483bb8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>