Forum: IronRuby Re: Lowercase classname

49937800ddb918787f61f88fe100562f?d=identicon&s=25 andrew Wilson (Guest)
on 2010-11-19 16:52
(Received via mailing list)
This is only an acceptable solution if the user has the source code and
is
capable of modifying it.  For how I test things with IronRuby, this
isn't
always possible.  Seems odd to me that one of the most flexible language
I
know of can't read/integrate with another language due to code not
following
a rigid structure.

Doesn't IronPython allow for this?  I was fairly sure I could import
non-standard .Net convention based code into it.

-Andrew


On Fri, Nov 19, 2010 at 2:41 PM, Shay Friedman <shay.friedman@gmail.com
>wrote:
> Look here:
>
http://www.ironshay.com/post/Working-with-NET-Lowe...
> <
http://www.ironshay.com/post/Working-with-NET-Lowe...
>
> Shay.
>
Excellent solution. I mean, really, all the C# classes should start with
an
uppercase letter, thats basically a standard, therefore this should be
the
only solution and I don't see no need to actually hack this otherwise
into
IronRuby.


--
If I had six hours to chop down a tree, Id spend the first four of them
sharpening my axe.

-Abraham Lincoln
637f25ef9ecc971bdeeb05c533f36b60?d=identicon&s=25 Andrius Bentkus (Guest)
on 2010-11-19 17:36
(Received via mailing list)
On Fri, Nov 19, 2010 at 4:48 PM, andrew Wilson <a.wilson82@gmail.com>
wrote:

> This is only an acceptable solution if the user has the source code and is
> capable of modifying it.  For how I test things with


Why? Just use 'LowerCase = get_const("lowerCase")'.
Actually I don't understand why one would code C# using camelStyle. The
standard is CamelStyle.


> IronRuby, this isn't always possible.  Seems odd to me that one of the most
> flexible language I know of can't read/integrate with another language due
> to code not following a rigid structure.


The fact that it is dynamic does not implicate that IronRuby should be
able
to read all kind of crazy naming styles, it should implicate the you
could
modify it to your needs with minimum amount of coding, just add
something
like this before you use that library in ruby:

modul.constants.each do |const|
    eval "#{const.uppercase} = modul.const_get(const)"
end

This is only semi-pseudocode, but you should get the idea.

Doesn't IronPython allow for this?  I was fairly sure I could import
> non-standard .Net convention based code into it.
>

True or False.
A2b000877e1057e84b9b8fc1d270e457?d=identicon&s=25 Jimmy Schementi (Guest)
on 2010-11-19 17:39
(Received via mailing list)
Andrew,

Not sure I follow. IronRuby does support this via DotNetClassName =
Object.const_get("lower_case_dotnet_class_name"), so you don't need to
change your code. This is an issue because of Ruby itself; classes are
required to be Ruby constants, which syntactically can only start with
an
upper-case letter. Since IronRuby is syntactically equivalent to Ruby,
we
will not remove this rule. Instead, we either suggest changing your C#
code,
or if you can't, use const_get. WRT your IronPython comment, it doesn't
have
this issue because the Python language doesn't enforce a naming scheme
on
type names.

~Jimmy
D91500918a07bfae5b38b8943fd42fbe?d=identicon&s=25 Mike Moore (Guest)
on 2010-11-19 18:50
(Received via mailing list)
I disagree. You don't need to be able to modify the .NET source code to
get
this to work. You can use Ruby to make Ruby happy. The reason for the
friction is because .NET != Ruby. When you create a class in Ruby, you
are
actually creating an object that inherits from Class, and then you are
creating a constant that points to that object. In Ruby all constants
start
with an upper case character. Ruby doesn't allow you to create a class
that
starts with a lower case letter.

 > class foo; def to_s; puts 'wha?!'; end; end
SyntaxError: (irb):1: class/module name must be CONSTANT
class foo; def to_s; puts 'wha?!'; end; end
          ^

IronRuby does a lot of work to match Ruby's conventions of snake_case
methods, but it cannot resolve a lower case namespace or class from
.NET. I
think IronRuby is doing the right thing here. Its very simple to setup
your
Ruby constants that point to your .NET namespaces and classes using the
method shown in the URL provided.

Foo      = Object.const_get("foo")
Foo::Bar = Foo.const_get("bar")
bar      = Foo::Bar.new

Ruby is awesome but it is not infinitely flexible. You gotta jump to
Lisp
for that. :)
D91500918a07bfae5b38b8943fd42fbe?d=identicon&s=25 Mike Moore (Guest)
on 2010-11-19 19:07
(Received via mailing list)
For some reason Jimmy's reply didn't show up in my inbox until I sent my
reply. Sorry for the duplicate explanation.
F0f461459193aa098a80bd3e74e0ac9c?d=identicon&s=25 Shay Friedman (shayfriedman)
on 2010-11-19 19:44
(Received via mailing list)
Ruby can do crazy stuff but it doesn't support one thing that C# does -
camelCase names for classes and modules (because they're eventually
constants). It just can't be done.
Taking this into consideration, what name would you expect a camelCased
C#
class name get in IronRuby? its PascalCased form? and what if there are
two
classes in the C# assembly, one named camelCase and the second CamelCase
-
totally legit in C#... what would you expect to happen then?

It's a problematic situation and I think IronRuby goes with the right
solution here.

Shay.


On Fri, Nov 19, 2010 at 6:05 PM, Andrius Bentkus
9bc73a477811a9578b3c526bbe567f3d?d=identicon&s=25 Tinco Andringa (Guest)
on 2010-11-20 23:40
(Received via mailing list)
Hey guys.. it's very nice that you all say the same thing, but it
doesn't work in IronRuby 1.1.1:

>>> Object.const_get "foo"
(ir):1:in `const_get': `foo' is not allowed as a constant name
(NameError)
        from (ir):1

If this would've worked then I wouldn't have had to ask the question
in the first place :)

Kind regards,
Tinco Andringa
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2010-11-21 00:06
(Received via mailing list)
Can you send a link to the assembly that defines the class you are
trying to use?

Tomas
9bc73a477811a9578b3c526bbe567f3d?d=identicon&s=25 Tinco Andringa (Guest)
on 2010-11-21 00:47
(Received via mailing list)
http://code.google.com/p/bwapi-mono-bridge/ here it is :)

Thanks

On Sat, Nov 20, 2010 at 11:53 PM, Tomas Matousek
9bc73a477811a9578b3c526bbe567f3d?d=identicon&s=25 Tinco Andringa (Guest)
on 2010-11-21 00:47
(Received via mailing list)
Okey, I just tried it myself on those assemblies, and now I find it
actually does work :D Sorry guys :) I was thrown off by the error that
is thrown when the constant with the lower case name doesn't exist. I
failed at first because I tried Object.const_get('bwapi') instead of
BWAPI.const_get('bwapi').

Thanks for the tips :)
This topic is locked and can not be replied to.