PostgREST – A fully RESTful API from any existing PostgreSQL database
github.com
github.com
Postgrest is a great example of a real-world Haskell codebase. It's concise for the amount of functionality it offers, which is characteristic of functional languages (<3000SLOC of source, not counting tests). I'd encourage anyone interested in working with non-toy functional codebases to take a look around with it, or better yet, submit a PR (there are a few "beginner" issues!).
It's hard to read. Very messy.
https://github.com/begriffs/postgrest/tree/master/src/PostgR...
Despite 15 years of programming experience in python, js, C, etc. I feel like I'm going to have to duck my head down to be chastised for not understanding the language and not being "intelligent" enough to see the depth.
It looks like jibberish, to me. Not trying to be offensive. I'm sure the person who written it had it make sense to them. You likely also notice, a lack of code documentation. Bad form. Don't tell me it's because I don't know haskell, that's why I'm not expending the time to learn it, despite the buzz.
Meanwhile, SQLAlachemy and Hibernate isn't reporting complaints and a human being could actually parse it to understand what the hecks going on there. And despite it being Python or Java - easier and far more widely adopted languages - they're documented extensively, the authors didn't solipsistically assume others would "get it".
Which is a pattern I've been seeing with hardcore functional advocates in communities. They are the kind of people who'd work 2 weeks on a paper for a mathematical proof, shove it to you in the hallway to look smart, and say "It's obvious". It's not, you're just trying to show you're smart, but no one's understanding you - and that is important in you winning people over and not looking arrogant.
> It's concise for the amount of functionality it offers
Make it 4 times as many lines. Because there is so much condensed inside of this.
>8k stars. Less than 50 contributors. Of which, only the top 7 changes more than 100 lines.
If this considered a real world haskell, it's no wonder there's not a lot of people using it.
It does more to demonstrate functional programmers lack empathy for enterprise ones. Because even with solid grasp of CS concepts, even Haskell's own proponents are having a hard time stomaching contributing to it.
To me you're a classic example of the "Blub Paradox" [1]: languages with other features/language constructs than you're used to just seem worthless, complex, without value and foreign to you.
You mention a lot of experience in hardcore imperative/imperative-OOP languages (C, JS, Python). Haskell, Rust, Scala etc. require a bit of a different mindset and thus have an initial steep learning curve.
Compare it to lamda's. Did you see the value in anonymous functions the very first time you were introduced to the concept? Now that you've probably used them for a while, would you be happy to use a programming language without them?
You're not willing to learn the language because you don't understand it, and dismiss the language as having no value because you don't understand it. Is that really fair without at least having a basic understanding of the language?
[1] http://wiki.c2.com/?BlubParadox / http://www.paulgraham.com/avg.html . I'm not a fan of the "I Know LISP So I'm Better Than You" tone of the original article, but I do fully agree with the key point that it's hard to evaluate language constructs you're not used to.
offsetParams :: M.HashMap ByteString NonnegRange
offsetParams = M.fromList [(toS (replaceLast "limit" k), fromMaybe allRange (rangeGeq <$> (readMaybe =<< (toS <$> v)))) | (k,v) <- qParams, isJust v, endingIn ["offset"] k]
Not because it's something I don't understand at the concept level (there isn't anything complicated there), but because of the formatting and general lack of comments.Maybe I'm talking about bike shed color, but it could be much better just by having some extra newlines that separate the pieces of list comprehension expression.
Also, I don't think his criticism is of the "blub" mold anyhow. It seems to me more like it's criticism of the particular codebase's documentation, although it does seem to stretch into a hasty generalization about "all Haskell".
Blub basically says "you need to be proficient in X before you can see value in X, this if you are not proficient in X you won't see it's value". You can disagree with the statement, but there's no logical fallacy there.
Document the Haskell code and not stuff so much logic into one line. I think that's a fair thing to ask for in software engineering.
Anyone who complains about Haskell seems to have either a.) not programmed it b.) weren't programming "correctly" c.) a xenophobe/blub/NOS
I know what lambdas are, I know there are functions and folds. That in and of itself doesn't tell the story of the data that's actually being manipulated and the expected output. So that's why you have a 20-30 line comment block explaining what's going on in important API functions.
You could program python, JS or ruby similarly; wrapping multiple functions on the same line until you have to actually trial each function to figure out why your not getting an expected result. It feels clever, at the moment, but we don't do it because we're not helping colleagues understand it.
> You're not willing to learn the language because you don't understand it, and dismiss the language as having no value because you don't understand it. Is that really fair without at least having a basic understanding of the language?
The commenter was heralding the project as a "great example" of "real-world haskell" and recommended contributing to it. I was shocked to see 8k stars and a paltry 50 contributors; of which, only the top 10 have contributed over 100 lines of code. That's half the contributors, proportionally, to something like neovim or redis, and even worse compared to node.js projects.
And, I looked at the code of the project, which is open source, and didn't see code documentation.
I'm trying to be generous. My advice: stop packing the code so close and document it, probably more than normal, since the symbology in their is highly dense.
There's a line of too much abstraction, and lots of.haskell code crossed it, but the postgres code ive looked at doesn't seem to suffer from it.
Also I really hate the types are documentation people, but I mean it's hard to argue with it for asking about what transformation is happening.
Edit: also if be surprised if those numbers are all that bad if you consider the size of the codebase but yeah it's hard to get contributors to a Haskell code base.
https://github.com/graphql/graphql-js/graphs/contributors?fr...
:) So by your logic, i could say:
"If this considered a real world javascript/node, it's no wonder there's not a lot of people using it." which is obviously wrong.
You are using the wrong metrics to judge the language popularity. Virtually every OSS project has only a handful of core contributors.
PS1: Note that i am not arguing PostgREST is a great example of real world haskell, it's not for me to say since i have bias :)
PS2: You are right that the source code is not commented and it could use a little of that but what you are missing (because you are not used to haskell) is that a lot of the documentation for haskell projects comes from the types and type signature of the functions. So just by looking at that, in a lot of cases, a haskell programmer can reliably tell what the function is doing without any documentation
Don't care if it's Python (basically pseudocode), Javascript, Haskell or Erlang.
For all the time Haskell commenters turn criticism into a Socratic dialog, they could be considering ways to make their code digestable. It's been what, 20 years now?
Not just to non-haskell programmers, but all the haskell programmers I see swarming around threads like these on the internet; you'd think they'd actually be teaming up and collaborating with each other. I can't put my finger on it, I think there's a trend, a feeling, that it's not suitable for programmers focused on achieving business ends. It's more of a hobby thing
Programming in the enterprise means confronting the reality that there are design trade-offs and someone else has to read the code. Haskell programmers seem to go off the deep end trying to pull off a hack of making haskell work a certain way, then its "pencils down", sayonara. The real world doesn't accept that, programs have to be maintained by others.
I have little experience in Haskell despite that it was easy for me to understand the gist of what postgREST does and port it to java.
https://blog.afoolishmanifesto.com/posts/install-and-configu... explains how to get it going on debian.
A lot of people are happy writing Haskell. In fact they seem to like it so much that they would kill for a Haskell job!
Interesting, because I totally disagree with this. My preference is for programs designed for safety and amenability to static analysis first. Maybe there's a reason I'm not a Python dev anymore=)
Sure, the complexity difference in operating a cart vs a car is not that big. But if someone has never seen a car or familiarized themselves with how to operate one then the perceived complexity is going to be enormous.
That said, the complexity of operation in a car arises from increasing the number of controls from 1 to, at minimum, 10. I would say the cart to car analogy is more akin to learning a complex API.
I would say that a better analogy for traditional languages vs. Haskell is that of a car to a fighter jet. The fighter jet is faster and really really good at certain things like movement on 2 planes and firing missiles. However, the fighter jet is orders of magnitude more difficult to operate and requires much more maintenance. For real world concerns such as getting groceries or transporting furniture, a car is the much more practical choice. I mean, we'd all love to own a fighter jet, but would any of us really have a use for it other than screwing around?
On the other hand, I heard somebody say "Haskell program file usually consists of 10 language extensions, 20 imports, and 1 line of Perl" and I understand the sentiment :-)
[1] https://github.com/begriffs/postgrest/blob/0b486ccf446c6480d...
I looked at the docs and they seem to discuss various concepts and other minutiae but there is no real overview that cuts through the fat.
It's not immediately obvious to me how it fulfills its stated claim:
> PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API. The structural constraints and permissions in the database determine the API endpoints and operations.
> Using PostgREST is an alternative to manual CRUD programming. Custom API servers suffer problems. Writing business logic often duplicates, ignores or hobbles database structure. Object-relational mapping is a leaky abstraction leading to slow imperative code. The PostgREST philosophy establishes a single declarative source of truth: the data itself.
The second paragraph in particular is a pretty bold claim, so I find it strange that there is very little elaboration on how this project can eliminate the need for custom APIs.
The big picture is that it's not PostgREST alone that accomplishes this "big claim" of eliminating the need for custom APIs. It's the combination of using openresty(nginx)/postgrest/postgres/rabbitmq together that gives you the possibility of "defining" apis rather then "manually coding" apis.
select=id,foreignkey(name)
pREST : GOlang based RESTful API ( PostgreSQL database ) : https://github.com/nuveo/prest http://postgres.rest/
"Problem: There is the PostgREST written in haskell, keep a haskell software in production is not easy job, with this need that was born the pREST."
Dec 15, 2016: "Today the postgrest is not distributed a binary, need to install Haskell to compile. pREST in its 1.0 version will be binary distributed (cross compiling, run in Windows by example), so you don't need to have anything installed on the server to run. How old is Haskell and how many developers exist? Go has less years and more developers, if you need to fix a problem in postgrest turn where?"
"The reason the pREST was born was because of a lack of developer, I am using pREST in my company, I know haskell and my developers nothing, if you have any problem (in production) just sits in my hand (hand want that)."
Honestly, the authors seem to have no clue what they're talking about and were looking for a good excuse to build something cool :). Which is fine!
> "Problem: There is the PostgREST written in Haskell, not in Go"
Moreover, if you want to use something like PostgREST but need to extend it, and don't know Haskell, this is a completely legitimate problem. While I'm all for competing implementations, the pREST author's claim for why it's needed is inaccurate.
[0] By "like Haskell", I really mean "unreadable/unwritable by the team supporting it". This could apply equally to Ruby, Java, bash, SQL, JavaScript, and Python depending on the makeup of the team supporting it.
q: "What issues did you have with Haskell in production?"
a: "PostgREST doesn't provide binaries and building it is hard"
q: "Actually PostgREST binaries are provided for multiple platforms." [1]
a: "The real reason is we don't have Haskell developers here." Case closed.
From personal experience PostgREST is high quality work; a set it and forget it service that doesn't need babysitting. Bugs are typically about missing capabilities, as opposed to failures. "Low defect" Haskell that does what it says on the tin.
[1] I don't know exactly when binaries first appeared but they were available as of April 2016, about seven months before the first prest commit.
https://news.ycombinator.com/item?id=9927771 (613 days ago)
https://news.ycombinator.com/item?id=8831960 (812 days ago)
You point it to a schema that consist only of views (that you define) and stored procedures (that you write) that abstract away the underlying tables. You define constraints on all your columns so junk does not get into the db. You define database roles and RLS policies and give them privileges so that you control who has access to what.
You still in a way write backend code, but in this case backend code is mostly views/constraints/triggers and in rare cases stored procedures.
A NOTIFY SQL command can be sent out from either a stored procedure or a table trigger. (The docs could use some examples of this, but that's the idea.)
I would instead have the trigger insert a row into a "pending tasks" table - and then send a NOTIFY.
It uses the logical decoding feature to get all row changes and writes them to a Kafka queue.
This means it can pick up where it left when it crashes.
That said, you could add event handling inside of Postgresql via triggers and one of the supported procedural languages (like PL/Python)
Not as simple as Parse, I guess, but that's a tradeoff of using lower-level technology.
But forget all that talk about horizontal scalability, 99% of the projects will never outgrow a single (big) database so it's no use in complicating things with "elastic" setups and "webscale". People don't realise just how fast postgres is http://akorotkov.github.io/blog/2016/05/09/scalability-towar...
Who among us have worked on projects that have 1M queries per second, not many.
https://www.postgresql.org/docs/current/static/queries-with....
consider there are 3 tables clients/projects/tasks with FKs between them.
Please paste the query that returns all the information above using "with recursive"
This is how the communication between the client an PG goes https://www.pgcon.org/2014/schedule/attachments/330_postgres...
- client sends an SQL command - server replies with RowDescription detailing the structure - after that a DataRow message is sent for every row - finally, the server sends CommandComplete and ReadyForQuery
So inherently the protocol can only represent a 2D array.
https://www.reddit.com/r/ruby/comments/61bb6h/squad_simple_e...
Postgrest basically shifts the work of writing a basic CRUD API (a task for which you would probably use an ORM) to declaring a SQL schema. From that schema, it infers which endpoints should exist and what they should do. For a certain class of web app, this can be a HUGE time saver.
Beyond that, consider checking out the "Motivation" section of the website: https://postgrest.com/en/v0.4/intro.html
- [name, age, sex, phone]
- [Taylor Swift, 27, female, 555-SWIFT]
I find YAML to be the best format for everything.