Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #63063

Re: one type less language

From Bartc <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: one type less language
Date 2015-06-08 11:28 +0100
Organization A noiseless patient Spider
Message-ID <ml3qlp$77e$1@dont-email.me> (permalink)
References (1 earlier) <4fc72288-16e5-41cc-a814-7b598cbc2c13@googlegroups.com> <cthdk0Fnjb7U2@mid.uni-berlin.de> <0132eb60-ad1e-45ca-8284-947863adb446@googlegroups.com> <ml25fu$ebr$1@dont-email.me> <ctl6bfFm8ngU1@mid.uni-berlin.de>

Show all headers | View raw


On 08/06/2015 10:42, Jens Thoms Toerring wrote:
> Bartc <bc@freeuk.com> wrote:

[Dynamic typing and scripting languages]
>> Actually, it makes it a bit harder to write, and the bytecode compiler,
>> if there is one, a bit easier. But writing source code becomes quicker
>> and easier too, which is the advantage.

> But the interpreter must follow certain rules. And some-
> times it follows different rules from what you might have
> expected. For example, in Perl you might attempt to ado
>
> $a  = ' 2.3 ';   # that's a string, isn't it?
> $a += '   2 ';   # this appends another string to it, doesn't it?
> print "$a\n";    # guess what this will print...
>
> Of course, this isn't a string concatenation (since in Perl
> you'd have to use the '.' operator for that). But it's also
> not a syntax error since the interpreter recognizes that
> both strings contain something that can be interpreted as
> numbers (disregarding the spaces) and thus adds these two
> numbers. And the result is the number 4.3. So the mistake
> of using '+' instead of '.', made because you had written in
> Python or C++ for the last hours where '+' is used for string
> concatenation, gives a completely different result from what
> you probably intended.
>
> My point is that in these languages you have to learn quite
> a large set of rules of how the interpreter will behave in
> all kinds of situations.

Not really. You have to learn that if you have two strings A and B, then 
A+B means string concatenation in some, and arithmetical add in others.

That doesn't take long. And making mistakes after switching languages 
occurs both ways.

> And many things that in a strongly
> typed language would be syntax errors may have unexpected
> meanings. That's not meant as a criticism of these languages
> but just an observation that certain, quite nice-to-have
> features come at a prize.

(I'm sure that's a Freudian slip rather than a typo...)

  And given that many people already
> moan about the complexities of type promotions in C it might
> be a bit of an unexpected steep learning curve when so many
> other things look that simple in these languages.

What would string concatenation look like in C? (Hint: it isn't just a 
called to strcat().)

There are huge benefits to being to just write A+B (or whatever the 
language uses) and let someone else worry about all the memory management.

Something else not often mentioned is that dynamic typing gives you 
generics and templates for free. Try writing a /single/ function sum() 
in C that takes an array of /any/ numeric type, of any length, and 
returns the sum of all the elements, and compare how elegant it looks 
compared to the dynamic version.

-- 
Bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

one type less language asetofsymbols@gmail.com - 2015-06-05 22:08 -0700
  Re: one type less language David Kleinecke <dkleinecke@gmail.com> - 2015-06-06 09:35 -0700
  Re: one type less language Richard Damon <Richard@Damon-Family.org> - 2015-06-06 13:10 -0400
    Re: one type less language Les Cargill <lcargill99@comcast.com> - 2015-06-06 13:01 -0500
    Re: one type less language Michael Angelo Ravera <maravera@prodigy.net> - 2015-06-07 13:03 -0700
  Re: one type less language Les Cargill <lcargill99@comcast.com> - 2015-06-06 12:55 -0500
  one type less language asetofsymbols@gmail.com - 2015-06-06 12:15 -0700
    Re: one type less language Bartc <bc@freeuk.com> - 2015-06-06 20:23 +0100
    Re: one type less language Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-06 20:28 +0100
    Re: one type less language jt@toerring.de (Jens Thoms Toerring) - 2015-06-06 23:21 +0000
      Re: one type less language Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-06-07 09:59 -0700
        Re: one type less language Bartc <bc@freeuk.com> - 2015-06-07 20:20 +0100
          Re: one type less language jt@toerring.de (Jens Thoms Toerring) - 2015-06-08 09:42 +0000
            Re: one type less language Bartc <bc@freeuk.com> - 2015-06-08 11:28 +0100
              Re: one type less language Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-06-08 05:10 -0700
                Re: one type less language Mel <mel@zzzzz.com> - 2015-06-08 15:39 +0300
      Re: one type less language "J. Clarke" <j.clarke.873638@gmail.com> - 2015-09-08 05:23 -0400
        Re: one type less language Robert Wessel <robertwessel2@yahoo.com> - 2015-09-08 10:20 -0500
  Re: one type less language Keith Thompson <kst-u@mib.org> - 2015-06-06 13:56 -0700
    Re: one type less language luser droog <luser.droog@gmail.com> - 2015-06-07 23:20 -0700
      Re: one type less language asetofsymbols@gmail.com - 2015-06-08 02:50 -0700

csiph-web