Laracon Online 2019 Notes and Thoughts

Dan Holloran Avatar Dan Holloran • March 7, 2019

These are my notes from Laracon 2019 was an interesting conference and a lot of fun. I think you may still be able to buy tickets to access the recordings at https://laracon.net/. It is nice being online not having to travel makes it easier to go.

Getting started with event sourcing in Laravel

Writing less complex, more readable code

  • Jason McCreary @gonedark
  • Code quality level how many WTFs per minute
  • Martin Fowler - Refactoring

Guidelines for good code

  • Formatting
    • Consitency matters
    • Choose it, automate it and forget it
    • Use community standard if possible
    • https://styleci.io/
  • Dead code
    • Why is it here and why is it not used
    • Commented code just remove it
    • Unused variables
    • Boy Scouting - Leave it better than you found it
    • Unreachable code may be harder to see in larger blocks
    • Unnecessary syntax. Such as a switch with just returns break is not needed and never for default
    • Flagged code some sort of state such as promotion or coupon code
    • If you encounter it remove it
    • Make sure primary action is at top level. Helpful to early return aka guard clause
  • Nested Code
    • Avoid else where possible
    • Avoid nested code
  • Using objects
    • Pass objects of grouped date (data clump) if possible over simple types (int,string,etc.)
      • Use value objects basically a class with private props and getters no setters allows it to be immutable
    • Allows for adding methods to abstract complex logic
    • Options array are abused in PHP and do not have a specific structure makes it untidy hard to know all options
    • Use enums to reduce options to allowed values.
  • Big blocks
    • Leverage framework when possible
      • Validation → form request
      • Model look up → implicit model binding
    • For top level methods such as a controller try to make as simple as possible
  • Naming
    • Two hardest things in programming naming, cache invalidation and off by 1 errors
    • don't be a special snowflake use language conventions
    • Foreach use plural and singular make it specific to context
    • No need to over abbreviate
    • Try to relay human aspects $str_error$error_message
    • Start with technical name and allow time to come up with something better
    • Use a thesaurus
  • Removing comments

    • Misleading comments are confusing
    • Comments can be skipped over
    • Attempt to improve the code over comments
    • Doc Blocks ≠ Comments they server documentation purposes
    • Look for inline comments that explain exactly what the code is doing such as // date for yesterday
    • Proximity rule take variables closer to where they are being used makes it easier to tie it together
    • If comment is relaying why this are still important
  • Reasonable returns
    • Return something other than null
    • Possibly return a mock or null object that behaves like the real object
      • UserGuestUser
  • Rule of three
    • Wait until ~3 duplications before abstracting to avoid over engineering
    • Helps you find the correct solution
    • Make sure names align.
  • Symetry
    • Naming and thinks like keeping methods with methods
    • Keep object access level consistent
    • Keep not checks the same

Realtime applications with Laravel

What's New in React

  • Wes Bos @wesbos
  • Slides: https://wesbos.github.io/Whats-New-In-React/#1
  • Context API
    • React context allows you to pas data down multiple levels the need to pass through props at each level
    • Prop drilling passing props down through multiple components
    • Allows for injecting a consumer into a component one solution for global shared data
    • It relies on a parent provider component
    • Good for medium sized applications
  • Fragements
    • Fixes extra <div>s since you can not have more than one html element in a component.
    • Fixes descendent selectors since you do not need a wrapping <div>
    • Does Vue have a solution for this?
  • Error boundaries
    • Handles not being able to try/catch in JSX
  • Refs
    • Escape hatch for getting DOM elements. Seems to be like Vue.js this.$refs
    • Helpful for wrapping older plugins/code
  • Portals
    • Useful for modals and what not
    • Somewhat like a built in version of Portal Vue
    • Can be used to handle tags out side of the React root element
  • Suspense (Coming Soon)
    • Waiting for things to load before rendering
    • Helps with code splitting, data fetching and images
    • Decouples loading ui from components
    • Minimizes loaders on faster connections
  • Hooks
    • New way to write state and other things without classes

Exploring Laravel 5.8

  • Taylor Otwell @taylorotwell
  • hasOneThrough relationship
    • Basically handles accessing has one relationship has one relationship $supplier→account→history to $supplier→accountHistory
  • Auto discovering of model policies
  • Supports hashing API tokens with sha256 for simple API authentication without using Laravel Passport. Basically for Bearer Token API instead of oAuth.
  • Pivot models dispatch model events
    • Not new but custom pivot models are pretty cool
  • Default scheduler timezone
  • Artisan in code simplification can pass like you would on the command line
  • Testing mock helpers cleans up mocking then replacing in the container
  • orWhere() higher order function helps remove callbacks on orWhere scopes.
  • Atomic lock process running longer than requested fixed
  • Artisan serve adds port scanning to allow for multiple instances
  • Improvements to Redis blocking pop allows pinging of Redis block time. Still allows queues to be processed quickly

Laravel, the Blockchain, and You!

  • Samantha Geitz @SamanthaGeitz
  • Slides: https://speakerdeck.com/samanthamichele7/laravel-the-blockchain-and-you
  • Should i use blockchain probably not unless you are solving a specific problem
  • Blockchain is decentralized multiple servers with entire copy of database
  • Add new blocks that shows how the data should change
  • Somewhat like Git more in the way the changes are tracked

    • It is slow and comparatively expensive then a MySQL database
    • If you cant do it on a smartphone from 1999 probably shouldn't do it
    • Helps solve currency forging and other issues
    • You can buy or "mine" them
    • Needs a private key and public to access much like SSH Keys
    • Mining incentivizes integrity of the network
    • Ethereum is meant to build decentralized apps and built in JavaScript
      • Used to solve Xbox game publisher royalties
        • Went from ~45 days to almost immediately
        • Reduced publishers cost 99% and cut Microsofts in half
      • Webjet a travel company
        • Problem is double booking/disputes about 5% annually
    • Possible good use cases
      • Voting app
      • DRM management of video/games
      • Verifying identity of participants is important financial, legal, doctor
    • Bad use cases
      • Most things
      • Data is in constant flux
      • If you want ability to add/edit records
      • Speed/performance important
    • Tools

Databases in space

Practical Solutions to Common UI Design Problems

Tailwind CSS by Example