• 0 Posts
  • 113 Comments
Joined 1 year ago
cake
Cake day: June 12th, 2023

help-circle







  • Funny, the forced indentation is what I hate about Python. If you think a missing semicolon can be hard to catch, don’t ever think about a missing whitespace :p

    The end keyword really isn’t a big deal for me. I find it to be a good way to easily spot the end of a method. But if you wouldn’t like it I’d still find it a good compromise to avoid syntax issues due to whitespace.


  • I think you’ll like Ruby. It has mostly done away with braces and code blocks end with end, e.g.

    def create
      unless admin redirect_to new_session_path and return
      
      @product = Product.new product_params
    
      if @product.save
        flash[:success] = "New product has been created!"
        redirect_to edit_product_path(@product) and return
      else
        flash[:error] = "Something went wrong!
        render :new
      end
    end
    

    This is working code that I simplified a bit from an old project of mine.







  • Code should always by itself document the “how” of the code, otherwise the code most likely isn’t good enough. Something the code can never do is explain the “why” of the code, something that a lot of programmers skip. If you ever find yourself explaining the “how” in the comments, maybe run through the code once more and see if something can be simplified or variables can get more descriptive names.

    For me, that’s what was originally meant with self-documenting code. A shame lazy programmers hijacked the term in order to avoid writing any documentation.