language-comparisons

Equivalent of .NET's WebClient and HttpWebRequest in Java?

我的未来我决定 提交于 2019-12-18 04:46:12
问题 .NET has the HttpWebRequest and WebClient classes for simulating a browser's requests. I'd google it, but I'm not sure what keyword to use. I want to write code that does does HTTP GETs and POSTs, along with cookies, in an applet or local .jar and gives me back the response in a text string or some other parseable structure. 回答1: HttpURLConnection is Java's equivalent of HttpWebRequest . URL iurl = new URL(url); HttpURLConnection uc = (HttpURLConnection)iurl.openConnection(); uc.connect(); if

What are the PowerShell equivalents of Bash's && and || operators?

爱⌒轻易说出口 提交于 2019-12-17 07:24:29
问题 In Bash I can easily do something like command1 && command2 || command3 which means to run command1 and if command1 succeeds to run command2 and if command1 fails to run command3. What's the equivalent in PowerShell? 回答1: What Bash must be doing is implicitly casting the exit code of the commands to a Boolean when passed to the logical operators. PowerShell doesn't do this - but a function can be made to wrap the command and create the same behavior: > function Get-ExitBoolean($cmd) { & $cmd

Is Grails (now) worth it?

≡放荡痞女 提交于 2019-12-12 07:07:44
问题 I know this is a duplicate, however, the Grails world has moved on considerably since that question was asked more than a year ago, as has the IDE support in Eclipse, so please don't just blindly close it. I thought the answer was yes and have embarked on a new project with Grails 1.2.0 and have flirted with the Groovy/Grails bits of the STS Eclipse Integration. I think the question deserves revisiting after a year of Grails evolution, when the answer was definitely mixed. So, as an

What is the Python equivalent of embedding an expression in a string? (ie. “#{expr}” in Ruby)

蓝咒 提交于 2019-12-10 17:33:01
问题 In Python, I'd like to create a string block with embedded expressions. In Ruby, the code looks like this: def get_val 100 end def testcode s=<<EOS This is a sample string that references a variable whose value is: #{get_val} Incrementing the value: #{get_val + 1} EOS puts s end testcode 回答1: If you need more than just a simple string formatting provided by str.format() and % then templet module could be used to insert Python expressions: from templet import stringfunction def get_val():

Does Java have a default copy constructor (like in C++)? [duplicate]

你说的曾经没有我的故事 提交于 2019-12-08 17:01:52
问题 This question already has answers here : Why doesn't Java have a copy constructor? (9 answers) Closed 3 years ago . Does Java has a default copy constructor as C++? If it has one - does it remain usable if I declare another constructor (not a copy constructor) explicitly? 回答1: Java does not have bulit-in copy constructors. But you can write your own such constructors. See an example below: class C{ private String field; private int anotherField; private D d; public C(){} public C(C other){

What is the difference between Java's equals() and C++'s operator ==?

帅比萌擦擦* 提交于 2019-12-05 20:23:00
问题 In a question regarding the use of typeid is C++, I suggested it could be used to compare types in objects comparison. I haven't seen it done much, but I had Java's equals in mind. Looking into Java a bit more, this seems to be the case: Some say the actual classes of the two objects should be compared, and some say instanceof is the right tool to use, possibly with double dispatch. There are of course cases in which one of the two is definitively more suitable, but at least both options are

Surprises Moving from C++ to C#

半世苍凉 提交于 2019-12-05 02:48:33
问题 I am a C++ programmer moving into C#. I worked with the language for a month now and understand many concepts. What are some surprises I may get while moving from C++ to C#? I was warned about destructors not being executed as I intended. Recently I tried to do something with generics that would use T as the base class. That didn't work. I also had another problem but I'll chalk that up to inexperience in C#. I was also surprised that my app was eating RAM, then I figured out I needed to use

PHP equivalent of Python's `str.format` method?

微笑、不失礼 提交于 2019-12-05 00:48:52
Is there an equivalent of Python str.format in PHP? In Python: "my {} {} cat".format("red", "fat") All I see I can do in PHP natively is by naming the entries and using str_replace : str_replace(array('{attr1}', '{attr2}'), array('red', 'fat'), 'my {attr1} {attr2} cat') Is there any other PHP's native alternatives? sprintf is the closest thing. It's the old-style Python string formatting: sprintf("my %s %s cat", "red", "fat") As PHP doesn't really have a proper alternative to str.format in Python, I decided to implement my very simple own which as most of the basic functionnalitites of the

What is the difference between Java's equals() and C++'s operator ==?

牧云@^-^@ 提交于 2019-12-04 02:22:32
In a question regarding the use of typeid is C++, I suggested it could be used to compare types in objects comparison. I haven't seen it done much, but I had Java's equals in mind. Looking into Java a bit more , this seems to be the case: Some say the actual classes of the two objects should be compared, and some say instanceof is the right tool to use, possibly with double dispatch. There are of course cases in which one of the two is definitively more suitable, but at least both options are considered . In C++, OTOH, I could barely find code in which the actual types are compared. On most

Implementing python slice notation

给你一囗甜甜゛ 提交于 2019-12-03 15:15:23
问题 I'm trying to reimplement python slice notation in another language (php) and looking for a snippet (in any language or pseudocode) that would mimic the python logic. That is, given a list and a triple (start, stop, step) or a part thereof, determine correct values or defaults for all parameters and return a slice as a new list. I tried looking into the source. That code is far beyond my c skills, but I can't help but agree with the comment saying: /* this is harder to get right than you