Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Created November 20, 2011 20:05
Show Gist options
  • Save AndrewVos/1380805 to your computer and use it in GitHub Desktop.
Save AndrewVos/1380805 to your computer and use it in GitHub Desktop.

SRP

SRP kind of implies that each class has only one public method, and perhaps multiple supporting private methods.

What if our language forced this?

Reading files

ReadsFiles
  path

  execute
    # return file contents
  end
end

file_text = ReadsFile("file.txt")!

See how we only have one usage? Could this language even be usable?

Sending email

email = Email("andrew.vos@gmail.com", "hey!", "what's up?")
SendsEmail(email)!

Email
  to, subject, body
end

SendsEmail
  email

  execute
    connection = SmtpConnection("smtp.bla.com")
    SendsSmtpMail(connection, email)!
  end
end

Recursively delete files

    path = Path("files/")
    DeletesFiles(path)!

    DeletesFiles
      path

      each file in ListsFiles(path)!
        DeletesFile(path)
      end

      each directory in ListsDirectories(path)!
        DeletesFiles(path)!
      end
    end

    DeletesFile
      path

      execute
        ExecutesCommand("rm " + path)
      end
    end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment