Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31628 > unrolled thread
| Started by | Sebastian <news@seyweiler.dyndns.org> |
|---|---|
| First post | 2015-04-30 14:52 +0200 |
| Last post | 2015-04-30 20:37 +0100 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: What is your favorite WC++IETJ? Sebastian <news@seyweiler.dyndns.org> - 2015-04-30 14:52 +0200
Re: What is your favorite WC++IETJ? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-30 10:03 -0400
Re: What is your favorite WC++IETJ? Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-30 12:18 -0400
Re: What is your favorite WC++IETJ? Robbie Brown <rob@example.com> - 2015-04-30 20:37 +0100
| From | Sebastian <news@seyweiler.dyndns.org> |
|---|---|
| Date | 2015-04-30 14:52 +0200 |
| Subject | Re: What is your favorite WC++IETJ? |
| Message-ID | <mht8ic$20f$1@news.albasani.net> |
Am 30.04.2015 13:44, schrieb Stefan Ram: > An WC++IETJ is something »where C++ is easier than Java«. > [snip] > auto const result = new java.util.HashSet< java.lang.Character >(); > > Java is so difficult, beginners just can't understand > why they have to write everything twice: > > final java.util.Set< java.lang.Character >result > = new java.util.HashSet< java.lang.Character >(); [snip] Since Java 7, that would be Set<Character> result = new HashSet<>(); and there's really no repetition. > > What are your favorite WC++IETJs? Command line input is more cumbersome with Java, for example it is not possible to read an int directly from stdin, you need a Reader (or Scanner) and need to convert from String to int yourself. However, command line interaction is atypical for most Java applications. -- Sebastian
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-04-30 10:03 -0400 |
| Message-ID | <mhtclu$nh5$1@dont-email.me> |
| In reply to | #31628 |
On 4/30/2015 9:28 AM, Stefan Ram wrote:
> Sebastian <news@seyweiler.dyndns.org> writes:
>> Since Java 7, that would be Set<Character> result = new HashSet<>();
>> and there's really no repetition.
>
> But this is difficult to remember. One can start from:
>
> HashSet<Character> result = new HashSet<Character>();
Surely, you meant
java.util.HashSet<java.lang.Character> result
= new java.util.HashSet<java.lang.Character>();
;-)
> . Now, we want to generalize and omit some specializations
> (details):
>
> Set<Character> result = new HashSet<>();
>
> We have to omit the »Hash« on the left, but the »Character«
> on the right!
Not a fair criticism, I'd say. "Hash" is not a specialization,
nor even a "thing" in its own right: It is merely a few characters
extracted from an identifier. In
class Settler<T> implements Set<T> {...}
Set<Character> result = new Settler<>();
... would it be in any sense useful to describe the LHS as being
derived from the RHS by the omission of "tler"?
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2015-04-30 12:18 -0400 |
| Message-ID | <mhtkib$n7t$1@dont-email.me> |
| In reply to | #31628 |
On 4/30/2015 9:28 AM, Stefan Ram wrote:
<snip>
>
> Well, C++ also has its difficulties here. For example, when
> one wants to read a number, but the user enters a string,
> one needs to reset the stream in a laborious way, before the
> read operation can do another attempt at reading a number:
>
> int x; bool ok; do
> { ok = ::std::cin >> x;
> else
> { ::std::cin.clear();
> ::std::cin.ignore
> ( ::std::numeric_limits< ::std::streamsize >::max(), '\n' ); }}
> while( !ok );
>
> and the meaning of »ok = ::std::cin >> x« is also not
> very obvious to a beginner.
>
Which is why it's a bad idea to write code such as this, especially
without any comments. A code review should reject it (and would on the
projects I have managed).
You can obfuscate your code in almost any language (including Java).
Some make it easier than others. But that does not mean it's a good
idea. Unless there is an overwhelming reason otherwise, code should
always be clear and easy to understand - even if it does take a few more
lines to make it so.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Robbie Brown <rob@example.com> |
|---|---|
| Date | 2015-04-30 20:37 +0100 |
| Message-ID | <mhu088$b3a$1@dont-email.me> |
| In reply to | #31628 |
On 30/04/15 14:58, Stefan Ram wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> . Now, we want to generalize and omit some specializations
>> (details):
>> Set<Character> result = new HashSet<>();
>
> The general idea of an assignment in Java is:
>
> supertypeVariable = subtypeExpression
>
> , however in the case of
>
> Set<Character> result = new HashSet<>()
>
> now, confusingly, the more general designation »<>«
> appears on the right side, while the more special
> designation »<Character>« appears on the left side.
The generalization is on the left, the rhs is simply shorthand to stop
us having to write Set<Character> result = new HashSet<Character>()
which used to cause howls of protest from even experienced Java
developers. Try compiling Set<Character> result = new HashSet<Object>()
if the rhs was a generalization we should be able to generalize but we
can't.
HashSet<>() is not a generalization it is simply shorthand.
The Generalization Set<Character> allows for information hiding, a
fundamental concept behind the idea of encapsulation.
public Set getFoo(){
Set x = new HashSet();
...
return x;
}
the implementation of x can be changed without affecting clients of
getFoo();
Seems perfectly reasonable to me.
--
Not floundering ... just fishing
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web