<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vieri Lusen</title>
    <description>The latest articles on DEV Community by Vieri Lusen (@vierilusen).</description>
    <link>https://dev.to/vierilusen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1092760%2F95cc6e7c-347e-48d2-8f04-aa714c9b37d7.jpg</url>
      <title>DEV Community: Vieri Lusen</title>
      <link>https://dev.to/vierilusen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vierilusen"/>
    <language>en</language>
    <item>
      <title>The Use of Condition '1=1' in SQL Database</title>
      <dc:creator>Vieri Lusen</dc:creator>
      <pubDate>Sat, 03 Jun 2023 03:00:00 +0000</pubDate>
      <link>https://dev.to/vierilusen/the-use-of-condition-11-in-sql-database-4ohl</link>
      <guid>https://dev.to/vierilusen/the-use-of-condition-11-in-sql-database-4ohl</guid>
      <description>&lt;p&gt;Have you ever seen or come across an SQL query that includes the condition '1=1'?&lt;/p&gt;

&lt;p&gt;In essence, '1=1' is a condition that always evaluates to true. When used in a query, this condition does not have any effect on the query results. However, can we actually utilize and benefit from '1=1' in the implementation of writing SQL queries?&lt;/p&gt;

&lt;p&gt;Although it may seem trivial and the use of '1=1' is very simple, it can be highly useful. One of its applications is in creating dynamic queries.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Simply put, a dynamic query is a query that can change based on needs or input provided.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;The challenge in creating dynamic queries in some SQL databases is when we need to start the conditional statement using the WHERE clause, which can be cumbersome for creating dynamic queries.&lt;/p&gt;

&lt;p&gt;Therefore, when creating dynamic queries, we often make use of the condition '1=1' at the beginning of the query's conditional statement (WHERE). This allows us to flexibly build condition criteria based on user input more easily, as we only need to add additional conditions (AND).&lt;/p&gt;

&lt;p&gt;Here's a brief example in PHP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Assume dynamic filters from user input
$inputFilterName = $request-&amp;gt;input('name');
$inputFilterAddress = $request-&amp;gt;input('address');

//String Query
$sql = "SELECT * FROM users WHERE 1=1";

//Dynamic condition for name
if($inputFilterName !== null){
 $sql .= "AND name = '$inputFilterName'";
}

//Dynamic condition for address
if($inputFilterAddress !== null){
 $sql .= "AND address = '$inputFilterAddress'";
}

//Exec query
mysqli_query($koneksi, $sql);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the above condition, we have created a dynamically generated query based on different inputs and requirements. The use of '1=1' in the example above is very helpful, as it simplifies the process of creating dynamic queries.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: The code and query above are just examples to illustrate the use of '1=1'. In practice, the above query example is not optimal and additional mechanisms are needed to prevent the risk of SQL injection attacks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this article, we have explored the use of the '1=1' condition in SQL queries and how it can be beneficial in creating dynamic queries. Although it may appear simple, '1=1' provides flexibility in constructing query conditions based on user input more easily.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article is translated using AI from the original article written in Indonesian language : &lt;a href="https://vierilusen.medium.com/75aa1b5d0374"&gt;Medium&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>codenewbie</category>
      <category>learning</category>
      <category>productivity</category>
      <category>database</category>
    </item>
    <item>
      <title>Comedy Techniques Every Programmer Should Know</title>
      <dc:creator>Vieri Lusen</dc:creator>
      <pubDate>Wed, 31 May 2023 04:30:16 +0000</pubDate>
      <link>https://dev.to/vierilusen/comedy-techniques-every-programmer-should-know-11ci</link>
      <guid>https://dev.to/vierilusen/comedy-techniques-every-programmer-should-know-11ci</guid>
      <description>&lt;p&gt;Comedy and programming may seem like two very different fields. However, like with anything else, as programmers, we can also learn from seemingly unrelated fields, such as comedy.&lt;/p&gt;

&lt;p&gt;From comedy, we can learn some techniques that are also applicable in the world of programming, and these techniques have actually been used by programmers and can be applied in application development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rule of Three
&lt;/h3&gt;

&lt;p&gt;In comedy, the Rule of Three is a technique where a punchline or tagline is repeated three times, making the joke more effective and memorable.&lt;/p&gt;

&lt;p&gt;In programming, the Rule of Three refers to a principle that states that if a piece of code is used three or more times in a program, it's better to refactor that code into a separate function or method.&lt;/p&gt;

&lt;p&gt;Before applying the Rule of Three, let's say we have three functions with the same logic for calculating the volume of a rectangular object. We can apply the rule of three by refactoring the logic into a separate reusable function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Object 1
let lengthObject1: number = 10.0;
let widthObject1: number = 5.0;
let heightObject1: number = 2.5;
let volumeObject1: number = lengthObject1 * widthObject1 * heightObject1;
console.log("Volume of object 1 is:", volumeObject1);

// Object 2
let lengthObject2: number = 2.0;
let widthObject2: number = 8.0;
let heightObject2: number = 3.5;
let volumeObject2: number = lengthObject2 * widthObject2 * heightObject2;
console.log("Volume of object 2 is:", volumeObject2);

// Object 3
let lengthObject3: number = 15.0;
let widthObject3: number = 3.0;
let heightObject3: number = 2.5;
let volumeObject3: number = lengthObject3 * widthObject3 * heightObject3;
console.log("Volume of object 3 is:", volumeObject3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After separating the logic into a separate function, we can use these functions more easily and efficiently in our program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function calculateVolume(length: number, width: number, height: number): number {
   return length * width * height;
}

// Object 1
let lengthObject1: number = 10.0;
let widthObject1: number = 5.0;
let heightObject1: number = 2.5;
const volumeObject1: number = calculateVolume(lengthObject1, widthObject1, heightObject1);
console.log("Volume of object 1 is:", volumeObject1);

// Object 2
let lengthObject2: number = 2.0;
let widthObject2: number = 8.0;
let heightObject2: number = 3.5;
const volumeObject2: number = calculateVolume(lengthObject2, widthObject2, heightObject2);
console.log("Volume of object 2 is:", volumeObject2);

// Object 3
let lengthObject3: number = 15.0;
let widthObject3: number = 3.0;
let heightObject3: number = 2.5;
const volumeObject3: number = calculateVolume(lengthObject3, widthObject3, heightObject3);
console.log("Volume of object 3 is:", volumeObject3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  One Liner
&lt;/h3&gt;

&lt;p&gt;In comedy, a one-liner is a joke delivered in a concise and short sentence. One-liners are usually compact, meaningful, and contain an element of surprise or confusion that triggers laughter from the audience.&lt;/p&gt;

&lt;p&gt;In programming, the term "one-liner" refers to a coding technique where the code is written in a single line or a few lines that are concise and readable, without sacrificing code clarity and safety.&lt;/p&gt;

&lt;p&gt;Here's an example of using a one-liner in an if-else conditional statement in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Before using a one-liner
x = 10
y = 5
if x &amp;gt; y:
  print("x is greater than y")
else:
  print("y is greater than x")

#After using a one-liner
x = 10
y = 5
print("x is greater than y" if x &amp;gt; y else "y is greater than x")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the use of one-liners should be done carefully and only in specific situations, especially if the code needs to be accessed and modified by others in the future.&lt;/p&gt;

&lt;h3&gt;
  
  
  Callback
&lt;/h3&gt;

&lt;p&gt;In comedy, a callback is a technique where a comedian refers back to a previous joke or punchline in their performance to create a new and funnier punchline. It is done to strengthen the impact of the previous joke and create a stronger effect on the audience.&lt;/p&gt;

&lt;p&gt;In programming, a callback is a piece of code (usually a function, but not always) that is passed as an argument to another function and then invoked by that function when a certain task is completed. With callbacks, we can perform an action or run code after a specific task is finished by another function.&lt;/p&gt;

&lt;p&gt;Callback is often used in JavaScript because JavaScript is event-driven, meaning that many tasks performed by JavaScript need to wait for events to occur, such as server requests or user interactions with a web page. In this case, callbacks are used to handle those events when they happen, allowing JavaScript to continue running without waiting for tasks that are waiting for events to complete.&lt;/p&gt;

&lt;p&gt;Here's an example of a callback in a simple function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greeting(name, callback) {
   console.log("Hello, " + name);
   callback();
}

function sayGoodbye() {
   console.log("Goodbye!");
}

greeting("John", sayGoodbye);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the callback parameter is sayGoodbye(). Therefore, the sayGoodbye() function will be executed after the greeting() function finishes executing. The output will be as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, John
Goodbye!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another example of using a callback in JavaScript is handling the response of a server request using the fetch() method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch('https://www.example.com/data')
   .then(response =&amp;gt; response.json())
   .then(data =&amp;gt; console.log(data))
   .catch(error =&amp;gt; console.log(error));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, callbacks are used in the .then() method to handle the response from a request made with the fetch() method. After the request is successfully made, the callback will be invoked to handle the received response from the server. Additionally, if there's an error in the request, the callback in the .catch() method will be called to handle the error. By using callbacks, we can effectively and structurally handle response results from requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Although they may seem very different, comedy and programming have similarities in some techniques that can be learned and applied by programmers in application development. By observing and understanding techniques from different fields, programmers can expand their problem-solving skills and improve the quality and effectiveness of their code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article is translated using AI from the original article written in Indonesian language : &lt;a href="https://medium.com/@vierilusen/comedy-techniques-every-programmer-should-know-8737fb36830a"&gt;Medium&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>codenewbie</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
