Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21055 > unrolled thread

How to get from A to B (actually, from type "A" to type "B")

Started by"Ramon F. Herrera" <ramon@conexus.net>
First post2013-01-06 11:22 -0800
Last post2013-01-07 14:03 +0000
Articles 20 — 8 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  How to get from A to B (actually, from type "A" to type "B") "Ramon F. Herrera" <ramon@conexus.net> - 2013-01-06 11:22 -0800
    Re: How to get from A to B (actually, from type "A" to type "B") Ramon F Herrera <ramon@conexus.net> - 2013-01-06 11:27 -0800
    Re: How to get from A to B (actually, from type "A" to type "B") "Aryeh M. Friedman" <Aryeh.Friedman@gmail.com> - 2013-01-06 11:31 -0800
      Re: How to get from A to B (actually, from type "A" to type "B") Ramon F Herrera <ramon@conexus.net> - 2013-01-06 11:42 -0800
        Re: How to get from A to B (actually, from type "A" to type "B") Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 15:06 -0500
          Re: How to get from A to B (actually, from type "A" to type "B") Ramon F Herrera <ramon@conexus.net> - 2013-01-06 12:16 -0800
            Re: How to get from A to B (actually, from type "A" to type "B") Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 15:27 -0500
      Re: How to get from A to B (actually, from type "A" to type "B") Ramon F Herrera <ramon@conexus.net> - 2013-01-06 11:58 -0800
        Re: How to get from A to B (actually, from type "A" to type "B") Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 15:08 -0500
        Re: How to get from A to B (actually, from type "A" to type "B") Bill Gill <billnews2@cox.net> - 2013-01-06 17:31 -0600
    Re: How to get from A to B (actually, from type "A" to type "B") Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 15:04 -0500
      Re: How to get from A to B (actually, from type "A" to type "B") Ramon F Herrera <ramon@conexus.net> - 2013-01-06 12:05 -0800
        Re: How to get from A to B (actually, from type "A" to type "B") Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 15:10 -0500
          Re: How to get from A to B (actually, from type "A" to type "B") Ramon F Herrera <ramon@conexus.net> - 2013-01-06 12:18 -0800
            Re: How to get from A to B (actually, from type "A" to type "B") Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 15:29 -0500
            Re: How to get from A to B (actually, from type "A" to type "B") lipska the kat <lipskathekat@yahoo.co.uk> - 2013-01-07 08:45 +0000
    Re: How to get from A to B (actually, from type "A" to type "B") Joshua Cranmer <Pidgeot18@verizon.invalid> - 2013-01-06 19:12 -0600
      Re: How to get from A to B (actually, from type "A" to type "B") Arne Vajhøj <arne@vajhoej.dk> - 2013-01-06 20:29 -0500
    Re: How to get from A to B (actually, from type "A" to type "B") Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-07 02:45 +0000
      Re: How to get from A to B (actually, from type "A" to type "B") Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-07 14:03 +0000

#21055 — How to get from A to B (actually, from type "A" to type "B")

From"Ramon F. Herrera" <ramon@conexus.net>
Date2013-01-06 11:22 -0800
SubjectHow to get from A to B (actually, from type "A" to type "B")
Message-ID<b1a4c163-c843-4d36-b9bd-f504dd5bc4e6@d10g2000yqe.googlegroups.com>
I was flabbergasted the first time I used an IDE that had the "period
completion" feature (or the similar, "left parenthesis"). It made me
considering leaving old trusted "vi".

The problem with the period is that it only goes one step deep: more
steps are needed! Additionally, sometimes the period is not the answer
to your travails, when a non-member function is the one that will
convert from type "A" to type "B".

When I was learning Java, a large number of questions (and time
wasted) that I posted were of the form:

      "How do I convert [some type] to [some other type]?"

The text conversions alone occupy an inordinate amount of time to
programmers (just try Google to see what I mean).

Some C++ examples:

I had been using for a long time this (from Boost::Filesystem):

    string somestring = "abc/de";
    path p = path(somestring);

Only to realize, accidentally, that the conversion is done
automatically. The IDE should help you in those cases:

    path p = somestring;

This one made me kick myself. I used this many, many times:

    const char* sometext = somestring.string().c_str();

Well, it turns out that this one is just as good:

    const char* sometext = somestring.c_str();

My question is about R&D done in this particular field. I tried Google
but the word "type" is too ambiguous.

This problem is very similar to the resolution of Rubik's Cube. Your
expression is in some "scrambled" state and you need the computer to
tell you -not only any path! mind you- but the shortest path (known as
God's algorithm) to the desired type. Exhaustive, aka brute force
search can be used: after all, we are not talking Rubik type of steps,
most of the time we are 1 or 2 steps away from the conversion.

Regards,

-Ramon

[toc] | [next] | [standalone]


#21056

FromRamon F Herrera <ramon@conexus.net>
Date2013-01-06 11:27 -0800
Message-ID<8345795a-4c3f-413f-94e1-494b8b85c37f@z8g2000yqo.googlegroups.com>
In reply to#21055
Correction:

  const char* sometext = p.string().c_str();

-RFH

[toc] | [prev] | [next] | [standalone]


#21057

From"Aryeh M. Friedman" <Aryeh.Friedman@gmail.com>
Date2013-01-06 11:31 -0800
Message-ID<2c8c633a-917b-4573-b246-ae622ac3e04e@googlegroups.com>
In reply to#21055
On Sunday, January 6, 2013 2:22:55 PM UTC-5, Ramon F Herrera wrote:
> I was flabbergasted the first time I used an IDE that had the "period
> 
> completion" feature (or the similar, "left parenthesis"). It made me
> 
> considering leaving old trusted "vi".
> 
> 
> 
> The problem with the period is that it only goes one step deep: more
> 
> steps are needed! Additionally, sometimes the period is not the answer
> 
> to your travails, when a non-member function is the one that will
> 
> convert from type "A" to type "B".
> 
> 
> 
> When I was learning Java, a large number of questions (and time
> 
> wasted) that I posted were of the form:
> 
> 
> 
>       "How do I convert [some type] to [some other type]?"
> 
> 
> 
> The text conversions alone occupy an inordinate amount of time to
> 
> programmers (just try Google to see what I mean).
> 
> 
> 
> Some C++ examples:
> 
> 
> 
> I had been using for a long time this (from Boost::Filesystem):
> 
> 
> 
>     string somestring = "abc/de";
> 
>     path p = path(somestring);
> 
> 
> 
> Only to realize, accidentally, that the conversion is done
> 
> automatically. The IDE should help you in those cases:
> 
> 
> 
>     path p = somestring;
> 
> 
> 
> This one made me kick myself. I used this many, many times:
> 
> 
> 
>     const char* sometext = somestring.string().c_str();
> 
> 
> 
> Well, it turns out that this one is just as good:
> 
> 
> 
>     const char* sometext = somestring.c_str();
> 
> 
> 
> My question is about R&D done in this particular field. I tried Google
> 
> but the word "type" is too ambiguous.
> 
> 
> 
> This problem is very similar to the resolution of Rubik's Cube. Your
> 
> expression is in some "scrambled" state and you need the computer to
> 
> tell you -not only any path! mind you- but the shortest path (known as
> 
> God's algorithm) to the desired type. Exhaustive, aka brute force
> 
> search can be used: after all, we are not talking Rubik type of steps,
> 
> most of the time we are 1 or 2 steps away from the conversion.
> 
> 
> 
> Regards,
> 
> 
> 
> -Ramon

whats your point/question?

[toc] | [prev] | [next] | [standalone]


#21059

FromRamon F Herrera <ramon@conexus.net>
Date2013-01-06 11:42 -0800
Message-ID<6b36d5a5-19e9-49e7-b385-5f19afb1da36@10g2000yqk.googlegroups.com>
In reply to#21057
On Jan 6, 1:31 pm, "Aryeh M. Friedman" <Aryeh.Fried...@gmail.com>
wrote:

 > whats your point/question?

It is an open question, to feed my curiosity. I had this post in mind
for years, it's not like I am under a deadline or anything.

Folks could comment, for instance that the period features fails more
often than it works on MSVS-2005 but with the addition of "dependent
includes" in MSVS-2010 the situation has improved.

I have not used Eclipse or JavaBeans for years, but it was there were
I first discovered the period.

Maybe Java lends itself more to the implementation of this type of
feature?

-Ramon

[toc] | [prev] | [next] | [standalone]


#21064

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-06 15:06 -0500
Message-ID<50e9d933$0$294$14726298@news.sunsite.dk>
In reply to#21059
On 1/6/2013 2:42 PM, Ramon F Herrera wrote:
> On Jan 6, 1:31 pm, "Aryeh M. Friedman" <Aryeh.Fried...@gmail.com>
> wrote:
>
>   > whats your point/question?
>
> It is an open question, to feed my curiosity. I had this post in mind
> for years, it's not like I am under a deadline or anything.
>
> Folks could comment, for instance that the period features fails more
> often than it works on MSVS-2005 but with the addition of "dependent
> includes" in MSVS-2010 the situation has improved.
>
> I have not used Eclipse or JavaBeans for years, but it was there were
> I first discovered the period.
>
> Maybe Java lends itself more to the implementation of this type of
> feature?

I doubt it.

The only relevant difference I can think of is that Java
does not support user defined casts.

Arne

[toc] | [prev] | [next] | [standalone]


#21067

FromRamon F Herrera <ramon@conexus.net>
Date2013-01-06 12:16 -0800
Message-ID<b76bd81a-39a1-4e02-bea7-46295936e945@d10g2000yqe.googlegroups.com>
In reply to#21064
On Jan 6, 2:06 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> On 1/6/2013 2:42 PM, Ramon F Herrera wrote:
>
>
>
>
>
>
>
>
>
> > On Jan 6, 1:31 pm, "Aryeh M. Friedman" <Aryeh.Fried...@gmail.com>
> > wrote:
>
> >   > whats your point/question?
>
> > It is an open question, to feed my curiosity. I had this post in mind
> > for years, it's not like I am under a deadline or anything.
>
> > Folks could comment, for instance that the period features fails more
> > often than it works on MSVS-2005 but with the addition of "dependent
> > includes" in MSVS-2010 the situation has improved.
>
> > I have not used Eclipse or JavaBeans for years, but it was there were
> > I first discovered the period.
>
> > Maybe Java lends itself more to the implementation of this type of
> > feature?
>

 > I doubt it.
 >
 > The only relevant difference I can think of is that Java
 > does not support user defined casts.
 >
 > Arne

I guess I was thinking of "Programming by Example" (Java Window
Builder Pro and XAML type of stuff). In order to implement those
properly, bidirectionally (JavaBeans uses a hack inside the comments)
the language must support Introspection, or at the very least,
Reflection, right?

That is why C# has such a nice graphical generating code tool, but C++
(in the same IDE) lacks it.

Somehow I see the period issue as related.

-Ramon

[toc] | [prev] | [next] | [standalone]


#21070

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-06 15:27 -0500
Message-ID<50e9de4b$0$292$14726298@news.sunsite.dk>
In reply to#21067
On 1/6/2013 3:16 PM, Ramon F Herrera wrote:
> On Jan 6, 2:06 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>> On 1/6/2013 2:42 PM, Ramon F Herrera wrote:
>>> Maybe Java lends itself more to the implementation of this type of
>>> feature?
>   > I doubt it.
>   >
>   > The only relevant difference I can think of is that Java
>   > does not support user defined casts.
>
> I guess I was thinking of "Programming by Example" (Java Window
> Builder Pro and XAML type of stuff). In order to implement those
> properly, bidirectionally (JavaBeans uses a hack inside the comments)
> the language must support Introspection, or at the very least,
> Reflection, right?
>
> That is why C# has such a nice graphical generating code tool, but C++
> (in the same IDE) lacks it.
>
> Somehow I see the period issue as related.

The easy reflection in Java and makes it easier for the
IDE writers to provide the completion functionality. But
VS has had that for C++ since before C# was invented and
maybe even before Java was invented.

GUI builder and bidirectional GUI builder are different problems
than the completion.

You can certainly create such for C++ GUI's. VS provide such
for .NET Win Forms - well it is C++/CLR but let us ignore
that little difference.

I don't know why VS never had GUI builder for Win32 API and
MFC. I can not see any technical reasons why they could not
have done it, so it is most likely a business decision.

Arne


[toc] | [prev] | [next] | [standalone]


#21061

FromRamon F Herrera <ramon@conexus.net>
Date2013-01-06 11:58 -0800
Message-ID<d973402f-be71-4289-8b83-11db3ced3cc4@b8g2000yqh.googlegroups.com>
In reply to#21057
On Jan 6, 1:31 pm, "Aryeh M. Friedman" <Aryeh.Fried...@gmail.com>
wrote:

 > whats your point/question?

Part of the question is about research, I am just curious to see what
is being done about this glaringly obvious need.

I tried to find some sci.research.comp comp.sci.research or similar
newsgroup, but apparently there is no such thing in Usenet!

I found this one, outside:

http://www.scienceforums.net/topic/71989-how-to-get-from-a-to-b-actually-from-type-a-to-type-b/

Which brings me back to the point! (pun intended): If the Google folks
are so smart how come they don't have a facility to explore the Usenet
forums? I would type:

  comp [followed by a dot]

and the children NGs would appear.

I believe that Google Groups has gone out of its way to block this
type of concise perusal.

-Ramon

[toc] | [prev] | [next] | [standalone]


#21065

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-06 15:08 -0500
Message-ID<50e9d9c0$0$294$14726298@news.sunsite.dk>
In reply to#21061
On 1/6/2013 2:58 PM, Ramon F Herrera wrote:
> On Jan 6, 1:31 pm, "Aryeh M. Friedman" <Aryeh.Fried...@gmail.com>
> wrote:
>
>   > whats your point/question?
>
> Part of the question is about research, I am just curious to see what
> is being done about this glaringly obvious need.
>
> I tried to find some sci.research.comp comp.sci.research or similar
> newsgroup, but apparently there is no such thing in Usenet!
>
> I found this one, outside:
>
> http://www.scienceforums.net/topic/71989-how-to-get-from-a-to-b-actually-from-type-a-to-type-b/

You may be able to find a group where desirable features for
new languages are discussed, but for existing languages the choices
has been made.

> Which brings me back to the point! (pun intended): If the Google folks
> are so smart how come they don't have a facility to explore the Usenet
> forums? I would type:
>
>    comp [followed by a dot]
>
> and the children NGs would appear.
>
> I believe that Google Groups has gone out of its way to block this
> type of concise perusal.

This is a client app thing - if Google expose an API, then you can
write such a client.

Arne

[toc] | [prev] | [next] | [standalone]


#21081

FromBill Gill <billnews2@cox.net>
Date2013-01-06 17:31 -0600
Message-ID<kcd1h7$rgh$1@dont-email.me>
In reply to#21061
On 1/6/2013 1:58 PM, Ramon F Herrera wrote:
> On Jan 6, 1:31 pm, "Aryeh M. Friedman" <Aryeh.Fried...@gmail.com>
> wrote:
SNIP

> Which brings me back to the point! (pun intended): If the Google folks
> are so smart how come they don't have a facility to explore the Usenet
> forums? I would type:
>
>    comp [followed by a dot]
>
> and the children NGs would appear.
>
> I believe that Google Groups has gone out of its way to block this
> type of concise perusal.
>
> -Ramon
>

Google used to have a good usenet search engine.  But I don't
think it is there or at least doesn't work very good any more.
Right after they bought DejaNews they allowed some good searches
in the whole usenet database.  I haven't tried anything there
lately, but I understand that their handling of the usenet
news groups has gotten very poor.

Bill

[toc] | [prev] | [next] | [standalone]


#21062

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-06 15:04 -0500
Message-ID<50e9d8c4$0$294$14726298@news.sunsite.dk>
In reply to#21055
On 1/6/2013 2:22 PM, Ramon F. Herrera wrote:
> I was flabbergasted the first time I used an IDE that had the "period
> completion" feature (or the similar, "left parenthesis"). It made me
> considering leaving old trusted "vi".
>
> The problem with the period is that it only goes one step deep: more
> steps are needed! Additionally, sometimes the period is not the answer
> to your travails, when a non-member function is the one that will
> convert from type "A" to type "B".
>
> When I was learning Java, a large number of questions (and time
> wasted) that I posted were of the form:
>
>        "How do I convert [some type] to [some other type]?"
>
> The text conversions alone occupy an inordinate amount of time to
> programmers (just try Google to see what I mean).
>
> Some C++ examples:
>
> I had been using for a long time this (from Boost::Filesystem):
>
>      string somestring = "abc/de";
>      path p = path(somestring);
>
> Only to realize, accidentally, that the conversion is done
> automatically. The IDE should help you in those cases:
>
>      path p = somestring;
>
> This one made me kick myself. I used this many, many times:
>
>      const char* sometext = somestring.string().c_str();
>
> Well, it turns out that this one is just as good:
>
>      const char* sometext = somestring.c_str();
>
> My question is about R&D done in this particular field. I tried Google
> but the word "type" is too ambiguous.
>
> This problem is very similar to the resolution of Rubik's Cube. Your
> expression is in some "scrambled" state and you need the computer to
> tell you -not only any path! mind you- but the shortest path (known as
> God's algorithm) to the desired type. Exhaustive, aka brute force
> search can be used: after all, we are not talking Rubik type of steps,
> most of the time we are 1 or 2 steps away from the conversion.

I don't think there is much science in this.

You learn and remember the most common conversions as
you learn language and associated libraries.

You learn to find the uncommon conversions in the
documentation when you need them.

Arne

[toc] | [prev] | [next] | [standalone]


#21063

FromRamon F Herrera <ramon@conexus.net>
Date2013-01-06 12:05 -0800
Message-ID<e8a04b52-25db-4277-b19c-7112768bd496@b11g2000yqh.googlegroups.com>
In reply to#21062
On Jan 6, 2:04 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:

> I don't think there is much science in this.
>
> You learn and remember the most common conversions as
> you learn language and associated libraries.
>
> You learn to find the uncommon conversions in the
> documentation when you need them.
>
> Arne

You should definitely watch this:

   http://www.youtube.com/watch?v=OC3qFtgeogE&noredirect=1

-Ramon

[toc] | [prev] | [next] | [standalone]


#21066

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-06 15:10 -0500
Message-ID<50e9da35$0$294$14726298@news.sunsite.dk>
In reply to#21063
On 1/6/2013 3:05 PM, Ramon F Herrera wrote:
> On Jan 6, 2:04 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>
>> I don't think there is much science in this.
>>
>> You learn and remember the most common conversions as
>> you learn language and associated libraries.
>>
>> You learn to find the uncommon conversions in the
>> documentation when you need them.
>
> You should definitely watch this:
>
>     http://www.youtube.com/watch?v=OC3qFtgeogE&noredirect=1

Why?

He did not write code. Wozniak did.

Arne

[toc] | [prev] | [next] | [standalone]


#21068

FromRamon F Herrera <ramon@conexus.net>
Date2013-01-06 12:18 -0800
Message-ID<a9eea34d-883e-45a7-99fc-0451a1689bf4@j4g2000yqh.googlegroups.com>
In reply to#21066
On Jan 6, 2:10 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> On 1/6/2013 3:05 PM, Ramon F Herrera wrote:
>
> > On Jan 6, 2:04 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>
> >> I don't think there is much science in this.
>
> >> You learn and remember the most common conversions as
> >> you learn language and associated libraries.
>
> >> You learn to find the uncommon conversions in the
> >> documentation when you need them.
>
> > You should definitely watch this:
>
> >    http://www.youtube.com/watch?v=OC3qFtgeogE&noredirect=1
>

 > Why?
 >
 > He did not write code. Wozniak did.
 >
 > Arne

At this point you are trolling, right?

Not to dismiss good ole' Woz (big fan!), but for every million of them
(us, actually) there is one Steve Jobs.

-Ramon

[toc] | [prev] | [next] | [standalone]


#21071

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-06 15:29 -0500
Message-ID<50e9deae$0$292$14726298@news.sunsite.dk>
In reply to#21068
On 1/6/2013 3:18 PM, Ramon F Herrera wrote:
> On Jan 6, 2:10 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>> On 1/6/2013 3:05 PM, Ramon F Herrera wrote:
>>
>>> On Jan 6, 2:04 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>>
>>>> I don't think there is much science in this.
>>
>>>> You learn and remember the most common conversions as
>>>> you learn language and associated libraries.
>>
>>>> You learn to find the uncommon conversions in the
>>>> documentation when you need them.
>>
>>> You should definitely watch this:
>>
>>>     http://www.youtube.com/watch?v=OC3qFtgeogE&noredirect=1
>>
>
>   > Why?
>   >
>   > He did not write code. Wozniak did.
>   >
>   > Arne
>
> At this point you are trolling, right?

No.

> Not to dismiss good ole' Woz (big fan!), but for every million of them
> (us, actually) there is one Steve Jobs.

I am not so sure about that.

But even if it were the case, then programming is the
topic here not business.

Arne

[toc] | [prev] | [next] | [standalone]


#21141

Fromlipska the kat <lipskathekat@yahoo.co.uk>
Date2013-01-07 08:45 +0000
Message-ID<xcCdnY-9XO-6FnfNnZ2dnUVZ8j2dnZ2d@bt.com>
In reply to#21068
On 06/01/13 20:18, Ramon F Herrera wrote:
> On Jan 6, 2:10 pm, Arne Vajhøj<a...@vajhoej.dk>  wrote:
>> On 1/6/2013 3:05 PM, Ramon F Herrera wrote:
>>
>>> On Jan 6, 2:04 pm, Arne Vajhøj<a...@vajhoej.dk>  wrote:
>>
>>>> I don't think there is much science in this.
>>
>>>> You learn and remember the most common conversions as
>>>> you learn language and associated libraries.
>>
>>>> You learn to find the uncommon conversions in the
>>>> documentation when you need them.
>>
>>> You should definitely watch this:
>>
>>>     http://www.youtube.com/watch?v=OC3qFtgeogE&noredirect=1
>>
>
>   >  Why?
>   >
>   >  He did not write code. Wozniak did.
>   >
>   >  Arne
>
> At this point you are trolling, right?

ROFL

Really, very funny

lipska

-- 
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun

[toc] | [prev] | [next] | [standalone]


#21091

FromJoshua Cranmer <Pidgeot18@verizon.invalid>
Date2013-01-06 19:12 -0600
Message-ID<kcd7ev$tnk$1@dont-email.me>
In reply to#21055
On 1/6/2013 1:22 PM, Ramon F. Herrera wrote:
> I had been using for a long time this (from Boost::Filesystem):
>
>      string somestring = "abc/de";
>      path p = path(somestring);
>
> Only to realize, accidentally, that the conversion is done
> automatically. The IDE should help you in those cases:
>
>      path p = somestring;

This is mainly an issue, in C++, of detecting whether or not an explicit 
conversion is necessary. Note, however, that many style guides tend to 
prefer explicit conversions over implicit ones.

> This one made me kick myself. I used this many, many times:
>
>      const char* sometext = somestring.string().c_str();
>
> Well, it turns out that this one is just as good:
>
>      const char* sometext = somestring.c_str();
>
> My question is about R&D done in this particular field. I tried Google
> but the word "type" is too ambiguous.

There was actually a project by Google using Clang that automatically 
eliminated instances where std::string and const char* interconversion 
was being unnecessarily performed. Note that this is a reason why 
implicit conversion is frowned upon by style guides. :-)

> This problem is very similar to the resolution of Rubik's Cube. Your
> expression is in some "scrambled" state and you need the computer to
> tell you -not only any path! mind you- but the shortest path (known as
> God's algorithm) to the desired type.

No, the algorithm you're looking for is "BFS", specifically in a 
directed graph, as taught in any introductory algorithms class and often 
many more too.

The problem is not doing graph traversal, but actually computing the 
graph in the first place: you are basically asking people to solve a 
very hard AI problem of inferring intent, and this can be difficult even 
for humans with very good documentation. Let's use your filesystem 
example to motivate why it's hard.

Suppose you have a file class like so:

class File {
   public String getAbsolutePath(); // Removes . and ..
   public String getCanonicalPath(); // Resolve symlinks
   public String getFilename();
   public String getExtension();
   public int getSize();
   public int getPermissions(); // Unix-style octal permissions
   public int getInodeNumber(); // Unix filesystem UID
   public int open(); // Returns file descriptor number
}

What should you return if you want to query File -> String? A human 
responder would probably say one of the first too, but there are times 
to prefer one over the other (it depends on what you are doing!). 
Automated analysis would have to either require the human to annotate 
all the conversion methods or use heuristics to guess. The irony is that 
getExtension() is probably the simplest method of the lot, so heuristics 
based on implementation complexity will probably fail here.

Now suppose you queried File -> int. This, to most humans, is probably a 
nonsensical request, but on Unix systems, you might want to get file 
descriptor numbers. This would necessitate opening the file, which is a 
stateful request. Supporting this kind of query would almost certainly 
render a tool useless due to false positives.

If we look at our classic friend, in C and C++, const char *, note that 
there tend to be about 4 distinct semantic types that this type refers 
to. They are the following:
1. Raw binary data
2. Pure ASCII data, so it should only contain \x01-\x7f.
3. Native platform charset (what you can, e.g., pass into filesystem APIs)
4. Proper UTF-8

Sometimes, functions don't care which of these semantic type is in use, 
assuming they're all null-terminated anyways (C's strchr is an example). 
Sometimes, though, it matters hugely which definition is in use 
(converting to/from UTF-16). The answer I as a human would give for 
conversion functions depends heavily on context.

That said, I don't know if people have written papers on this topic 
before; you might find software engineering conference archives useful 
in this regard.
-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

[toc] | [prev] | [next] | [standalone]


#21097

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-01-06 20:29 -0500
Message-ID<50ea24eb$0$285$14726298@news.sunsite.dk>
In reply to#21091
On 1/6/2013 8:12 PM, Joshua Cranmer wrote:
> On 1/6/2013 1:22 PM, Ramon F. Herrera wrote:
>> I had been using for a long time this (from Boost::Filesystem):
>>
>>      string somestring = "abc/de";
>>      path p = path(somestring);
>>
>> Only to realize, accidentally, that the conversion is done
>> automatically. The IDE should help you in those cases:
>>
>>      path p = somestring;
>
> This is mainly an issue, in C++, of detecting whether or not an explicit
> conversion is necessary. Note, however, that many style guides tend to
> prefer explicit conversions over implicit ones.

C# supports implicit conversions if it is explicit defined.

And before somebody without C# knowledge thinks that I am babbling the
syntax I am talking about is:

public static implicit operator X(Y o)

which has the to be expected behavior.

Arne

[toc] | [prev] | [next] | [standalone]


#21121

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-01-07 02:45 +0000
Message-ID<0.a35275a09305adb314b3.20130107024539GMT.877gnppv70.fsf@bsb.me.uk>
In reply to#21055
"Ramon F. Herrera" <ramon@conexus.net> writes:
<snip>
> I had been using for a long time this (from Boost::Filesystem):
>
>     string somestring = "abc/de";
>     path p = path(somestring);
>
> Only to realize, accidentally, that the conversion is done
> automatically. The IDE should help you in those cases:
>
>     path p = somestring;

Maybe the IDE can help.  All three of the following forms do pretty much
the same thing:

  T t = T(x);
  T t = x;
  T t(x);

Because of this, many people prefer the last syntax because it's the one
that makes it plain what's really happening -- a constructor is being
called.

(I point this out simply because your post suggests that the second form
is implicitly doing a conversion that is explicit in the first form --
it's not.  Of course all three forms may involve a conversion from the
type of x to some type that is acceptable as a constructor argument but
if that is the case it occurs in all three forms.)

Anyway, the point is that if type type "path p(" maybe the IDE has a
command to suggest what types of argument are permitted at that point.

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#21153

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-01-07 14:03 +0000
Message-ID<0.1fd49f2ecba7b1af0595.20130107140341GMT.871udxozsy.fsf@bsb.me.uk>
In reply to#21121
ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>  T t = T(x);
>>  T t = x;
>>  T t(x);
>>Because of this, many people prefer the last syntax because it's the one
>>that makes it plain what's really happening -- a constructor is being
>>called.
>
>   People prefer {}-initialization, the uniform
>   initialization syntax and semantics. For example
>
> T t{a};
>
>   , see:
>
> http://www.stroustrup.com/C++11FAQ.html#uniform-init
>
>   .

C++ 2011 gives people good reasons to prefer it, but I would not say
that it is the current preference (at least I don't see it at all
often).  I should certainly have mentioned it, though, so thanks for
bringing it up.

-- 
Ben.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web