Re: What is your favorite WC++IETJ?

Posted by =?UTF... on 03. May 2015

On 4/30/2015 6:44 AM, Stefan Ram wrote:




C++ can transfer the RHS type to the left side
(using »auto«) as a beginner would expect:




This is only true as of C++11, and this particular feature has only been
reliably implemented cross-platform for a few years...




final java.util.Set< java.lang.Character >result
= new java.util.HashSet< java.lang.Character >();




... but Java 7 allowed you to say new HashSet<>(); here.



Also, to be fair, in practice, Java names are almost never used
fully-qualified. C++ namespaces are more varied in their practical use
of fully-qualified names, but explicitly using std::foo is fairly common
in standard style guides (using namespace std; or using std::foo; are
also common).




C++ can manage resources via RAII:



{ file f( "tmp.txt" ); ... }



when the block is exited, even by an exception, the file
will be closed automatically. Beginners that already know
how to declare a variable do not have to learn anything new.



Java is difficult: One needs to remember a special "try"
syntax that only works for some classes that implement a
special interface to come anywhere near RAII, or otherwise,
one has to manage the resource manually. Java has several
different means to manage resources, C++ nearly always uses
RAII uniformly.




The try-resource block is a relatively recent introduction, but it is
used in all I/O resources in the standard library already. try-finally
usually serves the same purpose as RAII, with the advantage of letting
method names be descriptive. Where try-finally falls down is that both
creation and deletion of most I/O resources can end up throwing, so
handling multiple simultaneous constructions is problematic.




C++ iterates the letters of a string in a way that
is easy to read and write for beginners:



include



include



include



using namespace ::std::literals;
int main()
{ for( auto c : "abc"s )::std::cout << c << '\n'; }




If I change "abc" to "é", I get
?
?
as output. So it does something which is completely wrong.



Of course, to be fair, it should be noted that since Java is




In C++, "\n" will be automatically converted to the line separator
of the platform when it is written to a text file.




Only if the file is opened in text mode, which is the default. Which
means you usually want binary mode, since otherwise writing binary data
(which is not distinguished from character data at any type level in
C++) will silently corrupt your file sometimes.




Beginners in Java have to learn painfully that "\n" is not
necessarily correct sometimes, instead they are supposed to write
»java.lang.System.lineSeparator()« sometimes, Wow!




IMHO, just use LF everywhere (unless you're using a protocol that
requires CRLF). Automatic line conversion tends to be a headache,
especially when "binary strings" and "character strings" are poorly
differentiated. And the only major text editor on any system which
refuses to consider a plain LF as a line terminator is Notepad on
Windows. So you only need to use CRLF as a line terminator when you want
to support people opening up your file with Notepad, which is probably a
very rare occurrence.



Oh, and while we're on the topic of "what's default isn't necessarily
what you want", it should be noted that you usually want to use for
(auto &elem : thing), not for (auto elem : thing).




What are your favorite WC++IETJs?




Multiple return values via out-parameters. std::pair.





Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth


22. May 2015: Re: Can we convert a Java ResultSet/SqlRowSet from Database query directly to JSON array without Mapping it to a List<Type>? by Arne ...

22. May 2015: Re: Recommendation for a good Android programming book? by e d p...

22. May 2015: Can we convert a Java ResultSet/SqlRowSet from Database query directly to JSON array without Mapping it to a List<Type>? by kaush...

21. May 2015: Re: Recommendation for a good Android programming book? by ram a...

21. May 2015: Re: Recommendation for a good Android programming book? by Arne ...

20. May 2015: Java and C# and Threadpool by Ramin...

20. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by Jim H...

20. May 2015: Recommendation for a good Android programming book? by Knute...

20. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by Knute...

18. May 2015: Re: Main Loop porblm by Silvi...

18. May 2015: Re: Main Loop porblm by Eric ...

18. May 2015: Re: Main Loop porblm by Micha...

18. May 2015: Main Loop porblm by Micha...

18. May 2015: Re: Puzzler: Fun with Streams. by scatt...

18. May 2015: Re: Puzzler: Fun with Streams. by scatt...

17. May 2015: Re: get a list of classes at runtime by Arne ...

17. May 2015: Re: get a list of classes at runtime by Arne ...

16. May 2015: C*C*C: CIUCCIA CAZZI DI CAVALLO PAOLO BARRAI DI WMO E BSI ITALIA SRL, UNA VOLTA CACCIATO (E FATTO CONDANNARE A GALERA) DA CITIBANK, PRIMA DI SPENNARE POLLI VIA WEB, FECE FILM PEDOPORNOMOSESSUALI! E CON CAVALLI! CIUCCIANDO E PRENDENDO FALLI EQUINI E.. by CARME...

15. May 2015: Need Oracle DBA Resumes for the position in Chicago,IL by srini...

14. May 2015: About Java... by Ramin...

14. May 2015: Re: JNI Wrapper for Delphi and FreePascal version 2.82 is here.. by Ramin...

14. May 2015: JNI Wrapper for Delphi and FreePascal version 2.82 is here.. by Ramin...

14. May 2015: Re: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by ram a...

14. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Rober...

13. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

13. May 2015: Re: get a list of classes at runtime by Marti...

13. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

13. May 2015: Re: get a list of classes at runtime by Joshu...

13. May 2015: Re: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by Joshu...

13. May 2015: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by garlo...

13. May 2015: [Javascript] How do I find out what this bug means and how to fix it? Uncaught ReferenceError: Invalid left-hand side in assignment by garlo...

13. May 2015: Re: get a list of classes at runtime by j4n b...

13. May 2015: Re: get a list of classes at runtime by Joerg...

13. May 2015: Re: get a list of classes at runtime by Phili...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: Puzzler: Fun with Streams. by Danie...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: How to programatically limit the number of threads in a java by Joerg...

13. May 2015: Re: get a list of classes at runtime by e d p...

13. May 2015: Re: Puzzler: Fun with Streams. by Jeff ...

13. May 2015: Call for Papers: World Congress on Engineering and Computer Science WCECS 2015 by iaeng...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

12. May 2015: Re: How to programatically limit the number of threads in a java by Marce...

12. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by Knute...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

12. May 2015: Puzzler: Fun with Streams. by Danie...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Rober...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by ram a...

12. May 2015: Re: Use URL for HTTPS request using Proxy by Silvi...

12. May 2015: Re: what are the senarios when we should override equals and hashcode by Lew l...

12. May 2015: JNI Wrapper for Delphi and FreePascal version 2.8 by Ramin...

12. May 2015: Re: How to programatically limit the number of threads in a java by Eric ...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Ajay ...

12. May 2015: How to programatically limit the number of threads in a java by Ajay ...

12. May 2015: Re: API vc MVC by Joerg...

12. May 2015: Need Java Developers/Tech Leads/Architects at Reston, VA (Permanent) by ashok...

11. May 2015: API vc MVC by Leona...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Gene ...

11. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by e d p...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by v_bor...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Joerg...

10. May 2015: Re: Animations with jTextPane by H L a...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: Animations with jTextPane by H L a...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

10. May 2015: how does a marker interface give specific instruction to jvm(java internals) by Ajay ...

10. May 2015: Animations with jTextPane by H L a...

09. May 2015: JScrollPane not scrolling smoothly on fast computer by Knute...

09. May 2015: PEZZO DI MERDA BASTARDO DAVIDE SERRA DI ALGEBRIS INVESTMENTS - TWITTER, HA RICEVUTO INSIDER SULLE POPOLARI DAL MEGALAVA SOLDI MAFIOSI PIER LUIGI BOSCHI DI BANCA ETRURIA! SON TUTTI NAZISTI, TIPO NOTO VERME PAOLO BARRAI DI WMO, CHE SI FINGON DEL PD X.. by CARME...

09. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

08. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by ram a...

08. May 2015: How to read the Java tutorial offline? by ram a...

08. May 2015: Re: best and worst sorting algorithm for 1 to 10,000 and then 10,000 + elements by Marti...

08. May 2015: Re: How to read the Java tutorial offline? by Jeff ...

06. May 2015: Re: Why Islam is the true religion of God. by Danci...

06. May 2015: CCC: CIUCCIA CAZZI DI CAVALLO PAOLO BARRAI DI CRIMINALI WMO E BSI ITALIA SRL, UNA VOLTA CACCIATO (E FATTO CONDANNARE AL CARCERE) DA CITIBANK, PRIMA DI SPENNARE POLLI NEL WEB, FECE FILM PEDOPORNOMOSESSUALI! E CON CAVALLI! CIUCCIANDO CAZZI EQUINI E ... by CHE S...

05. May 2015: Why Islam is the true religion of God. by BV BV...

04. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Marce...

04. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

04. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

04. May 2015: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Ajay ...

04. May 2015: Re: What is your favorite WC++IETJ? by ram a...

03. May 2015: Re: What is your favorite WC++IETJ? by Joshu...

03. May 2015: Re: what are the senarios when we should override equals and hashcode by Arne ...

03. May 2015: NAZIPEDERASTA SODOMIZZA BAMBINI: PAOLO BARRAI DI CRIMINALI WMO E BSI ITALIA SRL VIA SOCRATE 26 MILANO (OLTRE CHE MEGALAVA CASH MAFIOSO E POLITI-CRIMINALI)! STALKA A MORTE CHI LO FOTOGRAFA E SE "1 INSISTE", KILLER PAOLO BARRAI FA "SUICIDARE" DAVVERO!! by CARME...

03. May 2015: Re: what are the senarios when we should override equals and hashcode by ram a...

02. May 2015: what are the senarios when we should override equals and hashcode by Ajay ...

02. May 2015: imported maven project can't be recognized as java in eclipse by Ajay ...

02. May 2015: Re: Good example of EJB interface for CRUD operations by pavel...

01. May 2015: Very urgent requirement || Technical Lead - .Net @ Golden Valley, MN by Vasan...

01. May 2015: Re: If java doesn't support operator overloading, how does String + concatenation work by v_bor...

30. Apr 2015: Re: If java doesn't support operator overloading, how does String + concatenation work by Rober...

30. Apr 2015: Re: What is your favorite WC++IETJ? by Robbi...

30. Apr 2015: Re: What is your favorite WC++IETJ? by Sebas...

30. Apr 2015: Re: What is your favorite WC++IETJ? by ram a...