Live data from Hacker News

Rails 5.0: Action Cable, API mode, and more

weblog.rubyonrails.org

101–110 of 225 posts

Re: Rails 5.0: Action Cable, API mode, and more

#101
post #93
post #85

Concurrency aside, why is Elixir preferred over Ruby when it doesn't even have a native array implementation? No, lists and tuples are no substitute nor are maps with numeric keys as Jose has suggested. If you want an array in Elixir your only option is Erlang's implementation which ain't pretty - http://erlang.org/doc/man/array.html . When I raised this issue in the mailing list and on IRC the response was invariabl…

Does absence of arrays look a problem for you, while general immutability of most everything and message-based approach look totally normal and easy to grasp? I suspect that to use Elixir, you need to study a new way of doing things first. Then you'll see arrays in a different light.

I have studied Elixir and other functional languages such as Clojure where vectors are 1 of the 3 basic collection types so the "new way of doing things" isn't an issue for me. Elixir took a lot of inspiration from Clojure so the 2 languages are not that different.

Re: Rails 5.0: Action Cable, API mode, and more

#102
post #85

Concurrency aside, why is Elixir preferred over Ruby when it doesn't even have a native array implementation? No, lists and tuples are no substitute nor are maps with numeric keys as Jose has suggested. If you want an array in Elixir your only option is Erlang's implementation which ain't pretty - http://erlang.org/doc/man/array.html . When I raised this issue in the mailing list and on IRC the response was invariabl…

This isn't a defensive response, just a genuinely curious one. For certain types of programming - generally in lower-level languages - arrays can be essential for performance. But then my assumption is that if you needed that kind of performance, you'd be using those languages. So outside of performance, what's the functional difference between an actual array implementation - and a thing that looks, walks, and quack…

Ruby, Python and Javascript all have native array support but can hardly be considered lower-level languages.

Re: Rails 5.0: Action Cable, API mode, and more

#103
post #92
post #88

Earlier quoted context omitted.

I've just started learning Elixir out of interest so I can't quite answer your question. However, I'd like to ask: what have you found to be difficult to do using the Elixir types such as tuples, list, keyword lists, and maps that would otherwise be easy to do using arrays? I'm asking out of genuine curiosity because I've specifically noticed a lack of arrays when learning Elixir and I'm quite used to using them in o…

Elixir has no native array syntax nor any array functions in the stlib so arrays are basically second class citizens rather than completely absent. Ask not why I need them but why anyone might need them if the Elixir is supposed to be a general purpose language. Why does Clojure need them or Ruby or Python (lists)? If I want to process data as a large indexed array Elixir isn't going to help me and some Elixir devs h…

> Why does Clojure need them or Ruby or Python (lists)?

So you want a list it seems

   > l=[1,2,3]
   > [h | t] = l
       [1, 2, 3]
   > h
       1
   > t
       [2, 3]
> If I want to process data as a large indexed array Elixir isn't going to help me

But neither will Python. You'd want a large indexed array you probably want numpy.

See now you are revealing a bit more about your usecase that's helpful. So you have large amount of data and want to query it and process it. In that case you might want to check out ETS. The nice benefit, you have have cool matching or query list comprehensions of it. Can also access it concurrently from multiple processes:

http://elixir-lang.org/getting-started/mix-otp/ets.html

This is the Erlang side of it:

http://learnyousomeerlang.com/ets

> but the question here is whether it is deficient in other areas, making it too much of a niche language.

Of course it is deficient. C is deficient. Java, C++ is they all. Every language is deficient in some way. I haven't found a Perfect one yet. Still looking... Maybe Rust, who knows, still struggling to learn it.

Re: Rails 5.0: Action Cable, API mode, and more

#104
post #98
post #90

Earlier quoted context omitted.

Why do you want an array? You mean you want a memory area with adjacent cells layed out, to talk to C perhaps? Perhaps might want a list, a binary, or a sorted set, a tuple, a map and so on. You have to tell a bit more about your use case. I used Erlang for many years, and in the last one full time. Not one time have I needed an "array". It seems you picked one odd feature no-one uses and are upset about it, I thik i…

I would need an array for processing any large data set as an indexed collection. Why is that considered an "odd feature no-one uses" when it's a fundamental data type in most mainstream languages?

How are you planning on accessing it though?

If it's iterated over sequentially then a list works perfectly.

If it's random access then a map works.

Re: Rails 5.0: Action Cable, API mode, and more

#105
post #85

Concurrency aside, why is Elixir preferred over Ruby when it doesn't even have a native array implementation? No, lists and tuples are no substitute nor are maps with numeric keys as Jose has suggested. If you want an array in Elixir your only option is Erlang's implementation which ain't pretty - http://erlang.org/doc/man/array.html . When I raised this issue in the mailing list and on IRC the response was invariabl…

if you need constant time access by index to a sequence of fixed size elements you can use binaries. if you want constant time access to a sequence of fixed size you can use tuples. if you want both you can get close with maps using integer keys or with trees (which i believe are used by clojure behind the scenes for arrays)

If it comes to that I can just use Erlang's implementation but my question is why the omission in Elixir when arrays are supported in Erlang? With Elixir's excellent macro support surely an Elixir wrapper around Erlang's arrays wouldn't be so difficult?

Re: Rails 5.0: Action Cable, API mode, and more

#106

Earlier quoted context omitted.

It's around 12 times faster in the general sense. Your mileage may vary. If you spend $200 you could theoretically hosting the same product on $50 worth of hardware.

That saving of $150 is equivalent to one hour of pro dev work time. It's hardly worth converting unless Elxir / Phoenix is much more productive and maintainable.

Converting? Absolutely not.

A greenfield project? Sure why not, it's a great choice.

Re: Rails 5.0: Action Cable, API mode, and more

#108
post #98

Earlier quoted context omitted.

I would need an array for processing any large data set as an indexed collection. Why is that considered an "odd feature no-one uses" when it's a fundamental data type in most mainstream languages?

How are you planning on accessing it though? If it's iterated over sequentially then a list works perfectly. If it's random access then a map works.

What if I want to push/pop it and also access it randomly by index? PHP gets a lot of stick for making arrays serve double purpose but the Elixir advocates of using maps for array purposes are basically arguing for the same thing, no?

Re: Rails 5.0: Action Cable, API mode, and more

#109
post #6

Earlier quoted context omitted.

Been using Elixir / Phoenix as well, and it's been a breath of fresh air. That said, I'm glad that rails has been looking at projects like Phoenix for inspiration as it continues to grow and adapt.

I'm glad that rails has been looking at projects like Phoenix for inspiration Other way around. Phoenix was explicitly inspired by Rails and founded by Rails core members. Elixir was first created by a Rails core member. Phoenix is the performance-really-matters successor to Rails.

IIRC Action Cable was inspired by Phoenix's Channels.

Re: Rails 5.0: Action Cable, API mode, and more

#110
post #102

Earlier quoted context omitted.

This isn't a defensive response, just a genuinely curious one. For certain types of programming - generally in lower-level languages - arrays can be essential for performance. But then my assumption is that if you needed that kind of performance, you'd be using those languages. So outside of performance, what's the functional difference between an actual array implementation - and a thing that looks, walks, and quack…

Ruby, Python and Javascript all have native array support but can hardly be considered lower-level languages.

Just to be clear, Javascript's arrays will, depending on the implementation, dynamically switch between sparse and compact implementations. A sparse javascript array literally behaves like a javascript object or a map with an integer index. Ruby and Python's arrays will grow as long as the allocator can alloc more memory onto the end, but has to copy the entire array if there's memory fragmentation...it's not quite the same as a C array.

Because of the immutable data, your best hopes are actually vectors or maps.

Btw, the erlang library you mention implements arrays on top of a tree of 10-ary(-ish) tuples. It'd need to be measured, but I'd be willing to bet that the native maps are faster at access, insert, and delete. The maps are implemented in C, and worst case for all operations would be O(n log n) or similar.

Post reply on HN