[{"content":"Someone asked me:\n \u0026ldquo;What should you do when you lose the enthusiasm for coding?\u0026rdquo;\n I got tired of working as a software developer 3 or 4 times in my career. Maybe more. I had burnouts as well, and I didn\u0026rsquo;t even know what burnout was until a couple of years ago. 😆\nLosing the enthusiasm for coding can be normal: it\u0026rsquo;s hard to do the same thing, day in day out, and not get sick of it after so many years.\nBut if you are experiencing burnouts every 1-2 years, this is a sign. You need to stop and think deeply about the reasons behind that.\nAre you taking care of your mental health? Are you happy with your life? Are you happy with yourself?\nOr maybe you have to re-examine your perspective about life and work.\nDon\u0026rsquo;t be a coffee-drinking burnout-seeking coding machine For a very long time in my career, I could never allow myself to take any paid time off. Yes, it was bad.\nOne time, I worked so many extra hours on a job that they had to pay me a full extra month! Not because they wanted to, they had to for legal reasons.\n  Are you busy being busy?\n  You can probably understand how unhealthy this is. Burning out and jumping from one job to another. Never taking any breaks. Never having the space to think about what you want out of life.\nAnd to be completely honest, it\u0026rsquo;s because I didn\u0026rsquo;t know how to relax and enjoy time off. I was always thinking about the next big thing, the next step to take. I was living life on Autopilot.\nThe funny thing about it is that I don\u0026rsquo;t think I was ever really tired of coding. I was mostly tired of all the bullshit:\n useless meetings not having agency and autonomy to make my own decisions building features on a product no one will ever use fighting with crappy tools shiny new tool syndrome and general hype-driven development fatigue toxic cultures and pointless competition  If you don\u0026rsquo;t want to write code anymore, don\u0026rsquo;t! What I\u0026rsquo;ve learned from those experiences is that you have to take it easy sometimes. Don\u0026rsquo;t be so harsh on yourself.\nThe wrong way to go about it is to try and force yourself to do something you don\u0026rsquo;t want to do anymore. Take a month off of work if you can, and stop coding. Or maybe take a full year off, who cares? Go offline, focus on other hobbies that don\u0026rsquo;t involve technology.\nIt\u0026rsquo;s very easy to be sucked into the tech vortex and feel like you have to learn everything, read HackerNews every day, add more tech articles to the massive list of tabs on your browser\u0026hellip; This is so exhausting.\nSome other reasons behind all the information overload and stress:\n Not having any other hobbies that don\u0026rsquo;t involve technology and computers All of your friends are developers and all they want to talk about is tech Staring at a screen all day, every day  Close all your tabs - right now! If you have 10,000 tabs open in your browser, it\u0026rsquo;s time to close them. Seriously.\nIf you have a plugin to manage and sync tabs across devices, that\u0026rsquo;s one of the reasons you are so stressed out all the time.\nEvery tech article you add to your read list, every HackerNews tab you open, adds another bit of cognitive burden to your day.\nThe fear of missing out, the shame of not being \u0026ldquo;up-to-date\u0026rdquo; on the latest tech will make your life miserable.\nAnd it\u0026rsquo;s a choice. It\u0026rsquo;s completely up to you. You can always let these things slip and start fresh every day.\nSome software vendors and tech evangelists want you to believe that technology is changing exponentially. It\u0026rsquo;s not! Most of the shiniest, latest tech is just a re-packaging of very old ideas (nihil sub sole novum).\nFind some non-tech hobbies The easiest way to get out of the vortex is to pick up new (non-tech) hobbies and do something different. Here are some ideas for you:\n Hang out with people from different backgrounds Find new hobbies (hiking, cycling, cooking, painting\u0026hellip;) Go to a woodworking meetup Join Toastmasters and learn public speaking Learn how to play the banjo  Work with something new Sometimes moving to a different team or different company with a better culture, or working with different tech, can help you get excited about coding again.\nIt\u0026rsquo;s always refreshing to work on new stuff, especially if you don\u0026rsquo;t have much experience with it. Being a newbie again and getting curious can help you rekindle your passion about software development.\nMeditate The thing that helped me the most is Meditation. More specifically, Self-Compassion Meditation. This changed my life completely.\nYou can learn to accept yourself just as you are.\nBe able to forgive yourself for your mistakes and shortcomings. This will open up so many new possibilities in your life.\nTry it out and see it for yourself!\n Let me know if you\u0026rsquo;ve adopted any of these ideas into your life. I\u0026rsquo;m sure they\u0026rsquo;ll help you get some new perspective and I hope you find more happiness in your life!\n  Did you like this article? Then you're gonna love these other ones:\n  New job, new codebase. How do you even get started?   ","permalink":"https://thdaraujo.github.io/posts/what-to-do-when-you-get-tired-of-coding-and-developer-burnout/","summary":"Someone asked me:\n \u0026ldquo;What should you do when you lose the enthusiasm for coding?\u0026rdquo;\n I got tired of working as a software developer 3 or 4 times in my career. Maybe more. I had burnouts as well, and I didn\u0026rsquo;t even know what burnout was until a couple of years ago. 😆\nLosing the enthusiasm for coding can be normal: it\u0026rsquo;s hard to do the same thing, day in day out, and not get sick of it after so many years.","title":"What should you do when you get tired of coding?"},{"content":"One of my readers asked:\n How do you get started when you join a new company? How do you add features to a codebase that is massive, scary, and completely new to you?\n The first day at your new developer job is just like the first day at a new school. 🚸\nA sea of stranger\u0026rsquo;s faces watching your every move. Unfamiliar smells in the hallway.\nEvery chair is uncomfortable and makes weird noises when you sit. \u0026ldquo;Eek, there\u0026rsquo;s chewed-up gum under the seat!\u0026quot;\nThe cafeteria, as expected, serves undrinkable coffee.\nJust like the first zoom meeting with your new team.\nAre they friendly and cool people? Will they think your code sucks? What about that Github link they\u0026rsquo;ve just sent you? Urgh, look at all that foreign code!\nYour first day at your new job can be quite scary.\nBut what if you could feel confident, supported, respected, and comfortable collaborating with your new team? What if you knew how to find your way around any codebase?\nWhat if you could be so focused and productive that you don\u0026rsquo;t even notice time passing? Your working day goes like a breeze!\nAfter you read this post, you will know what strategies to use so you feel comfortable and know exactly how and where to get started 🌟\nBefore You Join, Take Time Off This might not be possible in every situation. Do your best to take some time for yourself.\nTake some time off before you start at a new job. Two weeks at the very least. Take this opportunity to start fresh and spend a couple of weeks relaxing and clearing your head.\nHaving this extra headspace will help on your first week as you learn new things and get to know your teammates.\nThe reason you feel so tired on your first week even has a scientific name: it\u0026rsquo;s called Acculturation. It\u0026rsquo;s hard for anyone.\nCompanies might try to pressure you into starting as soon as possible, but it\u0026rsquo;s always your choice. Assertive communication and taking care of yourself are qualities of a confident software engineer.\nAsk for Onboarding Materials or Documentation Ask if the company has any kind of onboarding materials you can look at the day before you join. Try to learn more about the stack, the codebase, and how the team works.\nFor a startup, it\u0026rsquo;s always good to look at their pitch deck so you can understand the problem they are solving and what kind of customers they are serving.\nSome companies won\u0026rsquo;t be able to share anything with you before your first day for confidential or security reasons, while others might.\nIn the past, one of my colleagues was given access to our codebase and got paid to work on it as part of the interview, which is a very neat way to get people onboarded more easily.\nOnboarding Buddy   When your onboarding buddy is SpongeBob SquarePants\n  When the company has some form of onboarding process plus good documentation, it makes things so much easier. Take advantage of it.\nHaving an onboarding buddy helps a lot in your first few weeks, as you get to know your team, the company\u0026rsquo;s culture, how the product helps customers, and how people collaborate.\nHaving someone to talk to and support you on your first week is very important.\nThis onboarding buddy should also help you set up your dev environment. If there\u0026rsquo;s no onboarding process in place, you can always ask for an onboarding buddy. Help them understand the value of good onboarding and get the ball rolling.\nI\u0026rsquo;ve managed the onboarding process for one of my past employers and we\u0026rsquo;ve onboarded dozens of software engineers. Every one of them said that having a good onboarding process made them feel much more confident, welcomed, and productive.\nIf there\u0026rsquo;s no go-to person to ask your questions, or you don\u0026rsquo;t feel comfortable asking for someone to help you in your first few weeks, read on. There are a couple of other things you can try.\nUpdate the documentation and onboarding materials (optional) When you are getting started, it\u0026rsquo;s always good to update the documentation being used for onboarding. It\u0026rsquo;s often out-of-date, so it\u0026rsquo;s a good opportunity to make things better for yourself and your team in the future.\nThat\u0026rsquo;s an easy way to show your peers you are a team player and you are committed to making things better for everyone.\nIssues and Feature Requests: Make Sure You Understand Them First and foremost, you have to understand what a new feature is supposed to do, and what would it mean for it to be \u0026ldquo;done and complete.\u0026rdquo; Teams often have different interpretations of done.\nFor some, \u0026lsquo;done\u0026rsquo; means \u0026lsquo;tested and shipped to production\u0026rsquo;. Other times it just means \u0026lsquo;ready for QA\u0026rsquo;.\nWork with the person that created the issue or feature request to make sure you understand it well.\nNot every team is good at writing and explaining things well on paper. Trying to understand what you need to do just by looking at the issue description or feature request can be challenging. You will be missing a lot of context as a new member of the team.\nDon\u0026rsquo;t be afraid to ask questions if you\u0026rsquo;re not sure what needs to be done, and take notes. Updating the issue/feature description always helps.\nWrite well, be kind to your future self.\nI love writing good and descriptive user stories even if it\u0026rsquo;s just for me to read. They help me a lot a week from now when I don\u0026rsquo;t even remember what I\u0026rsquo;m supposed to build. Happens all the time. 🤷‍♂️\nLatest Merged Pull Requests: A Gold Mine of Information After trying the usual stuff such as looking at the documentation and potentially outdated READMEs, you can move on to the next step:\nLook at the latest merged Pull Requests\nOne thing that helps the most is going through the latest merged pull requests and seeing what happened and how they look.\nThis is the best way to see how people approach building new features on your team. Pull Requests usually have linked issues or feature requests you can read as well.\nThis shows which parts/modules/classes/files in the system usually need to be changed in order to ship feature X or Y.\nFor example: let\u0026rsquo;s say the latest PR shipped the orders endpoint.\nYou look at the diff, you might see this:\n a new database migration a new model a new controller a new policy changes to the routes.rb file a new serializer and/or views new tests: feature tests, request tests, model tests, etc. a new factory documentation updates etc.  Sometimes a feature touches infrastructure code as well (terraform files, CI stuff). Some teams ship database migrations in a separate PR.\nLooking at the diff/code changes helps you see what needs to be done.\nCollaboration You will also get a sense of how the team works.\nFor example, you might get answers to these technical aspects:\n How much test coverage is good enough? What\u0026rsquo;s the coding style people follow? What are the conventions and best practices being followed? Which libraries are being used? Which patterns are being used and how code is organized? Do people open large Pull Requests or small ones? Do people split changes into frontend and backend changes? Is the project organized as a monorepo or a multi-repo? How does the CI/CD look like? How code gets deployed (manual vs automated deployments)? How and when do database migrations get merged? Does the team refactor code and pay down technical debt? When?  You will learn how people give feedback. How much do they nitpick on the small stuff. How much bikeshedding is allowed. How technical discussions are conducted.\nSome teams care about good architecture and design. Others like to do incremental changes, refactoring, and paying down technical debt when needed. While others don\u0026rsquo;t really care about any of this stuff and prefer to move fast and break things.\nThese are useful things to know and expect when you submit your first PR. That will give you more confidence.\nTake a peek at routes.rb One simple trick is to look at config/routes.rb first. Routes give you a sense of the endpoints and features that are available without having to go too deep into the codebase.\nBy looking at the routes, you will know if the project has an external API or not, which is very useful information.\nRead Related Code Take a look at code related to the feature you\u0026rsquo;re working on. Models, Controllers, and the Schema or related migrations are good places to look.\nLet the Team Help You: Submit Your PR and Ask for Feedback Your new team wants you to be successful. That\u0026rsquo;s why they hired you in the first place: because you\u0026rsquo;re a great developer and you kick ass!\nLet them help you be successful.\nYou can always submit your PR as is and wait for feedback. Let people help you finish it. You\u0026rsquo;ll never know everything up front, there\u0026rsquo;s no point in trying to make it perfect on the first try.\nIf you get stuck, ask for help. Let people help you! There\u0026rsquo;s no shame in that.\nRemember to add enough context in the Pull Request description so people can understand what you are trying to do.\nHow to receive feedback Constructive feedback is always valuable. Listening to constructive criticism is how you learn and get better.\n Ask: what can I learn from the feedback I\u0026rsquo;ve received?\n Ask questions so you can understand their point of view. Be curious and open-minded.\nDon\u0026rsquo;t worry too much if people request changes or point to you things that could be improved. Don\u0026rsquo;t be afraid to make mistakes.\n Ask: did I add enough context in the Pull Request description?\n Sometimes they don\u0026rsquo;t have enough context into what you are doing. In that case, add more context to help them.\nSometimes they have a point and they are right. Be flexible and open, as they are giving you feedback so the team can ship good code. They could be asking you to follow some of the team\u0026rsquo;s conventions that you might not know of.\nOther times, the reviewer just thinks differently than you. This is also fine. No two developers would ever write code in the same manner or style all the time. For these types of requests for change, you can politely disagree.\nWith time you will learn how to separate changes that are \u0026ldquo;nice to have\u0026rdquo; but don\u0026rsquo;t make any real difference, and changes that are really important.\nHaving integrity and being assertive are hallmarks of a confident coder. Be graceful when receiving feedback. Even if people do criticize you for no good reason, don\u0026rsquo;t take it personally.\nBe kind, be gentle, and remember: your work does not define your value as a person.\nAsking questions is an effective way to change your approach to receiving criticism. By asking a question, you stop judging yourself or others, and you start to be more curious.\nThe Confident Developer Onboarding Checklist Here\u0026rsquo;s a quick checklist you can use for self-onboarding ✅\n Ask for some time off before I start Ask for documentation or onboarding materials Take advantage of the onboarding process Find an onboarding buddy Understand the issue or feature request I\u0026rsquo;m working on Look at the latest merged Pull Requests Take a peek at the routes.rb file, or any code related to my work Let the team help me Get out of code perfectionism paralysis Ask for feedback Learn from the received feedback  If you have other ideas that helped you in the past and want me to add them here, please let me know! 💡\n Hope you apply these strategies to give you more confidence in your first few weeks at your new developer job.\nPrint your checklist and don\u0026rsquo;t forget to use it! Bookmark this post and share it with any friends who need to read this ⭐\nBefore I forget: congratulations on getting a new job, that\u0026rsquo;s awesome! I wish you all the best!\n  Did you like this article? Then you're gonna love these other ones:\n  What should you do when you get tired of coding?   How to Learn the Syntax of a Programming Language When You Know How to Code   Learn Ruby on Rails Best Practices With One Exercise   ","permalink":"https://thdaraujo.github.io/posts/new-job-new-codebase-how-to-get-started/","summary":"One of my readers asked:\n How do you get started when you join a new company? How do you add features to a codebase that is massive, scary, and completely new to you?\n The first day at your new developer job is just like the first day at a new school. 🚸\nA sea of stranger\u0026rsquo;s faces watching your every move. Unfamiliar smells in the hallway.\nEvery chair is uncomfortable and makes weird noises when you sit.","title":"New job, new codebase. How do you even get started?"},{"content":"Are you having a hard time picking up the syntax of a new programming language, even though you know how to code?\nYou\u0026rsquo;re new to Ruby, and people say it\u0026rsquo;s an easy language, but you find the syntax difficult to understand.\nYou know a bit of Javascript, Python, Java, or any other language. But Ruby seems like alien technology to you.\nBy the end of this post, you\u0026rsquo;ll have a tool to help you transfer your knowledge of [INSERT PROGRAMMING LANGUAGE HERE] to Ruby.\nRuby is all about messages and objects Ruby is all about objects sending messages to other objects. It\u0026rsquo;s a slightly different way of thinking.\nRuby is similar to languages like Smalltalk and Lisp. They\u0026rsquo;re very flexible languages based on a small number of basic building blocks.\nThat flexibility allows you to make your code very readable and descriptive. Almost like writing English text.\nLearn the Basic Building Blocks To learn the syntax and the style of a new language, you should understand the basic building blocks of the new language you want to learn and compare them to another one you understand well.\nThen you can try to translate a small piece of code from one language that you understand well to another you\u0026rsquo;re trying to learn.\nThat\u0026rsquo;s how you spot their differences and similarities and understand how to apply these ideas in different scenarios.\nThis is something similar to Transfer Learning, or Knowledge Transfer.\nYou can use the knowledge you already have about how one language works, and use that to help you pick up the syntax of another language.\nGot it? Let\u0026rsquo;s practice!\nHow to transfer coding knowledge from one language to another Here\u0026rsquo;s an exercise you can use to transfer knowledge from one language to another.\n1. Start with a simple problem Always start with a simple problem you can easily solve with just a few lines of code in the original language.\nLet\u0026rsquo;s assume you know Golang.\nHow would you write a piece of code that prints numbers from 1 up to 10 in Go and Ruby?\nMaybe something like this:\nGo:\n// Go for i := 1; i \u0026lt;= 10; i++ { fmt.Println(i) } This is one way you could do it in Ruby:\n# Ruby (1..10).each do |n| puts n end 2. Identify similarities and differences between the basic building blocks What are the big differences you can spot at first glance? Do you see any differences in style?\nIn the Ruby example, here are some of the basic building blocks we can spot:\n a range 1..10 the usage of an each iterator instead of a for-loop a block do ... end with a parameter n a puts n method called with one argument and no parenthesis  3. Ask yourself some questions Here are a couple of suggested questions you can start with:\n Ruby has for loops, but why are we iterating over a range here? Is each a method call on range? Why are we using do |n| ... end instead of { |n| ... }? What if you change the code to puts(n)?  You could even ask a slightly harder question:\n Would you be able to send a message to a variable in Go?  This is how you can send a message to an object in Ruby:\n# sending a message instead of calling a method (1..10).send(:each) { |n| puts n } Do you see what I mean?\nConclusion To recap:\n pick a simple problem you can easily solve with just a few lines of code in the original language solve the problem by writing code in a language you know well solve the problem by using the new language you want to learn try to spot the basic building blocks, styles, and patterns in both pieces of code compare both implementations to see any differences and similarities ask yourself some questions and try to answer them  You can learn a lot about Ruby (or any other language) just by trying to answer one of these questions above.\nAnd then trying to write a similar piece of code by yourself in the new language so you can practice what you just learned.\nYou will learn not only the style and syntax of Ruby but also the mindset behind it.\nThis exercise will help you pick up any other programming language. Change the questions a bit and practice.\nNow go practice!\n  Did you like this article? Then you're gonna love these other ones:\n  New job, new codebase. How do you even get started?   Learn Ruby on Rails Best Practices With One Exercise   How to Write a Clean Order By Case Query with Arel on Rails   ","permalink":"https://thdaraujo.github.io/posts/how-to-learn-programming-language-syntax/","summary":"Are you having a hard time picking up the syntax of a new programming language, even though you know how to code?\nYou\u0026rsquo;re new to Ruby, and people say it\u0026rsquo;s an easy language, but you find the syntax difficult to understand.\nYou know a bit of Javascript, Python, Java, or any other language. But Ruby seems like alien technology to you.\nBy the end of this post, you\u0026rsquo;ll have a tool to help you transfer your knowledge of [INSERT PROGRAMMING LANGUAGE HERE] to Ruby.","title":"How to Learn the Syntax of a Programming Language When You Know How to Code"},{"content":"You want to write smooth professional-looking code.\nYou\u0026rsquo;re craving some squeaky-clean code. But all you have for lunch every day is a big bowl of legacy spaghetti code.\nYou consider yourself a decent developer, but you\u0026rsquo;re never sure how to organize a project. How to name things. Where some piece of business logic should live.\nHow can you become a Ruby on Rails expert if the code you read every day stinks? 🦨\nIs it possible to learn and follow best practices when you\u0026rsquo;re trapped in a big ball of stale legacy code?\nOf course, it is! Start changing your coding diet today by consuming something healthier.\nYes, it\u0026rsquo;s going to take some work. But don\u0026rsquo;t get discouraged. If you want to advance your skills, you\u0026rsquo;ve gotta try something different.\nReady to get started?\nFirst: Be Careful When You Ask for Advice You\u0026rsquo;re committed to advancing your skills. When you ask people for guidance, they tell you to read a bunch of books and start throwing these terms at you:\n Skinny controllers, fat models, service objects, design patterns, DRY, SOLID, OOP\u0026hellip;\n The list goes on.\nIs this information really helpful to you? What are you supposed to do with all of that?\nThe problem is that it\u0026rsquo;s not actionable information, just a bunch of ideas and vague suggestions.\nThere is a more practical way to learn all this stuff. Here\u0026rsquo;s how.\nOne Exercise to Teach You Ruby on Rails Best Practices Instead of reading another book or watching youtube videos about pasta making during your lunch break, do this exercise instead:\nExercise  Set a timer for 10 minutes. Open this link in another tab: practice.rb from Upcase by Thoughtbot Read the app/services/practice.rb class. Ask yourself: What\u0026rsquo;s going on here? Come back here when the time is up! ⌛  Sounds good?\nOkay, now go do it! I\u0026rsquo;ll wait for you.\n\u0026hellip;\n\u0026hellip;\n\u0026hellip;\n⏰ beep! beep! beep! beep!\nNow that the time is up, answer at least one of these questions:\n Why is this class so short? It\u0026rsquo;s less than a hundred lines! Why is the variable trails being passed down to the initialize constructor? Did you notice these methods promoted_unstarted_trails and unpromoted_unstarted_trails? Why do you think they were given these names, and what\u0026rsquo;s the difference between them? What is this class responsible for? 🤔 What else picked your interest?  Write down the questions and your answers to make them stick.\nLast but not least:\n Repeat this exercise tomorrow, but pick a different class from the same repository. Add a daily reminder to your calendar so you don\u0026rsquo;t forget about it. 📅  It\u0026rsquo;s okay if you don\u0026rsquo;t understand anything The goal of this exercise is to notice some patterns. Not to understand every single line of code.\nUse your answers to the questions above as a study guide. Even if you answered \u0026ldquo;I don\u0026rsquo;t know\u0026rdquo;, that\u0026rsquo;s useful information.\nIt\u0026rsquo;s okay if you feel uncomfortable Feeling uncomfortable means you\u0026rsquo;re doing something different. You\u0026rsquo;re challenging yourself. You\u0026rsquo;re learning and growing.\nIf you\u0026rsquo;re thinking \u0026ldquo;OMG this code is too clean and my code is super dirty!\u0026quot; or \u0026ldquo;I\u0026rsquo;ll never be able to work on such a clean codebase!\u0026quot;, don\u0026rsquo;t worry!\nThat\u0026rsquo;s okay. That\u0026rsquo;s not the point of this exercise.\nThe point of this exercise is to read the code and notice anything that looks different or any interesting pattern.\nFrequently Asked Questions Here are the answers to some questions you might have about this exercise.\nHow am I going to learn anything just by reading one class? It might seem like it\u0026rsquo;s not much.\nIf you do this every day, here\u0026rsquo;s what\u0026rsquo;s going to happen:\n At the very least, you\u0026rsquo;re going to learn how the Upcase codebase works. You will pick up new ideas and patterns. You will end up with a list of things you don\u0026rsquo;t understand. That\u0026rsquo;s a great guide on what you need to focus on. You will see how other experts structure a project to make the code neat and clean. You will learn how to find answers to your own questions and how to read source code.  That\u0026rsquo;s pretty good, right?\nAll professional developers and experts have these skills. It comes from practice.\nWhy Pick a Well-Written Codebase? Good question. You have to be exposed to good code if you want to advance your skills. Especially if you don\u0026rsquo;t have this opportunity at work.\nIf your goal is to learn best practices, you have to read a well-written codebase.\nThoughtbot, the company behind Upcase, is well-known in the Ruby on Rails community for setting industry standards and following good coding practices.\nWhat if I get stuck? When that happens, ask one of your colleagues for help.\nIf that doesn\u0026rsquo;t work or you don\u0026rsquo;t feel comfortable doing that, ask Rails Forum or Reddit.\nYou can also send me a DM on Bluesky and I\u0026rsquo;ll be happy to help.\nCan you give me other examples of questions to ask? I\u0026rsquo;m glad you asked!\nSome other interesting questions you may ask:\n What does this class/object afford? What is the potential action enabled by this class/object? What are the dependencies of this class? How would I feel if I had to use this class (happy, angry, confused)? Why is this code here and not somewhere else? If I call this method, how much do I need to know about its implementation?  Be curious.\nEven when you think you know something well, challenge your knowledge about it by asking interesting questions.\nIt can be hard to separate understanding from memory or just familiarity.\nSometimes you think you understand a concept because it\u0026rsquo;s familiar to you. You remember it vividly. But you\u0026rsquo;re not able to explain the idea to anyone, even to yourself. And that\u0026rsquo;s not fun!\nIs there a list of projects I can use for this exercise? Sure thing! When you\u0026rsquo;re finished with Upcase, you can pick a different project to study.\nBut BEWARE: Analysis paralysis is a real thing, so be careful!\nIt\u0026rsquo;s easy to procrastinate instead of doing real work and practicing.\nDon\u0026rsquo;t waste too much time choosing a project. Pick one at a time and keep practicing.\nI\u0026rsquo;ve compiled a list of projects and other resources to help you.\n Now that you\u0026rsquo;ve done this exercise, you will improve your Rails skills every time you practice.\nIt\u0026rsquo;s just a matter of consistently exposing yourself to good code. Keep using the suggested questions as a guide, or come up with different ones. Pick a different class every day, and keep going.\nYou\u0026rsquo;ve already done the hardest part: getting started. Now keep practicing.\nLet me know what you\u0026rsquo;ve learned by practicing this exercise.\nBookmark this post to keep the questions on hand. Share it with a friend who will find this exercise helpful. ⭐\nHappy learnings! 📓\nPS: I recently gave a talk about this exercise, you can find the slides here 🍝\n  Did you like this article? Then you're gonna love these other ones:\n  New job, new codebase. How do you even get started?   How to Learn the Syntax of a Programming Language When You Know How to Code   How to Write a Clean Order By Case Query with Arel on Rails   ","permalink":"https://thdaraujo.github.io/posts/learn-ruby-best-practices-with-one-exercise/","summary":"You want to write smooth professional-looking code.\nYou\u0026rsquo;re craving some squeaky-clean code. But all you have for lunch every day is a big bowl of legacy spaghetti code.\nYou consider yourself a decent developer, but you\u0026rsquo;re never sure how to organize a project. How to name things. Where some piece of business logic should live.\nHow can you become a Ruby on Rails expert if the code you read every day stinks?","title":"Learn Ruby on Rails Best Practices With One Exercise"},{"content":"You\u0026rsquo;re working on a feature and someone tells you that one of your models needs to be ordered based on some complicated rule. You realize you\u0026rsquo;ll need to write a complex order by query\u0026hellip;\nHere\u0026rsquo;s how it usually goes:\n You think to yourself: \u0026ldquo;Should I write an order by case when statement? Maybe I\u0026rsquo;ll just add a little bit of SQL\u0026hellip;\u0026quot; Two minutes later, you end up with a bunch of nested case when statements, subqueries, common table expressions, angry statements, shouting, and a whole lot of tears. 😤  If you\u0026rsquo;ve ever tried to write a complicated order by statement with ActiveRecord, you probably know that it\u0026rsquo;s kind of painful, and you end up with ugly-looking code. That\u0026rsquo;s not what you want, right?\nThat sort of query quickly becomes unreadable as you add more and more cases to it.\nMost examples and tutorials don\u0026rsquo;t even mention that you might need to sanitize your query\u0026hellip; Not cool!\nIt\u0026rsquo;s okay to write raw SQL queries sometimes, but for this type of problem, let\u0026rsquo;s try something different, shall we?\nI want to show you a better way: use Arel to generate the statements for you.\nFollow along and you\u0026rsquo;ll learn how to do it.\nExample Let\u0026rsquo;s suppose you have a simple schema containing users, posts and comments:\nActiveRecord::Schema.define do create_table :posts, force: true do |t| end create_table :users, force: true do |t| t.string :country end create_table :comments, force: true do |t| t.integer :post_id t.integer :user_id end end The models would look something like this:\nclass Post \u0026lt; ActiveRecord::Base has_many :comments end class User \u0026lt; ActiveRecord::Base has_many :comments end class Comment \u0026lt; ActiveRecord::Base belongs_to :post belongs_to :user end Normally, you\u0026rsquo;d order a post\u0026rsquo;s comments by their creation date. That\u0026rsquo;s the simple case.\nHowever, the simple case is seldom enough. Let\u0026rsquo;s say you need to order comments by something more complicated than that:\n The current_user\u0026rsquo;s comments should come first; Followed by comments created by people who live in the same country as the current_user.  Your first instinct might be to write a raw SQL query. See how this is done on the next section.\nHow to write an order by case statement with raw SQL If you try to do a simple raw SQL query, you could write an order-by case stamement based on the user\u0026rsquo;s id and country.\nHowever, if you allow people to store any type of string on their user.country field, you would also need to sanitize the query to prevent SQL injections.\nLet me tell you something: sanitizing case-statements is annoying, specially for order by statements.\nHere\u0026rsquo;s how that would look like:\n# sad-face case_statement = \u0026lt;\u0026lt;-SQL.squish  CASE WHEN users.id = ? THEN 1 WHEN users.country = ? then 2 ELSE 3 END SQL # country could be anything, so let\u0026#39;s sanitize the query: sanitized_case_statement = ActiveRecord::Base.sanitize_sql_array( [case_statement, user.id, user.country] ) post.comments .joins(:user, :post) .order( Arel.sql(sanitized_case_statement) ) Which is not the cleanest-looking code.\nIf you\u0026rsquo;ve read this far, you\u0026rsquo;re probably thinking: \u0026ldquo;Is there a better way?\u0026quot; Absolutely! Enter Arel.\nHow to Write a Clean Order By Case Statement with Arel Arel supports case-statements, a not well-known feature.\nUse it to generate a complex order by case statement query. Better yet, you won\u0026rsquo;t need to worry about sanitization.\nThe idea is to leverage Arel::Nodes::Case to build the SQL expression. Here\u0026rsquo;s how:\nusers = User.arel_table same_user = users[:id].eq(current_user.id) same_country = users[:country].eq(current_user.country) case_statement = Arel::Nodes::Case.new .when(same_user).then(1) .when(same_country).then(2) .else(3) post.comments.joins(:user, :post).order(case_statement) Much cleaner, right?\nYou could even write subqueries to expose more information and add them to your case-statement.\nThen, you can break things down into scopes, or refactor pieces of the query into a Query Object. That gives you more flexibility and the code will be a little easier to extend and maintain.\nTake a look at this gist to see the full example plus tests if you\u0026rsquo;d like to try it out.\nAnd there you have it: a clean way to write case-when statements on complex order_by queries with ruby code. No need to write crazy raw SQL queries any longer! Enjoy!\n  Did you like this article? Then you're gonna love these other ones:\n  How to Learn the Syntax of a Programming Language When You Know How to Code   Learn Ruby on Rails Best Practices With One Exercise   What\u0026rsquo;s the Best Way to Learn Webpack?   ","permalink":"https://thdaraujo.github.io/posts/how-to-write-order-by-case-query-with-arel/","summary":"You\u0026rsquo;re working on a feature and someone tells you that one of your models needs to be ordered based on some complicated rule. You realize you\u0026rsquo;ll need to write a complex order by query\u0026hellip;\nHere\u0026rsquo;s how it usually goes:\n You think to yourself: \u0026ldquo;Should I write an order by case when statement? Maybe I\u0026rsquo;ll just add a little bit of SQL\u0026hellip;\u0026quot; Two minutes later, you end up with a bunch of nested case when statements, subqueries, common table expressions, angry statements, shouting, and a whole lot of tears.","title":"How to Write a Clean Order By Case Query with Arel on Rails"},{"content":"If you\u0026rsquo;re feeling lost whenever you have to add some javascript library to your Rails application, this post is for you!\nI see a lot of people battling against Webpacker whenever they need to add a new javascript library or have to fix a bug on the asset pipeline. I suffered from the same problems, too. I talked about why this happens on a previous post:\n\u0026ldquo;Adding Bootstrap or Javascript Sprinkles to Rails breaks everything. What should you do?\u0026quot;.\nForget about reading yet another Bootstrap + Rails tutorial. They\u0026rsquo;re not going to help you. Better to invest your time on something that will help you: learning the basics.\nThe only thing that helped me was learning how Webpack works behind the curtains.\nThat\u0026rsquo;s why I compiled this list of good resources that will teach you everything you need to learn about Webpack to give you more confidence.\nTips:\n If you\u0026rsquo;re in a hurry, at least watch the Webpack Survival Guide talk. If you have some time, check out the Webpack From Nothing tutorial.  Hope you find these resources useful!\nWebpack from Nothing (if you can pick only one resource to read, this is the one!)\nI highly recommend the tutorial Webpack from Nothing from David Bryant Copeland, who is a Ruby on Rails expert.\nHe shows you how to create a web application from scratch using only minimal tooling and Webpack. Building something is always a great way to learn!\nHe goes over which problems Webppack solves and how it works. He also talks about some of the expected problems so you don\u0026rsquo;t get too frustrated.\nThis tutorial will give you a good sense of how to work with modern Javascript, many of the gotchas to look out for, and a glimpse into the worldview of Webpack developers.\nYes, for someone used to good developer experience, the JS tooling is definetely lacking in that area, but it\u0026rsquo;s still useful to learn it from first principles so you can debug things when they break.\nRails Guides You probably know this one, but it\u0026rsquo;s always good to have it as a reference. The Webpacker Rails Guide is the most up-to-date reference about working with Webpacker on a Rails app.\nWebpack Survival Guide This is a great talk about the process of migrating from the Rails asset pipeline to Webpacker and all the lessons learned along the way.\nThere\u0026rsquo;s also a bunch of good resources about Webpack that you can also check out.\nWebpack Survival Guide for Rails Developers\n  Javascript Modules Cartoon This is a good tutorial to learn how ES modules work and what problems they solve.\nES modules: A cartoon deep-dive\nJavascript Modules Mozilla has in-depth documentation about how javascript modules work. This will help you understand how modude loading works and what import and export statements are supposed to do.\nJavascript modules - MDN\nMoving from Sprockets to Webpacker I wrote about this and compiled a list of resources on a previous post, check it out:\nMove From Sprockets to Webpacker On Small to Large Rails Apps.\nConclusion These resources will definetely help you become much more confident in your Webpacking skills, so make sure you check out at least one of them!\nLearning and practicing the basics pays off big time in the long run.\n  Did you like this article? Then you're gonna love these other ones:\n  New job, new codebase. How do you even get started?   How to Learn the Syntax of a Programming Language When You Know How to Code   Learn Ruby on Rails Best Practices With One Exercise   ","permalink":"https://thdaraujo.github.io/posts/how-to-learn-webpack/","summary":"If you\u0026rsquo;re feeling lost whenever you have to add some javascript library to your Rails application, this post is for you!\nI see a lot of people battling against Webpacker whenever they need to add a new javascript library or have to fix a bug on the asset pipeline. I suffered from the same problems, too. I talked about why this happens on a previous post:\n\u0026ldquo;Adding Bootstrap or Javascript Sprinkles to Rails breaks everything.","title":"What's the Best Way to Learn Webpack?"},{"content":"Did you spend a billion hours trying to add jQuery, or Bootstrap, or Tailwind to your Rails project, but now everything on the frontend is broken?\nOr worse: you can\u0026rsquo;t even tell whether the frontend is broken or not. It\u0026rsquo;s in a unkown state of brokenness.\nMaybe you just want some javascript sprinkles, but Webpacker makes things so much harder and frustrating.\nDo you wait until an angry customer complains about the checkout button not working anymore to know which page to fix? Probably not!\nI know how that feels. I often ask myself: \u0026ldquo;What\u0026rsquo;s the difference between Webpacker and Webpack again? This is so confusing!\u0026rdquo;\n(Old developer yells at Webpack)* 👴🗯️\nWebpack(er) is more complicated, but it\u0026rsquo;s not rocket science! Good ol' Sprockets was so much easier, right? Just drop some JS files in app/assets/javascripts, add a line to application.js, and call it a day.\nWebpacker out-of-the-box experience is indeed more complicated than Sprockets, people are terrified of touching anything except the most basic configuration.\nBut it\u0026rsquo;s not really Webpacker\u0026rsquo;s fault. This gem is just a wrapper around Webpack.\nWebpack is a static module bundler for JavaScript. It\u0026rsquo;s responsible for grabbing a bunch of javascript modules and bundling them together so your application can use it.\nI know what you\u0026rsquo;re thinking: why not just use Sprockets instead?\nThe problem is that you would be stuck in Sprockets-land forever: the issues would only increase over time, as all the new features get ported over to Webpack while older gems become deprecated in favor of npm packages.\nYou can read my previous post for more details.\nSorry to break it to you, but there\u0026rsquo;s no going back to Sprockets. There\u0026rsquo;s really no other popular, modern and production-ready option to work with besides Webpack. Until something better comes along, you\u0026rsquo;ll need to get used to it and move on.\nWorking with javascript packages became much more complicated, but honestly, it\u0026rsquo;s not rocket science.\nThe problem is that you might not be used to the \u0026ldquo;Javascript Way of Doing Things\u0026rdquo; ™️, but it\u0026rsquo;s okay. If you learn a little bit more about how this stuff works, you will stop suffering so much.\nHow to Make the Webpack Pain Go Away? After I accepted that I needed to understand more about Webpack to be able to do my work, and decided to learn a bit about it, my life got so much easier.\nIf this is something you\u0026rsquo;d like to try, here\u0026rsquo;s my recommendation:\n Learn a little bit of how javascript modules work Learn how Webpack works behind the curtains, and what problem it solves  Trust me on this, most of my javascript-related pain went away after learning a bit more about the inner workings of Webpack.\nAnd I\u0026rsquo;m not even talking about the Webpacker gem, because it will definetely not solve all the problems for you. Like I said, it\u0026rsquo;s just a wrapper around Webpack. If you don\u0026rsquo;t really grasp how Webpack works and Webpacker starts throwing errors at you, you\u0026rsquo;ll get lost.\nBut if you understand Webpack a little better, you\u0026rsquo;ll be able to debug issues yourself and configure things with more confidence and understand what\u0026rsquo;s going on.\nIf you\u0026rsquo;re convinced, check out this list of resources I created for you:\nWhat\u0026rsquo;s the Best Way to Learn Webpack? 📚\nIf you follow these recommendations, they will teach you everything you need to learn about Webpack. Better than yelling at it, right? 🙉\n  Did you like this article? Then you're gonna love these other ones:\n  New job, new codebase. How do you even get started?   How to Learn the Syntax of a Programming Language When You Know How to Code   Learn Ruby on Rails Best Practices With One Exercise   ","permalink":"https://thdaraujo.github.io/posts/rails-and-webpack-pain/","summary":"Did you spend a billion hours trying to add jQuery, or Bootstrap, or Tailwind to your Rails project, but now everything on the frontend is broken?\nOr worse: you can\u0026rsquo;t even tell whether the frontend is broken or not. It\u0026rsquo;s in a unkown state of brokenness.\nMaybe you just want some javascript sprinkles, but Webpacker makes things so much harder and frustrating.\nDo you wait until an angry customer complains about the checkout button not working anymore to know which page to fix?","title":"Adding Bootstrap or Javascript Sprinkles to Rails breaks everything. What should you do?"},{"content":"Rails 6 comes with Sprockets and Webpacker by default. Confusing, right?\nThe default configuration is Webpacker for Javascript while Sprockets takes care of all the rest (CSS, images, fonts\u0026hellip;).\nLet me tell you a secret: You don\u0026rsquo;t need both. Just use Webpacker.\n Legacy applications and older gems still use Sprockets to serve assets. This was done to add backwards compatibility. If you don\u0026rsquo;t have a good reason to keep Sprockets around, don\u0026rsquo;t.\n Most apps can just use Webpacker. In case you\u0026rsquo;re wondering, Webpacker is just a wrapper around Webpack, which is a tool responsible for bundling assets. It takes care of static assets (Javascript, CSS, even images and fonts), and it\u0026rsquo;s a more complete solution, altough a little harder to get used to.\nAdvantages of Webpack(er):\n You can easily import npm packages to take care of your frontend needs There are way more tutorials about how to set up a Javascript library using Webpack that you can adapt Most tools from the JS ecosystem will target Webpack users anywway You\u0026rsquo;ll only need to debug one asset bundling tool instead of two!  If we take a look at what the Elixir folks are doing, they use Webpack by default on Phoenix Applications. This is great because it keeps things straightforward, specially when you need to debug something.\nWatch out for these two situations before making this decision:\n You have a large legacy Rails application with a complicated frontend that depends heavily on Sprockets. See section Huge Legacy Apps below to learn more. Your project is split into multiple Rails engines that expose any sort of theme, Javascript or other static assets. This is tricky. You might need to create an npm package and refactor some Javascript code, which can be a lot of work (see this discussion on the rails forum).  But if you\u0026rsquo;re ready to ditch Sprockets in favor of Webpacker, here\u0026rsquo;s a list of good resources for new and small apps, up to huge legacy ones:\nNew or Small Rails Apps: Keep it Webpacker-only If you\u0026rsquo;re creating a new Rails app, do youself a favor and just skip generating anything related to Sprockets:\n$ rails new myapp --no-sprockets If you have an existing app, this guide is perfect for people who are in a hurry or not doing anything crazy on the frontend side of things.\nRails 6 with Webpacker in app/assets (and no Sprockets)\nMedium-sized apps: Move everything over to Webpacker This guide explains how to migrate everything over to Webpacker - CSS, Javascript, fonts and images on Rails 6.\nGoodbye Sprockets. Welcome Webpacker\nThis other tutorial is very similar but goes over a couple of extra things and gives some tips about Polyfills and deployment.\nMigrating From Sprockets to Webpacker\nHuge Legacy Apps: Keep Sprockets Working While Migrating to Webpacker Impossible? Maybe not! Check out this example of a successful migration:\nHow we switched from Sprockets to Webpacker.\nThis is an in-depth post explaining how a team gradually switched from Sprockets to Webpacker on a larger Rails App. They had to support both Webpacker and Sprockets to maintain backwards compatibility. They go over the challenges and how they were able to solve the issues that popped up.\nTheir approach had 3 distinct phases:\n preparation migration cleanup  Read this when you\u0026rsquo;re not sure if you should make the move or not.\nPlan for these types of migrations when you have a complex frontend or legacy gems that rely on Sprockets.\nThe best way to go about it is by gradually moving assets to Webpacker while keeping the existing asset pipeline intact until you get rid of Sprockets completely. This process will take a while, be ready for it.\nAnd always make sure you have good tests!\n  Did you like this article? Then you're gonna love these other ones:\n  How to Learn the Syntax of a Programming Language When You Know How to Code   Learn Ruby on Rails Best Practices With One Exercise   How to Write a Clean Order By Case Query with Arel on Rails   ","permalink":"https://thdaraujo.github.io/posts/from-sprockets-to-webpacker/","summary":"Rails 6 comes with Sprockets and Webpacker by default. Confusing, right?\nThe default configuration is Webpacker for Javascript while Sprockets takes care of all the rest (CSS, images, fonts\u0026hellip;).\nLet me tell you a secret: You don\u0026rsquo;t need both. Just use Webpacker.\n Legacy applications and older gems still use Sprockets to serve assets. This was done to add backwards compatibility. If you don\u0026rsquo;t have a good reason to keep Sprockets around, don\u0026rsquo;t.","title":"Move From Sprockets to Webpacker On Small to Large Rails Apps"},{"content":"Did you always want to help an open-source project like Ruby on Rails, but never got started?\nMany people have the interest of contributing to open-source, myself included. I\u0026rsquo;ve done a couple of small contributions, but nothing fancy.\nIt\u0026rsquo;s a little intimidating, right? You\u0026rsquo;re not part of the group of contributors and you don\u0026rsquo;t really know where to start. You see 800 open issues, which one is a good one to pick?\nI\u0026rsquo;ve had those feelings as well. But if you never get started, you\u0026rsquo;ll never learn what is really needed. Besides that, the rails community is super friendly and helpful, you don\u0026rsquo;t need to be scared.\nEverybody\u0026rsquo;s got to start somewhere. Better now than later. And you can just learn as you go.\nThat\u0026rsquo;s what Stefanni and I have been doing. We just decided we wanted to start contributing to open-source and we picked our first issue.\nWe started a project called Open Source Thursdays.\nWe\u0026rsquo;re doing a livestream every thursday on our youtube channel showing what we\u0026rsquo;re doing and what we\u0026rsquo;re learning.\nThe goal is to show the real life of working on a new codebase: lots of googling, stumbling around, debugging, making lots of mistakes, reading docs and learning in real-time. We\u0026rsquo;ve been having lots of fun!\nLast week, we went over a couple of Rails issues, and some of them looked promising. There was no open issue labeled as \u0026ldquo;good for beginners\u0026rdquo;, and we didn\u0026rsquo;t really want to work on an issue that was too simple (such as changing documentation), so we tried a different approach.\nWe looked for issues that had:\n a good description of the bug had reproduction steps written down had no open pull request available we could understand the problem without needing too much context about the codebase  We selected a couple of issues, and then decided to pick this one: Active Storage Disk Service NoMethodError: undefined method `rails_disk_service_url' related to ActiveStorage.\nThe first step was to try and reproduce the error by following the reproduction steps, which was possible.\nWe were able to run a Rails app that is just a single ruby file by using the bundler/inline feature.\nThis script will automatically install any missing gems, require the gems you listed, and then run your code. Pretty cool, right?\nThen we tried one of the solutions that someone commented, but we were not able to fix the problem. So we created a gist showing what happened and asking for feedback and more information. That was the end of the livestream!\nDuring the week, we got some more answers and ideas. One of the problems was that we were using the wrong ruby version (2.7 vs 3.x), and that fixed our problem.\nNow have a little bit more context (from this comment and this other comment).\nWe\u0026rsquo;ll start writing some code to implement a fix. That\u0026rsquo;s going to happen this Thursday, so stay tuned!\nCheck our youtube channel!\n  Did you like this article? Then you're gonna love these other ones:\n  How to Learn the Syntax of a Programming Language When You Know How to Code   Learn Ruby on Rails Best Practices With One Exercise   How to Write a Clean Order By Case Query with Arel on Rails   ","permalink":"https://thdaraujo.github.io/posts/picking-a-rails-issue/","summary":"Did you always want to help an open-source project like Ruby on Rails, but never got started?\nMany people have the interest of contributing to open-source, myself included. I\u0026rsquo;ve done a couple of small contributions, but nothing fancy.\nIt\u0026rsquo;s a little intimidating, right? You\u0026rsquo;re not part of the group of contributors and you don\u0026rsquo;t really know where to start. You see 800 open issues, which one is a good one to pick?","title":"How to pick your first Rails Issue and start contributing to Open-Source"},{"content":"You need to change production data. You know that doing it manually is unsafe and will definetely cause lots of trouble, like corrupting all you customer\u0026rsquo;s data.\nHow else should you do it?\nYou might be spending a lot of time asking yourself these questions:\n Is there a proper rails way to change data in production? Should I run data and schema modifications in one database migration? Should I run rake scripts in production to modify data? Should I use a specialized data migration gem?  You will get different answers depending on whom you ask. Some people will tell you that changing data with a database migration is an anti-pattern and migrations should only contain schema changes.\nBut isn\u0026rsquo;t the whole point of a migration to be a good way to define a point-in-time transition of database structure or data, using code?\nIf you have a larger application or a mission-critical system, be careful with production data updates. This can lead to downtime and big problems. This post won\u0026rsquo;t cover this scenario.\nHowever, if your app is still relatively new and small, this post is for you. Here\u0026rsquo;s how you can use data migrations to change production data without shooting yourself in the foot.\n1. Schema changes and data changes are like water and oil: they do not hangout together Write data manipulation code in separate Rails migrations and give them proper names. NEVER change schema and data in the same migration.\nAnother tip: consider separating complicated migrations and code changes in multiple pull requests you can merge and deploy separately. That way you can incrementally change the database and catch errors or rollback more easily.\n2. Stick to plain old SQL, if you can Careful when using models in migrations. It\u0026rsquo;s better to just write data manipulation as Arel or plain SQL queries and not use models at all, because if you change the model, your old migrations might break.\nSQL is independent from ActiveRecord model\u0026rsquo;s definitions, queries won\u0026rsquo;t trigger callbacks, and most importantly: any future code changes to a model won\u0026rsquo;t cause you a world of pain.\nWell-written SQL queries can be really fast. Just be careful and make sure you\u0026rsquo;re updating the right things.\nAlways ask yourself: Am I missing a where statement here somewhere?\nSee this nice example from Discourse of a simple data migration:\nclass MigrateAtDesktopBookmarkReminders \u0026lt; ActiveRecord::Migration[6.0] def up DB.exec( \u0026lt;\u0026lt;~SQL, now: Time.zone.now UPDATE bookmarks SET reminder_type = NULL, reminder_at = NULL, updated_at = :now WHERE reminder_type = 0 SQL ) end def down # add some code to revert this migration, if possible end end 3. Strong Migrations (optional) Consider adding the strong_migrations gem to your project and following its suggestions as much as possible. These guidelines will help you catch unsafe migration code during development and teach you some good practices.\nPay special attention to the warnings related to adding indexes and default values to existing columns, as this can cause downtime.\nDoing these things will put you in a good spot and make your life easier in the future.\n  Did you like this article? Then you're gonna love these other ones:\n  New job, new codebase. How do you even get started?   How to Learn the Syntax of a Programming Language When You Know How to Code   Learn Ruby on Rails Best Practices With One Exercise   ","permalink":"https://thdaraujo.github.io/posts/rails-data-migrations/","summary":"You need to change production data. You know that doing it manually is unsafe and will definetely cause lots of trouble, like corrupting all you customer\u0026rsquo;s data.\nHow else should you do it?\nYou might be spending a lot of time asking yourself these questions:\n Is there a proper rails way to change data in production? Should I run data and schema modifications in one database migration? Should I run rake scripts in production to modify data?","title":"How should I change production data on a new Rails application?"},{"content":"My wife and I are launching the greatest podcast in the world and a new site called hexdevs!\nWe\u0026rsquo;ll talk about how to start a business, and how to get better at your craft.\nWe want everyone to be more confident, successful, and smarter, so if you want to become an awesome dev, listen to our podcast and sign up for the mailing list!\nAnd stay tuned!\n  ","permalink":"https://thdaraujo.github.io/posts/podcast/","summary":"My wife and I are launching the greatest podcast in the world and a new site called hexdevs!\nWe\u0026rsquo;ll talk about how to start a business, and how to get better at your craft.\nWe want everyone to be more confident, successful, and smarter, so if you want to become an awesome dev, listen to our podcast and sign up for the mailing list!\nAnd stay tuned!\n  ","title":"hexdevs podcast"},{"content":"The EMR (Elastic Map Reduce) service on Amazon has some nice packages that come pre-installed, and one of them is Apache Zeppelin, which is a Jupyter Notebook interface for Spark.\nZeppelin has interpreters for spark, pyspark, spark-sql and others, but if you want to run spark-sql code on a PostgreSQL database, you need first to install the JDBC interpreter and add some extra configuration to Zeppelin.\nThe JDBC adapter supports a wide variety of database engines, and it allows you to configure multiple database connections, which makes data exploration much easier.\nThe generic JDBC interpreter supports these databases:\n PostgreSQL MariaDB MySQL Redshift Apache Hive  In the next section, I\u0026rsquo;ll explain how to install and configure the JDBC interpreter on Apache Zeppelin.\nInstalling the JDBC Interpreter on Zeppelin When you\u0026rsquo;re creating your EMR cluster on AWS, on the Software Configuration step, make sure to include these applications: Zeppelin 0.8.1, Spark 2.4.0. You can also go to Advanced Options and check all the applications you need. Also, make sure to add an EC2 key pair so you can connect to it with ssh.\nThen, after your cluster is running, connect to it via ssh:\n$ ssh -i [path-to-your-ec2-keypair].pem hadoop@[some-address].compute.amazonaws.com Then run this command to install the jdbc interpreter:\n$ sudo /usr/lib/zeppelin/bin/install-interpreter.sh --name jdbc \u0026gt; Interpreter jdbc installed under /usr/lib/zeppelin/interpreter/jdbc. Restart Zeppelin by running these commands:\n$ sudo stop zeppelin \u0026gt; zeppelin stop/waiting $ sudo start zeppelin \u0026gt; zeppelin start/running, process 24434 PROTIP: this step can also be run as a bootstrap-action for convenience. EMR allows you to define a bash script that is run when creating your EMR cluster and it will be executed when each node is started, once on the master node and once on all the slave nodes. You can define bootstrap actions before creating the EMR cluster.\nNow, in order to run a query, you need to configure the Zeppelin interpreter. To access Zeppelin notebook, first you need to open an ssh tunnel to your EMR cluster and configure a proxy that will safely access the cluster through the ssh tunnel.\nConnecting to EMR with FoxyProxy 6.x In order to access the web tools on your EMR cluster, you need to configure the Web Connection. Go to Amazon EMR \u0026gt; Clusters \u0026gt; click on the cluster you just created, then click on Enable Web Connection. This will explain how to set up an ssh tunnel and configure foxyproxy.\nTo set up the tunnel on port 8157, run:\nssh -i ~/emr-key.pem -ND 8157 hadoop@[master-public-dns-of-your-cluster] Then you need to configure a proxy management tool. The tutorial description on amazon explains how to set up foxyproxy, but this is not up-to-date because foxyproxy doesn\u0026rsquo;t support XML configurations anymore, so you\u0026rsquo;re gonna need to use a json config. To do that, copy this configuration example here and save it as foxyproxy-config.json.\nThen, follow these steps:\n Install the FoxyProxy add-on, then click on the FoxyProxy icon on the top right corner of firefox click on Import On the first section Import Settings from FoxyProxy 6.x (current version), click on Browse Select foxyproxy-config.json and confirm. You\u0026rsquo;re gonna see a new proxy configuration on the foxyproxy list called EMR SOCKS Proxy. Enable the proxy by clicking on the foxyproxy icon on the top right corner of your browser and select Use proxy EMR SOCKS Proxy for all URLs (ignore patterns)  Now you should be able to access any of the web application interfaces running on your EMR cluster, like Zeppelin, Ganglia, and YARN. You can see a list of them here.\nTo access Zeppelin, go to http://[master-public-dns-of-your-cluster]:8890/.\nConfigure Database Connections  On Zeppelin, go to Interpreters http://[master-public-dns-of-your-cluster]:8890/#/interpreter. Click on + Create to configure a new Interpreter Give it a name (like jdbc) to be used on your notes as %jdbc Choose JDBC as the interpreter group Configure the connection properties, like default.url, default.password, default.user and default.driver (if needed) to access your database.  The interesting thing about the JDBC interpreter is that you can define multiple connections to any different type of database by using a prefix instead of the default one and defining an appropriate driver, as described here. As an example, I wanted to connect to three different PostgreSQL databases, so I configured my connections as following:\nDatabase DB1\ndb1.url -\u0026gt; jdbc:postgresql://db1-url:5432/db-name1 (string) db1.password -\u0026gt; ******* (password) db1.user -\u0026gt; db1user (string) db1.driver -\u0026gt; org.postgresql.Driver (string) Database DB2\ndb2.url -\u0026gt; jdbc:postgresql://db2-url:5432/db-name2 (string) db2.password -\u0026gt; ******* (password) db2.user -\u0026gt; db2user (string) db2.driver -\u0026gt; org.postgresql.Driver (string) And so on. The JDBC interpreter uses the driver and the connection details to access the database in a generic way, so it\u0026rsquo;s pretty easy to connect to any kind of database and use the same querying interface. In order to use a different connection on your notebook, you define the interpreter and add a prefix, like so:\n%jdbc(db1) SHOW TABLES; %jdbc(db2) SHOW TABLES; Running Queries To use the generic JDBC interpreter, create a new zeppelin note. Then click on Settings (Interpreter Binding) and enable/bind the JDBC interpreter to your note. You just need to enable jdbc.\nThen, to use the interpreter you just created, create a new paragraph, and define the interpreter and the connection prefix you want to use:\n%jdbc(prefix) SELECT * FROM tableA; In my case:\n%jdbc(db1) SELECT * FROM client; Now you have a simple way to connect and explore different databases in a very simple way. Hope you find it useful!\n  Did you like this article? Then you're gonna love these other ones:\n  Fast ElasticSearch Indexing with Apache Spark on EMR (overview)   ","permalink":"https://thdaraujo.github.io/posts/jdbc-on-emr-zeppelin/","summary":"The EMR (Elastic Map Reduce) service on Amazon has some nice packages that come pre-installed, and one of them is Apache Zeppelin, which is a Jupyter Notebook interface for Spark.\nZeppelin has interpreters for spark, pyspark, spark-sql and others, but if you want to run spark-sql code on a PostgreSQL database, you need first to install the JDBC interpreter and add some extra configuration to Zeppelin.\nThe JDBC adapter supports a wide variety of database engines, and it allows you to configure multiple database connections, which makes data exploration much easier.","title":"Generic JDBC Queries on EMR Zeppelin"},{"content":"I\u0026rsquo;ve been building the data infrastructure for a project and I needed to efficiently query, merge, process and clean terabytes of structured data and then index hundreds of millions of documents on elasticsearch.\nThe problem is that querying and joining data on a RDBMS like Postgres is very painful when you have more than low terabytes of data. You\u0026rsquo;re going to spend a huge amount of time tuning your database, reading query plans, adding indexes, sharding, and slowly moving data around until you have something decent that take hours, days, maybe weeks to run. Trust me, I\u0026rsquo;ve been there.\nBesides, indexing millions of documents on elasticsearch is also complicated, you have to spin up lots of new nodes even when you don\u0026rsquo;t really need to scale your cluster right away. In my case, I just needed fast and efficient bulk indexing, searching and filtering don\u0026rsquo;t need to be super fast because data velocity is not a problem yet, but volume is. Tuning bulk indexing and optimizing memory usage on elasticsearch is not fun either.\nBut I\u0026rsquo;m an impatient developer, and I need my stuff right now. The only way to do that is by liberating the data and moving it to a large hadoop cluster.\nNowadays, with Amazon EMR (Elastic Map Reduce) and spot instances, it\u0026rsquo;s really, really cheap to just spin up a cluster with hundreds of nodes and run your big data processing job in a very cost-efficient way. And you don\u0026rsquo;t even have to manage it, EMR has templates with pre-installed tools, like Apache Sqoop, Spark and Hadoop.\n  light speed is too slow, we\u0026rsquo;re gonna have to go right to Ludicrous Speed!\n  Why you should consider this approach? It\u0026rsquo;s really cheap! I have a couple of jobs that are memory-heavy, and I run them on Spark. One of them runs on a cluster with 41 r4.2xlarge instances, each one of them has 8 vCPUS and 61GB of memory, so that\u0026rsquo;s a total of 328 CPUs and 2.5Tb of memory. Neat, huh?\nThey\u0026rsquo;re all spot instances that I can rent and pay $0.14 per hour, so running the cluster costs $6 dollars per hour :moneybag::moneybag::moneybag:. It may look like a lot, but here\u0026rsquo;s the cool thing about it: my job runs in about 30 minutes. After that, I just kill the cluster.\nIt\u0026rsquo;s really fast! Compared to the process we had before (SQL, logstash, some elixir code, and some bash scripts), I calculated it would take more than a month to run the whole thing and index all the data (yeah, it\u0026rsquo;s very slow). And this is assuming that one server would even be able to handle it (I bet it wouldn\u0026rsquo;t), and I\u0026rsquo;m not even considering the time it would take me to fix and optimize the whole process just to make it run properly and consistently.\nAmazon even has a service right now called AWS Glue that abstracts away the whole cluster thing, so you just pay by the hour to run your Spark jobs, pretty much like Lambda. And if you prefer Google cloud, they also have some options too.\nIn my case, I can spin up the EMR cluster and let it crunch some terabytes of data while I brew my coffee, and spend just $6 dollars. That\u0026rsquo;s a huge improvement for an impatient dev like myself. After all, time is a very precious thing.\nSometimes running Hadoop and Spark is overkill, but for this problem it was a no-brainer: one person can build the whole map-reduce job and manage the cluster easily, and just move the final data to S3 when finished. So if you have a problem like that, you should seriously consider if a proper big data tool could be a better solution than your current one.\n  Did you like this article? Then you're gonna love these other ones:\n  Generic JDBC Queries on EMR Zeppelin   ","permalink":"https://thdaraujo.github.io/posts/elasticsearch-indexing-with-spark-overview/","summary":"I\u0026rsquo;ve been building the data infrastructure for a project and I needed to efficiently query, merge, process and clean terabytes of structured data and then index hundreds of millions of documents on elasticsearch.\nThe problem is that querying and joining data on a RDBMS like Postgres is very painful when you have more than low terabytes of data. You\u0026rsquo;re going to spend a huge amount of time tuning your database, reading query plans, adding indexes, sharding, and slowly moving data around until you have something decent that take hours, days, maybe weeks to run.","title":"Fast ElasticSearch Indexing with Apache Spark on EMR (overview)"},{"content":"An interesting quote about the unexpected effects of actions and the limitations of rationality and the planning fallacy:\n A net set up to catch fish may snare a duck; a mantis hunting an insect may itself be set upon by a sparrow.\n  Machinations are hidden within machinations; changes arise beyond changes. So how can wit and cleverness be relied upon?\n \u0026ndash; Back to Beginnings, Reflections on the Tao by Huanchu Daoren, translated by Thomas Cleary. They were written around 1600 by a retired Chinese Scholar, Hong Yingming, whose Taoist name, Huanchu Daoren, means “A Wayfarer Back to Beginnings.”\n  ","permalink":"https://thdaraujo.github.io/posts/machinations/","summary":"An interesting quote about the unexpected effects of actions and the limitations of rationality and the planning fallacy:\n A net set up to catch fish may snare a duck; a mantis hunting an insect may itself be set upon by a sparrow.\n  Machinations are hidden within machinations; changes arise beyond changes. So how can wit and cleverness be relied upon?\n \u0026ndash; Back to Beginnings, Reflections on the Tao by Huanchu Daoren, translated by Thomas Cleary.","title":"Machinations"},{"content":"The Collatz Conjecture is a simple mathematical problem that still has no formal proof. So it\u0026rsquo;s an open problem.\nThis is how it works:\nChoose any positive integer x. While x \u0026gt; 0, do: if x is even, divide it by 2 (x = x/2) if x is odd, multiply it by 3 and add 1 (x = 3x + 1) The Collatz Conjecture states that no matter what value of x you start with, the sequence will always reach x = 1.\nExample:\nIf x = 10, you get the following sequence: [10, 5, 16, 8, 4, 2, 1].\nIf x = 77, you get the following collatz sequence: [77, 232, 116, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1].\nIn other words, it doesn\u0026rsquo;t matter the initial value you pick for x, you always end up going back to x = 1.\nA ruby implementation would look like this:\ndef collatz n seq = [n] until n == 1 n = (n.even?) ? (n / 2) : (3 * n + 1) seq \u0026lt;\u0026lt; n end seq end A Haskell implementation[1] could look like this:\nchain :: (Integral a) =\u0026gt; a -\u0026gt; [a] chain 0 = error \u0026#34;Invalid!\u0026#34; chain 1 = [1] chain x | even x = x:chain (x `div` 2) | odd x = x:chain (x*3 + 1) [1] Source: a gist that is not available anymore.\n  Did you like this article? Then you're gonna love these other ones:\n  New job, new codebase. How do you even get started?   How to Learn the Syntax of a Programming Language When You Know How to Code   Learn Ruby on Rails Best Practices With One Exercise   ","permalink":"https://thdaraujo.github.io/posts/collatz-conjecture/","summary":"The Collatz Conjecture is a simple mathematical problem that still has no formal proof. So it\u0026rsquo;s an open problem.\nThis is how it works:\nChoose any positive integer x. While x \u0026gt; 0, do: if x is even, divide it by 2 (x = x/2) if x is odd, multiply it by 3 and add 1 (x = 3x + 1) The Collatz Conjecture states that no matter what value of x you start with, the sequence will always reach x = 1.","title":"Collatz Conjecture"},{"content":"Would you like to become an expert developer? Are you struggling to develop your software engineering skills and advance your career? Do you feel that you hit a plateau?\nImproving your skills as a software engineer can be quite hard if you don\u0026rsquo;t know where to look, or what to do next.\nYou are not alone.\nIn college, no one taught you how to become an expert developer. Or how to make the best decisions to help your team succeed.\nNo one told you how to ship code faster. How to talk to a client or understand a customer.\nMost importantly: no one showed you how to avoid software project failures.\nThat\u0026rsquo;s exactly what this blog is all about: how to win as a software engineer.\nI offer tools, exercises, workshops, and tips to help you become an expert developer. Learn how to:\n Understand and empathize with your customers/users Get better at communication and help your team succeed Write and ship professional, maintainable code, and improve your existing codebase Practice the skills every professional developer requires and build confidence in your abilities  How can I help you? Hi 👋 I\u0026rsquo;m Thiago Araujo (thd), nice to meet you!\nI\u0026rsquo;m a software engineer, entrepreneur, and educator.\nI\u0026rsquo;m on a mission to help developers grow and get better at their software engineering skills.\nThe world doesn\u0026rsquo;t need more ninjas, gurus, or wizards. It needs professional developers.\nDevelopers who are kind and humble. Who can build better software to help more people and improve society.\nI write on the hexdevs newsletter about Software Development. Sign up here. 📧\nTalks and Podcasts I’ve done a few talks and interviews about Software Development:\n Code with Jason #143 with Stefanni Brasil and Thiago Araujo, co-creators of hexdevs - Code with Jason Podcast. Get to Senior with Stefanni Brasil and Thiago Araujo (hexdevs) - The Ruby on Rails Podcast. Discussing Tech Careers with Thiago Araujo and Stefanni Brasil of hexdevs - Remote Ruby Podcast. Learn Ruby on Rails Best Practices With One Exercise 🍝 - Vanruby Meetup. Ruthless Prioritization - Polyglot Podcast. Carbon-Neutral Rails - Vanruby Meetup.  Quick facts about me Living in Vancouver, Canada. 🏞️\nI\u0026rsquo;ve been working as a software engineer since 2010.\nI\u0026rsquo;ve built products for many early-stage startups. Started a consulting firm to build digital products for companies following Agile practices.\nI\u0026rsquo;m the co-founder of hexdevs where I help developers build expertise by running workshops, mentoring, sharing knowledge, and giving talks.\nI ❤️ Ruby and Elixir.\nI write about software development here at ☄️hexdevs.\nI co-host the 🎙️hexdevs podcast with Stefanni Brasil.\nPreviously @patch, @commit.dev, @cto.ai, @predictable-revenue.\nI have a degree in Computer Science, was pursuing a Master\u0026rsquo;s in CompSci. I also have done research in the field of AI.\n 📫 How to reach me: @thdaraujo 😄 Pronouns: he/him 🗨️ How to pronounce my name: /chee-AH-go/ ⚡ Fun fact: My parents were smugglers of computer parts back in the 90s in Brazil (ask me about their story!) 🚲 Hobbies: photography, hiking, cycling, cooking, and calligraphy.  ","permalink":"https://thdaraujo.github.io/about/","summary":"Would you like to become an expert developer? Are you struggling to develop your software engineering skills and advance your career? Do you feel that you hit a plateau?\nImproving your skills as a software engineer can be quite hard if you don\u0026rsquo;t know where to look, or what to do next.\nYou are not alone.\nIn college, no one taught you how to become an expert developer. Or how to make the best decisions to help your team succeed.","title":"about me"},{"content":"","permalink":"https://thdaraujo.github.io/search/","summary":"search","title":"Search"}]