When making a personal app, I was wondering whether to make it using haml

Introduction

When I started learning programming with ruby, rails, I often heard these opinions around me. "When it comes time to develop an app individually, I'm wondering whether to make it with haml or erb." "I'm searching for how to write in haml, but I can't find it at all." "Do you really use haml when you run on your own?"

I made an app with both notations and looked back on how to decide whether to use haml or erb. I'm not explaining which one is better.

Judgment material

I hope you can see it while referring to the "Differences in notation" below.

--Code amount haml has an overwhelmingly smaller amount of description. Writing less time can be shortened. Once you get used to it, you can write fast and easy-to-read code.

--Structural understanding In haml, how to write the composition of elements is clearly decided. After all, haml indents the parent-child element. An error will occur if there is only one half-width space off. On the other hand, if you write the selector name according to the writing style, you can nest the selectors in SCSS and match each other's structure. It's easy to find the selector later. If you have the notation in mind, it will be easier to understand when you look at the code written by others. However, it may be difficult to read if the members do not follow the writing style properly.

--Amount of information in search results HTML is the basis. You can often see haml and erb by searching for development using rails, but the amount of information is less than that of html. Therefore, at the beginning, you have to check how to write in HAML what you write in HTML, and even if you check it, it often does not come out. Converting <script> </ script> is annoying. In addition, I'm wondering how to write erb in haml. (There is a conversion site, but if you don't understand the meaning and convert it, you won't be able to write by yourself ...) Also, when I used Vue.js to learn other languages, all the searched articles were written in HTML. The formula is also HTML.

Difference in notation

If you create the following スクリーンショット 2020-10-02 12.46.13.png

code

haml


.outer
  .outer__inner
    %p.text
      = link_to root_path, class: "text-link" do
        Hello New World!

erb


<div class="outer">
  <div class="outer__inner">
    <p class="text">
      <%= link_to root_path, class: "text-link" do %>
        Hello New World!
      <% end %>
    </p>
  </div>
</div>
styling

haml


.outer {
  height: 150px;
  width: 500px;
  background-color: lightblue;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 30px;
  &__inner {
    height: 100px;
    width: 400px;
    background-color: lightyellow;
    display: flex;
    justify-content: center;
    align-items: center;
    .text {
      height: 50px;
      width: 200px;
      background-color: lightpink;
      text-align: center;
      line-height: 50px;
    }
  }
}

erb


.outer {
  height: 150px;
  width: 500px;
  background-color: lightblue;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 30px;
}
.outer__inner {
  height: 100px;
  width: 400px;
  background-color: lightyellow;
  display: flex;
  justify-content: center;
  align-items: center;
}
.text {
  height: 50px;
  width: 200px;
  background-color: lightpink;
  text-align: center;
  line-height: 50px;
}

Styling does not always make this difference. However, using haml makes it easier to match each other's structures by using scss. You can also write in CSS.

Recommended Posts

When making a personal app, I was wondering whether to make it using haml
A story I was addicted to when testing the API using MockMVC
A memo that I was addicted to when making batch processing with Spring Boot
I tried using Hotwire to make Rails 6.1 scaffold a SPA
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
[Unity] I tried to make a native plug-in UniNWPathMonitor using NWPathMonitor
When a beginner makes a personal app with rails, the procedure to bring it to the starting point anyway.
I tried to make it an arbitrary URL using routing nesting
When installing a gem with C extension in Ruby, I want to finish it quickly using multiple CPU cores like make -j4
I tried to make a simple face recognition Android application using OpenCV
Inexperienced create a weather app using OpenWeatherMap and deploy it to Netlify
[Rails] I was addicted to the nginx settings when using Action Cable.
It was a life I wanted to reset the thread-safe associative counter
I tried to make a talk application in Java using AI "A3RT"
I want to make an ios.android app
When I wanted to create a method for Premium Friday, it was already in the Java 8 standard API
[Beginner] What I learned when trying to introduce bootstrap to the rails6 app without using a CDN [Asset pipeline]
A story when I tried to make a video by linking Processing and Resolume
When I tried to use a Wacom tablet with ubuntu 20.04, I didn't recognize it.
[Rails] How to write when making a subquery
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I tried to create a LINE clone app
Try to make a music player using Basic Player
I tried to implement a server using Netty
I want to issue a connection when a database is created using Spring and MyBatis
What I was addicted to when developing a Spring Boot application with VS Code
I stumbled when I tried using neo4j in the jenv environment, so make a note
A site that was easy to understand when I was a beginner when I started learning Spring Boot
A story I was addicted to when getting a key that was automatically tried on MyBatis
I want to implement it additionally while using kotlin on a site running Java
kintone clone? I was quite addicted to launching OSS WebDB Extension with Lightsail + Docker, so make a note of it.
Whether to enable SSL when using JDBC with MySQL.
A memorandum when trying to create a GUI using JavaFX
I tried to make a login function in Java
How to batch initialize arrays in Java that I didn't know when I was a beginner
A story I was addicted to before building a Ruby and Rails environment using Ubuntu (20.04.1 LTS)
I was able to convert my GMS app to G + H support within 10 minutes using ToolKit
[It takes 3 minutes] When I tried to install VS Code on Ubuntu 18.04, it was unexpectedly easy.
When I personally developed with Rails, it was a painful story that Rails was hit very much
When I tried to run Azure Kinect DK with Docker, it was blocked by EULA