Re: OT: C or C++?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 15 October 2010 08:13, Philipp Überbacher <hollunder@xxxxxxxxxxx> wrote:
> Excerpts from R. Mattes's message of 2010-10-14 22:35:56 +0200:
>> > What does the following example evaluate to?
>> >    1.2+3+"||"+3+2.1
>>
>> $ cat > Foo.ava
>> class Foo
>> {
>>   static { System.out.println( 1.2+3+"||"+3+2.1 ); System.exit( 0 ); }
>> }
>> ^D
>> $ javac Foo.java
>> $ java Foo
>>
>> C'm on, that's not really that hard, no Eclipse, no packages, no real object.
>
> Is this using some implicit main() or something?
>
>> > I think there's far too much distracting mess to sort out before you
>> > even get to programing, so I don't think it's a good teaching language
>> > (for total beginners at least).
>>
>> What's distracting here?
>>
>> Regarding your example -my main question would be: what do _you_ expect from that
>> code. 'I'd say you get what you ask for.
>
> I wouldn't expect 4.2||32.1 as a result. Either interpret the whole
> thing as a string, or the number parts as float or don't do this kind of
> automagic conversion at all. Interpreting numbers as numbers and
> interpreting numbers as string in the same statement is something I
> wouldn't expect.

Breaking your expectations is the exact point of statements like
1.2+3+"||"+3+2.1. You'll find similar statements for every language.
Knowing why they produce the unexpected is important for debugging
your code. Unless you're entering a code-obfuscation contest you
shouldn't write code like that.


James.
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@xxxxxxxxxxxxxxxxxxxx
http://lists.linuxaudio.org/listinfo/linux-audio-user



[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux