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

  • Thread starter Ramon F. Herrera
  • Start date
R

Ramon F. Herrera

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
 
A

Aryeh M. Friedman

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?
 
R

Ramon F Herrera

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
 
R

Ramon F Herrera

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
 
A

Arne Vajhøj

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
 
R

Ramon F Herrera

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:


-Ramon
 
A

Arne Vajhøj

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
 
A

Arne Vajhøj

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
 
R

Ramon F Herrera

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
 
R

Ramon F Herrera

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
 
A

Arne Vajhøj

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
 
A

Arne Vajhøj

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
 
B

Bill Gill

On Jan 6, 1:31 pm, "Aryeh M. Friedman" <[email protected]>
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
 
J

Joshua Cranmer

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.
 
A

Arne Vajhøj

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
 
B

Ben Bacarisse

Ramon F. Herrera said:
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>
 
S

Stefan Ram

Ramon F. Herrera said:
"How do I convert [some type] to [some other type]?"

Programming is all about the details.

First, choose a programming language.

You wrote:

Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.java.programmer

Choose a specific language.

Then, choose two specific types.

For example, you might ask:

How do I convert from int to double in C? -- Then post this to

comp.lang.c

only.

How do I convert from java.lang.Object to boolean in Java? --
Then post this to

comp.lang.java.programmer

only.

And so on.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top