Program in or into (was Python handles globals badly)

Steven D'Aprano steve at pearwood.info
Sat Sep 5 22:35:09 EDT 2015


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. 



-- 
Steven




More information about the Python-list mailing list