SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Features and/or Improvements => Topic started by: rowbearto on February 13, 2018, 03:26:28 pm

Title: Automatic population of a variable's type in C++ and Java
Post by: rowbearto on February 13, 2018, 03:26:28 pm
I recently stumbled across this comment in a reddit thread:

Quote
in java/eclipse i really enjoyed just writing String x = methodcall(); for everything, then press ctrl+1,enter to fix the type of x.

From:
https://www.reddit.com/r/cpp/comments/7wuygc/the_15_c11_features_you_must_really_use_in_your_c/du4ewje/ (https://www.reddit.com/r/cpp/comments/7wuygc/the_15_c11_features_you_must_really_use_in_your_c/du4ewje/)

Would be great to have a feature like this in SE!
Title: Re: Automatic population of a variable's type in C++ and Java
Post by: Dennis on February 13, 2018, 03:46:56 pm
I'll also file a feature request for this one, though I think this is a bit eclipsed by "auto" and ":="
Title: Re: Automatic population of a variable's type in C++ and Java
Post by: rowbearto on February 13, 2018, 03:48:37 pm
I'm not aware of "auto" and ":=", can you provide more info?
Title: Re: Automatic population of a variable's type in C++ and Java
Post by: Dennis on February 13, 2018, 04:04:43 pm
I was referring to "auto" in C++11 for type inference, and := which is used in languages like Go and Slick-C for type inference (declaration and assignment operator, or as Go calls it, "short variable declaration").  I had thought that := was part of Java 8, but I must have been mistaken.

x := "a string value";   // x is a string
Title: Re: Automatic population of a variable's type in C++ and Java
Post by: rowbearto on February 13, 2018, 04:13:52 pm
Yes, I was referring to "auto" as well. Sometimes I find "auto" not so readable, so I'd like to be able to start by writing "auto variable = function()", then press a key and have SE replace the "auto" with the actual type of the variable, so it is easier to read.

Java 8 doesn't have auto, but I'd still like to put in any type (even put "auto"), and then press a key and have it replaced with the real type.
Title: Re: Automatic population of a variable's type in C++ and Java
Post by: Dennis on February 13, 2018, 04:25:28 pm
Type inference is planned for Java 10.  They are going with "var" instead of "auto" or ":=".
http://openjdk.java.net/jeps/286

Few languages have a type inference as good as Slick-C's, in Slick-C, you can even use type inference to declare local variables that are passed by reference as output parameters.

Code: [Select]
save_pos(auto p);
tag_get_local_info(auto localInfo);
Title: Re: Automatic population of a variable's type in C++ and Java
Post by: rowbearto on February 13, 2018, 04:33:26 pm
Good to know.

Still, I generally want to avoid putting "auto" or whatever keyword that language has in my code, while it is easier to write, it is harder to read.

So having a feature where SE can replace the "auto"/whatever with the actual type would be really useful to me.