Search Results

Search found 250 results on 10 pages for 'toy'.

Page 8/10 | < Previous Page | 4 5 6 7 8 9 10  | Next Page >

  • Why Apple’s New SDK Limitation is So Offensive

    - by TStewartDev
    I am not an Apple fanboy, nor have I ever been. However, I have owned a Mac, an iPod, and an iPhone in my lifetime, and for more than a decade, I have defended Apple against the untruths that the haters so enjoy spewing. I encouraged my wife to buy a MacBook when she needed a new laptop two years ago, and I often recommend them to my friends and relatives. I have proudly and happily used my first generation iPhone for nearly three years. Now, for the first time in well over ten years, I find myself ready to swear off Apple and encourage everyone I know to do the same. I was disappointed when Apple wouldn't allow native apps, but I still bought the iPhone. I've stomached their ambiguous app approval process even though it's apparent that Steve may just reject your app because he doesn't like you or feels threatened by you (I'm still lamenting the rejection of the Google Voice app). But, as a developer, I can no longer tolerate Apple's terms and the kind of totalitarian control they indicate Apple wants. In case you are not already familiar, Apple has dictated in their OS 4.0 SDK license agreement (the now infamous Section 3.3.1) that all apps developed for the iPhone must be coded in C, C++, or Objective C, and moreover, that using any cross-compiling platforms is a violation of the agreement. For those of you who aren't developers, let me try to illustrate why this angers those of us who are. Imagine you're a professional writer. You've had articles published in some journals and magazines, and you've got a couple popular books out there, too. You've got an idea for a new book, and so you take it to your publisher. Your publisher agrees that it's a good idea. "But," says the publisher, "we want to hold our books to a tighter standard so that our readers get the experience we want them to have. Therefore, from now on, all our writers may only use words from this list of the 10,000 most common English words. Furthermore, if you cite any other works or quote anyone, they must comply with that same list, or you'll have to rewrite the entire work as well in case our readers want to look up your citation." What do you do? If your work is a children's book, this probably isn't a big deal to you. If it's an autobiography, textbook, or even a novel, though, you're going to have a lot of trouble describing your content with only common words. It's going to take you longer to complete your book, too, since you'll be looking up less common words frequently to see if you can use them. You could always go to another publisher, but this one has the best ability to distribute your book. The next largest distributor can only do a quarter as much. You could abandon the project altogether, but then everyone loses. Isn't this a silly scenario? Who would put such a limitation on writers? Yet this is very much what Apple is doing. They are using their dominant position in the market to coerce developers to write their apps exclusively for the iPhone OS by making it too expensive to write for multiple platforms. It is at least a threefold attack, striking at Adobe who is set to release a compiler that lets Flash source be compiled to iPhone binaries; striking at Google whose Android platform stands the best chance at the moment of providing serious competition to the iPhone; and reinforcing their own strong position by keeping popular apps exclusively to iPhone. And while developers are already very upset about this, the sad fact is that most of us will cave and give in to Apple because consumers don't know any better. They will continue to buy Apple's toy forcing developers to play Apple's maniacal game in order to make any money, at least until Steve Jobs decides he doesn't like them or he intends to release a competing application (bye-bye OpenFeint). Apple has been kept in check on the desktop front by a very dominant Microsoft, but I'm afraid that their success with iPods, iTunes, and iPhones has created a monster that we may have to bear until it is slain by an anti-trust suit or dies with the retirement of Steve Jobs.

    Read the article

  • What's a good way to teach my son to program Java

    - by Software Monkey
    OK, so I've read through various posts about teaching beginner's to program, and there were some helpful things I will look at more closely. But what I want to know is whether there are any effective tools out there to teach a kid Java specifically? I want to teach him Java specifically because (a) with my strong background in C I feel that's too complex, (b) Java is the other language I know extremely well and therefore I can assist meaningfully without needing to teach myself a new but (to me) useless language, and (c) I feel that managed languages are the future, and lastly (d) Java is one of the simplest of all the languages I know well (aside from basic). I learned in basic, and I am open to teaching that first, but I am unaware of a decent free basic shell for Windows (though I haven't really searched, yet since it's not my first choice), and would anyway want to progress quickly to Java. My son is 8, so that's a couple of years earlier than I started - but he has expressed an interest in learning to program (possibly because I work from home a lot and he sees me programming all the time). If no-one can suggest a tool designed for this purpose, I will probably start him off with text/console based apps to teach the basics, and then progress to GUI building. Oh, one last thing, I am not a fan of IDE's (old school text editor type), so I would not be put off at all by a system that has him typing real code, and would likely prefer that to a toy drag/drop system. EDIT: Just to clarify; I really am specifically after ways to teach him Java; there are already a good many posts with good answers for other language alternatives - but that's not what I am looking for here. EDIT: What about Java frameworks for 2D video games - can anyone recommend any of them from personal experience? I like the idea of him starting with the mechanics in place (main game loop, scoring, etc) and adding the specifics for a game of his own imagining - that's what I did, though for me it was basic on a Commodore VIC-20 and a Sinclair ZX-81.

    Read the article

  • Throttling outbound API calls generated by a Rails app

    - by Sharpie
    I am not a professional web developer, but I like to wrench on websites as a hobby. Recently, I have been playing with developing a Rails app as a project to help me learn the framework. The goal of my toy app is to harvest data from another service through their API and make it available for me to query using a search function. However, the service I want to pull data from imposes a rate limit on the number of API calls that may be executed per minute. I plan on having my app run a daily update which may generate a burst of API calls that far exceeds the limit provided by the external service. I wish to respect the performance of the external site and so would like to throttle the rate at which my app executes the calls. I have done a little bit of searching and the overwhelming amount of tutorial material and pre-built libraries I have found cover throttling inbound API calls to a web app and I can find little discussion of controlling the flow of outbound calls. Being both an amateur web developer and a rails newbie, it is entirely possible that I have been executing the wrong searches in the wrong places. Therefore my questions are: Is there a nice website out there aggregating Rails tutorials that has material related to throttling outbound API requests? Are there any ruby gems or other libraries that would help me throttle the requests? I have some ideas of how I might go about writing a throttling system using a queue-based worker like DelayedJob or Resque to manage the API calls, but I would rather spend my weekends building the rest of the site if there is a good pre-built solution out there already.

    Read the article

  • malloc works, cudaHostAlloc segfaults?

    - by Mikhail
    I am new to CUDA and I want to use cudaHostAlloc. I was able to isolate my problem to this following code. Using malloc for host allocation works, using cudaHostAlloc results in a segfault, possibly because the area allocated is invalid? When I dump the pointer in both cases it is not null, so cudaHostAlloc returns something... works in_h = (int*) malloc(length*sizeof(int)); //works for (int i = 0;i<length;i++) in_h[i]=2; doesn't work cudaHostAlloc((void**)&in_h,length*sizeof(int),cudaHostAllocDefault); for (int i = 0;i<length;i++) in_h[i]=2; //segfaults Standalone Code #include <stdio.h> void checkDevice() { cudaDeviceProp info; int deviceName; cudaGetDevice(&deviceName); cudaGetDeviceProperties(&info,deviceName); if (!info.deviceOverlap) { printf("Compute device can't use streams and should be discared."); exit(EXIT_FAILURE); } } int main() { checkDevice(); int *in_h; const int length = 10000; cudaHostAlloc((void**)&in_h,length*sizeof(int),cudaHostAllocDefault); printf("segfault comming %d\n",in_h); for (int i = 0;i<length;i++) { in_h[i]=2; } free(in_h); return EXIT_SUCCESS; } ~ Invocation [id129]$ nvcc fun.cu [id129]$ ./a.out segfault comming 327641824 Segmentation fault (core dumped) Details Program is run in interactive mode on a cluster. I was told that an invocation of the program from the compute node pushes it to the cluster. Have not had any trouble with other home made toy cuda codes.

    Read the article

  • What are practical guidelines for evaluating a language's "Turing Completeness"?

    - by AShelly
    I've read "what-is-turing-complete" and the wikipedia page, but I'm less interested in a formal proof than in the practical implications of being Turing Complete. What I'm actually trying to decide is if the toy language I've just designed could be used as a general-purpose language. I know I can prove it is if I can write a Turing machine with it. But I don't want to go through that exercise until I'm fairly certain of success. Is there a minimum set of features without which Turing Completeness is impossible? Is there a set of features which virtually guarantees completeness? (My guess is that conditional branching and a readable/writeable memory store will get me most of the way there) EDIT: I think I've gone off on a tangent by saying "Turing Complete". I'm trying to guess with reasonable confidence that a newly invented language with a certain feature set (or alternately, a VM with a certain instruction set) would be able to compute anything worth computing. I know proving you can building a Turing machine with it is one way, but not the only way. What I was hoping for was a set of guidelines like: "if it can do X,Y,and Z, it can probably do anything".

    Read the article

  • Linear feedback shift register?

    - by Mattia Gobbi
    Lately I bumped repeatedly into the concept of LFSR, that I find quite interesting because of its links with different fields and also fascinating in itself. It took me some effort to understand, the final help was this really good page, much better than the (at first) cryptic wikipedia entry. So I wanted to write some small code for a program that worked like a LFSR. To be more precise, that somehow showed how a LFSR works. Here's the cleanest thing I could come up with after some lenghtier attempts (Python): def lfsr(seed, taps): sr, xor = seed, 0 while 1: for t in taps: xor += int(sr[t-1]) if xor%2 == 0.0: xor = 0 else: xor = 1 print xor sr, xor = str(xor) + sr[:-1], 0 print sr if sr == seed: break lfsr('11001001', (8,7,6,1)) #example I named "xor" the output of the XOR function, not very correct. However, this is just meant to show how it circles through its possible states, in fact you noticed the register is represented by a string. Not much logical coherence. This can be easily turned into a nice toy you can watch for hours (at least I could :-) def lfsr(seed, taps): import time sr, xor = seed, 0 while 1: for t in taps: xor += int(sr[t-1]) if xor%2 == 0.0: xor = 0 else: xor = 1 print xor print time.sleep(0.75) sr, xor = str(xor) + sr[:-1], 0 print sr print time.sleep(0.75) Then it struck me, what use is this in writing software? I heard it can generate random numbers; is it true? how? So, it would be nice if someone could: explain how to use such a device in software development come up with some code, to support the point above or just like mine to show different ways to do it, in any language Also, as theres not much didactic stuff around about this piece of logic and digital circuitry, it would be nice if this could be a place for noobies (like me) to get a better understanding of this thing, or better, to understand what it is and how it can be useful when writing software. Should have made it a community wiki? That said, if someone feels like golfing... you're welcome.

    Read the article

  • Code bacteria: evolving mathematical behavior

    - by Stefano Borini
    It would not be my intention to put a link on my blog, but I don't have any other method to clarify what I really mean. The article is quite long, and it's in three parts (1,2,3), but if you are curious, it's worth the reading. A long time ago (5 years, at least) I programmed a python program which generated "mathematical bacteria". These bacteria are python objects with a simple opcode-based genetic code. You can feed them with a number and they return a number, according to the execution of their code. I generate their genetic codes at random, and apply an environmental selection to those objects producing a result similar to a predefined expected value. Then I let them duplicate, introduce mutations, and evolve them. The result is quite interesting, as their genetic code basically learns how to solve simple equations, even for values different for the training dataset. Now, this thing is just a toy. I had time to waste and I wanted to satisfy my curiosity. however, I assume that something, in terms of research, has been made... I am reinventing the wheel here, I hope. Are you aware of more serious attempts at creating in-silico bacteria like the one I programmed? Please note that this is not really "genetic algorithms". Genetic algorithms is when you use evolution/selection to improve a vector of parameters against a given scoring function. This is kind of different. I optimize the code, not the parameters, against a given scoring function.

    Read the article

  • How do programming languages bind identifiers to functions

    - by sub
    I'm talking about C and/or C++ here as this are the only languages I know used for interpreters where the following could be a problem: If we have an interpreted language X how can a library written for it add functions to the language which can then be called from within programs written in the language? PHP example: substr( $str, 5, 10 ); How is the function substr added to the "function pool" of PHP so it can be called from within scripts? It is easy for PHP storing all registered function names in an array and searching through it as a function is called in a script. However, as there obviously is no eval in C(++), how can the function then be called? I assume PHP doesn't have 100MB of code like: if( identifier == "substr" ) { return PHP_SUBSTR(...); } else if( ... ) { ... } Ha ha, that would be pretty funny. I hope you have understood my question so far. How do interpreters solve this problem? How can I solve this for my own experimental toy interpreter?

    Read the article

  • animated swap position of two buttons

    - by Jagat
    I am trying to swap the position of two buttons. my swapping code looks as below. private void exchangeButtons(Button btn1, Button btn2) { // Create the animation set AnimationSet exchangeAnimation = new AnimationSet(true); TranslateAnimation translate = new TranslateAnimation( Animation.RELATIVE_TO_SELF, btn2.getLeft(), Animation.RELATIVE_TO_SELF, btn1.getLeft(), Animation.RELATIVE_TO_SELF, btn2.getRight(), Animation.RELATIVE_TO_SELF, btn1.getRight() ); translate.setDuration(500); exchangeAnimation.addAnimation(translate); // int fromX = btn1.getLeft(); // int fromY = btn1.getRight(); // int toX = btn2.getLeft(); // int toY = btn2.getRight(); Log.d("ArrangeMe", "view1 pos:" + btn1.getLeft() + ", " +btn1.getRight() + "view2 pos:" + btn2.getLeft() + ", " + btn2.getRight()); AnimationSet exchangeAnimation1 = new AnimationSet(true); TranslateAnimation translate1 = new TranslateAnimation( Animation.RELATIVE_TO_SELF, btn1.getLeft(), Animation.RELATIVE_TO_SELF, btn2.getLeft(), Animation.RELATIVE_TO_SELF, btn1.getRight(), Animation.RELATIVE_TO_SELF, btn2.getRight() ); translate1.setDuration(500); exchangeAnimation1.addAnimation(translate1); // EXECUTE btn1.startAnimation(exchangeAnimation); btn2.startAnimation(exchangeAnimation1); } I call the code as below exchangeButtons(button1, button2); my layout looks as below what happens when i execute the code is, instead of the buttons exchanging their positions, they just disappear for sometime[may be 500 ms] and reappear as they were originally. how to resolve this problem ? will it work properly in device ? regards

    Read the article

  • How to do cleanup reliably in python?

    - by Cheery
    I have some ctypes bindings, and for each body.New I should call body.Free. The library I'm binding doesn't have allocation routines insulated out from the rest of the code (they can be called about anywhere there), and to use couple of useful features I need to make cyclic references. I think It'd solve if I'd find a reliable way to hook destructor to an object. (weakrefs would help if they'd give me the callback just before the data is dropped. So obviously this code megafails when I put in velocity_func: class Body(object): def __init__(self, mass, inertia): self._body = body.New(mass, inertia) def __del__(self): print '__del__ %r' % self if body: body.Free(self._body) ... def set_velocity_func(self, func): self._body.contents.velocity_func = ctypes_wrapping(func) I also tried to solve it through weakrefs, with those the things seem getting just worse, just only largely more unpredictable. Even if I don't put in the velocity_func, there will appear cycles at least then when I do this: class Toy(object): def __init__(self, body): self.body.owner = self ... def collision(a, b, contacts): whatever(a.body.owner) So how to make sure Structures will get garbage collected, even if they are allocated/freed by the shared library? There's repository if you are interested about more details: http://bitbucket.org/cheery/ctypes-chipmunk/

    Read the article

  • forward invocation, by hand vs magically?

    - by John Smith
    I have the following two class: //file FruitTree.h @interface FruitTree : NSObject { Fruit * f; Leaf * l; } @end //file FruitTree.m @implementation FruitTree //here I get the number of seeds from the object f @end //file Fruit @interface Fruit : NSObject { int seeds; } -(int) countfruitseeds; @end My question is at the point of how I request the number of seeds from f. I have two choices. Either: Since I know f I can explicitly call it, i.e. I implement the method -(int) countfruitseeds { return [f countfruitseeds]; } Or: I can just use forwardInvocation: - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector { // does the delegate respond to this selector? if ([f respondsToSelector:selector]) return [f methodSignatureForSelector:selector]; else if ([l respondsToSelector:selector]) return [l methodSignatureForSelector:selector]; else return [super methodSignatureForSelector: selector]; } - (void)forwardInvocation:(NSInvocation *)invocation { [invocation invokeWithTarget:f]; } (Note this is only a toy example to ask my question. My real classes have lots of methods, which is why I am asking.) Which is the better/faster method?

    Read the article

  • Game architecture: modeling different steps/types of UI

    - by Sander
    I have not done any large game development projects, only messed around with little toy projects. However, I never found an intuitive answer to a specific design question. Namely, how are different types/states of UI modeled in games? E.g. how is a menu represented? How is it different from a "game world" state (let's use an FPS as an example). How is an overlaid menu on top of a "game world" modeled? Let's imagine the main loop of a game. Where do the game states come into play? It it a simple case-by-case approach? if (menu.IsEnabled) menu.Process(elapsedTime); if (world.IsEnabled) world.Process(elapsedTime); if (menu.IsVisible) menu.Draw(); if (world.IsVisible) world.Draw(); Or are menu and world represented somewhere in a different logic layer and not represented at this level? (E.g. a menu is just another high-level entity like e.g. player input or enemy manager, equal to all others) foreach (var entity in game.HighLevelEntities) entity.Process(elapsedTime); foreach (var entity in game.HighLevelEntities) entity.Draw(elapsedTime); Are there well-known design patterns for this? Come to think of it, I don't know any game-specific design patterns - I assume there are others, as well? Please tell me about them.

    Read the article

  • Is there a safe / standard way to manage unstructured memory in C++?

    - by andand
    I'm building a toy VM that requires a block of memory for storing and accessing data elements of different types and of different sizes. I've done this by writing a wrapper class around a uint8_t[] data block of the needed size. That class has some template methods to write / read typed data elements to / from arbitrary locations in the memory block, both of which check to make certain the bounds aren't violated. These methods use memmove in what I hope is a more or less safe manner. That said, while I am willing to press on in this direction, I've got to believe that other with more expertise have been here before and might be willing to share their wisdom. In particular: 1) Is there a class in one of the C++ standards (past, present, future) that has been defined to perform a function similar to what I have outlined above? 2) If not, is there a (preferably free as in beer) library out there that does? 3) Short of that, besides bounds checking and the inevitable issue of writing one type to a memory location and reading a different from that location, are there other issues I should be aware of? Thanks.-&&

    Read the article

  • Syntax error beyond end of program

    - by a_m0d
    I am experimenting with writing a toy compiler in ocaml. Currently, I am trying to implement the offside rule for my lexer. However, I am having some trouble with the ocaml syntax (the compiler errors are extremely un-informative). The code below (33 lines of it) causes an error on line 34, beyond the end of the source code. I am unsure what is causing this error. open Printf let s = (Stack.create():int Stack.t); let rec check x = ( if Stack.is_empty s then Stack.push x s else if Stack.top s < x then ( Stack.push x s; printf "INDENT\n"; ) else if Stack.top s > x then ( printf "DEDENT\n"; Stack.pop s; check x; ) else printf "MATCHED\n"; ); let main () = ( check 0; check 4; check 6; check 8; check 5; ); let _ = Printexc.print main () Ocaml output: File "lexer.ml", line 34, characters 0-0: Error: Syntax error Can someone help me work out what the error is caused by and help me on my way to fixing it?

    Read the article

  • How can I make NSUndoManager's undo/redo action names work properly?

    - by Gabe
    I'm learning Cocoa, and I've gotten undo to work without much trouble. But the setActionName: method is puzzling me. Here's a simple example: a toy app whose windows contain a single text label and two buttons. Press the On button and the label reads 'On'. Press the Off button and the label changes to read 'Off'. Here are the two relevant methods (the only code I wrote for the app): -(IBAction) turnOnLabel:(id)sender { [[self undoManager] registerUndoWithTarget:self selector:@selector(turnOffLabel:) object:self]; [[self undoManager] setActionName:@"Turn On Label"]; [theLabel setStringValue:@"On"]; } -(IBAction) turnOffLabel:(id)sender { [[self undoManager] registerUndoWithTarget:self selector:@selector(turnOnLabel:) object:self]; [[self undoManager] setActionName:@"Turn Off Label"]; [theLabel setStringValue:@"Off"]; } Here's what I expect: I click the On button The label changes to say 'On' In the Edit menu is the item 'Undo Turn On Label' I click that menu item The label changes to say 'Off' In the Edit menu is the item 'Redo Turn On Label' In fact, all these things work as I expect apart from the last one. The item in the Edit menu reads 'Redo Turn Off Label', not 'Redo Turn On Label'. (When I click that menu item, the label does turn to On, as I'd expect, but this makes the menu item's name even more of a mystery. What am i misunderstanding, and how can I get these menu items to display the way I want them to?

    Read the article

  • stealing inside the move constructor

    - by FredOverflow
    During the implementation of the move constructor of a toy class, I noticed a pattern: array2D(array2D&& that) { data_ = that.data_; that.data_ = 0; height_ = that.height_; that.height_ = 0; width_ = that.width_; that.width_ = 0; size_ = that.size_; that.size_ = 0; } The pattern obviously being: member = that.member; that.member = 0; So I wrote a preprocessor macro to make stealing less verbose and error-prone: #define STEAL(member) member = that.member; that.member = 0; Now the implementation looks as following: array2D(array2D&& that) { STEAL(data_); STEAL(height_); STEAL(width_); STEAL(size_); } Are there any downsides to this? Is there a cleaner solution that does not require the preprocessor?

    Read the article

  • Finding the Column Index for a Specific Value

    - by Btibert3
    Hi All, I am having a brain cramp. Below is a toy dataset: df <- data.frame( id = 1:6, v1 = c("a", "a", "c", NA, "g", "h"), v2 = c("z", "y", "a", NA, "a", "g"), stringsAsFactors=F) I have a specific value that I want to find across a set of defined columns and I want to identify the position it is located in. The fields I am searching are characters and the trick is that the value I am looking for might not exist. In addition, null strings are also present in the dataset. Assuming I knew how to do this, the variable position indicates the values I would like returned. > df id v1 v2 position 1 1 a z 1 2 2 a y 1 3 3 c a 2 4 4 <NA> <NA> 99 5 5 g a 2 6 6 h g 99 The general rule is that I want to find the position of value "a", and if it is not located or if v1 is missing, then I want 99 returned. In this instance, I am searching across v1 and v2, but in reality, I have 10 different variables. It is also worth noting that the value I am searching for can only exist once across the 10 variables. What is the best way to generate this recode? Many thanks in advance.

    Read the article

  • Unsort: remembering a permutation and undoing it.

    - by dreeves
    Suppose I have a function f that takes a vector v and returns a new vector with the elements transformed in some way. It does that by calling function g that assumes the vector is sorted. So I want f to be defined like so: f[v_] := Module[{s, r}, s = Sort[v]; (* remember the permutation applied in order to sort v *) r = g[s]; Unsort[r] (* apply the inverse of that permutation *) ] What's the best way to do the "Unsort"? Or could we get really fancy and have this somehow work: answer = Unsort[g[Sort[v]]]; ADDED: Let's make this concrete with a toy example. Suppose we want a function f that takes a vector and transforms it by adding to each element the next smallest element, if any. That's easy to write if we assume the vector is sorted, so let's write a helper function g that makes that assumption: g[v_] := v + Prepend[Most@v, 0] Now for the function we really want, f, that works whether or not v is sorted: f[v_] := (* remember the order; sort it; call g on it; put it back in the original order; return it *)

    Read the article

  • Testing When Correctness is Poorly Defined?

    - by dsimcha
    I generally try to use unit tests for any code that has easily defined correct behavior given some reasonably small, well-defined set of inputs. This works quite well for catching bugs, and I do it all the time in my personal library of generic functions. However, a lot of the code I write is data mining code that basically looks for significant patterns in large datasets. Correct behavior in this case is often not well defined and depends on a lot of different inputs in ways that are not easy for a human to predict (i.e. the math can't reasonably be done by hand, which is why I'm using a computer to solve the problem in the first place). These inputs can be very complex, to the point where coming up with a reasonable test case is near impossible. Identifying the edge cases that are worth testing is extremely difficult. Sometimes the algorithm isn't even deterministic. Usually, I do the best I can by using asserts for sanity checks and creating a small toy test case with a known pattern and informally seeing if the answer at least "looks reasonable", without it necessarily being objectively correct. Is there any better way to test these kinds of cases?

    Read the article

  • Cannot overload function

    - by anio
    So I've got a templatized class and I want to overload the behavior of a function when I have specific type, say char. For all other types, let them do their own thing. However, c++ won't let me overload the function. Why can't I overload this function? I really really do not want to do template specialization, because then I've got duplicate the entire class. Here is a toy example demonstrating the problem: http://codepad.org/eTgLG932 The same code posted here for your reading pleasure: #include <iostream> #include <cstdlib> #include <string> struct Bar { std::string blah() { return "blah"; } }; template <typename T> struct Foo { public: std::string doX() { return m_getY(my_t); } private: std::string m_getY(char* p_msg) { return std::string(p_msg); } std::string m_getY(T* p_msg) { return p_msg->blah(); } T my_t; }; int main(int, char**) { Foo<char> x; Foo<Bar> y; std::cout << "x " << x.doX() << std::endl; return EXIT_SUCCESS; } Thank you everyone for your suggestions. Two valid solutions have been presented. I can either specialize the doX method, or specialize m_getY() method. At the end of the day I prefer to keep my specializations private rather than public so I'm accepting Krill's answer.

    Read the article

  • How do interpreters written in C and C++ bind identifiers to C(++) functions

    - by sub
    I'm talking about C and/or C++ here as this are the only languages I know used for interpreters where the following could be a problem: If we have an interpreted language X how can a library written for it add functions to the language which can then be called from within programs written in the language? PHP example: substr( $str, 5, 10 ); How is the function substr added to the "function pool" of PHP so it can be called from within scripts? It is easy for PHP storing all registered function names in an array and searching through it as a function is called in a script. However, as there obviously is no eval in C(++), how can the function then be called? I assume PHP doesn't have 100MB of code like: if( identifier == "substr" ) { return PHP_SUBSTR(...); } else if( ... ) { ... } Ha ha, that would be pretty funny. I hope you have understood my question so far. How do interpreters written in C/C++ solve this problem? How can I solve this for my own experimental toy interpreter written in C++?

    Read the article

  • Understanding REST through an example

    - by grifaton
    My only real exposure to the ideas of REST has been through Ruby on Rails' RESTful routing. This has suited me well for the kind of CRUD-based applications I have built with Rails, but consequently my understanding of RESTfulness is somewhat limited. Let's say we have a finite collection of Items, each of which has a unique ID, and a number of properties, such as colour, shape, and size (which might be undefined for some Items). Items can be used by a client for a period of time, but each Item can only be used by one client at once. Access to Items is regulated by a server. Clients can request the temporary use of certain items from a server. Usually, clients will only be interested in getting access to a number of Items with particular properties, rather than getting access to specific Items. When a client requests use of a number of Items, the server responds with a list of IDs corresponding to the request, or with a response that says that the requested Items are not currently available or do not exist. A client can make the following kinds of request: Tell me how many green triangle Items there are (in total/available). Give me use of 200 large red Items. I have finished with Items 21, 23, 23. Add 100 new red square Items. Delete 50 small green Items. Modify all big yellow pentagon Items to be blue. The toy example above is like a resource allocation problem I have had to deal with recently. How should I go about thinking about it RESTfully?

    Read the article

  • How do C and C++ interpreters bind identifiers to functions

    - by sub
    I'm talking about C and/or C++ here as this are the only languages I know used for interpreters where the following could be a problem: If we have an interpreted language X how can a library written for it add functions to the language which can then be called from within programs written in the language? PHP example: substr( $str, 5, 10 ); How is the function substr added to the "function pool" of PHP so it can be called from within scripts? It is easy for PHP storing all registered function names in an array and searching through it as a function is called in a script. However, as there obviously is no eval in C(++), how can the function then be called? I assume PHP doesn't have 100MB of code like: if( identifier == "substr" ) { return PHP_SUBSTR(...); } else if( ... ) { ... } Ha ha, that would be pretty funny. I hope you have understood my question so far. How do C/C++ interpreters solve this problem? How can I solve this for my own experimental toy interpreter?

    Read the article

  • Best way to design a class in python

    - by Fraz
    So, this is more like a philosophical question for someone who is trying to understand classes. Most of time, how i use class is actually a very bad way to use it. I think of a lot of functions and after a time just indent the code and makes it a class and replacing few stuff with self.variable if a variable is repeated a lot. (I know its bad practise) But anyways... What i am asking is: class FooBar: def __init__(self,foo,bar): self._foo = foo self._bar = bar self.ans = self.__execute() def __execute(self): return something(self._foo, self._bar) Now there are many ways to do this: class FooBar: def __init__(self,foo): self._foo = foo def execute(self,bar): return something(self._foo, bar) Can you suggest which one is bad and which one is worse? or any other way to do this. This is just a toy example (offcourse). I mean, there is no need to have a class here if there is one function.. but lets say in __execute something() calls a whole set of other methods.. ?? Thanks

    Read the article

  • STLifying C++ classes

    - by shambulator
    I'm trying to write a class which contains several std::vectors as data members, and provides a subset of vector's interface to access them: class Mesh { public: private: std::vector<Vector3> positions; std::vector<Vector3> normals; // Several other members along the same lines }; The main thing you can do with a mesh is add positions, normals and other stuff to it. In order to allow an STL-like way of accessing a Mesh (add from arrays, other containers, etc.), I'm toying with the idea of adding methods like this: public: template<class InIter> void AddNormals(InIter first, InIter last); Problem is, from what I understand of templates, these methods will have to be defined in the header file (seems to make sense; without a concrete iterator type, the compiler doesn't know how to generate object code for the obvious implementation of this method). Is this actually a problem? My gut reaction is not to go around sticking huge chunks of code in header files, but my C++ is a little rusty with not much STL experience outside toy examples, and I'm not sure what "acceptable" C++ coding practice is on this. Is there a better way to expose this functionality while retaining an STL-like generic programming flavour? One way would be something like this: (end list) class RestrictedVector<T> { public: RestrictedVector(std::vector<T> wrapped) : wrapped(wrapped) {} template <class InIter> void Add(InIter first, InIter last) { std::copy(first, last, std::back_insert_iterator(wrapped)); } private: std::vector<T> wrapped; }; and then expose instances of these on Mesh instead, but that's starting to reek a little of overengineering :P Any advice is greatly appreciated!

    Read the article

< Previous Page | 4 5 6 7 8 9 10  | Next Page >