Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to get from A to B (actually, from type "A" to type "B")

Reply
Thread Tools

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

 
 
Ramon F Herrera
Guest
Posts: n/a
 
      01-06-2013
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

 
Reply With Quote
 
 
 
 
Ramon F Herrera
Guest
Posts: n/a
 
      01-06-2013
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
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      01-06-2013
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



 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      01-06-2013
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


 
Reply With Quote
 
Bill Gill
Guest
Posts: n/a
 
      01-06-2013
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

 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      01-07-2013
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
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      01-07-2013
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

 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      01-07-2013
"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.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      01-07-2013
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

 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      01-07-2013
"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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Get ubuntu ! Get ubuntu ! Get ubuntu ! Get ubuntu ! Getubuntu Windows 64bit 1 06-01-2009 08:54 AM
#define ALLOCIT(Type) ((Type*) malloc (sizeof (Type))) Yevgen Muntyan C Programming 10 02-13-2007 02:52 AM
Re: Type casting- a larger type to a smaller type pete C Programming 4 04-02-2004 05:19 PM
Re: Type casting- a larger type to a smaller type heyo C Programming 3 04-01-2004 06:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57