class: center, middle, inverse, title-slide .title[ # Vibe Coding
✨
The Art of Coding with Flow ] .author[ ### S. Mason Garrison ] --- layout: true <div class="my-footer"> <span> <a href="https://DataScience4Psych.github.io/DataScience4Psych/" target="_blank">Data Science for Psychologists</a> </span> </div> --- # Hello world! --- class: middle # Learning Goals --- ## Learning Goals By the end of this session, you will be able to... - Define vibe coding and explain how it enhances the coding experience - Use AI tools (GitHub Copilot, ChatGPT, Claude) to write code with better flow and aesthetics - Apply the five core principles of vibe coding to your R programming practice - Leverage AI assistance to achieve flow state and improve code quality - Evaluate when AI-assisted coding enhances vs. hinders the vibe --- class: middle # What is Vibe Coding? --- ## Vibe Coding Defined .large[ **Vibe coding** is a programming philosophy that emphasizes: ] -- - ✨ **Aesthetic pleasure** in writing code -- - 🌊 **Flow state** and intuitive development -- - 🎨 **Elegance** over complexity -- - 🎵 **Rhythm** in your coding process -- .large[ It's about making the *journey* of coding as enjoyable as the destination. ] --- ## The Philosophy Behind Vibe Coding .pull-left[ **Traditional Coding:** - Focus on solving problems - Efficiency first - "Get it working" - Technical correctness ] -- .pull-right[ **Vibe Coding:** - Focus on the experience - Joy and flow first - "Make it feel good" - Aesthetic harmony - *Then* optimize ] -- <br> .large[ 💡 **Key Insight:** When coding feels good, you code better! ] --- class: middle # Core Principles of Vibe Coding --- ## Principle 1: Embrace the Flow 🌊 .large[ **Flow state** is when you're completely immersed in your work. ] -- **How to achieve flow in coding:** -- - Minimize distractions (notifications off 🔕) -- - Choose tasks that match your skill level -- - Set clear, achievable goals for each session -- - Use tools that feel natural and responsive -- .tip[ **Tip:** Set up your environment before you start. Good music 🎧, comfortable setup, and a clear plan help you enter flow faster. ] --- ## Principle 2: Code with Intention 🎯 .large[ Every line of code should have a clear purpose and feel right. ] -- **Bad vibe code:** ``` r # Unclear, rushed code x <- filter(data, a > 5) y <- select(x, b, c, d) z <- mutate(y, e = b * c) ``` -- **Good vibe code:** ``` r # Clear, intentional pipeline analysis_data <- raw_data %>% filter(age > 5) %>% select(participant_id, response_time, accuracy) %>% mutate(performance_score = response_time * accuracy) ``` -- .large[ ✅ The second version tells a story and feels right to read! ] --- ## Principle 3: Aesthetics Matter 🎨 .large[ Beautiful code is easier to understand and maintain. ] -- .pull-left[ **Elements of aesthetic code:** - Consistent formatting - Meaningful names - Balanced spacing - Visual alignment - Color-coded syntax ] -- .pull-right[ **Benefits:** - Easier to read - Fewer bugs - More enjoyable - Better collaboration - Faster debugging ] --- ## Principle 4: Trust Your Intuition 🤔 .large[ If code feels awkward to write, it probably needs refactoring. ] -- **Listen to your gut:** -- - Does this function name make sense? ❓ -- - Is this too complex for what it does? 😕 -- - Would I understand this tomorrow? 📆 -- - Does this feel elegant or clunky? ⚖️ -- <br> .large[ ⭐ **Remember:** Your intuition improves with experience! ] --- ## Principle 5: Create a Vibe-Friendly Environment 🏠 .large[ Your coding environment affects your vibe. ] -- **Physical setup:** - Comfortable chair and desk - Good lighting (natural or warm) - Plants or personal touches 🌰 - Clean, organized space -- **Digital setup:** - Pleasing color theme - Organized file structure - Helpful keyboard shortcuts - Background music (if it helps) --- class: middle # AI Tools for Vibe Coding --- ## AI as Your Vibe Coding Partner 🤖 .large[ AI tools can enhance your vibe coding experience when used thoughtfully. ] -- **Popular AI coding assistants:** -- .pull-left[ **GitHub Copilot** - Inline code suggestions - Context-aware completions - Maintains your flow state - Learns your coding style ] -- .pull-right[ **ChatGPT / Claude** - Code explanation & refactoring - Debugging assistance - Pattern suggestions - Documentation help ] --- ## When AI Enhances the Vibe ✨ .large[ AI tools work best when they support your flow, not interrupt it. ] -- **Good vibe AI use:** -- - ✅ **Autocomplete mundane code** - Let AI handle boilerplate while you focus on logic -- - ✅ **Suggest better names** - "What's a clearer name for this function?" -- - ✅ **Refactor for clarity** - "How can I make this more readable?" -- - ✅ **Explain complex code** - Understanding beats copy-pasting -- - ✅ **Generate test cases** - AI excels at creating thorough examples --- ## When AI Kills the Vibe ❌ .large[ Beware of AI anti-patterns that disrupt flow. ] -- **Bad vibe AI use:** -- - ❌ **Accepting without understanding** - Code you can't explain isn't yours -- - ❌ **Over-reliance on suggestions** - Kills your creative flow -- - ❌ **Using outdated patterns** - AI may suggest old approaches -- - ❌ **Copying complex logic blindly** - Recipe for future debugging pain -- .large[ 💡 **Remember:** You're the architect, AI is your assistant! ] --- ## Vibe Coding with GitHub Copilot .large[ Copilot can maintain flow when configured properly. ] -- **Vibe-enhancing Copilot workflow:** .midi[ ``` r # 1. Write a clear comment about your intent # Calculate average response time by participant group # 2. Let Copilot suggest, but review carefully response_data %>% group_by(participant_group) %>% summarise( avg_response_time = mean(response_time_ms, na.rm = TRUE), n = n() ) # 3. Refine the suggestion to match your style # 4. Keep coding with momentum! ``` ] -- .tip[ **Pro tip:** Use Copilot for structure, add your own variable names for clarity. ] --- ## Vibe Coding with ChatGPT/Claude .large[ Use conversational AI for bigger picture vibe improvements. ] -- **Example conversation:** .pull-left[ **You:** "I have this code that works but feels clunky. How can I make it more elegant?" ``` r for (i in 1:nrow(data)) { if (data$age[i] > 18) { data$adult[i] <- "yes" } else { data$adult[i] <- "no" } } ``` ] -- .pull-right[ **AI:** "Here's a more 'vibe-friendly' approach using tidyverse:" ``` r data <- data %>% mutate( adult = if_else( age > 18, "yes", "no" ) ) ``` ] --- ## The Vibe Coding AI Workflow ♻️ .large[ Integrate AI smoothly into your coding rhythm. ] -- **The cycle:** 1. 💭 **Think** - Clarify your intent first -- 2. ⌨️ **Code** - Start writing with your own understanding -- 3. 🤖 **Assist** - Let AI suggest improvements or completions -- 4. 👀 **Review** - Does the AI suggestion feel right? -- 5. 🎨 **Refine** - Adapt to your style and standards -- 6. ✅ **Test** - Verify it works as expected -- <br> .large[ ✨ **This workflow maintains YOUR vibe while leveraging AI power!** ] --- ## AI for Code Review and Refactoring .large[ AI excels at suggesting vibe improvements to existing code. ] -- **Ask AI to:** - "Review this function for readability" - "Suggest better variable names" - "How can I make this more idiomatic in R?" - "What edge cases am I missing?" - "Refactor this to use tidyverse patterns" -- **Example prompt:** ``` "I wrote this code for data cleaning. Can you suggest improvements for readability and maintainability while keeping the tidyverse style?" ``` --- ## Prompt Engineering for Vibe Coding .large[ Good prompts lead to good vibes. ] -- **Vibe-friendly prompts:** -- .pull-left[ **Specific:** - "Write a function to calculate Z-scores that follows tidyverse style" - "Refactor this loop into a purrr::map() call" ] -- .pull-right[ **Context-aware:** - "Using ggplot2, create an elegant visualization of..." - "In the style of the tidyverse, how would you..." ] -- **Include your constraints:** ``` "Create a readable function for [task] that: - Uses descriptive variable names - Includes error handling - Follows tidyverse conventions - Has a clear return value" ``` --- ## Maintaining Your Vibe with AI .large[ Stay in control of the coding experience. ] -- **Best practices:** -- 1. **Set boundaries** - Decide when to use AI vs. code independently -- 2. **Maintain ownership** - Understand every line AI suggests -- 3. **Preserve your style** - Adapt AI suggestions to your aesthetic -- 4. **Stay critical** - Question AI recommendations -- 5. **Learn continuously** - Use AI to discover new patterns, not replace learning -- <br> .large[ ⚖️ **Balance: AI as enhancer, not replacement** ] --- class: middle # Vibe Coding in R and Data Science --- ## The Tidyverse: Vibe Coding Champion 🏆 .large[ The tidyverse embodies vibe coding principles! ] -- **Why the tidyverse has good vibes:** ``` r # Reads like a sentence, flows naturally starwars %>% filter(!is.na(height)) %>% group_by(species) %>% summarise( avg_height = mean(height), count = n() ) %>% arrange(desc(avg_height)) ``` -- .large[ ✨ The pipe operator `%>%` creates natural flow and rhythm! ] --- ## Example: Data Cleaning with Good Vibes .pull-left[ **Without vibe:** ``` r d <- read.csv("data.csv") d <- d[complete.cases(d),] d$x2 <- d$x * d$x d <- d[d$y > 0,] names(d)[3] <- "z" ``` ] -- .pull-right[ **With vibe:** ``` r clean_data <- read_csv("data.csv") %>% drop_na() %>% mutate(x_squared = x^2) %>% filter(response > 0) %>% rename(score = original_score) ``` ] -- <br> .large[ ✅ The second version flows, tells a story, and feels satisfying to write! ] --- ## Visualization: Where Vibe Really Shines 🌈 .midi[ Creating beautiful visualizations is peak vibe coding! ] -- .midi[ ``` r ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g, color = species)) + geom_point(alpha = 0.7, size = 3) + scale_color_viridis_d() + theme_minimal(base_size = 14) + labs( title = "Palmer Penguins: Body Mass vs. Flipper Length", x = "Flipper Length (mm)", y = "Body Mass (g)", color = "Species" ) ``` ] -- .large[ 🎨 Building plots layer by layer has a satisfying rhythm! ] --- ## Function Writing: The Vibe Way .large[ Well-named, single-purpose functions are pure vibe. ] -- .midi[ **Bad vibe function:** ``` r f <- function(x, y, z) { a <- x + y b <- a * z c <- sqrt(b) return(c) } ``` ] -- .midi[ **Good vibe function:** ``` r calculate_performance_score <- function(accuracy, speed, weight = 1.0) { raw_score <- accuracy + speed weighted_score <- raw_score * weight normalized_score <- sqrt(weighted_score) return(normalized_score) } ``` ] -- .large[ ✨ Clear names and structure = good vibes! ] --- class: middle # Practical Vibe Coding Tips --- ## Tip 1: Use Consistent Style 🎨 .large[ Pick a style guide and stick to it. ] -- **Popular R style guides:** - [Tidyverse Style Guide](https://style.tidyverse.org/) - Google's R Style Guide - Your own consistent approach --- # Key style elements: ``` r # Good spacing result <- function_name(argument1 = value1, argument2 = value2) # Clear structure if (condition) { action() } else { alternative_action() } # Meaningful names user_age <- calculate_age(birth_date) ``` --- ## Tip 2: Comment with Purpose 📝 .large[ Comments should add value, not clutter. ] -- .pull-left[ **Bad comments:** ``` r # Add 1 to x x <- x + 1 # Loop through data for (i in 1:10) { # Print i print(i) } ``` ] -- .pull-right[ **Good comments:** ``` r # Adjust for zero-indexing position <- position + 1 # Process each participant # Note: Excluding participant 7 # due to equipment failure for (id in valid_participants) { analyze_responses(id) } ``` ] --- ## Tip 3: Take Breaks ☕ .large[ Vibe coding isn't about grinding—it's about quality time with code. ] -- .pull-left[ **The Pomodoro Vibe:** - Code for 25-50 minutes - Take a 5-10 minute break - Repeat with good energy ] .pull-right[ **Benefits:** - Maintains mental freshness - Prevents burnout - Keeps the creative flow going - Better problem-solving ] -- .tip[ **Pro tip:** Some of your best coding insights come *during* breaks! 💡 ] --- ## Tip 4: Refactor with Joy ♻️ .large[ Refactoring is not a chore—it's an art form! ] -- **Refactoring opportunities:** - Repetitive code → Functions - Nested conditionals → Guard clauses - Long functions → Smaller, focused functions - Cryptic names → Descriptive names --- **The refactoring vibe:** ``` r # Before: Repetitive and dull mean_height <- mean(data$height) mean_weight <- mean(data$weight) mean_age <- mean(data$age) # After: Elegant and satisfying summary_stats <- data %>% summarise(across(c(height, weight, age), mean)) ``` --- ## Tip 5: Celebrate Small Wins 🎉 .large[ Acknowledge your progress, no matter how small! ] -- **Celebrate when you:** - Write an elegant function ✅ - Fix a tricky bug 🐛 - Create a beautiful visualization 🎨 - Refactor messy code ✨ - Learn something new 📚 -- <br> .large[ ⭐ **Remember:** Programming is a journey, enjoy each step! ] --- class: middle # Common Vibe Killers (and How to Fix Them) --- ## Vibe Killer 1: Analysis Paralysis 🤔 .large[ **Problem:** Overthinking before starting ] -- **The fix:** - Start with a minimal viable solution - Iterate and improve - "Done is better than perfect" (then refine) -- ``` r # Don't wait for the perfect approach # Start simple: preliminary_result <- data %>% filter(condition == "treatment") %>% summarise(mean_score = mean(score)) # Then enhance: # Add error handling, visualization, etc. ``` --- ## Vibe Killer 2: Error Frustration 😡 .large[ **Problem:** Errors killing your flow ] -- **The fix:** - Errors are learning opportunities 📚 - Read error messages carefully - Break the problem into smaller pieces - Take a short walk if stuck -- .tip[ **Pro tip:** Keep a "solved errors" notebook. Future-you will thank present-you! 📓 ] --- ## Vibe Killer 3: Comparison 👀 .large[ **Problem:** Comparing yourself to others ] -- **The fix:** - Focus on your own progress - Everyone starts somewhere - Celebrate your unique coding style - Learn from others, don't compete -- <br> .large[ 🌈 **Your vibe is unique—embrace it!** ] --- ## Vibe Killer 4: Messy Environment 🌪 .large[ **Problem:** Cluttered workspace or code ] -- **The fix:** ``` r # Regular cleanup ritual # 1. Archive old experiments archive/ old_analysis_v1.R abandoned_approach.R # 2. Organize current work scripts/ 01_data_cleaning.R 02_exploratory_analysis.R 03_modeling.R # 3. Clear working directory rm(list = ls()) # But save important objects first! ``` --- class: middle # Building Your Vibe Coding Practice --- ## Start Your Vibe Coding Journal 📓 .large[ Track your coding journey and insights. ] -- **What to include:** - Elegant code snippets you're proud of - Problems solved and how - New techniques learned - Moments of flow and insight - Personal coding preferences -- **Benefits:** - Reinforces learning - Creates a personal reference - Shows your progress - Identifies patterns in your work --- ## Find Your Coding Rhythm 🎵 .large[ Discover when and how you code best. ] -- **Questions to explore:** - What time of day do you feel most creative? - Does music help or hinder? (If yes, what type?) - Short bursts or long sessions? - Morning freshness or evening focus? -- **Experiment and adjust:** - Try different schedules - Test various environments - Notice what feels best - Honor your natural rhythms --- ## Build a Vibe Coding Community 👥 .large[ Share the vibe with others! ] -- **Ways to connect:** - Join R communities (R-Ladies, local R user groups) - Share your code and visualizations - Participate in TidyTuesday - Attend coding meetups - Pair program with friends -- <br> .large[ ❤️ **Good vibes are contagious!** ] --- class: middle # Vibe Coding Challenges --- ## Your Turn: Vibe-ify This Code 🔧 .your-turn[ Take this code and improve its vibe: .pull-left[ ``` r d <- read.csv("data.csv") d <- d[d$age > 18,] d$bmi <- d$weight / (d$height^2) m <- mean(d$bmi) print(m) ``` ] .pull-right[ **Consider:** - Variable names - Readability - Flow - Comments (if needed) ] ] --- **Possible solution on next slide...** --- ## Vibe-ified Solution ✨ ``` r # Calculate BMI for adult participants participant_data <- read_csv("data.csv") %>% filter(age > 18) %>% mutate( bmi = weight_kg / (height_m^2) ) # Summary statistics average_bmi <- participant_data %>% summarise(mean_bmi = mean(bmi, na.rm = TRUE)) %>% pull(mean_bmi) # Report findings glue::glue("Average BMI for adult participants: {round(average_bmi, 2)}") ``` -- .large[ ✅ Much better vibe! Clear, readable, and purposeful. ] --- class: middle # Advanced Vibe Coding --- ## Vibe Coding with Projects 📁 .large[ Good project structure = sustained good vibes ] -- **Example R project structure:** ``` my_analysis/ ├── data/ │ ├── raw/ │ └── processed/ ├── scripts/ │ ├── 01_import.R │ ├── 02_clean.R │ └── 03_analyze.R ├── outputs/ │ ├── figures/ │ └── tables/ ├── R/ │ └── custom_functions.R └── README.md ``` --- ## Vibe Coding with Version Control 💾 .large[ Git commits can have good vibes too! ] -- **Bad commit messages:** ``` "fixed stuff" "asdf" "final version" "FINAL VERSION 2" ``` -- **Good vibe commit messages:** ``` "Add data cleaning pipeline for survey responses" "Improve visualization color scheme for accessibility" "Refactor analysis functions for clarity" "Document assumptions in modeling approach" ``` -- .tip[ **Tip:** Write commit messages your future self will appreciate! 📆 ] --- ## Vibe Coding with Collaboration 🤝 .large[ Spread good vibes to your team! ] -- **Best practices:** - Write code others can understand - Document your reasoning - Be open to feedback - Share your discoveries - Celebrate team wins -- **Code review mindset:** - Assume positive intent - Ask questions, don't criticize - Offer suggestions, not demands - Learn from each other --- class: middle # The Future of Your Vibe Coding Journey --- ## Growing Your Vibe 🌱 .large[ Vibe coding is a practice, not a destination. ] -- **Continue to:** - Experiment with new approaches - Refine your personal style - Stay curious and playful - Share your knowledge - Keep learning -- **Remember:** - There's no "perfect" vibe - Your vibe will evolve - What matters is enjoying the journey - Code with intention and joy --- ## Resources for Vibe Coders 📚 **Learning resources:** - [R for Data Science](https://r4ds.had.co.nz/) - The vibe-friendly intro - [Tidyverse Style Guide](https://style.tidyverse.org/) - For consistent aesthetics - [The Programmer's Brain](https://www.manning.com/books/the-programmers-brain) - Understanding flow - [#TidyTuesday](https://github.com/rfordatascience/tidytuesday) - Weekly practice -- **Community:** - [RStudio Community](https://community.rstudio.com/) - [R-Ladies](https://rladies.org/) - [R4DS Online Learning Community](https://www.rfordatasci.com/) --- class: middle # Summary: Learning Goals Achieved --- ## What We've Learned Today, you should now be able to... .pull-left[ ### Concepts - ✅ Define vibe coding philosophy - ✅ Five core principles - ✅ AI tools for vibe coding - ✅ Vibe-friendly workflows ] .pull-right[ ### Skills - ✅ Use GitHub Copilot effectively - ✅ Prompt ChatGPT/Claude for better code - ✅ Achieve flow state while coding - ✅ Refactor with intention and aesthetics - ✅ Evaluate AI suggestions critically ] --- ## Summary: The Vibe Coding Manifesto 📜 .large[ **We believe:** ] 1. Code should be a joy to write and read 2. Aesthetics and clarity matter 3. Flow state enhances creativity 4. Small, intentional improvements compound 5. The journey is as important as the destination 6. Good vibes lead to better code 7. Community makes us all better -- <br> .large[ ✨ **Now go forth and code with good vibes!** ✨ ] --- class: middle, center # Questions? ❓ --- ## Contact Information - Email: _garrissm@wfu.edu_ - Website: [smasongarrison.com](https://www.smasongarrison.com) - GitHub: [github.com/smasongarrison](https://github.com/smasongarrison) <br> .large[ 🙏 **Happy vibe coding!** 💻 ]