language-comparisons

Python: Assign Value if None Exists

我的未来我决定 提交于 2019-11-30 05:36:21
I am a RoR programmer new to Python. I am trying to find the syntax that will allow me to set a variable to a specific value only if it wasn't previously assigned. Basically I want: # only if var1 has not been previously assigned var1 = 4 This is a very different style of programming, but I always try to rewrite things that looked like bar = None if foo(): bar = "Baz" if bar is None: bar = "Quux" into just: if foo(): bar = "Baz" else: bar = "Quux" That is to say, I try hard to avoid a situation where some code paths define variables but others don't. In my code, there is never a path which

What is the Bash equivalent of Python's pass statement

旧时模样 提交于 2019-11-29 22:44:43
Is there a Bash equivalent to the Python's pass statement? You can use : for this. true is a command that successfully does nothing. ( false would, in a way, be the opposite: it doesn't do anything, but claims that a failure occurred.) 来源: https://stackoverflow.com/questions/2421586/what-is-the-bash-equivalent-of-pythons-pass-statement

What advantages does modern Fortran have over modern C++? [closed]

被刻印的时光 ゝ 提交于 2019-11-29 20:21:54
I'm trying to decide between Fortran and C++ for an application in scientific computing. It's not clear to me if Fortran still has advantages over other languages when it comes to performance. For example, I believe since Fortran enforces strict aliasing, better optimizations could be made by the compiler when compared to C before C99. I'm unsure of how C++ fits in here. Any guidance? I took a look at some of the stuff in the latest Fortran standards , and frankly I'm impressed. A lot of what I hated about the language 20 years ago is gone now. No more line numbers and special columns (may

Should I learn Haskell or F# if I already know OCaml? [closed]

谁说我不能喝 提交于 2019-11-29 19:22:56
I am wondering if I should continue to learn OCaml or switch to F# or Haskell. Here are the criteria I am most interested in: Longevity Which language will last longer? I don't want to learn something that might be abandoned in a couple years by users and developers. Will Inria, Microsoft, University of Glasgow continue to support their respective compilers for the long run? Practicality Articles like this make me afraid to use Haskell. A hash table is the best structure for fast retrieval. Haskell proponents in there suggest using Data.Map which is a binary tree. I don't like being tied to a

Python: Assign Value if None Exists

我怕爱的太早我们不能终老 提交于 2019-11-29 05:48:23
问题 I am a RoR programmer new to Python. I am trying to find the syntax that will allow me to set a variable to a specific value only if it wasn't previously assigned. Basically I want: # only if var1 has not been previously assigned var1 = 4 回答1: This is a very different style of programming, but I always try to rewrite things that looked like bar = None if foo(): bar = "Baz" if bar is None: bar = "Quux" into just: if foo(): bar = "Baz" else: bar = "Quux" That is to say, I try hard to avoid a

What is C# equivalent of <map> in C++? [duplicate]

允我心安 提交于 2019-11-29 05:24:08
This question already has an answer here: C# equivalent of C++ map<string,double> 8 answers I have defined a class myComplex. I need to map it to integers. In C++ I would have created a map as map<myComplex,int> first; How to do such thing in C#? The equivalent would be class SortedDictionary<TKey, TValue> in the System.Collections.Generic namespace. If you don't care about the order the class Dictionary<TKey, TValue> in the System.Collections.Generic namespace would probably be sufficient. hansmaad std::map<Key, Value> → SortedDictionary<TKey, TValue> std::unordered_map<Key, Value> →

Is there a Python equivalent to Ruby symbols?

拜拜、爱过 提交于 2019-11-28 22:13:29
Is there a Python equivalent to Ruby symbols? If so then what is it? If not then are we stuck with using strings as our keys in dictionaries only? sepp2k No, python doesn't have a symbol type. However string literals are interned by default and other strings can be interned using the intern function. So using string literals as keys in dictionaries is not less performant than using symbols in ruby. As others have said, there is no symbol in Python, but strings work well. To avoid quoting strings as keys, use the dict() constructor syntax: d = dict( a = 1, b = 2, c = "Hello there", ) Also for

What is the Bash equivalent of Python's pass statement

一笑奈何 提交于 2019-11-28 19:24:22
问题 Is there a Bash equivalent to the Python's pass statement? 回答1: You can use : for this. 回答2: true is a command that successfully does nothing. ( false would, in a way, be the opposite: it doesn't do anything, but claims that a failure occurred.) 来源: https://stackoverflow.com/questions/2421586/what-is-the-bash-equivalent-of-pythons-pass-statement

Does Python do variable interpolation similar to “string #{var}” in Ruby?

試著忘記壹切 提交于 2019-11-28 18:13:05
In Python, it is tedious to write: print "foo is" + bar + '.' Can I do something like this in Python? print "foo is #{bar}." Sean Vieira Python 3.6+ does have variable interpolation - prepend an f to your string: f"foo is {bar}" For versions of Python below this (Python 2 - 3.5) you can use str.format to pass in variables: # Rather than this: print("foo is #{bar}") # You would do this: print("foo is {}".format(bar)) # Or this: print("foo is {bar}".format(bar=bar)) # Or this: print("foo is %s" % (bar, )) # Or even this: print("foo is %(bar)s" % {"bar": bar}) Python 3.6 will have has literal

Is there something in PHP equivalent to LINQ in C#? [closed]

纵饮孤独 提交于 2019-11-28 17:25:02
Is there something in PHP equivalent to LINQ in C#? Justin Niessner There is PHPLinq - LINQ for PHP . cystbear Try YaLinqo . It is the best LINQ for PHP. Here is a comparison table: (YaLinqo developer here.) Currently, there are three major implementations of LINQ in PHP: YaLinqo — the most minimalistic library architecture-wise (4 classes), but the most featureful, the most performant, with the best documentation and the only one supporting "string lambdas". Ginq — a library of average size (70 classes), on par with YaLinqo in the number of functions, around 1.5–3x times slower, contains