# C or C++?

**URL:** <https://rubytalk.org/t/c-or-c/8358>\
**Category:** ruby-talk\
**Created:** [2 October 2003 04:45 UTC](https://rubytalk.org/t/c-or-c/8358 "2003-10-02T04:45:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Cheng](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@Joe\_Cheng](https://rubytalk.org/u/Joe_Cheng)\
**Post date:** [2 October 2003 04:45 UTC](https://rubytalk.org/t/c-or-c/8358/1 "2003-10-02T04:45:09Z")

</div>

I’d like to start writing Ruby extensions. Does it make a difference  
whether you use C or C++? I took a C++ in college but haven’t done any of  
it since, so I’m more or less starting from scratch.

Thanks for any input!

---

<div class="post-metadata">

**Author:** ![Seth\_Kurtzberg1](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Seth\_Kurtzberg1](https://rubytalk.org/u/Seth_Kurtzberg1)\
**Post date:** [2 October 2003 05:19 UTC](https://rubytalk.org/t/c-or-c/8358/2 "2003-10-02T05:19:10Z")

</div>

Write using the same language and libraries that Ruby itself is written in.

Joe Cheng wrote:

> **···**
>
> > I’d like to start writing Ruby extensions. Does it make a difference  
> > whether you use C or C++? I took a C++ in college but haven’t done any of  
> > it since, so I’m more or less starting from scratch.
> > 
> > Thanks for any input!
> > 
> > .

---

<div class="post-metadata">

**Author:** ![Sean\_O\_Dell1](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@Sean\_O\_Dell1](https://rubytalk.org/u/Sean_O_Dell1)\
**Post date:** [2 October 2003 06:50 UTC](https://rubytalk.org/t/c-or-c/8358/3 "2003-10-02T06:50:22Z")

</div>

Joe Cheng wrote:

> I’d like to start writing Ruby extensions. Does it make a difference  
> whether you use C or C++? I took a C++ in college but haven’t done any of  
> it since, so I’m more or less starting from scratch.

Ruby is really C-oriented. It longjmps on errors, so the stack doesn’t  
“unwind” the way C++ objects really wants it to. There are work-arounds  
for that, but I found that without a good foundation of libraries to  
work with, C++ was a real pain, so I stick with C. Plain C is also a  
bit more portable than C++.

```
Sean O'Dell

```

---

<div class="post-metadata">

**Author:** ![Paul\_William](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Paul\_William](https://rubytalk.org/u/Paul_William)\
**Post date:** [2 October 2003 11:00 UTC](https://rubytalk.org/t/c-or-c/8358/4 "2003-10-02T11:00:13Z")

</div>

Why do you want to write extensions? Why cant you write ruby code? If  
you want to write and bindings for a library and the library is C++ then  
you had better write the binding in C++ otherwise I recommend using C.

or…

I think I saw some benchmarking that said C is faster than C++ so if you  
are writing a calculation heavy program then C may be a better option,  
IMHO.

Good luck

Paul

> **···**
>
> On Thu, 2003-10-02 at 16:45, Joe Cheng wrote:
> 
> > I’d like to start writing Ruby extensions. Does it make a difference

---

<div class="post-metadata">

**Author:** ![Thomas\_Sondergaard](https://avatars.discourse-cdn.com/v4/letter/t/ecae2f/32.png) [@Thomas\_Sondergaard](https://rubytalk.org/u/Thomas_Sondergaard)\
**Post date:** [2 October 2003 09:45 UTC](https://rubytalk.org/t/c-or-c/8358/5 "2003-10-02T09:45:37Z")

</div>

> Ruby is really C-oriented. It longjmps on errors, so the stack doesn’t  
> “unwind” the way C++ objects really wants it to.

I think I understand what you mean. Is it that destructors may not be called  
as expected? Please elaborate!

> There are work-arounds  
> for that, but I found that without a good foundation of libraries to  
> work with, C++ was a real pain, so I stick with C.

What kind of work arounds? If you rb\_protect everything the longjmp’s should  
only happen in ruby-land, and you should be safe in C++, right?

Cheers,

Thomas

---

<div class="post-metadata">

**Author:** ![Aleksei\_Guzev](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Aleksei\_Guzev](https://rubytalk.org/u/Aleksei_Guzev)\
**Post date:** [2 October 2003 11:45 UTC](https://rubytalk.org/t/c-or-c/8358/6 "2003-10-02T11:45:46Z")

</div>

“Paul William” [maillist@bestworldweb.homelinux.com](mailto:maillist@bestworldweb.homelinux.com) wrote in message  
news:1065092409.545.11.camel@debian…

> **···**
>
> > On Thu, 2003-10-02 at 16:45, Joe Cheng wrote:
> > 
> > > I’d like to start writing Ruby extensions. Does it make a difference
> > 
> > Why do you want to write extensions? Why cant you write ruby code? If  
> > you want to write and bindings for a library and the library is C++ then  
> > you had better write the binding in C++ otherwise I recommend using C.
> 
> I think C is useful for acessing some system resources.  
> Massive computations should be made with assembler or at least fortran 😉
> 
> Aleksei Guzev

---

<div class="post-metadata">

**Author:** ![David\_A\_Black2](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@David\_A\_Black2](https://rubytalk.org/u/David_A_Black2)\
**Post date:** [2 October 2003 12:22 UTC](https://rubytalk.org/t/c-or-c/8358/7 "2003-10-02T12:22:32Z")

</div>

Hi –

> **···**
>
> On Thu, 2 Oct 2003, Paul William wrote:
> 
> > On Thu, 2003-10-02 at 16:45, Joe Cheng wrote:
> > 
> > > I’d like to start writing Ruby extensions. Does it make a difference
> > 
> > Why do you want to write extensions? Why cant you write ruby code?
> 
> It’s not an either-or choice; lots of Ruby programmers do both.  
> C extensions are usually written for speed.
> 
> David
> 
> –  
> David Alan Black  
> home: [dblack@superlink.net](mailto:dblack@superlink.net)  
> work: blackdav@shu.edu  
> Web: [http://pirate.shu.edu/~blackdav](http://pirate.shu.edu/~blackdav)

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [2 October 2003 10:05 UTC](https://rubytalk.org/t/c-or-c/8358/8 "2003-10-02T10:05:38Z")

</div>

“Thomas Sondergaard” [thomas@FirstNameGoesHereSondergaard.com](mailto:thomas@FirstNameGoesHereSondergaard.com) schrieb im  
Newsbeitrag news:3f7bef63$0$48887$edfadb0f@dtext02.news.tele.dk…

> > Ruby is really C-oriented. It longjmps on errors, so the stack  
> > doesn’t  
> > “unwind” the way C++ objects really wants it to.
> 
> I think I understand what you mean. Is it that destructors may not be  
> called  
> as expected? Please elaborate!
> 
> > There are work-arounds  
> > for that, but I found that without a good foundation of libraries to  
> > work with, C++ was a real pain, so I stick with C.
> 
> What kind of work arounds? If you rb\_protect everything the longjmp’s  
> should  
> only happen in ruby-land, and you should be safe in C++, right?

You can only be safe in C++ land if your C++ never invokes Ruby C  
functions which might longjump. So, if you just do C++ processing and  
return values it’s ok, but if part of your C++ processing is to invoke  
methods defined in Ruby (likely for callbacks such as blocks) you can  
easily shoot yourself in the foot…

Regards

```
robert

```

---

<div class="post-metadata">

**Author:** ![paul\_vudmaska1](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@paul\_vudmaska1](https://rubytalk.org/u/paul_vudmaska1)\
**Post date:** [2 October 2003 14:28 UTC](https://rubytalk.org/t/c-or-c/8358/9 "2003-10-02T14:28:04Z")

</div>

The biggest problem i have with Ruby is the sleepness  
nights… ;-\>

Has anyone heard of e4x…emcascript(aka javascript)  
for xml?

[http://dev2dev.bea.com/products/wlworkshop/articles/JSchneider\_XML.jsp](http://dev2dev.bea.com/products/wlworkshop/articles/JSchneider_XML.jsp)

Basically it is an attempt to roll xml as a native  
type into ecmascript. I’d suggest Ruby could benefit  
and set itself apart by doing so. Following is my own  
quick and dirty Ruby’d version of the above.(you might  
want to check it out first)

# xml literal…

p = %x{

paul

john

}  
or  
p \<\<\<XML

paul

  

john

  

XML  
#access  
mary = p.Peeps.P[3]#xpath starts with 1…

#edit  
mary = ‘mary’#convenience method appending text to P  
element  
#add element  
p.Peeps \<\< %x{

Ringo

}

#iter.  
p.Peeps.each(‘P’) do |person|

puts person #\>paul,john,mary,ringo

end

Instead of the dot notation for swiching context  
suggested in the above article, perhaps use xpath  
exclusively,imo.

p.each(’//P’) do …end

So, basically, rexml rolled into ruby natively.

But what about the much maligned xsl stylesheets? We  
need style too - Rubystyle!

# prob a million ways to do this…

style = \<\<\<STYLE

# #{P}
 is a rock star
STYLE ...here's one output = p.each('//P').transform(style)

There’s plenty of room for rolling more  
organic/programic/rubylike approaches to style than  
xsl into Ruby(particulary considering Ruby’s iters and  
blocks). I’m not sure this is the wisest approach, and  
think people like Michael Kay(an xsl guru) might point  
out the folly of this. And keeping to a standard would  
be good for a product such as Ruby but it sure is  
intersting…at least to me.

So now we’ve

1. done what javascript might be doing but totally  
trumped them with (ruby)style.
2. added a feature that python and perl can only wish  
for
3. created an internal common data structure that is  
similar to the array, hash and struct but is sometimes  
better and certainly more portable/readable.
4. now a native type, we can import/export data to  
whatever speaks xml without worrying about  
implementation.
5. have an inherent mechanism for seperating duties  
within code- ie data from style  
6)a powerful native templating system. Great for web  
stuff particularily. Picture putting the power of ruby  
in templates that are sandboxed. No need to learn  
template language X. Do it in ruby or subset of.  
6+) prob much more, xml tends to feed upon itself

Whatcha think? Can i count on this by 1.8.1? ;-\>

:pv

PS:as for the previous comment at artima about the  
limitations of Ruby - stone that guy! 🙂 Not really-  
seemed like legit points 2me. I want Ruby to scale to  
1 mil hits per sec on my ipaq too - but not at the  
expense of creativity, malability, fidelity,  
pragmatism or effectiveness.

> **···**
>
> * * *
> 
> Do you Yahoo!?  
> The New Yahoo! Shopping - with improved product search  
> [http://shopping.yahoo.com](http://shopping.yahoo.com)

---

<div class="post-metadata">

**Author:** ![Chad\_Fowler](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@Chad\_Fowler](https://rubytalk.org/u/Chad_Fowler)\
**Post date:** [2 October 2003 15:02 UTC](https://rubytalk.org/t/c-or-c/8358/10 "2003-10-02T15:02:04Z")

</div>

# Hi –

> **···**
>
> On Thu, 2 Oct 2003 [dblack@superlink.net](mailto:dblack@superlink.net) wrote:
> 
> # 
> 
> # On Thu, 2 Oct 2003, Paul William wrote:
> 
> # 
> 
> # \> On Thu, 2003-10-02 at 16:45, Joe Cheng wrote:
> 
> # \> \> I’d like to start writing Ruby extensions. Does it make a difference
> 
> # \>
> 
> # \> Why do you want to write extensions? Why cant you write ruby code?
> 
> # 
> 
> # It’s not an either-or choice; lots of Ruby programmers do both.
> 
> # C extensions are usually written for speed.
> 
> …or to integrate with C-based libraries, which I’d say is one of the  
> best reasons to use C in your Ruby development. My process would be:
> 
> - If it requires a C library, evaluate how difficult it would be to  
> obviate the need for the C library by rewriting the part I need in Ruby (I  
> don’t necessarily recommend this, but it’s how I am).
> - If it requires a C library, wrap the C library with a small Ruby  
> extension.
> - If it doesn’t require a C library, try pure Ruby before jumping into a  
> C extension based on the assumption that C is necessary for speed.
> - If the ruby version is too slow, try to optimize it in Ruby.
> - If it’s not going to be fast enough in Ruby, rewrite the required bits  
> in C as an extension.
> 
> I’m very C-averse I guess.
> 
> Chad

---

<div class="post-metadata">

**Author:** ![Sean\_O\_Dell1](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@Sean\_O\_Dell1](https://rubytalk.org/u/Sean_O_Dell1)\
**Post date:** [2 October 2003 16:08 UTC](https://rubytalk.org/t/c-or-c/8358/11 "2003-10-02T16:08:09Z")

</div>

Thomas Sondergaard wrote:

> > Ruby is really C-oriented. It longjmps on errors, so the stack doesn’t  
> > “unwind” the way C++ objects really wants it to.
> 
> I think I understand what you mean. Is it that destructors may not be called  
> as expected? Please elaborate!

Destructors don’t get called, correct.

> > There are work-arounds  
> > for that, but I found that without a good foundation of libraries to  
> > work with, C++ was a real pain, so I stick with C.
> 
> What kind of work arounds? If you rb\_protect everything the longjmp’s should  
> only happen in ruby-land, and you should be safe in C++, right?

I believe, at least under Windows, that rb\_protect didn’t protect me  
quite as well as I needed (I still got longjmp’d past), so I abandonded  
C++ entirely. I’m a devoted C++ user, so I didn’t give it up easily,  
believe me. It was just FAR more trouble trying to be Mr. C++ around  
the Ruby engine than it was using C. C isn’t so bad if you got your  
head on for it.

```
Sean O'Dell

```

---

<div class="post-metadata">

**Author:** ![Chad\_Fowler](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@Chad\_Fowler](https://rubytalk.org/u/Chad_Fowler)\
**Post date:** [2 October 2003 15:17 UTC](https://rubytalk.org/t/c-or-c/8358/12 "2003-10-02T15:17:49Z")

</div>

# Basically it is an attempt to roll xml as a native

# type into ecmascript. I’d suggest Ruby could benefit

# and set itself apart by doing so. Following is my own

# quick and dirty Ruby’d version of the above.(you might

# want to check it out first)

> **···**
>
> On Thu, 2 Oct 2003, paul vudmaska wrote:
> 
> # 
> 
> Pretty much everything you’ve mentioned here is possible with REXML  
> already. The only thing I can see that isn’t possible is the built-in XML  
> syntax. I can’t see how hard-wiring XML as a part of Ruby’s syntax  
> provides much of a benefit at all. It would be fashionable (though not  
> really all that fashionable these days), but barring that it’s just more  
> baggage to carry around.
> 
> # There’s plenty of room for rolling more
> 
> # organic/programic/rubylike approaches to style than
> 
> # xsl into Ruby(particulary considering Ruby’s iters and
> 
> # blocks). I’m not sure this is the wisest approach, and
> 
> # think people like Michael Kay(an xsl guru) might point
> 
> # out the folly of this. And keeping to a standard would
> 
> # be good for a product such as Ruby but it sure is
> 
> # intersting…at least to me.
> 
> # 
> 
> Interesting in the same way that Lojban is interesting  
> ([http://www.lojban.org](http://www.lojban.org)). 🙂
> 
> # So now we’ve
> 
> # 1) done what javascript might be doing but totally
> 
> # trumped them with (ruby)style.
> 
> # 2) added a feature that python and perl can only wish
> 
> # for
> 
> Are we playing sports or writing programming languages? I didn’t know it  
> was a competition. Who are the enemies? Is anyone on our team?
> 
> # 3) created an internal common data structure that is
> 
> # similar to the array, hash and struct but is sometimes
> 
> # better and certainly more portable/readable.
> 
> more readable?  
> blahblah2lkjsdf  
> vs.  
> [“blah”, “blah2”, “lkjsdf”]
> 
> # 4) now a native type, we can import/export data to
> 
> # whatever speaks xml without worrying about
> 
> # implementation.
> 
> With REXML in the distribution you can already do this. Just requires a  
> few more keystrokes.
> 
> # 5) have an inherent mechanism for seperating duties
> 
> # within code- ie data from style
> 
> But you’ve now joined a data representation format to a language. Where  
> would you rather have coupling?
> 
> # Whatcha think? Can i count on this by 1.8.1? ;-\>
> 
> # 
> 
> No offense intended, but I hope not 🙂

---

<div class="post-metadata">

**Author:** ![Erik\_Terpstra2](https://avatars.discourse-cdn.com/v4/letter/e/d9b06d/32.png) [@Erik\_Terpstra2](https://rubytalk.org/u/Erik_Terpstra2)\
**Post date:** [2 October 2003 15:26 UTC](https://rubytalk.org/t/c-or-c/8358/13 "2003-10-02T15:26:52Z")

</div>

Last year I made a quick hack that could do something like that.  
I didn’t have much experience with Ruby back then, so it is a quick and  
very dirty solution. But the following works:

require ‘XML’

y = XML %{  
  
  
Joe  
28  
  
Engineering  
  
  
  
Ken  
26  
  
Engineering  
  
  
  
}

puts y.employees.employee[0].age  
y.employees.employee[0].age = '9’  
puts y.employees.employee[0].age

y.employees.employee.each do |employee|  
puts "name: #{[employee.name](http://employee.name)}, age: #{employee.age}"  
end

doc = XML %{  
  
  
I. Wannabuy  
  
53 Party Lane  
Anywhere  
CA  
12345  
  
  
  
Large Purple Dinosaur,  
Generic  
35  
24.99  
  
  
Catapult  
1  
149.95  
  
  
300 foot measuring tape  
1  
9.95  
  
  
}

def calc\_total(order)  
total = 0  
order.item.each do |item|  
total += item.price.to\_f \* item.quantity.to\_i  
end  
return total  
end

puts “total: #{calc\_total(doc.order)}”

> **···**
>
> ======================================================
> 
> This is the file XML.rb that makes it work:
> 
> ======================================================
> 
> require 'xmltreebuilder’  
> require ‘perlvalue’
> 
> ELEMENT\_NODE = 1; ATTRIBUTE\_NODE = 2; TEXT\_NODE = 3
> 
> module Kernel  
> def XML(xml)  
> RNX.new(xml)  
> end  
> end
> 
> class RNX  
> def initialize(xml)  
> @level = 0; @line = @source = ‘’; @path = []  
> builder = XML::DOM::Builder.new  
> begin  
> dom = builder.parse xml.gsub(/\s+/, ‘’)  
> rescue  
> puts “#{$0}: #{$!} (in line #{builder.line}”;  
> exit 1  
> end  
> dom.documentElement.normalize  
> traverse dom  
> eval %{  
> @#{dom.documentElement.nodeName} = PerlValue.new  
> #{@source}
> 
> ```
> def self.#{dom.documentElement.nodeName}
> return @#{dom.documentElement.nodeName}
> end
> }
> end
> 
> def traverse(node)
> index = 0
> node.childNodes.each do |n|
> if n.nodeType == ELEMENT_NODE
> @path[@level] = n.nodeName
> if (n.nextSibling and 
> 
> ```
> 
> n.nextSibling.nodeName == n.nodeName) or (n.previousSibling and  
> n.previousSibling.nodeName == n.nodeName)  
> @path[@level] += "[#{index}]“  
> index += 1  
> end  
> @line = @path.join(’.’)  
> @level += 1; traverse n; @level -= 1  
> @path.delete\_at(@level)  
> elsif n.nodeType == TEXT\_NODE  
> @line += " = ‘#{n.data}’\n” if n.data  
> =~ /\S/ #optional!!!  
> @source += "@#{@line}"  
> end  
> end  
> end  
> end

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [2 October 2003 16:21 UTC](https://rubytalk.org/t/c-or-c/8358/14 "2003-10-02T16:21:46Z")

</div>

> I believe, at least under Windows, that rb\_protect didn't protect me  
> quite as well as I needed (I still got longjmp'd past), so I abandonded  
> C++ entirely.

With C++, never try to mix 'try {} catch {}' with rb\_protect() even with C  
be carefull. For example, look at plruby to see how it made the call to  
rb\_protect() with a setjmp()/longjmp() need by postgres

static VALUE  
pl\_protect(plth)  
&nbsp;&nbsp;&nbsp;&nbsp;struct pl\_thread\_st \*plth;  
{  
&nbsp;&nbsp;&nbsp;&nbsp;Datum retval;  
&nbsp;&nbsp;&nbsp;&nbsp;VALUE result;

&nbsp;&nbsp;&nbsp;&nbsp;if (sigsetjmp(Warn\_restart, 1) != 0) {  
&nbsp;&nbsp;return pl\_eCatch;  
&nbsp;&nbsp;&nbsp;&nbsp;}  
/\* ... \*/  
}

static VALUE  
pl\_real\_handler(struct pl\_thread\_st \*plth)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;VALUE result;  
&nbsp;&nbsp;&nbsp;&nbsp;int state;  
/\* ... \*/  
&nbsp;&nbsp;&nbsp;&nbsp;state = 0;  
&nbsp;&nbsp;&nbsp;&nbsp;pl\_call\_level++;  
&nbsp;&nbsp;&nbsp;&nbsp;result = rb\_protect(pl\_protect, (VALUE)plth, &state);  
&nbsp;&nbsp;&nbsp;&nbsp;pl\_call\_level--;  
/\* ... \*/  
}

the order is really important : after this I can safely use rb\_raise() in  
plruby and I can catch the error given by postgres (when it use longjmp())

Guy Decoux

---

<div class="post-metadata">

**Author:** ![paul\_vudmaska1](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@paul\_vudmaska1](https://rubytalk.org/u/paul_vudmaska1)\
**Post date:** [2 October 2003 16:46 UTC](https://rubytalk.org/t/c-or-c/8358/15 "2003-10-02T16:46:38Z")

</div>

> > * * *

“Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)  
Pretty much everything you’ve mentioned here is  
possible with REXML  
--------------------\<\<  
Except the style. Besides, that was part of my point.

> > * * *

“Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)  
I can’t see how hard-wiring XML as a part of Ruby’s  
syntax  
provides much of a benefit at all. It would be  
fashionable (though not  
really all that fashionable these days), but barring  
that it’s just  
more  
baggage to carry around.  
---------\<\<  
It’s interesting to me that you would wrap an xml  
file(rss) in an object  
[http://www.chadfowler.com/ruby/rss/](http://www.chadfowler.com/ruby/rss/)  
but belittle an offhanded attempt to make inherent  
those attributes that you so painstakingly crafted  
code for and call the former more baggage. Help me  
understand that, Chad!

> > * * *

“Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)

Interesting in the same way that Lojban is interesting

([http://www.lojban.org](http://www.lojban.org)). 🙂  
--------------------\<\<  
for you!

> > * * *

“Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)

Are we playing sports or writing programming  
languages? I didn’t know  
it  
was a competition. Who are the enemies? Is anyone on  
our team?  
--------------------\<\<

I’m just a simple scriptor making an open ended  
suggestion about a language that i enjoy in a forum  
that i would hope would encourage such things - even  
if they are stupid. What language are you writing,  
btw? Just an analogy, maybe a bad one. Sorry.

> > * * *

“Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)  
more readable?

…blahblah2lkjsdf

vs.  
[“blah”, “blah2”, “lkjsdf”]  
--------------------\<\<

More readable as in ‘more context’ not as in more  
succinct or fewer letters or anything else.(ie are  
those an array of items in a list or just a lot of  
blah?)

> > * * *

With REXML in the distribution you can already do  
this. Just requires a few more keystrokes.  
-----\<  
Sure but fewer works for me better.

> > * * *

“Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)  
Where  
would you rather have coupling?  
-----------\<\<  
Where it serves me best. I was merely contemplating  
another tool to choose from. I’m not unaware of the  
implications.

> > * * *

“Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)  
No offense intended, but I hope not 🙂  
-----------\<\<

None taken!

> > * * *

“Erik Terpstra” [erik@terpnet.nl](mailto:erik@terpnet.nl)  
Last year I made a quick hack that could do something  
like that.  
I didn’t have much experience with Ruby back then, so  
it is a quick and  
very dirty solution. But the following works:  
----------\>

Thanks Erik i’m going to take a look at this and see  
if i can use it! I’m still a newbie and will prob  
learn a lot from it in any case.

😛

> **···**
>
> * * *
> 
> Do you Yahoo!?  
> The New Yahoo! Shopping - with improved product search
> 
> > **[Yahoo Shopping - We'll track the prices for you!](https://shopping.yahoo.com/)**
> >
> > Discover deals, product reviews, and compare prices on your favorite items. Plus, shop stores like Walmart, Nordstrom Rack, Amazon and more.

---

<div class="post-metadata">

**Author:** ![Zach\_Dennis1](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@Zach\_Dennis1](https://rubytalk.org/u/Zach_Dennis1)\
**Post date:** [2 October 2003 17:03 UTC](https://rubytalk.org/t/c-or-c/8358/16 "2003-10-02T17:03:06Z")

</div>

I think it would be wonderful if Ruby could handle XML somewhat how Flash  
Actionscript handles XML( but with a few tweaks here and there of course ),  
but the overall way that the Actionscript XML Object is a beautiful thing.  
Or at least I think. I think it would be a plus.

-Zach

---

<div class="post-metadata">

**Author:** ![Chad\_Fowler](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@Chad\_Fowler](https://rubytalk.org/u/Chad_Fowler)\
**Post date:** [2 October 2003 17:09 UTC](https://rubytalk.org/t/c-or-c/8358/17 "2003-10-02T17:09:26Z")

</div>

# \>\>--------

# “Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)

# Pretty much everything you’ve mentioned here is

# possible with REXML

# --------------------\<\<

# Except the style. Besides, that was part of my point.

> **···**
>
> On Fri, 3 Oct 2003, paul vudmaska wrote:
> 
> # 
> 
> Well, when you say “style” I think you mainly mean syntax, right? Other  
> than XML being first-class syntax, the rest of the style you’ve proposed  
> is do-able (and reflected quite well in Erik’s posted code).
> 
> # \>\>--------
> 
> # “Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)
> 
> # I can’t see how hard-wiring XML as a part of Ruby’s
> 
> # syntax
> 
> # provides much of a benefit at all. It would be
> 
> # fashionable (though not
> 
> # really all that fashionable these days), but barring
> 
> # that it’s just
> 
> # more
> 
> # baggage to carry around.
> 
> # ---------\<\<
> 
> # It’s interesting to me that you would wrap an xml
> 
> # file(rss) in an object
> 
> # [http://www.chadfowler.com/ruby/rss/](http://www.chadfowler.com/ruby/rss/)
> 
> # but belittle an offhanded attempt to make inherent
> 
> # those attributes that you so painstakingly crafted
> 
> # code for and call the former more baggage. Help me
> 
> # understand that, Chad!
> 
> # 
> 
> First of all, you could hardly call the process of creating that simple  
> library painstaking. The fact that I wrapped RSS parsing in an object  
> demonstrates (though rather poorly considering the age of this code–see  
> Austin Ziegler’s replacement on SourceForge) my belief that things like this  
> should be abstracted into _libraries_ and not the language. Someone else has  
> created a CSV library. We could include CSV as a native data type too.  
> How about URIs? We have uri.rb, but why shouldn’t we be able to simply  
> say:
> 
> myURI = [http://www.ruby-lang.org](http://www.ruby-lang.org)
> 
> How about JPEG files? With the right graphical programming environment,  
> you could actually embed pictures into code. myVar = . myPic.vertical\_flip.
> 
> # 
> 
> # \>\>--------
> 
> # “Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)
> 
> # 
> 
> # Interesting in the same way that Lojban is interesting
> 
> # 
> 
> # ([http://www.lojban.org](http://www.lojban.org)). 🙂
> 
> # --------------------\<\<
> 
> # for you!
> 
> # 
> 
> Don’t you find Lojban interesting?
> 
> # 
> 
> # \>\>--------
> 
> # “Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)
> 
> # 
> 
> # Are we playing sports or writing programming
> 
> # languages? I didn’t know
> 
> # it
> 
> # was a competition. Who are the enemies? Is anyone on
> 
> # our team?
> 
> # --------------------\<\<
> 
> # 
> 
> # I’m just a simple scriptor making an open ended
> 
> # suggestion about a language that i enjoy in a forum
> 
> # that i would hope would encourage such things - even
> 
> # if they are stupid. What language are you writing,
> 
> # btw? Just an analogy, maybe a bad one. Sorry.
> 
> # 
> 
> “We” as in the community, of course. And the language would be ruby. I  
> certainly wasn’t implying that I’m personally creating Ruby, but that’s  
> pretty obvious. I was serious about the question I asked, though. Why  
> the competition?
> 
> # 
> 
> # 
> 
> # \>\>--------
> 
> # “Erik Terpstra” [erik@terpnet.nl](mailto:erik@terpnet.nl)
> 
> # Last year I made a quick hack that could do something
> 
> # like that.
> 
> # I didn’t have much experience with Ruby back then, so
> 
> # it is a quick and
> 
> # very dirty solution. But the following works:
> 
> # ----------\>
> 
> # 
> 
> Erik demonstrated the same point I was trying to make, but he had some  
> working code 🙂

---

<div class="post-metadata">

**Author:** ![David\_A\_Black2](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@David\_A\_Black2](https://rubytalk.org/u/David_A_Black2)\
**Post date:** [2 October 2003 17:11 UTC](https://rubytalk.org/t/c-or-c/8358/18 "2003-10-02T17:11:38Z")

</div>

Hi –

> Chad wrote:
> 
> > I can’t see how hard-wiring XML as a part of Ruby’s syntax  
> > provides much of a benefit at all. It would be fashionable  
> > (though not really all that fashionable these days), but barring  
> > that it’s just more baggage to carry around.
> 
> It’s interesting to me that you would wrap an xml file(rss) in an  
> object [http://www.chadfowler.com/ruby/rss/](http://www.chadfowler.com/ruby/rss/) but belittle an offhanded  
> attempt to make inherent those attributes that you so painstakingly  
> crafted code for and call the former more baggage. Help me  
> understand that, Chad!

That’s how it works: there’s a core language, and then there are  
libraries and programs. You can’t put everything in the core  
language.

> > more readable?
> > 
> > …blahblah2lkjsdf
> > 
> > vs.  
> > [“blah”, “blah2”, “lkjsdf”]
> 
> More readable as in ‘more context’ not as in more succinct or fewer  
> letters or anything else.(ie are those an array of items in a list  
> or just a lot of blah?)

It’s just a lot of blah – well, an array of strings, to be a little  
more specific. They may or may not serve as “items” in a “list” at  
some point, inside some kind of object and/or markup system. That’s a  
separate matter.

David

> **···**
>
> On Fri, 3 Oct 2003, paul vudmaska wrote:
> 
> –  
> David Alan Black  
> home: [dblack@superlink.net](mailto:dblack@superlink.net)  
> work: blackdav@shu.edu  
> Web: [http://pirate.shu.edu/~blackdav](http://pirate.shu.edu/~blackdav)

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Austin\_Ziegler2](https://rubytalk.org/u/Austin_Ziegler2)\
**Post date:** [2 October 2003 18:09 UTC](https://rubytalk.org/t/c-or-c/8358/19 "2003-10-02T18:09:46Z")

</div>

“Chad Fowler” [chad@chadfowler.com](mailto:chad@chadfowler.com)

> > I can’t see how hard-wiring XML as a part of Ruby’s syntax  
> > provides much of a benefit at all. It would be fashionable  
> > (though not really all that fashionable these days), but barring  
> > that it’s just more baggage to carry around.  
> > It’s interesting to me that you would wrap an xml file(rss) in an  
> > object [http://www.chadfowler.com/ruby/rss/](http://www.chadfowler.com/ruby/rss/) but belittle an  
> > offhanded attempt to make inherent those attributes that you so  
> > painstakingly crafted code for and call the former more baggage.  
> > Help me understand that, Chad!

I’m not Chad, but as someone who liked what Chad did and wrote a  
follow-up library that (mostly) conformed to his API, I can explain  
exactly why I did it much the same way. Basically, Chad is  
representing an object (a rich site summary, or a channel). That it  
happens to correspond to an XML format is somewhat irrelevant. There  
are actually four common variants on this, and two less common  
variants. By designing channels as objects, it becomes relatively  
easy to support those variant formats.

> > more readable?  
> > blahblah2lkjsdf  
> > vs.  
> > [“blah”, “blah2”, “lkjsdf”]  
> > More readable as in ‘more context’ not as in more succinct or  
> > fewer letters or anything else. (ie are those an array of items in  
> > a list or just a lot of blah?)

There is no meaningful distinction between an array and a list in  
Ruby. In all likelihood, you might do:

class List  
def initialize(\*items)  
@items = \*items  
end  
attr\_reader :items  
end

list = List.new(%w{blah blah2 ljksdf})  
list.items # =\> [“blah”, “blah2”, “lkjsdf”]

When you’re writing a program, why would you want to add unnecessary  
semantic information (e.g., encode the list as XML) when the  
necessary semantic information is already present. The only time you  
need to worry about such semantic information is when you write it  
to an external format … like XML.

> > With REXML in the distribution you can already do this. Just  
> > requires a few more keystrokes.  
> > Sure but fewer works for me better.

Yeah, but you’ve traded fewer keystrokes here in favour of more  
keystrokes elsewhere.

You may want to look around the archives for a discussion of %y{}  
(for YAML) and the like that happened around the 10th of September.  
Basically, some of the same suggestions you’ve made came up – and  
weren’t really liked.

-austin

> **···**
>
> ## On Fri, 3 Oct 2003 01:46:38 +0900, paul vudmaska wrote:
> 
> austin ziegler \* austin@halostatue.ca \* Toronto, ON, Canada  
> software designer \* pragmatic programmer \* 2003.10.02  
> \* 13.58.40

---

<div class="post-metadata">

**Author:** ![Chad\_Fowler](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@Chad\_Fowler](https://rubytalk.org/u/Chad_Fowler)\
**Post date:** [2 October 2003 17:10 UTC](https://rubytalk.org/t/c-or-c/8358/20 "2003-10-02T17:10:17Z")

</div>

# I think it would be wonderful if Ruby could handle XML somewhat how Flash

# Actionscript handles XML( but with a few tweaks here and there of course ),

# but the overall way that the Actionscript XML Object is a beautiful thing.

# Or at least I think. I think it would be a plus.

> **···**
>
> On Fri, 3 Oct 2003, Zach Dennis wrote:
> 
> # 
> 
> Zach, do you have a link or an example? I’ve heard good things about  
> ActionScript’s XML handling myself.
> 
> Chad

[Next page](https://rubytalk.org/t/c-or-c/8358.md?page=2)
