Program in or into (was Python handles globals badly)

MRAB python at mrabarnett.plus.com
Sat Sep 5 22:54:53 EDT 2015


On 2015-09-06 03:35, Steven D'Aprano wrote:
> On Sat, 5 Sep 2015 01:18 pm, Rustom Mody wrote:
>
>> Here's mergesort written in various languages
>> http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort
>>
>> You could look at the java if you like but I think C# takes the cake.
>> And of course also there's the python
>>
>> Now the thought experiment:
>>
>> For some reason you need to code in C#
>> [You need to do this part of the experiment honestly!!]
>>
>> Would you write the C# code?
>> Or would you write the python-ish code in C# ?
>
>
> That depends. Is the example C# code idiomatic for the language? Or was it
> written by somebody ignorant of C#, and consequently is a poor example of
> badly-written and unidiomatic "Java in C#"?
>
> If the first, then I expect I would write the C# code, because it is
> idiomatic and works. What would you do?
>
> It is certainly true that C# appears to be a more verbose language than
> Python. Based on this example, it prefers to use classes with methods
> rather than stand-alone functions, it requires static declarations, there's
> a lot of boilerplate needed to get things to work. It seems to lack some
> nice semantic features of Python, such as list slices and the ability to
> treat lists/arrays as first class values, that make Python so easy to work
> with. If C# lacks those features, how do you expect to use them?
>
> Lacking some of those features (or at least having significant downsides to
> the use of them) is why idiomatic C# or Java code looks the way it does.
>
C# and Java don't have functions. The closest you can get is static
(class) methods.

Note:

C programs start with the "main" function. Java tries to follow that
pattern, except that it doesn't have functions, so a static method
"main" is used instead, which means that it also requires a class to
hold it.

Similarly, C has "sin" and "cos" functions. Java tries to follow that
pattern, except that it doesn't have functions, so a static methods are
used instead, which means that it also requires a class to hold them.

And C# follows what Java does.




More information about the Python-list mailing list