AYDT - 03 ( Are You Doing This ) - Programming and Cases.
Tags: ruby, tutorial, beginners, bestpractice
Published: 2019-07-19 17:37:42

---
title: AYDT - 03 ( Are You Doing This ❓ ) - Programming and Cases.
published: true
description: AYDT - ( Are You Doing This❓ ) is a coding series that explains the common coding mistakes people make while learning to code.
cover_image: https://thepracticaldev.s3.amazonaws.com/i/1zbwq7dodwl34d1rmwex.png
---

Ben, a usual kid who came right out of college, got his first job. He was then introduced to the codebase of their application by one of his teammates.

You know what? Instead of me trying to explain the reaction of ben, I want you to have a direct look at how he might have reacted.

![Ben Reaction](https://thepracticaldev.s3.amazonaws.com/i/fgw34xyvaaypowf2ynmx.png)

Pretty cool huh? 🤣

Why he has the face as same as his first encounter with Omnitrix?

Let's look at the reason behind this.

Welcome to the third episode of the series: Are You Doing This❓. In case you haven't read the previous articles, I highly recommend you to have a look at those. Sure you'll love it 💙. Happy coding 👨🏻‍💻.

Previous week link :
https://dev.to/chintukarthi/aydt-02-are-you-doing-this-one-step-towards-ninja-land-5gm0


**Are You Doing This❓- Programming and Cases**

Why Ben freaked out when he looked at the source code?

It's because he came across some weird words, which resembled pretty much something like this,

```
# This is a ruby file containing a function called first_omnitrix.

module AzmuthFromOmniverse

  NO_HARM = '0'
  IS_HARMFUL = '1'

  def first_omnitrix(person)
    return IS_HARMFUL if person!= 'ben'
  end
end
```
Wait. What?

Ben is a kid who had a background in programming, but this code is insane. Why in the world would someone use this kind of mixed letters which causes a lot of confusion?

Hold your horses dear. You aren't alone 😅.

In Ruby, it's quite common. Many people who are new to ruby would find this odd at first ( Been there. Done that 🥶), but later you'll work around your way in understanding the meaning under the hood.

**Why cases are used?**

Cases are the one that differentiates one thing from another. Say for (e.g) Class Vs Function Vs Variables.

Interesting right? 😋

Come, let's dive in to know more 🏄🏻‍♂️

First thing First.

**1) CamelCase:**

![Camel Case image](https://thepracticaldev.s3.amazonaws.com/i/gvt96hjutkl6sen9tffi.jpg)

CamelCases in ruby are used around places like modules, classes and include definitions.
```
# This is a module with include.

module AzmuthFromOmniverse
  include OmnitrixPrototype
    ... something goes here ...
  end
end
```
The name called "AzmuthFromOmniverse" and "OmnitrixPrototype" used in the above code is called CamelCase.

You see, generally, when we use words in a sentence we differ them with space. But in programming especially in ruby, we don't use space for a module name. Instead, we start them by Capital letter followed by another word starting with a capital letter without any space.

This is known as Camel Case.

**2) snake_case:**

![snake case image](https://thepracticaldev.s3.amazonaws.com/i/zzjhrc17mziwfp6q2m6a.jpg)

Whoa, that's a snake bro. What does this have anything to do with code?

snake_case as the name suggests it has ups & downs and some flat surface. You can have an idea of the snake case in the below code snippet.

```
# Example method

def first_omnitrix
  return 'true'
end
```

Mostly for the definition of a function called ' def ', ruby uses snake_case. These are used to have a visual impact at the user end so that he/she can differentiate the code just by looking at the case itself.

This is known as snake_case

**3) CAPITAL CASE**

Sorry about the rude Heading. It was not meant to offend 🤭.
Usually using all words in Upper case is considered as shouting.

![not here gif](https://thepracticaldev.s3.amazonaws.com/i/kan5aoj25xrn6mhwhdln.gif)

Not here. Not in coding.

Upper case or CAPITAL case are used to denote the constants in ruby.

```
# Example of Capital case

module AzmuthFromOmniverse
  
  IS_HARMFUL = '1'

  def first_omnitrix
    return IS_HARMFUL
  end
end
```

Here, IS_HARMFUL is constant. Which takes input type like string, int or any other type as an input.

This is known as Capital case.

**Bonus Tip:**

You might have missed the part where I saved two lines in writing a piece of code.

Go through all the code snippet that I've given in this article and figure out which one it is.




Found it already? 🤓

This :
```
return IS_HARMFUL if person!= 'ben'
```

People who aren't familiar with ruby usually write something like this :
```
if(person) != 'ben' {
  return IS_HARMFUL
}
```
See, Saved two lines 😎.

Wanna know more about this?

You know the answer, wait till next week 😉.

So that's a wrap for this week. See you people around 🧙🏻‍♂️.

Cover image courtesy: https://www.codeninja.com.sg/