Are modern computers powerful enough to process strings without using characters (in Ruby)

Every text I read about Ruby characters shows the effectiveness of characters over strings. But this is not the 1970s. My computer can handle a bit of extra garbage collection. Am I mistaken? I have the latest and largest Pentium dual-core processor and 4 gigabytes of RAM. I think this should be enough to handle some lines.

+5
source share
5 answers

Your computer might be able to handle β€œa little extra garbage collection,” but what about when this β€œlittle” happens in an internal loop that runs millions of times? How about when it works in an embedded system with limited memory?

There are many places where you can avoid using strings perforce, but in some you cannot. It all depends on the context.

+17
source

It’s true that you don’t need tokens so badly for memory reasons. Your computer, no doubt, could handle all kinds of rough string processing.

, , ( ) : , KEY-VALUE. .

... , , - .

ruby ​​ . . , .

, ... .

: http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol

+13

, - , String (, , ).

, , , .

+2

. - ..

+1

: . , . . :

a = 'zowie'
b = 'zowie'
a == b         #=> true

, a b . , . :

a.object_id    #=> 2152589920 (when I ran this in irb)
b.object_id    #=> 2152572980
a.equal?(b)    #=> false

, . Ruby , String#initialize .. . ! , :

a += ''        #=> 'zowie'
a.object_id    #=> 2151845240

a , Ruby . - String, a, String , . , '' String, . :

''.object_id   #=> 2152710260
''.object_id   #=> 2152694840
''.object_id   #=> 2152681980

? . 4 ? , . , . , , , . .. String, , . - ; , , , .

, :

a = :zowie
b = :zowie
a.object_id    #=> 456488
b.object_id    #=> 456488
a == b         #=> true
a.equal?(b)    #=> true

:zowie, . , , . . , - , , , . , -, .

? , . , .

+1

All Articles