Late Binding

L

lgbjr

Hi All,

Actually, funny you mentioned the 2.0 Framework. The only reason I even
considered not using a jagged array was based on info I read in VS.NET 2005
docs. I've actually converted a copy of my project to run under 2.0, mostly
to get a feel for the 2005 IDE, but also to see what I might be up against
when clients wanted to go to the 2.0 framework.

To see just how easy it is to work in 2005, this is where I initially turned
Options Strict On, as all of the errors produced come with nice little
recommended fixes. when I got to the late binding issue regarding HIndex, I
started looking at Array of Arrays (just as Herfield and Jay said, using
HIndex()(), rather than HIndex() ). From the 2005 docs:

Jagged arrays are not compliant with the Common Language Specification
(CLS). This means you should not expose jagged arrays from any class you
want CLS-compliant code to consume.

Without really reading the second sentence, I decided I really didn't want
to introduce a potential problem into my app. However, I agree with Jay.
This is a private implementation, so the jagged array stays and it fixes the
late binding, so, that, as they say, is that!

thanks guys!!
Lee


Jay B. Harlow said:
Hmm...
| Which I read to mean that the jagged array "Integer()()" is implemented
as
| an "System.Array of System.Array Of Integer", of course if you look at
the
| IL shows this is how they are implemented!
Reading that just now, it doesn't make as much sense as I thought it did
when I wrote it. :-(

Reading the annotation accompanying Rule 16 in the Common Language
Infrastructure Annotated Standard it appears I was partially correct. What
I'm not certain about is if you do not overload a method on Jagged arrays
if
the method is CLS compliant or not. It definitely appears if you overload
a
method based on Jagged Arrays they are definitely not CLS compliant.

For example:

Public Compliant

Public Sub Sum(ByVal values As Integer()())
End Sub

End Class

Public Class NoneCompliant

Public Sub Sum(ByVal values As Integer()())
End Sub

Public Sub Sum(ByVal values As Single()())
End Sub

End Class

The way I am understanding the standard, the NoneCompliant class is not
compliant as both methods are treated as "Sum(ByVal values As
System.Array())", while the Compliant class may be compliant as there is
only a single method (its not overloaded)...

I'll have to see if I can find more info on this. Also I would be curious
if
.NET 2.0 has clarified this any...

Either way, as was suggested, if the jagged array is a private
implementation detail of the type or method (its not Publicly exposed)
then
the entire discussion of it being compliant or not, although interesting,
is
largely academic.

Hope this helps
Jay



| lgbjr,
|| But, As I posted earlier, I want to stay away from the jagged array, as
| it's
|| not CLS compliant.
| Where do you get that impression???
|
| According to The Common Language Infrastructure Annotated Standard:
| <quote>NOTE: So-called "jagged arrays" are CLS-compliant, but when
| overloading multiple array types they are one-dimensional, zero-based
arrays
| of type System.Array.</quote>
|
| Which I read to mean that the jagged array "Integer()()" is implemented
as
| an "System.Array of System.Array Of Integer", of course if you look at
the
| IL shows this is how they are implemented! Its just that C# & VB.NET
offers
| syntactical sugar to simplify it to Integer()() or int[][]. As you found
| putting an array, any array into a System.Array variable requires late
| binding, if you put the array into a strongly typed variable, such as
| Integer()(), then you avoid the late binding. Also using strongly typed
| variables may enable the compiler to use array specific IL instructions
| instead of the methods on System.Array...
|
| Hope this helps
| Jay
|
|
| || Hi All,
||
|| Cor, you are correct, the issue was really related to late binding,
though
| I
|| understand why Jay and Herfield hit on the jagged array.
||
|| But, As I posted earlier, I want to stay away from the jagged array, as
| it's
|| not CLS compliant.
||
|| I had to move onto something else temporarily, but I'll post back
tomorrow
|| with any questions regarding Cor's possible solution!
||
|| Thanks
||
|| Lee
||
|| || > Jay,
|| >
|| > The question is in my opinion a late binding question (see the
subject)
|| > not an array question.
|| >
|| > When you say like Herfried that, using a jagged array is always the
best
|| > solution to overcome late bindings problems, than I have nothing more
to
|| > discus.
|| >
|| >> The best solution is to create a jagged array (an array of arrays):
|| >
|| > That maybe the jagged array is the best solution for this problem,
can
| be.
|| > However, does not for me answer his more implicit question how to
| overcome
|| > late binding in general. I nowhere saw that in yours and either in
|| > Herfrieds text.
|| >
|| > When it is possible, than I think that it is *better* to learn how to
| fish
|| > than to give a fish.
|| >
|| > I hope this helps
|| >
|| > Cor
|| >
||
||
|
|
 
C

Cor Ligthert

Jay,
As you may know you use Option Strict On to avoid late binding! Simple,
isn't it.
No I did not know this, it's in my opinion a completly wrong statement. I
thought you knew better. It can in my opinion give a complete wrong idea
about what Option Strict On does.

However, I made my answer for the OP and was only asking with my reply to
Herfried why he wrote that something was the *best* way.

Programming is in my opinion not a religion where you just has to believe
something when somebody write that.

However probably we disagree about that

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
No I did not know this, it's in my opinion a completly wrong statement. I
thought you knew better. It can in my opinion give a complete wrong idea
about what Option Strict On does.

However, I made my answer for the OP and was only asking with my reply to
Herfried why he wrote that something was the *best* way.

It actually is the best way, even if you don't believe it.
 
C

Cor Ligthert

Herfried,
It actually is the best way, even if you don't believe it.

--
What do you mean that I don't believe? I don't see it in your quoting. What
are you referring too.

However when you want something based on believe, than you better can change
your study direction, go to a seminary. Now is the time for it while the
natural language from the Pope is German.

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Lee,
Although the VB specification states they are not CLS compliant, the CLS
specification seems to state that sometimes they are CLS compliant (as
suggested by the passages I quoted earlier).

| > | According to The Common Language Infrastructure Annotated Standard:
| > | <quote>NOTE: So-called "jagged arrays" are CLS-compliant,

Which is under CLS Rule 16.

I would value the CLI specification over the VB specification...

Hope this helps
Jay


| Hi All,
|
| Actually, funny you mentioned the 2.0 Framework. The only reason I even
| considered not using a jagged array was based on info I read in VS.NET
2005
| docs. I've actually converted a copy of my project to run under 2.0,
mostly
| to get a feel for the 2005 IDE, but also to see what I might be up against
| when clients wanted to go to the 2.0 framework.
|
| To see just how easy it is to work in 2005, this is where I initially
turned
| Options Strict On, as all of the errors produced come with nice little
| recommended fixes. when I got to the late binding issue regarding HIndex,
I
| started looking at Array of Arrays (just as Herfield and Jay said, using
| HIndex()(), rather than HIndex() ). From the 2005 docs:
|
| Jagged arrays are not compliant with the Common Language Specification
| (CLS). This means you should not expose jagged arrays from any class you
| want CLS-compliant code to consume.
|
| Without really reading the second sentence, I decided I really didn't want
| to introduce a potential problem into my app. However, I agree with Jay.
| This is a private implementation, so the jagged array stays and it fixes
the
| late binding, so, that, as they say, is that!
|
| thanks guys!!
| Lee
|
|
| | > Hmm...
| > | Which I read to mean that the jagged array "Integer()()" is
implemented
| > as
| > | an "System.Array of System.Array Of Integer", of course if you look at
| > the
| > | IL shows this is how they are implemented!
| > Reading that just now, it doesn't make as much sense as I thought it did
| > when I wrote it. :-(
| >
| > Reading the annotation accompanying Rule 16 in the Common Language
| > Infrastructure Annotated Standard it appears I was partially correct.
What
| > I'm not certain about is if you do not overload a method on Jagged
arrays
| > if
| > the method is CLS compliant or not. It definitely appears if you
overload
| > a
| > method based on Jagged Arrays they are definitely not CLS compliant.
| >
| > For example:
| >
| > Public Compliant
| >
| > Public Sub Sum(ByVal values As Integer()())
| > End Sub
| >
| > End Class
| >
| > Public Class NoneCompliant
| >
| > Public Sub Sum(ByVal values As Integer()())
| > End Sub
| >
| > Public Sub Sum(ByVal values As Single()())
| > End Sub
| >
| > End Class
| >
| > The way I am understanding the standard, the NoneCompliant class is not
| > compliant as both methods are treated as "Sum(ByVal values As
| > System.Array())", while the Compliant class may be compliant as there is
| > only a single method (its not overloaded)...
| >
| > I'll have to see if I can find more info on this. Also I would be
curious
| > if
| > .NET 2.0 has clarified this any...
| >
| > Either way, as was suggested, if the jagged array is a private
| > implementation detail of the type or method (its not Publicly exposed)
| > then
| > the entire discussion of it being compliant or not, although
interesting,
| > is
| > largely academic.
| >
| > Hope this helps
| > Jay
| >
| >
| >
message
| > | > | lgbjr,
| > || But, As I posted earlier, I want to stay away from the jagged array,
as
| > | it's
| > || not CLS compliant.
| > | Where do you get that impression???
| > |
| > | According to The Common Language Infrastructure Annotated Standard:
| > | <quote>NOTE: So-called "jagged arrays" are CLS-compliant, but when
| > | overloading multiple array types they are one-dimensional, zero-based
| > arrays
| > | of type System.Array.</quote>
| > |
| > | Which I read to mean that the jagged array "Integer()()" is
implemented
| > as
| > | an "System.Array of System.Array Of Integer", of course if you look at
| > the
| > | IL shows this is how they are implemented! Its just that C# & VB.NET
| > offers
| > | syntactical sugar to simplify it to Integer()() or int[][]. As you
found
| > | putting an array, any array into a System.Array variable requires late
| > | binding, if you put the array into a strongly typed variable, such as
| > | Integer()(), then you avoid the late binding. Also using strongly
typed
| > | variables may enable the compiler to use array specific IL
instructions
| > | instead of the methods on System.Array...
| > |
| > | Hope this helps
| > | Jay
| > |
| > |
| > | | > || Hi All,
| > ||
| > || Cor, you are correct, the issue was really related to late binding,
| > though
| > | I
| > || understand why Jay and Herfield hit on the jagged array.
| > ||
| > || But, As I posted earlier, I want to stay away from the jagged array,
as
| > | it's
| > || not CLS compliant.
| > ||
| > || I had to move onto something else temporarily, but I'll post back
| > tomorrow
| > || with any questions regarding Cor's possible solution!
| > ||
| > || Thanks
| > ||
| > || Lee
| > ||
| > || | > || > Jay,
| > || >
| > || > The question is in my opinion a late binding question (see the
| > subject)
| > || > not an array question.
| > || >
| > || > When you say like Herfried that, using a jagged array is always the
| > best
| > || > solution to overcome late bindings problems, than I have nothing
more
| > to
| > || > discus.
| > || >
| > || >> The best solution is to create a jagged array (an array of
arrays):
| > || >
| > || > That maybe the jagged array is the best solution for this problem,
| > can
| > | be.
| > || > However, does not for me answer his more implicit question how to
| > | overcome
| > || > late binding in general. I nowhere saw that in yours and either in
| > || > Herfrieds text.
| > || >
| > || > When it is possible, than I think that it is *better* to learn how
to
| > | fish
| > || > than to give a fish.
| > || >
| > || > I hope this helps
| > || >
| > || > Cor
| > || >
| > ||
| > ||
| > |
| > |
| >
| >
|
|
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
| > As you may know you use Option Strict On to avoid late binding! Simple,
| > isn't it.
| No I did not know this, it's in my opinion a completly wrong statement. I
| thought you knew better. It can in my opinion give a complete wrong idea
| about what Option Strict On does.
So what do you feel Option Strict On does?

According to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmoptionstrict.asp

It does two things:
1. Restricts implicit data type conversions to only widening conversions
(first paragraph)
2. Generates an error for late binding (third paragraph under the remarks).

It would seem obvious to me that if Option Strict On generates an error for
late binding, then ergo it is the what you use to avoid late binding, as
your program has a number of errors which prevents it from running, As I
stated fixing these errors will then avoid the late binding!

| Programming is in my opinion not a religion where you just has to believe
| something when somebody write that.
| However probably we disagree about that
That comment doesn't warrant a response!

Hope this helps
Jay

| Jay,
|
| > As you may know you use Option Strict On to avoid late binding! Simple,
| > isn't it.
| >
| No I did not know this, it's in my opinion a completly wrong statement. I
| thought you knew better. It can in my opinion give a complete wrong idea
| about what Option Strict On does.
|
| However, I made my answer for the OP and was only asking with my reply to
| Herfried why he wrote that something was the *best* way.
|
| Programming is in my opinion not a religion where you just has to believe
| something when somebody write that.
|
| However probably we disagree about that
|
| Cor
|
|
 
C

Cor Ligthert

Jay,

I know that page, I have read it before I gave my previous answer too you.
It would seem obvious to me that if Option Strict On generates an error
for
late binding, then ergo it is the what you use to avoid late binding, as
your program has a number of errors which prevents it from running, As I
stated fixing these errors will then avoid the late binding!
(this is not the text from your previous message by the way which is less
impliciet).

It generates an error and when you correct that, than the object, where is
spoken about in this page, can by instance using casting or converting be
early binded. However "Option Strict On" does not avoid late binding, that
is still posible using reflection.

I showed in my first sample in this thread how to fix those errors where you
are now talking about.

From that Herfried wrote explicitly.
I don't see how 'IList' fits into "how to learn to fish", moreover I think
it's misleading because it's not appropriate for the OP's problem.
("learn" was corrected by me in "teach" however Herfried quoted this one).

And because you did not amended or corrected this statement, while you are
active in this thread, do I see this as well as a message from you.

Now you are telling that "Option Strict On" needs fixing errors, while you
agreed first that where I showed how to fix those errors, and was talking
even about using for that the type or the interface, it was wrong. Even for
me, while I know what "Option Strict On" does, very confusing.

I hope this helps

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
Not worth a response...

Jay

| Jay,
|
| > According to:
| >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmoptionstrict.asp
|
| I know that page, I have read it before I gave my previous answer too you.
|
| > It would seem obvious to me that if Option Strict On generates an error
| > for
| > late binding, then ergo it is the what you use to avoid late binding, as
| > your program has a number of errors which prevents it from running, As I
| > stated fixing these errors will then avoid the late binding!
| (this is not the text from your previous message by the way which is less
| impliciet).
|
| It generates an error and when you correct that, than the object, where is
| spoken about in this page, can by instance using casting or converting be
| early binded. However "Option Strict On" does not avoid late binding, that
| is still posible using reflection.
|
| I showed in my first sample in this thread how to fix those errors where
you
| are now talking about.
|
| From that Herfried wrote explicitly.
| >I don't see how 'IList' fits into "how to learn to fish", moreover I
think
| >it's misleading because it's not appropriate for the OP's problem.
| ("learn" was corrected by me in "teach" however Herfried quoted this one).
|
| And because you did not amended or corrected this statement, while you are
| active in this thread, do I see this as well as a message from you.
|
| Now you are telling that "Option Strict On" needs fixing errors, while you
| agreed first that where I showed how to fix those errors, and was talking
| even about using for that the type or the interface, it was wrong. Even
for
| me, while I know what "Option Strict On" does, very confusing.
|
| I hope this helps
|
| Cor
|
|
 
C

Cor Ligthert

Cor,
Not worth a response...

I assume that with this answer (because you asked me impliciet in your last
message for an explanation) that you agree with me.

Option Strict does not as you wrote avoid late binding.

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
You assume wrong! Its just not worth my time to haggle with you.

Jay


|> Cor,
| > Not worth a response...
|
| I assume that with this answer (because you asked me impliciet in your
last
| message for an explanation) that you agree with me.
|
| Option Strict does not as you wrote avoid late binding.
|
| Cor
|
|
 
L

lgbjr

Hi Cor,

I understand what Jay is saying (and why you have a problem with what he's
saying).

It's basically a "If A causes B And B causes C, Then A causes C" scenario.

A= Setting Options Strict On
B= Errors from use of late binding
C=Writing Code that avoids Late binding (avoidance of Late binding)

If:

Setting Options Strict On causes errors from use of late binding

And:

Errors from use of late binding causes writing code that avoids late binding
(avoidance of late binding)

Then:

Setting Options Strict On causes avoidance of late binding (or as Jay
stated, Use Options Strict On to avoid late binding)

While the assumption that A causes C is correct in this scenario, it is not
always true:

If People eat cows and cows eat grass, then people eat grass. :)

Cheers
Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top