Search Results

Search found 4417 results on 177 pages for 'purpose'.

Page 9/177 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • What's the purpose of arrays starting with nonzero index?

    - by helios35
    I tried to find answers, but all I got was answers on how to realize arrays starting with nonzero indexes. Some languages, such as pascal, provide this by default, e.g., you can create an array such as var foobar: array[1..10] of string; I've always been wondering: Why would you want to have the array index not to start with 0? I guess it may be more familiar for beginners to have arrays starting with 1 and the last index being the size of the array, but on a long-term basis, programmers should get used to values starting with 0. Another purpose I could think of: In some cases, the index could actually represent something thats contained in the respective array-entry. e.g., you want to get all capital letters in an array, it may be handy to have an index being the ASCII-Code of the respective letter. But its pretty easy just to subtract a constant value. In this example, you could (in C) simply do something like this do get all capital letters and access the letter with ascii-code 67: #define ASCII_SHIFT 65 main() { int capital_letters[26]; int i; for (i=0; i<26; i++){ capital_letters[i] = i+ASCII_SHIFT; } printf("%c\n", capital_letters[67-ASCII_SHIFT]); } Also, I think you should use hash tables if you want to access entries by some sort of key. Someone might retort: Why should the index always start with 0? Well, it's a hell of a lot simpler this way. You'll be faster when you just have to type one index when declaring an array. Also, you can always be sure that the first entry is array[0] and the last one is array[length_of_array-1]. It is also common that other data structures start with 0. e.g., if you read a binary file, you start with the 0th byte, not the first. Now, why do some programming languages have this "feature" and why do some people ask how to achieve this in languages such as C/C++?, is there any situation where an array starting with a nonzero index is way more useful, or even, something simply cannot be done with an array starting at 0?

    Read the article

  • Jscript help? What is the main purpose of this Javascript?

    - by user577363
    Dear All, I don't know Javascript, can you please show me the main purpose of this Javascript? Many Thanks!! <script> var QunarUtil=new function(){var prefix='/scripts/';var suffix='';var host='';if(location.host.indexOf('src.')!=-1){prefix='/scripts/src/';host='http://hstatic.qunar.com';suffix='.js';}else if(location.host.indexOf('enc.')!=-1){prefix='/scripts/';host='http://hstatic.qunar.com';suffix='.js';}else if(location.host.substring(0,10)=='sdev-'){prefix=location.host.substring(5,location.host.indexOf('.'));prefix='/'+prefix.replace(/\-/ig,'/');host='http://hstatic.qunar.com';suffix='.js';}else if(location.host.indexOf("h.qunar.com")!=-1){host='http://hstatic.qunar.com';suffix='';} this.getScriptURL=function(name,isList){if(name.charAt(0)!='/') return this.getScript(prefix+name,isList);else return this.getScript(name,isList);} this.getScript=function(src,isList){return'<'+'script type="text/javascript" src="'+host+src+(isList?suffix:'.js')+'?'+__QUNARVER__+'"></'+'script>';} this.writeScript=function(name,isList){document.write(this.getScriptURL(name,isList));} this.writeScriptList=function(list){for(var i=0;i<list.length;i++) document.write(this.getScriptURL(list[i]));} var cssRoot='/styles/';this.writeCSS=function(cssList){for(var i=0;i<cssList.length;i++){document.write('<link rel="stylesheet" href="'+cssRoot+cssList[i]+'?'+__QUNARVER__+'">');}} this.writeStaticScript=function(src){document.write('<scr'+'ipt type="text/javascript" src="'+src+'"></'+'scr'+'ipt>');} this.writeStaticList=function(src){document.write('<scr'+'ipt type="text/javascript" src="'+src+suffix+'?'+__QUNARVER__+'"></'+'scr'+'ipt>');}} $include=function(){for(var i=0;i<arguments.length;i++){QunarUtil.writeScript(arguments[i],true);}} </script> Uncompressed version: <script> var QunarUtil = new function() { var prefix = '/scripts/'; var suffix = ''; var host = ''; if (location.host.indexOf('src.') != -1) { prefix = '/scripts/src/'; host = 'http://hstatic.qunar.com'; suffix = '.js'; } else if (location.host.indexOf('enc.') != -1) { prefix = '/scripts/'; host = 'http://hstatic.qunar.com'; suffix = '.js'; } else if (location.host.substring(0, 10) == 'sdev-') { prefix = location.host.substring(5, location.host.indexOf('.')); prefix = '/' + prefix.replace(/\-/ig, '/'); host = 'http://hstatic.qunar.com'; suffix = '.js'; } else if (location.host.indexOf("h.qunar.com") != -1) { host = 'http://hstatic.qunar.com'; suffix = ''; } this.getScriptURL = function(name, isList) { if (name.charAt(0) != '/') return this.getScript(prefix + name, isList); else return this.getScript(name, isList); } this.getScript = function(src, isList) { return '<' + 'script type="text/javascript" src="' + host + src + (isList ? suffix : '.js') + '?' + __QUNARVER__ + '"></' + 'script>'; } this.writeScript = function(name, isList) { document.write(this.getScriptURL(name, isList)); } this.writeScriptList = function(list) { for (var i = 0; i < list.length; i++) document.write(this.getScriptURL(list[i])); } var cssRoot = '/styles/'; this.writeCSS = function(cssList) { for (var i = 0; i < cssList.length; i++) { document.write('<link rel="stylesheet" href="' + cssRoot + cssList[i] + '?' + __QUNARVER__ + '">'); } } this.writeStaticScript = function(src) { document.write('<scr' + 'ipt type="text/javascript" src="' + src + '"></' + 'scr' + 'ipt>'); } this.writeStaticList = function(src) { document.write('<scr' + 'ipt type="text/javascript" src="' + src + suffix + '?' + __QUNARVER__ + '"></' + 'scr' + 'ipt>'); } } $include = function() { for (var i = 0; i < arguments.length; i++) { QunarUtil.writeScript(arguments[i], true); } } </script>

    Read the article

  • What is the role and purpose of a bootstrapper?

    - by ForeverDebugging
    I'm working on an application which uses a bootscrapper object to perform some operations when the application first starts. e.g. registers IoC objects, puts certain variables into the asp.net Application session object, does some security checks etc. I had a look around the internet and couldn't find a reference to a bootscrapper pattern, or any article about the subject. Is this a known pattern under a different name?

    Read the article

  • Violating 1st normal form, is it okay for my purpose?

    - by Nick
    So I'm making a running log, and I have the workouts stored as entries in a table. For each workout, the user can add intervals (which consist of a time and a distance), so I have an array like this: [workout] => [description] => [comments] => ... [intervals] => [0] => [distance] => 200m [time] => 32 [1] => [distance] => 400m [time] => 65 ... I'm really tempted to throw the "intervals" array into serialize() or json_encode() and put it in an "intervals" field in my table, however this violates the principles of good database design (which, incidentally, I know hardly anything about). Is there any disadvantage to doing this? I never plan on querying my table based on the contents of "intervals". Creating a separate table just for intervals seems like a lot of unnecessary complexity, so if anyone with more experience has had a situation like this, what route did you take and how did it work out?

    Read the article

  • Strategies for serializing an object for auditing/logging purpose in .NET?

    - by Jiho Han
    Let's say I have an application that processes messages. Messages are just objects in this case that implements IMessage interface which is just a marker. In this app, if a message fails to process, then I want to log it, first of all for auditing and troubleshooting purposes. Secondly I might want to use it for re-processing. Ideally, I want the message to be serialized into a format that is human-readable. The first candidate is XML although there are others like JSON. If I were to serialize the messages as XML, I want to know whether the message object is XML-serializable. One way is to reflect on the type and to see if it has a parameter-less constructor and the other is to require IXmlSerializable interface. I'm not too happy with either of these approaches. There is a third option which is to try to serialize it and catch exceptions. This doesn't really help - I want to, in some way, stipulate that IMessage (or a derived type) should be xml-serializable. The reflection route has obvious disadvantages such as security, performance, etc. IXmlSerializable route locks down my messages to one format, when in the future, I might want to change the serialization format to be JSON. The other thing is even the simplest objects now must implement ReadXml and WriteXml methods. Is there a route that involves the least amount of work that lets me serialize an arbitrary object (as long as it implements the marker interface) into XML but not lock future messages into XML?

    Read the article

  • Which Cortex-M3 interrupts can I use for general purpose work?

    - by Captain NedD
    I'd have some code that needs to be run as the result of a particular interrupt going off. I don't want to execute it in the context of the interrupt itself but I also don't want it to execute in thread mode. I would like to run it at a priority that's lower than the high level interrupt that precipitated its running but also a priority that higher than thread level (and some other interrupts as well). I think I need to use one of the other interrupt handlers. Which ones are the best to use and what the best way to invoke them? At the moment I'm planning on just using the interrupt handlers for some peripherals that I'm not using and invoking them by setting bits directly through the NVIC but I was hoping there's a better, more official way. Thanks,

    Read the article

  • Silverlight Vs. WPF Vs. Winforms What is good for specifically my purpose?

    - by Cyril Gupta
    I am about to start a new Windows applications and the contenders for the platform are: Windows Forms WPF Silverlight Now my experience with WPF at least in my last application was not very encouraging (the app failed to run on the deployment machines and I had to re-do it in Winforms). So my confidence is shaken here. My app is for mass-distribution (the last version had some 100,000+ installations). So I want to make absolutely sure that my users will be able to use it and enjoy it without any problems. I would love to create a nice interface, going the next step like a Flex or Silverlight, iPhone app, with animations and effects. So I would really like to go with WPF or Silverlight if I can. My needs are Good support for visuals and animation effects. Support for database connectivity. Support for printing (Is there an equivalent of PrintDocument in Silverlight) Must not suffer from deployment troubles. Silverlight is universal, but does it have printing support and good controls toolset? WPF has printing support and a nice toolset, but can I depend on it? Winforms is dated already and is not so impressive, but should I go with it anyway? Your advice would be appreciated

    Read the article

  • How do I specify a keys password with MSBuild for the purpose of using Hudson?

    - by Brett Ryan
    We have just setup our hudson server to build .NET projects which seems to be working fine, however for projects that require a password when signing the assemblies I can not figure out how to tell hudson what the password is? For us the password is asked the first time a developer checks out the source code and they open with visual studio, how is this stored? Can we just place a secret file somewhere on the server?

    Read the article

  • .NET: What is the purpose of the ProhibitDtd property in XmlReaderSettings? Why is DTD a security i

    - by Cheeso
    The documentation says: When set to true, the XmlReader throws an XmlException when any DTD content is encountered. Do not enable DTD processing if you are concerned about Denial of Service issues or if you are dealing with untrusted sources. If you have DTD processing enabled, you can use the XmlSecureResolver to restrict the resources that the XmlReader can access. You can also design your application so that the XML processing is memory and time constrained. For example, configure time-out limits in your ASP.NET application. Can someone please explain the issue? Why would a reader application want to prohibit the retrieval of a DTD? Where is the denial-of-service issue, if it is a reading application? What is the "trust" issue that is mentioned? Thanks

    Read the article

  • c#: what is the purpose of wpf vs. winforms [closed]

    - by every_answer_gets_a_point
    i know wpf can be richer-looking, but what is the point of using them if they complicate things so much? for example if i want to do something on form load in wpf i have to through the trouble of writing this: public MyWindow() { Loaded += MyWindow_Loaded; } private void MyWindow_Loaded(object sender, RoutedEventArgs e) { // do work here } whereas in winforms all i do is double click on the form the question is what are the benefits of using wpf over winforms?

    Read the article

  • What do I name this class whose sole purpose is to report failure?

    - by Blair Holloway
    In our system, we have a number of classes whose construction must happen asynchronously. We wrap the construction process in another class that derives from an IConstructor class: class IConstructor { public: virtual void Update() = 0; virtual Status GetStatus() = 0; virtual int GetLastError() = 0; }; There's an issue with the design of the current system - the functions that create the IConstructor-derived classes are often doing additional work which can also fail. At that point, instead of getting a constructor which can be queried for an error, a NULL pointer is returned. Restructuring the code to avoid this is possible, but time-consuming. In the meantime, I decided to create a constructor class which we create and return in case of error, instead of a NULL pointer: class FailedConstructor : public IConstructor public: virtual void Update() {} virtual Status GetStatus() { return STATUS_ERROR; } virtual int GetLastError() { return m_errorCode; } private: int m_errorCode; }; All of the above this the setup for a mundane question: what do I name the FailedConstructor class? In our current system, FailedConstructor would indicate "a class which constructs an instance of Failed", not "a class which represents a failed attempt to construct another class". I feel like it should be named for one of the design patterns, like Proxy or Adapter, but I'm not sure which.

    Read the article

  • What is the main purpose and sense to have staging server the same as production?

    - by truthseeker
    Hi, In our company we have staging and production servers. I'm trying to have them in state 1:1 after latest release. We've got web application running on several host and many instances of it. The issue is that I am an advocate of having the same architecture (structure) of web applications on staging and production servers to easily test new features and avoid creating of new bugs with new releases. But not everyone agree with me, and for them is not a such big deal to have different connection between staging application instances. Even maybe to have more application and connections between application on staging than on production server. I would like to ask about pros and cons of such an approach? I mean some good points to agree with me, or some bad why maybe i don't have right. Some examples of consequences and so forth.

    Read the article

  • How can I determine if there is an open source software for a specific purpose?

    - by afsharm
    Hi, We are going to write an entire new application for a reservation system. In this system experts specify their free time in elaborated calendar and users seek them through searched and finally reserve the expert and his time. We prefer to find an open source program like this and try to evolve it instead of creating it from scratch. In this manner our time is saved and that open source program will be completer too. We are a entire .NET (ASP.NET, C#, NHibernate) company. We have same problem to find open source applications for our new projects. Any help is highly appreciated.

    Read the article

  • What's the purpose of the lua "stub" dll for windows.

    - by Roddy
    I'm looking at incorporating Lua into a C++ project, and am a bit confused by the presence of the two binaries (lua51.dll and lua5.1.dll) in the distribution from Luabinaries. According to the docs... In Windows your library or application must be linked with a stub library. A stub library is a library with only the function declarations that will bind your DLL with the Lua DLL. Why? I've never needed stub DLLs before when linking with third-party DLLs?

    Read the article

  • What is the purpose of Java's unary plus operator?

    - by Syntactic
    Java's unary plus operator appears to have come over from C, via C++. As near as I can tell, it has the following effects: promotes its operand to int, if it's not already an int or wider unboxes its operand, if it's a wrapper object complicates slightly the parsing of evil expressions containing large numbers of consecutive plus signs It seems to me that there are better (or, at least, clearer) ways to do all of these things. In this SO question, concerning the counterpart operator in C#, someone said that "It's there to be overloaded if you feel the need." But in Java, one cannot overload any operator. So does this operator exist in Java just because it existed in C++?

    Read the article

  • What is the purpose of "do!" notation in F#?

    - by Yacoder
    I'm a beginner in F#, so it's a simple question and maybe a duplicate, but I couldn't find the answer anywhere... I'm reading this LOGO DSL implementation and I don't understand, what is the meaning of the "do!" notation in here: this.Loaded.Add (fun _ -> async { do! Async.Sleep 200 for cmd in theDrawing do do! this.Execute(cmd) } |> Async.StartImmediate ) Can you help?

    Read the article

  • What is the point/purpose of Ruby EventMachine, Python Twisted, or JavaScript Node.js?

    - by CCw
    I don't understand what problem these frameworks solve. Are they replacements for a HTTP server like Apache HTTPD, Tomcat, Mongrel, etc? Or are they more? Why might I use them... some real world examples? I've seen endless examples of chat rooms and broadcast services, but don't see how this is any different than, for instance, setting up a Java program to open sockets and dispatch a thread for each request. I think I understand the non-blocking I/O, but I don't understand how that is any different than a multi-threaded web server.

    Read the article

  • What is the purpose of the s==NULL case for mbrtowc?

    - by R..
    mbrtowc is specified to handle a NULL pointer for the s (multibyte character pointer) argument as follows: If s is a null pointer, the mbrtowc() function shall be equivalent to the call: mbrtowc(NULL, "", 1, ps) In this case, the values of the arguments pwc and n are ignored. As far as I can tell, this usage is largely useless. If ps is not storing any partially-converted character, the call will simply return 0 with no side effects. If ps is storing a partially-converted character, then since '\0' is not valid as the next byte in a multibyte sequence ('\0' can only be a string terminator), the call will return (size_t)-1 with errno==EILSEQ. and leave ps in an undefined state. The intended usage seems to have been to reset the state variable, particularly when NULL is passed for ps and the internal state has been used, analogous to mbtowc's behavior with stateful encodings, but this is not specified anywhere as far as I can tell, and it conflicts with the semantics for mbrtowc's storage of partially-converted characters (if mbrtowc were to reset state when encountering a 0 byte after a potentially-valid initial subsequence, it would be unable to detect this dangerous invalid sequence). If mbrtowc were specified to reset the state variable only when s is NULL, but not when it points to a 0 byte, a desirable state-reset behavior would be possible, but such behavior would violate the standard as written. Is this a defect in the standard? As far as I can tell, there is absolutely no way to reset the internal state (used when ps is NULL) once an illegal sequence has been encountered, and thus no correct program can use mbrtowc with ps==NULL.

    Read the article

  • About to migrate :string but I'm thinking :text might be better. Performance/Purpose?

    - by Sam
    class CreateScrapes < ActiveRecord::Migration def self.up create_table :scrapes do |t| t.text :saved_characters t.text :sanitized_characters t.string :href t.timestamps end end def self.down drop_table :scrapes end end I'm about to rake db:migrate and I'm think about the attribute type if I should be using text or string. Since saved_characters and sanitized_characters will be arrays with thousands of unicode values, its basically comma delimited data, I'm not sure if `:text' is really the right way to go here. What would you do?

    Read the article

  • For what purpose does java have a float primitive type?

    - by Roman
    I heard plenty times different claims about float type in java. The most popular issues typicaly regard to converting float value to double and vice versa. I read (rather long time ago and not sure that it's actual now with new JVM) that float gives much worse performance then double. And it's also not recommended to use float in scientific applications which should have certain accuracy. I also remember that when I worked with AWT and Swing I had some problems with using float or double (like using Point2D.Float or Point2D.Double). So, I see only 2 advantages of float over double: it needs only 4 bytes while double needs 8 bytes JMM garantees that assignment operation is atomic with float variables while it's not atomic with double's. Are there any other cases where float is better then double? Do you use float's in your applications? It seems to me that the only valuable reason java has float is backward compatibility.

    Read the article

  • Android XML. What is the purpose of the star in the ID string?

    - by alex2k8
    In some sources I see such declarations <item android:id="@+id/menu_display_groups" android:icon="@*android:drawable/ic_menu_allfriends" android:title="@string/menu_displayGroup" /> Notice the * @*android: It seems to give access to internal resources. But would like to know for sure. Also curious, if it is safe to build application with such declarations using Android 2.2 SDK, and run it on 1.5.

    Read the article

  • What really is the purpose of "base" keyword in c#?

    - by Pandiya Chendur
    Thus for used base class for some commom reusable methods in every page of my application... public class BaseClass:System.Web.UI.Page { public string GetRandomPasswordUsingGUID(int length) { string guidResult = System.Guid.NewGuid().ToString(); guidResult = guidResult.Replace("-", string.Empty); return guidResult.Substring(0, length); } } So if i want to use this method i would just do, public partial class forms_age_group : BaseClass { protected void Page_Load(object sender, EventArgs e) { //i would just call it like this string pass = GetRandomPasswordUsingGUID(10); } } It does what i want but there is a "Base" keyword that deals with base class in c# ... I really want to know when should use base keyword in my derived class.... Any good example...

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >