grip-framework / grip

The microframework for writing powerful web applications.

Home Page:https://grip-framework.github.io/docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Index syntax

notramo opened this issue · comments

Why does Grip have so ugly method names like context.get_resp_headers("Content-Type")?
Idiomatic Crystal code should use the indexing syntax: context.response.headers["Content-Type"]

It is inspired by Phoenix, I don't really see anything "ugly" with method-naming such as that, no need to be rude!

Sorry, I didn't meant to be rude. I didn't know it was inspired by another framework. Unfortunately, in Crystal community, non-idiomatic naming occurs in mostly the same projects that have bad code (probably because if the developer don't even know the Crystal naming conventions, then they don't know Crystal either). But I took a look at the code, and this project is quite well designed. It's just the Context methods that are unusual (probably because Elixir is functional programming paradigm, while Crystal is OOP).

One problem I see is that as a newcomer, it's hard to see from the method names if it will raise or will return null on failure.
For example, using Crystal naming conventions, it would be clear:

context.request.headers["Referer"]? # this will return Nil if key doesn't exists
context.request.headers["Referer"] # this will raise if key doesn't exist
context.get_req_header("Referer") # I have to open the source of this framework to see what it does actually

After looking at the code, I noticed that Context is inherited from the Context in the standard library, so those methods are available as well. I rather use those as those might be familiar to developers coming from other Crystal microframeworks (e.g. Kemal). But those who come from Phoenix, might prefer these.
I will open a documentation PR to clarify this if you agree.