A note to those who might dismiss this without looking at it carefully because you assume it's just some SPA that mocks the Twitter UI: it's actually a NixOps file (with everything inlined) that deploys the entire stack, including a full backend and database.
FWIW, the link posted here is just to the Haskell part. This is the fully-inlined NixOps file: https://github.com/Gabriel439/simple-twitter/blob/master/sim... (which is no less impressive -- fewer than 500 lines in a single file to specify a full web app!)
I'm not an PG user but there does not appear to be an index on tweet.time - and even if there was wouldn't it better to do ORDER BY tweet.id DESC? I assume ordering by primary key is going to be the fastest, and would (ideally) prevent maintaining an index on tweet.time.
I was working on creating an rss reader with a reddit-like interface that allowed follows, voting, comments, etc. The computational expense of a fancy sort algorithm based on factors other than just one non-computed column is immense once you get to a decent number of users. I ended up removing the algo just to lower my hosting bills. Of course, there were other potential solutions, but for a side project, this was easiest.
There are a lot of very strong opinions in this thread on whether this code would be "production ready". I don't think that is the point here. This is awesome because of its brevity, it is like writing a ray tracer in 100 lines of C. It demonstrates that a task which might be perceived to highly complicated can be reduced to a file, of which the size many of us would just define a single class in such a system.
It's a nice demo. But there seems to be a surprising lack of validation? Seems like anyone can delete any other user, or post as anyone else, etc. Then again, I can't read Haskell, so I don't know if there's something preventing that at a higher level than the endpoint logic.
Doesn't look like there is. I think the idea is for this to be a nontrivial example of a full-stack Haskell+Nix(Ops) project. The Twitter part is meant to be more familiar that robust.
It's fair to argue auth should be included in a nontrivial example though. I honestly don't think it would add that much clutter either. Although unlike the other components, I don't know if there's a simple off-the-shelf Haskell solution for auth.
Small, easy to write/maintain approaches are at an evolutionary disadvantage vs classically "enterprise" styles.
Easier to work with -> fewer people needed -> fewer people hired -> fewer people learn -> fewer people know.
Now there's fewer people in the market who know Simple, vs many people who've learned OverEngineered (TM). Leadership wants to pick a language/style they'll be able to hire for as-needed. OverEngineered has a much larger talent pool.
import Database.PostgreSQL.Simple.SqlQQ (sql)
...
let index :: Handler Markup
index = do
tweets <- query_ [sql|
SELECT "user".name, tweet.contents
FROM "user"
INNER JOIN user_tweet ON "user".name = user_tweet."user"
INNER JOIN tweet ON user_tweet.tweet = tweet.id
ORDER BY tweet.time DESC
|]
Yeah, another comment said this is “unreadable” if you don’t do FP... I have done a little lisp + Elixir, but 99% of my coding has been in C-descendant languages and this was definitely readable.
I hope this is only the beginning of a series of popular web apps and social networks all recreated as pithy single file documents. Next should be Facebook.
This is cool and reminds me of the Twitter clone[1] I included as a coding exercise in my book[2]. It's a very good way to learn as a basic Twitter clone is relatively simple to implement.
Slightly related - If you want a pre-categorised tweets feed with ability to add new categories, I have written one - http://trysensible.com/ (Open source https://github.com/kgthegreat/sensible). It comes with some standard categories such as politics, sports etc. but you can add whatever categories you want such as - music, academia and start adding your own curated list of keywords to support this category.
This is written in golang and is open source https://github.com/kgthegreat/sensible
A lot of people complaining that this wouldn't be able to hold the load of the original thing like that. I'd argue that all platforms attempting to be all-encompassing is a big problem right now. Maybe a single instance of a platform should really just accept as much load as this could handle in this form. They could federate with eachother to replicate the massive connected structure.
[+] [-] apetresc|6 years ago|reply
[+] [-] panic|6 years ago|reply
[+] [-] cblum|6 years ago|reply
Why can’t the world move in that direction, instead of the insane Kubernetes hype that’s prevalent these days?
[+] [-] MuffinFlavored|6 years ago|reply
[+] [-] OrgNet|6 years ago|reply
[+] [-] joewrong|6 years ago|reply
sign me up
[+] [-] mc3|6 years ago|reply
[+] [-] jamroom|6 years ago|reply
[+] [-] WA|6 years ago|reply
[+] [-] nkozyra|6 years ago|reply
Best I can come up with is it'd make promoted comment more apparent?
[+] [-] mipmap04|6 years ago|reply
[+] [-] kgthegreat|6 years ago|reply
It has that and more!
Open source - https://github.com/kgthegreat/sensible
[+] [-] robobro|6 years ago|reply
[+] [-] singron|6 years ago|reply
[+] [-] TheUndead96|6 years ago|reply
[+] [-] blakesterz|6 years ago|reply
https://github.com/Gabriel439/simple-twitter
[+] [-] akersten|6 years ago|reply
[+] [-] whateveracct|6 years ago|reply
It's fair to argue auth should be included in a nontrivial example though. I honestly don't think it would add that much clutter either. Although unlike the other components, I don't know if there's a simple off-the-shelf Haskell solution for auth.
[+] [-] jpochtar|6 years ago|reply
Easier to work with -> fewer people needed -> fewer people hired -> fewer people learn -> fewer people know.
Now there's fewer people in the market who know Simple, vs many people who've learned OverEngineered (TM). Leadership wants to pick a language/style they'll be able to hire for as-needed. OverEngineered has a much larger talent pool.
[+] [-] kyllo|6 years ago|reply
[+] [-] cocochanel|6 years ago|reply
[+] [-] samcodes|6 years ago|reply
[+] [-] xwdv|6 years ago|reply
[+] [-] james_s_tayler|6 years ago|reply
[+] [-] dom96|6 years ago|reply
1 - https://github.com/dom96/nim-in-action-code/tree/master/Chap...
2 - https://book.picheta.me
[+] [-] jedimastert|6 years ago|reply
[+] [-] k__|6 years ago|reply
It would be awesome if Nix, NixOS and NixOps replaced the current mess that is Docker and K8s.
[+] [-] gulperxcx|6 years ago|reply
[+] [-] Gabriel439|6 years ago|reply
[+] [-] mark_l_watson|6 years ago|reply
[+] [-] kgthegreat|6 years ago|reply
[+] [-] cryptozeus|6 years ago|reply
[+] [-] grizzles|6 years ago|reply
[+] [-] cyborgx7|6 years ago|reply
[+] [-] beders|6 years ago|reply
[+] [-] gigatexal|6 years ago|reply
[+] [-] zemnmez|6 years ago|reply