Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'static': 0.03; 'subject:Python': 0.05; 'tries': 0.05; 'semantic': 0.07; 'works.': 0.07; 'closest': 0.09; 'slices': 0.09; 'subject:into': 0.09; 'python': 0.10; 'python.': 0.11; 'code?': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'similarly,': 0.16; 'verbose': 0.16; 'wrote:': 0.16; 'language': 0.19; '2015': 0.20; 'first,': 0.20; 'java': 0.22; 'features,': 0.22; 'sep': 0.22; 'appears': 0.23; 'code,': 0.23; '(or': 0.23; 'seems': 0.23; 'sat,': 0.23; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; "doesn't": 0.26; 'example': 0.26; 'least': 0.27; 'looks': 0.29; 'follows': 0.29; 'methods.': 0.29; 'them?': 0.29; 'classes': 0.30; 'url:wiki': 0.30; 'work.': 0.30; 'code': 0.30; 'certainly': 0.30; 'somebody': 0.30; 'class': 0.33; "d'aprano": 0.33; 'instead,': 0.33; 'steven': 0.33; 'languages': 0.34; 'except': 0.34; 'list': 0.34; 'could': 0.35; 'functions.': 0.35; 'but': 0.36; 'needed': 0.36; 'url:org': 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'method': 0.37; 'thought': 0.37; 'things': 0.38; 'means': 0.39; 'why': 0.39; 'takes': 0.39; 'received:192': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'easy': 0.60; 'programs': 0.62; 'course': 0.62; 'more': 0.63; 'note:': 0.66; 'treat': 0.72; 'lack': 0.76; 'consequently': 0.84; 'experiment': 0.84; 'idiomatic': 0.84; 'lacks': 0.84; 'prefers': 0.84; 'them)': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=CvRCCSMD c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=IkcTkHD0fZMA:10 a=DkV0aSFKAAAA:8 a=dONg7TfN3NvrSFtCEEsA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Subject: Re: Program in or into (was Python handles globals badly) To: python-list@python.org References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> From: MRAB Date: Sun, 6 Sep 2015 03:54:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441508106 news.xs4all.nl 23857 [2001:888:2000:d::a6]:45898 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96050 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.