Search Results

Search found 34668 results on 1387 pages for 'return'.

Page 1/1387 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • C# return variables

    - by pb01
    In a debate regarding return variables, some members of the team prefer a method to return the result directly to the caller, whereas others prefer to declare a return variable that is then returned to the caller (see code examples below) The argument for the latter is that it allows a developer that is debugging the code to find the return value of the method before it returns to the caller thereby making the code easier to understand: This is especially true where method calls are daisy-chained. Are there any guidelines as to which is the most efficient and/or are there any other reasons why we should adopt one style over another? Thanks private bool Is2(int a) { return a == 2; } private bool Is3(int a) { var result = a == 3; return result; }

    Read the article

  • " not all code paths return a value" when return enum type

    - by netmajor
    I have enum list and method and i get error: " not all code paths return a value" Some idea whats wrong in my method ? I am sure I always return STANY type :/ Thanks for help :) private enum STANY { PATROL, CHAT, EAT, SEARCH, DIE }; private STANY giveState(int id, List<Ludek> gracze, List<int> plansza) { // Sprawdz czy gracz stoi na polu z jedzeniem i nie ma 2000 jednostek jedzenia bool onTheFood = false; onTheFood = CzyPoleZjedzeniem(id, gracze, plansza, onTheFood); if (onTheFood && (gracze[id].IloscJedzenia < startFood / 2)) return STANY.EAT; // Sprawdz czy gracz nie stoi na polu z innym graczem bool allKnowledge = true; allKnowledge = CzyPoleZInnymGraczem(id, gracze, allKnowledge); if (!allKnowledge) return STANY.CHAT; // Jesli ma ponad i rowna ilosc jedzenia patroluj if (gracze[id].IloscJedzenia >= startFood / 2) return STANY.PATROL; // Jesli ma mniej niz polowe jedzenia szukaj jedzenia if (gracze[id].IloscJedzenia > 0 && gracze[id].IloscJedzenia < startFood / 2) return STANY.SEARCH; // Jesli nie ma jedzenia umieraj if (gracze[id].IloscJedzenia <= 0) return STANY.DIE; }

    Read the article

  • See return value in C#

    - by Snake
    Hi, Consider the following piece of code: As you can see we are on line 28. Is there any way to see the return value of the function at this point, without letting the code return to the caller function? Foo.Bar() is a function call which generates a unique path (for example). So it's NOT constant. In VB.NET it's possible by entering the function's name in the Watch, which will then threat it as a variable. But in C# this is not possible, any other tips? PS: rewriting is not an option.

    Read the article

  • Is conditional return type ever a good idea?

    - by qegal
    So I have a method that's something like this: -(BOOL)isSingleValueRecord And another method like this: -(Type)typeOfSingleValueRecord And it occurred to me that I could combine them into something like this: -(id)isSingleValueRecord And have the implementation be something like this: -(id)isSingleValueRecord { //If it is single value if(self.recordValue = 0) { //Do some stuff to determine type, then return it return typeOfSingleValueRecord; } //If its not single value else { //Return "NO" return [NSNumber numberWithBool:NO]; } } So combining the two methods makes it more efficient but makes the readability go down. In my gut, I feel like I should go with the two-method version, but is that really right? Is there any case that I should go with the combined version?

    Read the article

  • Proper way to return an array

    - by Ward
    Hey there, I never seem to get this right. I've got a method that returns a mutable array. What is the proper way to return the array and avoid potential memory leaks? If I plan to store the results locally inside another view controller, does that affect the way the array should be returned? Lastly, what if it's just an non-mutable array? Does that require a different technique? thanks, Howie

    Read the article

  • Return value from ajax call?

    - by Dan
    Hi, I'm making a basic ajax function in jquery which echoes the number of rows found in a MySQL Query. function checkEventIDClass(id) { var params = 'method=checkEventIDClash&table=test&id=' + id; $.ajax({ type: "POST", url: "ajax.php", data: params, success: function(result){ return result; } }); } Is it possible to use this returned value in another function? I have tried but only get undefined values. In this situation, it will be acceptable to use synchronous calls. Any advice appreciated. Thanks

    Read the article

  • Naming methods that do the same thing but return different types

    - by Konstantin Ð.
    Let's assume that I'm extending a graphical file chooser class (JFileChooser). This class has methods which display the file chooser dialog and return a status signature in the form of an int: APPROVE_OPTION if the user selects a file and hits Open /Save, CANCEL_OPTION if the user hits Cancel, and ERROR_OPTION if something goes wrong. These methods are called showDialog(). I find this cumbersome, so I decide to make another method that returns a File object: in the case of APPROVE_OPTION, it returns the file selected by the user; otherwise, it returns null. This is where I run into a problem: would it be okay for me to keep the showDialog() name, even though methods with that name — and a different return type — already exist? To top it off, my method takes an additional parameter: a File which denotes in which directory the file chooser should start. My question to you: Is it okay to call a method the same name as a superclass method if they return different types? Or would that be confusing to API users? (If so, what other name could I use?) Alternatively, should I keep the name and change the return type so it matches that of the other methods? public int showDialog(Component parent, String approveButtonText) // Superclass method public File showDialog(Component parent, File location) // My method

    Read the article

  • eventmachine on debian fails install via rubygems

    - by Max
    this has been killing me for the last 5 hours. I don't seem to be able to get eventmachine running on my debian box. here this output: $ gem install thin Building native extensions. This could take a while... ERROR: Error installing thin: ERROR: Failed to build gem native extension. /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb checking for rb_trap_immediate in ruby.h,rubysig.h... no checking for rb_thread_blocking_region()... yes checking for inotify_init() in sys/inotify.h... yes checking for writev() in sys/uio.h... yes checking for rb_wait_for_single_fd()... yes checking for rb_enable_interrupt()... yes checking for rb_time_new()... yes checking for sys/event.h... no checking for epoll_create() in sys/epoll.h... yes creating Makefile make compiling kb.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from kb.cpp:20: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from kb.cpp:20: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from kb.cpp:20: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from kb.cpp:20: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type compiling rubymain.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from rubymain.cpp:20: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from rubymain.cpp:20: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from rubymain.cpp:20: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from rubymain.cpp:20: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type compiling ssl.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from ssl.cpp:23: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from ssl.cpp:23: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from ssl.cpp:23: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from ssl.cpp:23: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type compiling cmain.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from cmain.cpp:20: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from cmain.cpp:20: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from cmain.cpp:20: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from cmain.cpp:20: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type cmain.cpp:96: warning: type qualifiers ignored on function return type cmain.cpp:107: warning: type qualifiers ignored on function return type cmain.cpp:117: warning: type qualifiers ignored on function return type cmain.cpp:127: warning: type qualifiers ignored on function return type cmain.cpp:269: warning: type qualifiers ignored on function return type cmain.cpp:279: warning: type qualifiers ignored on function return type cmain.cpp:289: warning: type qualifiers ignored on function return type cmain.cpp:299: warning: type qualifiers ignored on function return type cmain.cpp:309: warning: type qualifiers ignored on function return type cmain.cpp:329: warning: type qualifiers ignored on function return type cmain.cpp:678: warning: type qualifiers ignored on function return type compiling em.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from em.cpp:23: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from em.cpp:23: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from em.cpp:23: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from em.cpp:23: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type em.cpp: In member function 'bool EventMachine_t::_RunEpollOnce()': em.cpp:578: warning: 'int rb_thread_select(int, fd_set*, fd_set*, fd_set*, timeval*)' is deprecated (declared at /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379) em.cpp:578: warning: 'int rb_thread_select(int, fd_set*, fd_set*, fd_set*, timeval*)' is deprecated (declared at /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379) em.cpp: In member function 'bool EventMachine_t::_RunSelectOnce()': em.cpp:974: warning: 'int rb_thread_select(int, fd_set*, fd_set*, fd_set*, timeval*)' is deprecated (declared at /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379) em.cpp:974: warning: 'int rb_thread_select(int, fd_set*, fd_set*, fd_set*, timeval*)' is deprecated (declared at /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379) em.cpp: At global scope: em.cpp:1057: warning: type qualifiers ignored on function return type em.cpp:1079: warning: type qualifiers ignored on function return type em.cpp:1265: warning: type qualifiers ignored on function return type em.cpp:1338: warning: type qualifiers ignored on function return type em.cpp:1510: warning: type qualifiers ignored on function return type em.cpp:1593: warning: type qualifiers ignored on function return type em.cpp:1856: warning: type qualifiers ignored on function return type em.cpp:1982: warning: type qualifiers ignored on function return type em.cpp:2046: warning: type qualifiers ignored on function return type em.cpp:2070: warning: type qualifiers ignored on function return type em.cpp:2142: warning: type qualifiers ignored on function return type em.cpp:2361: fatal error: error writing to /tmp/ccdlOK0T.s: No space left on device compilation terminated. make: *** [em.o] Error 1 Gem files will remain installed in /home/eventhub/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-1.0.1 for inspection. Results logged to /home/eventhub/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-1.0.1/ext/gem_make.out Any thoughts? I read a lot of different ways to solve this issue, but none of them worked. Thanks

    Read the article

  • Given a main function and a cleanup function, how (canonically) do I return an exit status in Bash/Linux?

    - by Zac B
    Context: I have a bash script (a wrapper for other scripts, really), that does the following pseudocode: do a main function if the main function returns: $returncode = $? #most recent return code if the main function runs longer than a timeout: kill the main function $returncode = 140 #the semi-canonical "exceeded allowed wall clock time" status run a cleanup function if the cleanup function returns an error: #nonzero return code exit $? #exit the program with the status returned from the cleanup function else #cleanup was successful .... Question: What should happen after the last line? If the cleanup function was successful, but the main function was not, should my program return 0 (for the successful cleanup), or $returncode, which contains the (possibly nonzero and unsuccessful) return code of the main function? For a specific application, the answer would be easy: "it depends on what you need the script for." However, this is more of a general/canonical question (and if this is the wrong place for it, kill it with fire): in Bash (or Linux in general) programming, do you typically want to return the status that "means" something (i.e. $returncode) or do you ignore such subjectivities and simply return the code of the most recent function? This isn't Bash-specific: if I have a standalone executable of any kind, how, canonically should it behave in these cases? Obviously, this is somewhat debatable. Even if there is a system for these things, I'm sure that a lot of people ignore it. All the same, I'd like to know. Cheers!

    Read the article

  • ~/.bashrc return can only 'return' from a function or sourced script

    - by Timothy
    I am trying to setup a OpenStack box to have a look at OpenStack Object Storage (Swift). Looking through the web I found this link; http://swift.openstack.org/development_saio.html#loopback-section I followed the instructions line by line but stuck on step 7 in the "Getting the code and setting up test environment" section. When I execute ~/.bashrc I get; line 6: return: can only 'return' from a function or sourced script. Below is the Line 6 extract from ~/.bashrc. My first reaction is to comment this line out, but I dont know what it does. Can anyone help? #If not running interactively, dont't do anything [ -z "$PS1" ] && return I'm running Ubuntu 12.04 as a VM on Hyper-v if knowing that is useful.

    Read the article

  • What to Return? Error String, Bool with Error String Out, or Void with Exception

    - by Ranger Pretzel
    I spend most of my time in C# and am trying to figure out which is the best practice for handling an exception and cleanly return an error message from a called method back to the calling method. For example, here is some ActiveDirectory authentication code. Please imagine this Method as part of a Class (and not just a standalone function.) bool IsUserAuthenticated(string domain, string user, string pass, out errStr) { bool authentic = false; try { // Instantiate Directory Entry object DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, user, pass); // Force connection over network to authenticate object nativeObject = entry.NativeObject; // No exception thrown? We must be good, then. authentic = true; } catch (Exception e) { errStr = e.Message().ToString(); } return authentic; } The advantages of doing it this way are a clear YES or NO that you can embed right in your If-Then-Else statement. The downside is that it also requires the person using the method to supply a string to get the Error back (if any.) I guess I could overload this method with the same parameters minus the "out errStr", but ignoring the error seems like a bad idea since there can be many reasons for such a failure... Alternatively, I could write a method that returns an Error String (instead of using "out errStr") in which a returned empty string means that the user authenticated fine. string AuthenticateUser(string domain, string user, string pass) { string errStr = ""; try { // Instantiate Directory Entry object DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, user, pass); // Force connection over network to authenticate object nativeObject = entry.NativeObject; } catch (Exception e) { errStr = e.Message().ToString(); } return errStr; } But this seems like a "weak" way of doing things. Or should I just make my method "void" and just not handle the exception so that it gets passed back to the calling function? void AuthenticateUser(string domain, string user, string pass) { // Instantiate Directory Entry object DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, user, pass); // Force connection over network to authenticate object nativeObject = entry.NativeObject; } This seems the most sane to me (for some reason). Yet at the same time, the only real advantage of wrapping those 2 lines over just typing those 2 lines everywhere I need to authenticate is that I don't need to include the "LDAP://" string. The downside with this way of doing it is that the user has to put this method in a try-catch block. Thoughts? Is there another way of doing this that I'm not thinking of?

    Read the article

  • When should a method of a class return the same instance after modifying itself?

    - by modiX
    I have a class that has three methods A(), B() and C(). Those methods modify the own instance. While the methods have to return an instance when the instance is a separate copy (just as Clone()), I got a free choice to return void or the same instance (return this;) when modifying the same instance in the method and not returning any other value. When deciding for returning the same modified instance, I can do neat method chains like obj.A().B().C();. Would this be the only reason for doing so? Is it even okay to modify the own instance and return it, too? Or should it only return a copy and leave the original object as before? Because when returning the same modified instance the user would maybe admit the returned value is a copy, otherwise it would not be returned? If it's okay, what's the best way to clarify such things on the method?

    Read the article

  • sendmail is using return-path instead of from address

    - by magd1
    I have a customer that is complaining about emails marked as spam. I'm looking at the header. It shows the correct From: [email protected] However, it doesn't like the return-path. Return-Path: <[email protected]> Received-SPF: neutral (google.com: x.x.x.x is neither permitted nor denied by domain of [email protected]) client-ip=x.x.x.x; Authentication-Results: mx.google.com; spf=neutral (google.com: x.x.x.x is neither permitted nor denied by domain of [email protected]) [email protected] How do I configure sendmail to use the From address for the Return-Path?

    Read the article

  • Linux Exim set return-path header automaticly using from header

    - by solomongaby
    Hello, I use Exim on a Centos distribution and have some problems with the mail sending. In order to make all the email pass the spam filters the "Return-path" and "Sender" headers have to be attached to each email. What should I do in order to have "Return-path" and "Sender" headers added by Exim to be exactly the same as the "From" header created by my mail client ? Thanks

    Read the article

  • Which statically typed languages support intersection types for function return values?

    - by stakx
    Initial note: This question got closed after several edits because I lacked the proper terminology to state accurately what I was looking for. Sam Tobin-Hochstadt then posted a comment which made me recognise exactly what that was: programming languages that support intersection types for function return values. Now that the question has been re-opened, I've decided to improve it by rewriting it in a (hopefully) more precise manner. Therefore, some answers and comments below might no longer make sense because they refer to previous edits. (Please see the question's edit history in such cases.) Are there any popular statically & strongly typed programming languages (such as Haskell, generic Java, C#, F#, etc.) that support intersection types for function return values? If so, which, and how? (If I'm honest, I would really love to see someone demonstrate a way how to express intersection types in a mainstream language such as C# or Java.) I'll give a quick example of what intersection types might look like, using some pseudocode similar to C#: interface IX { … } interface IY { … } interface IB { … } class A : IX, IY { … } class B : IX, IY, IB { … } T fn() where T : IX, IY { return … ? new A() : new B(); } That is, the function fn returns an instance of some type T, of which the caller knows only that it implements interfaces IX and IY. (That is, unlike with generics, the caller doesn't get to choose the concrete type of T — the function does. From this I would suppose that T is in fact not a universal type, but an existential type.) P.S.: I'm aware that one could simply define a interface IXY : IX, IY and change the return type of fn to IXY. However, that is not really the same thing, because often you cannot bolt on an additional interface IXY to a previously defined type A which only implements IX and IY separately. Footnote: Some resources about intersection types: Wikipedia article for "Type system" has a subsection about intersection types. Report by Benjamin C. Pierce (1991), "Programming With Intersection Types, Union Types, and Polymorphism" David P. Cunningham (2005), "Intersection types in practice", which contains a case study about the Forsythe language, which is mentioned in the Wikipedia article. A Stack Overflow question, "Union types and intersection types" which got several good answers, among them this one which gives a pseudocode example of intersection types similar to mine above.

    Read the article

  • Is it bad to have multiple return statements?

    - by scot
    Hi, I have a code somethg like below: int method(string a ,int b , int c){ if(cond1) return -1; if(cond2 || cond3) return 3; if(cond1 && cond2) return 0; else return -999; } Does it perform badly when compared to having multiple if else and have single return?

    Read the article

  • Java return to position N in call stack.

    - by Finbarr
    Using the return keyword in Java code will return execution to the last piece of calling code in the call stack. If object foo calls baz.bar(), the return keyword in the bar method will continue code execution in foo. Let's say I have object foo that calls foofoo that calls foofoofoo in the above scenario, and foofoofoo calls baz.bar(). Is there anyway in Java to use the return keyword, or something else, so that the code in the bar method can return all the way back up to foo? (WITHOUT THROWING AN EXCEPTION)

    Read the article

  • Omit return type in C++0x

    - by Clinton
    I've recently found myself using the following macro with gcc 4.5 in C++0x mode: #define RETURN(x) -> decltype(x) { return x; } And writing functions like this: template <class T> auto f(T&& x) RETURN (( g(h(std::forward<T>(x))) )) I've been doing this to avoid the inconvenience having to effectively write the function body twice, and having keep changes in the body and the return type in sync (which in my opinion is a disaster waiting to happen). The problem is that this technique only works on one line functions. So when I have something like this (convoluted example): template <class T> auto f(T&& x) -> ... { auto y1 = f(x); auto y2 = h(y1, g1(x)); auto y3 = h(y1, g2(x)); if (y1) { ++y3; } return h2(y2, y3); } Then I have to put something horrible in the return type. Furthermore, whenever I update the function, I'll need to change the return type, and if I don't change it correctly, I'll get a compile error if I'm lucky, or a runtime bug in the worse case. Having to copy and paste changes to two locations and keep them in sync I feel is not good practice. And I can't think of a situation where I'd want an implicit cast on return instead of an explicit cast. Surely there is a way to ask the compiler to deduce this information. What is the point of the compiler keeping it a secret? I thought C++0x was designed so such duplication would not be required.

    Read the article

  • unable to return 'true' value in C function

    - by Byron
    If Im trying to check an input 5 byte array (p) against a 5 byte array stored in flash (data), using the following function (e2CheckPINoverride), to simply return either a true or false value. But it seems, no matter what I try, it only returns as 'false'. I call the function here: if (e2CheckPINoverride(pinEntry) == 1){ PTDD_PTDD1 = 1; } else{ PTDD_PTDD1 = 0; } Here is the function: BYTE e2CheckPINoverride(BYTE *p) { BYTE i; BYTE data[5]; if(e2Read(E2_ENABLECODE, data, 5)) { if(data[0] != p[0]) return FALSE; if(data[1] != p[1]) return FALSE; if(data[2] != p[2]) return FALSE; if(data[3] != p[3]) return FALSE; if(data[4] != p[4]) return FALSE; } return TRUE; } I have already assigned true and false in the defines.h file: #ifndef TRUE #define TRUE ((UCHAR)1) #endif #ifndef FALSE #define FALSE ((UCHAR)0) #endif and where typedef unsigned char UCHAR; when i step through the code, it performs all the checks correctly, it passes in the correct value, compares it correctly and then breaks at the correct point, but is unable to process the return value of true? please help?

    Read the article

  • Method return values and exceptions

    - by dnagirl
    I have an interface called iIncident which defines a single method when(). when() should return a DateTime object. I'm trying to decide what to do if $object->when() has no DateTime to return as might be the case just after an object is instantiated and before all its properties are set. My choices are: return false throw some kind of Exception return some default DateTime like '9999-01-01' My inclination is to go with an Exception since $object really can't act as an incident until it knows when it occurred. I don't want to return a default DateTime because it complicates comparisons and it's not true. And I don't really want to return false because then I have to check for it every time I call the method- but if that is the preferred method, I guess I will. Is throwing an exception the best way? And is there a predefined exception type I should use (none of the SPL ones struck me as particularly appropriate- but that might just indicate my lack of experience)?

    Read the article

  • Return from parent sub in Perl

    - by JS Bangs
    I want to write a subroutine which causes the caller to return under certain conditions. This is meant to be used as a shortcut for validating input to a function. What I have so far is: sub needs($$) { my ($condition, $message) = @_; if (not $condition) { print "$message\n"; # would like to return from the *parent* here } return $condition; } sub run_find { my $arg = shift @_; needs $arg, "arg required" or return; needs exists $lang{$arg}, "No such language: $arg" or return; # etc. } The advantage of returning from the caller in needs would then be to avoid having to write the repetitive or return inside run_find and similar functions.

    Read the article

  • C++ return a "NULL" object if search result not found

    - by aduric
    I'm pretty new to C++ so I tend to design with a lot of Java-isms while I'm learning. Anyway, in Java, if I had class with a 'search' method that would return an object T from a Collection< T that matched a specific parameter, I would return that object and if the object was not found in the collection, I would return a NULL. Then in my calling function I would just check if(T != NULL) { ... } In C++, I'm finding out that I can't return a NULL if the object doesn't exist. I just want to return an 'indicator' of type T that notifies the calling function that no object has been found. I don't want to throw an exception because it's not really an exceptional circumstance. class Node { .... Attr& getAttribute(const string& attribute_name) const { //search collection //if found at i return attributes[i]; //if not found return NULL; } private: vector<Attr> attributes; }

    Read the article

  • what is the point of return in ruby?

    - by Sam
    What is the difference between return and just putting a variable such as the following: return def write_code(number_of_errors) if number_of_errors > 1 mood = "WTF" else mood = "No Problem" end mood end no return def write_code(number_of_errors) if number_of_errors > 1 mood = "WTF" else mood = puts "No Problem" end return mood end

    Read the article

  • Is return an operator or a function?

    - by eSKay
    This is too basic I think, but how do both of these work? return true; // 1 and return (true); // 2 Similar: sizeof, exit My guess: If return was a function, 1 would be erroneous. So, return should be a unary operator that can also take in brackets... pretty much like unary minus: -5 and -(5), both are okay. Is that what it is - a unary operator?

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >