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

Discussion in 'Java' started by Ramon F. Herrera, Jan 6, 2013.

  1. 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
     
    Ramon F. Herrera, Jan 6, 2013
    #1
    1. Advertising

  2. Correction:

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

    -RFH
     
    Ramon F Herrera, Jan 6, 2013
    #2
    1. Advertising

  3. 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?
     
    Aryeh M. Friedman, Jan 6, 2013
    #3
  4. On Jan 6, 1:31 pm, "Aryeh M. Friedman" <>
    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
     
    Ramon F Herrera, Jan 6, 2013
    #4
  5. On Jan 6, 1:31 pm, "Aryeh M. Friedman" <>
    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
     
    Ramon F Herrera, Jan 6, 2013
    #5
  6. Ramon F. Herrera

    Arne Vajhøj Guest

    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
     
    Arne Vajhøj, Jan 6, 2013
    #6
  7. On Jan 6, 2:04 pm, Arne Vajhøj <> 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
     
    Ramon F Herrera, Jan 6, 2013
    #7
  8. Ramon F. Herrera

    Arne Vajhøj Guest

    On 1/6/2013 2:42 PM, Ramon F Herrera wrote:
    > On Jan 6, 1:31 pm, "Aryeh M. Friedman" <>
    > 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
     
    Arne Vajhøj, Jan 6, 2013
    #8
  9. Ramon F. Herrera

    Arne Vajhøj Guest

    On 1/6/2013 2:58 PM, Ramon F Herrera wrote:
    > On Jan 6, 1:31 pm, "Aryeh M. Friedman" <>
    > 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
     
    Arne Vajhøj, Jan 6, 2013
    #9
  10. Ramon F. Herrera

    Arne Vajhøj Guest

    On 1/6/2013 3:05 PM, Ramon F Herrera wrote:
    > On Jan 6, 2:04 pm, Arne Vajhøj <> 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
     
    Arne Vajhøj, Jan 6, 2013
    #10
  11. On Jan 6, 2:06 pm, Arne Vajhøj <> wrote:
    > On 1/6/2013 2:42 PM, Ramon F Herrera wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > On Jan 6, 1:31 pm, "Aryeh M. Friedman" <>
    > > 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
     
    Ramon F Herrera, Jan 6, 2013
    #11
  12. On Jan 6, 2:10 pm, Arne Vajhøj <> wrote:
    > On 1/6/2013 3:05 PM, Ramon F Herrera wrote:
    >
    > > On Jan 6, 2:04 pm, Arne Vajhøj <> 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
     
    Ramon F Herrera, Jan 6, 2013
    #12
  13. Ramon F. Herrera

    Arne Vajhøj Guest

    On 1/6/2013 3:16 PM, Ramon F Herrera wrote:
    > On Jan 6, 2:06 pm, Arne Vajhøj <> 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
     
    Arne Vajhøj, Jan 6, 2013
    #13
  14. Ramon F. Herrera

    Arne Vajhøj Guest

    On 1/6/2013 3:18 PM, Ramon F Herrera wrote:
    > On Jan 6, 2:10 pm, Arne Vajhøj <> wrote:
    >> On 1/6/2013 3:05 PM, Ramon F Herrera wrote:
    >>
    >>> On Jan 6, 2:04 pm, Arne Vajhøj <> 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
     
    Arne Vajhøj, Jan 6, 2013
    #14
  15. Ramon F. Herrera

    Bill Gill Guest

    On 1/6/2013 1:58 PM, Ramon F Herrera wrote:
    > On Jan 6, 1:31 pm, "Aryeh M. Friedman" <>
    > 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
     
    Bill Gill, Jan 6, 2013
    #15
  16. 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
     
    Joshua Cranmer, Jan 7, 2013
    #16
  17. 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
     
    Arne Vajhøj, Jan 7, 2013
    #17
  18. "Ramon F. Herrera" <> 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.
     
    Ben Bacarisse, Jan 7, 2013
    #18
  19. Ramon F. Herrera

    Stefan Ram Guest

    Ben Bacarisse <> 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
     
    Stefan Ram, Jan 7, 2013
    #19
  20. Ramon F. Herrera

    Stefan Ram Guest

    "Ramon F. Herrera" <> writes:
    >"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.
     
    Stefan Ram, Jan 7, 2013
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hammond
    Replies:
    1
    Views:
    488
    Oliver
    Nov 13, 2003
  2. neverstill
    Replies:
    0
    Views:
    309
    neverstill
    Jan 6, 2004
  3. David Krussow

    Send user back to last page actually opened

    David Krussow, Jan 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    412
    Steve C. Orr [MVP, MCSD]
    Jan 29, 2004
  4. K. Frank
    Replies:
    9
    Views:
    1,419
    Alf P. Steinbach
    Jan 16, 2012
  5. Guy
    Replies:
    2
    Views:
    189
    Dr John Stockton
    Dec 5, 2003
Loading...

Share This Page