
Swifton: Ruby on Rails-inspired web framework for Swift - necolt
https://github.com/necolt/swifton
======
autoreleasepool
It seems that, outside of what's used in Cocoa, the Swift language is pretty
volatile right now. I would hesitate to commit to a large project that didn't
involve the App Store.

~~~
sdegutis
I think the hope of projects like these is partly to try to advance interest
in Swift which draws in more users who then help contribute to making the
language more cross-platform, and partly to be _f1rst_ in the project's niche
when the language finally crosses that barrier, so that it becomes the de
facto standard. (Think Compojure for Clojure, in the same problem domain.)

------
bsaul
Seems to me like the real challenge in those framework (excepting performance,
of course) will be in the orm component. Having a library that can query a db
in a typesafe way is a must.

Another will be in the concurrency patterns ( promises ? Coroutines ?, etc).

But i get a great hope that they will succeed. Having a strong open source
community will help. In fact, i'm so fed up with the sad state of uikit right
now, that i see a brighter future for swift on the server side than on the
client. Maybe an android sdk for swift would be a great idea...

~~~
protomyth
I wish Apple had not ditched NeXT's EOF. It would make a fine open source
project these days.

~~~
bsaul
I never used this framework, but everything i know from the next era is
starting to show its age (including coredata, with its messed up support for
multi threading access).

The more i think about it, the more i think golang approach is the right one :
the only hard part today is concurrency. As long as swift ( and rust for that
matter) hasn't standardized patterns that people would use on the whole stack
for concurrent access to ressources,as well as asynchronicity, they won't have
made the necessary step to truely advance the state of the art.

~~~
seivan
GCD is the best I've seen in terms of language design for concurrency. It's
also a bit higher level than managing threads on your own. Though I might be
wrong.

~~~
bsaul
You probably should have a try at golang concurency management with channels,
and you'll see what i mean.

GCD isn't much more than a low level job launching and scheduling library. It
doesn't provide advanced patterns for resource sharing.

Concurrency goes further than parallelism, it's also a way to manage
concurrent memory access (although golang does let you shoot yourself in the
foot if you want to with low level mutexes as well). There's a great talk from
rob pike on the subject [http://blog.golang.org/concurrency-is-not-
parallelism](http://blog.golang.org/concurrency-is-not-parallelism)

~~~
seivan
Thanks for explaining and clearing things up. I'll read up.

------
hagmonk
The project banner depicting a damsel in distress on the railway tracks is
going to make some people twitch. I'd avoid that distraction by picking
something gender neutral. My 2c.

~~~
PKop
It's fun. You don't _have_ to get offended. It's just a silly picture. No one
was harmed in it's making.

Stop wasting people's time, let them focus on productive aspects of the
project.

~~~
ciconia
Please explain: how is it fun exactly? Do you enjoy the image of a bound woman
about to be hit by a train? Does your girlfriend / wife / mother find this
image "fun"?

~~~
jernfrost
It is a reference to Taylor Swift combined with Ruby on Rails. That sort of
makes sense. I assume they wanted to combine rails and Taylor swift somehow
and this seems like on easy way of doing it.

I reacted a bit like you, but given that this only makes sense with Taylor
Swift, I figured okay, whatever no need to moralize over this one.

------
seivan
You could have made it better by using protocols for the actions. So the
methods for adding routes would ensure that the methods for new and update
exists using a where clause checking protocol conformance.

There is potential here, I like a "full" package like "Omakase", granted its
built using Swifts strength and a pipeline model like Express.js and/or Rails
and its rack middlewares.

~~~
necolt
Seivan, thanks. Yes, Rails "Omakase" is driving Swifton development.

I'm not sure that protocols will help here, because Swifton supports
before/after filter. Could you explain more your idea about how protocols
could help here to implement actions with filters?

~~~
seivan
Sure, here
[https://gist.github.com/seivan/6b6bb19c899dd46f599e](https://gist.github.com/seivan/6b6bb19c899dd46f599e)

I might fork and do my own version where I try to adhere to Swifts strengths
while still staying close to Rails API where I can, e.g same naming scheme and
pipeline design as Rails.

Rails biggest weakness is Ruby. Leveraging Swifts strengths with protocol
extension, where clauses and generics could actually improve on Rails current
API.

Edit[0]:

Added an idea for filter API. Not happy with it, but it's a start.
Before/After filters could just be a list of "stuff" (selectors, closures,
etc) to be called before any action. It could also use group_dispatch to
ensure that filters are called in sequence and only call the method once all
filters are done.

group_dispatch (think semaphores, but not as "dangerous") :)

~~~
equalarrow
Rails biggest weakness is Ruby?!?! The only reason Rails came about (so says
DHH) is because of Ruby and its expressiveness as a dynamic language.

Granted, we're in Swift mode here and it's static typing, protocols, generics,
and closures all the way. I'm fine with this (I write in Swift everyday) but
Ruby is a great language as well - I love them both.

I think there's a place for both static and dynamic typed languages and I'm
not going to throw away Ruby just because Swift is more "correct" with typing.

Having worked on my own Swift web framework for the past few months, and Rails
for years, we're not even close to approaching Rails feature set. Rails has
been in active development for over a decade and it's going to take a while
for a Swift framework to make some inroads.

~~~
seivan
We're both right. Rails look the way it looks because of Ruby. What I am
advocating is a compromise between the two of them. Rails-esque packaging, and
API design on the entire stack e.g Active Record to Active Support. But using
Swift strengths with protocol conformance, extensions, associated-types and
etc.

I would never want to work on a larger Ruby code base again. It's just too
hard to iterate on as things break too much compared to a larger Swift code
base. That's just my take.

I actually like Ruby, but for scripts and smaller code. Not large
applications. Same applies for ES6, where I think TypeScript would do a better
job.

------
Razengan
I am mainly a hobbyist/newbie that recently started to learn Ruby, and Ruby on
Rails. While I like them both, I would prefer to just work in Swift.

How soon does HN expect a Swift-based framework that is comparable to the
maturity of Rails, or other powerful frameworks for that matter? Do you think
Apple might jump in and introduce one of their own?

~~~
herbst
Years, if ever. Things like Rails are very major based on the experience of
thousands of developers.

------
coldcode
So many of these now. I wonder which one will eventually become the node of
Swift.

~~~
fleshweasel
Node isn't a JavaScript framework so much as a platform to run JavaScript on.
Express is maybe more analogous to Swifton here.

------
yeskia
There's a lot of strings being thrown around for a type-safe language.

~~~
Pxtl
Hooray for being stringly typed.

------
vortico
Is Swift still OS X-only, or can I use this on Linux?

~~~
supster
> A Ruby on Rails inspired Web Framework for Swift that runs on Linux and OS
> X.

------
harunurhan
Now I think swift has enough web frameworks and somebody should build an ORM.

~~~
supster
[https://github.com/tannernelson/fluent](https://github.com/tannernelson/fluent)

------
jernfrost
There seems to be so many web frameworks popping out for Swift, how does this
compare with other languages such as C#, Scala and Go?

------
muhmi
So, why would you write systems requiring concurrency and fault tolerance in
Swift? What happens when a request explodes? Can it do hot code loading?

