instruction
stringlengths
0
30k
|c++|api|error-handling|error-logging|api-design|
I've encountered the following problem pattern frequently over the years: * I'm writing complex code for a package comprised of a standalone application and also a library version of the core that people can use from inside other apps. * Both our own app and presumably ones that users create with the core library are likely to be run both in batch mode (off-line, scripted, remote, and/or from command line), as well as interactively. * The library/app takes complex and large runtime input and there may be a variety of error-like outputs including severe error messages, input syntax warnings, status messages, and run statistics. Note that these are all *incidental* outputs, not the primary purpose of the application which would be displayed or saved elsewhere and using different methods. * Some of these (probably only the very severe ones) might require a dialog box if run interactively; but it needs to log without stalling for user input if run in batch mode; and if run as a library the client program obviously wants to intercept and/or examine the errors as they occur. * It all needs to be cross-platform: Linux, Windows, OSX. And we want the solution to not be weird on any platform. For example, output to stderr is fine for Linux, but won't work on Windows when linked to a GUI app. * Client programs of the library may create multiple instances of the main class, and it would be nice if the client app could distinguish a separate error stream with each instance. * Let's assume everybody agrees it's good enough for the library methods to log errors via a simple call (error code and/or severity, then printf-like arguments giving an error message). The contentious part is how this is recorded or retrieved by the client app. I've done this many times over the years, and am never fully satisfied with the solution. Furthermore, it's the kind of subproblem that's actually not very important to users (they want to see the error log if something goes wrong, but they don't really care about our technique for implementing it), but the topic gets the programmers fired up and they invariably waste inordinate time on this detail and are never quite happy. Anybody have any wisdom for how to integrate this functionality into a C++ API, or is there an accepted paradigm or a good open source solution (not GPL, please, I'd like a solution I can use in commercial closed apps as well as OSS projects)?
[AngelScript](http://www.angelcode.com/angelscript/) > lets you call standard C functions and C++ methods with no need for proxy functions. The application simply registers the functions, objects, and methods that the scripts should be able to work with and nothing more has to be done with your code. The same functions used by the application internally can also be used by the scripting engine, which eliminates the need to duplicate functionality. > For the script writer the scripting language follows the widely known syntax of C/C++ (with minor changes), but without the need to worry about pointers and memory leaks.
If you're using a winforms app you could try using [UserProperties][1] to store this info. Another possible solution could be [custom configuration sections][2]. [1]: http://msdn.microsoft.com/en-us/library/aa221771(office.11).aspx [2]: http://msdn.microsoft.com/en-us/library/2tw134k3.aspx
You didn't provide a budget or other considerations like sound footprint. You also didn't say if you actually can use more than a few cores at one time with the applications you are developing. So, everything below is a guess. If you have the budget, the Mac Pro with Bootcamp(or a vm if you are so inclinded) might be a consideration. You won't want to upgrade your HDD or memory from Apple, but, the parts are easy enough to find at Newegg. I know this seems a little crazy, but, you can get a good value if you need the dual processors at 4 cores each. It is currently $2800 for 2 x 2.8GHz 8 cores total.
Is this valid YAML?
|yaml|
So for my text parsing in C# [question][1], I got directed at YAML. I'm hitting a wall with this library I was recommended, so this is a quickie. heading: name: A name taco: Yes age: 32 heading: name: Another name taco: No age: 27 And so on. Is that valid? [1]:http://stackoverflow.com/questions/13963/best-method-of-textfile-parsing-in-c
I do it the other way around. I find that doing it database-schema-first gets the system stuck in a data-driven-design that is difficult to abstract from persistence. We try to do domain model designs first *and then* base the database schema on those. And then there's the infrastructure design: the team should settle on conventions on how to structure the program first and foremost. And then we work together to agree first on a design for the common functionality of the system (e.g., things everyone needs like persistence, logging, etc.). This becomes the framework of the system. We all work on that together first before we split the rest of the functionalities amongst ourselves.
Add a [pre-commit hook][1] which parses the file content and performs the munging of CRLF/LF/CR/etc for you before it's written to SVN. [1]: http://wordaligned.org/articles/a-subversion-pre-commit-hook
There were some excellent suggestions already, but I just wanted to mention that Perl can also be called / can call to C/C++.
If you right-click on your "Computer" (or "My Computer") icon and select "Manage" from the pop-up menu, that'll take you to the Computer Management console. In there, under System Tools\Shared Folders, you'll find "Open Files". This is probably close to what you want, but if the file is on a network share then you'd need to do the same thing on the server on which the file lives.
I *think* that an unordered_map and hash_map are more or less the same thing. The difference is that the STL doesn't officially have a hash_map (what you're using is probably a compiler specific thing), so unordered_map is the fix for that omission. unordered_map is just that... unordered. You can't depend on it preserving any ordering on iteration.
MSSQL Full Text Searching
|mssql|search|
I am currently working on an application where we have a mssql database and I need to get a full text search working that allows us to search people's names. Currently the user can enter a into a name field that searches 3 different varchar cols. First, Last, Middle names So say I have 3 rows with the following info. 1 - Phillip - J - Fry 2 - Amy - NULL - Wong 3 - Leo - NULL - Wong If the user enters a name such as 'Fry' it will return row 1. However if they enter Phillip Fry, or Fr, or Phil they get nothing.. and I don't understand why its doing this. If they search for Wong they get rows 2 and 3 if they search for Amy Wong they again get nothing. Currently the query is using CONTAINSTABLE but I have switched that with FREETEXTTABLE, CONTAINS, and FREETEXT without any noticeable differences in the results. The table methods are be preferred because they return the same results but with ranking. Here is the query. .... @Name nvarchar(100), .... --""s added to prevent crash if searching on more then one word. DECLARE @SearchString varchar(100) SET @SearchString = '"'+@Name+'"' SELECT Per.Lastname, Per.Firstname, Per.MiddleName FROM Person as Per INNER JOIN CONTAINSTABLE(Person, (LastName, Firstname, MiddleName), @SearchString) AS KEYTBL ON Per.Person_ID = KEYTBL.[KEY] WHERE KEY_TBL.RANK > 2 ORDER BY KEYTBL.RANK DESC; .... Any Ideas why this full text search is not working correctly?
|mssql|search|fulltextsearch|
|search|fulltextsearch|
|search|full-text-search|
|search|fulltextsearch|
|search|full-text-search|
|sql-server|search|full-text-search|
@wesc: STL has std::map... so what's the difference with unordered_map? I don't think STL would implement twice the same thing and call it differently.
I can think of a couple of reasons: - A modicum of security by obscurity - it's slightly more work to tamper with POST submissions than GET - Caching and resubmit rules are more restrictive for POST than GET. I'm not entirely sure this would matter for the OpenID use case, though. - Bots wouldn't follow the POST form, but would follow the redirect. This could impact server load. - Different browsers have different max lengths for GET requests - but none of them are as large as POST. - Some browsers will warn on redirect to another domain. They'll also warn if you're submitting POST to a non-HTTPS url. - By turning JavaScript off, I can have a relatively secure experience, and not be silently redirected to another domain. I don't know that any of these are a slam-dunk reason to choose POST - unless the amount of data being sent exceeds the querystring length for some major browser.
[xxd](http://gd.tuwien.ac.at/linuxcommand.org/man_pages/xxd1.html) is the 'standard' hex dump util and looks like it should solve your problems
XML => HTML with Hpricot and Rails
|hpricot|rubyonrails|ruby|ruby-on-rails|open-uri|
I've never worked with web services and rails, and obviously this is something I need to learn. I've chosen to use hpricot because it looks great. Anyway, _why's been nice enough to provide the following example on the [hpricot website][1]: #!ruby require 'hpricot' require 'open-uri' # load the RedHanded home page doc = Hpricot(open("http://redhanded.hobix.com/index.html")) # change the CSS class on links (doc/"span.entryPermalink").set("class", "newLinks") # remove the sidebar (doc/"#sidebar").remove # print the altered HTML puts doc Which looks simple, elegant, and easy peasey. Works great in Ruby, but my question is: How do I break this up in rails? I experimented with adding this all to a single controller, but couldn't think of the best way to call it in a view. So let's say you were parsing an XML file from a web API and printing it in nice clean HTML with Hpricot. How would you break up the activity over the models, views, and controllers, and what would you put where? [1]: http://code.whytheluckystiff.net/hpricot/
|ruby|xml|ruby-on-rails|hpricot|open-uri|
Is there a rake task for backing up the data in your database?
|rake|database|
Is there a rake task for backing up the data in your database? I already have my schema backed up, but I want to make a backup of the data. It's a small database.
|rake|database|sql|
Is there a rake task for backing up the data in your database? I already have my schema backed up, but I want to make a backup of the data. It's a small MySQL database.
|rake|database|mysql|ruby|ruby-on-rails|
|database|ruby|mysql|ruby-on-rails|rake|
Defensive programming
|security|quality|
When writing code do you consciously program defensively to ensure high program quality and to avoid the possibility of your code being exploited maliciously, e.g. through buffer overflow exploits or code injection ? What's the "minimum" level of quality you'll always apply to your code ?
|security|quality|defensive-programming|
Shift operator in C
|c|
Is the shift operator (<<, >>) in C arithmetic shift or logical shift?
|c|
Looks like Jeff is using [CruiseControl.NET][1] based on some leafing through the podcast transcripts. This seems to have automated deployment capabilities from source control to production. Might this be where the insertion is happening? [1]: http://confluence.public.thoughtworks.org/display/CCNET/What+is+CruiseControl.NET
Annotating YouTube videos programatically
|web|youtube|
I want to be able to display a normal youtube video with overlaid annotations. This consists of colored rectangles for each frame. The only requirement is that this be done programatically. Youtube has annotations now, but require you use their front end to create them by hand. I want to be able to generate them. What's the best way of doing this? Some ideas: 1. Build your own flash player (ew?) 2. Somehow draw over the youtube flash player. Will this work? 3. Reverse engineer & hijack youtube's annotation system. Either messing with the local files or redirecting it's attempt to download the annotations. (using greasemonkey? Firefox plugin?) Ideas that don't count: download the video, edit it, re-encode it, and upload it :P
Apache/PHP: error_log per Virtual Host?
|php|apache|
On one Linux Server running Apache and PHP 5, we got multiple Virtual Hosts with separate logfiles and everything. The only thing we cannot seem to separate between virtual hosts is the php error_log. Overriding this setting in the &lt;Location&gt; of the httpd.conf does not seem to do anything. Did I overlook something? Is there a way to have separate php error_logs for each Virtual Host?
Maybe this might help: http://jsefa.sourceforge.net/quick-tutorial.html Read csv file with this tool and serialize to xml :)
Adobe air - SQLStatement.execute() - Multiple queries in one statement
|actionscript-3|apache-flex|air|
I've written a database generation script in sql, and want to execute it in my Adobe air application: Create Table tRole ( roleID integer Primary Key ,roleName varchar(40) ); Create Table tFile ( fileID integer Primary Key ,fileName varchar(50) ,fileDescription varchar(500) ,thumbnailID integer ,fileFormatID integer ,categoryID integer ,isFavorite boolean ,dateAdded date ,globalAccessCount integer ,lastAccessTime date ,downloadComplete boolean ,isNew boolean ,isSpotlight boolean ,duration varchar(30) ); Create Table tCategory ( categoryID integer Primary Key ,categoryName varchar(50) ,parent_categoryID integer ); ... I execute this in Air using the following method: public static function RunSqlFromFile(fileName:String):void { var file:File = File.applicationDirectory.resolvePath(fileName); var stream:FileStream = new FileStream(); stream.open(file, FileMode.READ) var strSql:String = stream.readUTFBytes(stream.bytesAvailable); NonQuery(strSql); } No errors are generated, however only tRole exists. It seems that it only looks at the first query (up to the semicolon- if I remove it, the query fails). Is there anyway to call multiple queries in one statement?
>I don't use VS2008 for C++, only VB & C#, but I find that when intellisense stops working (true for VS2003/2005/2008) it's because something in the project/file is broken - usually a bad reference or code. VB and C# have much better intellisense support due to the ability to reflect on the referenced assemblies to build the intellisense tree. C++ has to walk the include files for function prototypes, and if the paths are not correct it will not find all the prototype headers.
ASP.NET MVC and IIS6
|asp.net-mvc|iis-6|
Where can I find some good pointers on best practices for running ASP.NET MVC on IIS6? I haven't seen any realistic options for web-hosts who provide IIS7-hosting yet. Mostly because I don't live in the U.S. So I was wondering on how you best build applications in ASP.NET MVC and make it easily available to deploy on both IIS6 and IIS7. Keep in mind that this is for standard web-hosts, so there is no access to ISAPI-filters or special settings inside IIS6. Are there anything else one should think about when developing ASP.NET MVC-applications to target IIS6? Any functions that doesn't work?
ASP.NET MVC on IIS6
Where can I find some good pointers on best practices for running ASP.NET MVC on IIS6? I haven't seen any realistic options for web-hosts who provide IIS7-hosting yet. Mostly because I don't live in the U.S. So I was wondering on how you best build applications in ASP.NET MVC and make it easily available to deploy on both IIS6 and IIS7. Keep in mind that this is for standard web-hosts, so there is no access to ISAPI-filters or special settings inside IIS6. Are there anything else one should think about when developing ASP.NET MVC-applications to target IIS6? Any functions that doesn't work? UPDATE: One of the bigger issues is the thing with routes. The pattern {controller}/{action} will work on IIS7, but not IIS6 which needs {controller}.mvc/{action}. So how do I make this transparent? Again, **no ISAPI** and **no IIS-settings**, please.
|.net|asp.net-mvc|iis-6|
|.net|asp.net-mvc|deployment|iis-6|
Your logic seems sound, but you might want to consider adding some code to prevent the insert if you had passed in a specific primary key. Otherwise, if you're always doing an insert if the update didn't affect any records, what happens when someone deletes the record before you "UPSERT" runs? Now the record you were trying to update doesn't exist, so it'll create a record instead. That probably isn't the behavior you were looking for. -- Kevin Fairchild
How to identify that you're running under a VM?
|virtualization|
Is there a way to identify, from within a VM, that your code is running inside a VM? I guess there are more or less easy ways to identify specific VM systems, especially if the VM has the provider's extensions installed (such as for VirtualBox or VMWare). But is there a general way to identify that you are not running directly on the CPU?
If you don't want it saved, you do not need to execute the cfg.Save command. The Configuration object will store your changes until it isn't needed anymore.
@lomaxx I also learned the other day (the same time I learned your tip) is that you can now have disparate access levels on the same property: public string Name { get; private set;} That way only the class itself can set the Name property. public Name(string name) { Name = name; }
Just so I'm clear, you've done something like this, right? public ListView MyListView { get { return this.listView1; } } So then you are accessing (at design time) the MyListView property on your UserControl? I think if you want proper design-time support you're better off changing the "Modifier" property on the ListView itself (back on the original UserControl) to Public - that way you can modify the ListView directly on instances of the UserControl. I've had success doing that anyway.
Try [Handle][1]. [Filemon][2] & [Regmon][3] are also great for trying to figure out what the duce program foo is doing to your system. [1]: http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx [2]: http://technet.microsoft.com/en-us/sysinternals/bb896642.aspx [3]: http://technet.microsoft.com/en-us/sysinternals/bb896652.aspx
> If you can I'd be horrified. Why would you be horrified? Air is a desktop platform, and having access to the OS's APIs (such as registry access) makes plenty of sense. That being said, it isn't supported now (and as Adobe seem to be very Mac-centric, I doubt it will ever be added). > I have settled on grabbing the users name from the name of the user directory Using File.userDirectory.name will work in most cases, but it seems like a very fragile implementation, it relies on the OS maintaining the convention of having the username as their directory. I can think of a few possible things that might break it (playing with TweakUI etc).
Use [Process Explorer][1] from the Sysinternals Suite, the Find Handle or DLL function will let you search for the process with that file open. [1]: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx "Process Explorer"
There appears to be a YAML validator called [Kwalify][1] which should give you the answer. You shoulda just gone with the String tokenizing, man. Writing parsers is fun :) [1]: http://www.kuwata-lab.com/kwalify/
Why not just add a dependency to the "startup" project for each of the plugins? This will force the project to be rebuilt if any of the others change, and you won't have to mess with any other pre/post-build events.
Partially. YAML supports the notion of multiple consecutive "documents". If this is what you are trying to do here, then yes, it is correct - you have two documents (or document fragments). To make it more explicit, you should separate them with three dashes, like this: --- heading: name: A name taco: Yes age: 32 --- heading: name: Another name taco: No age: 27 On the other hand if you wish to make them part of the same document (so that deserializing them would result in a list with two elements), you should write it like the following. Take extra care with the indentation level: - heading: name: A name taco: Yes age: 32 - heading: name: Another name taco: No age: 27 In general YAML is concise and human readable / editable, but not really human writable, so you should always use libraries to generate it. Also, take care that there exists some breaking changes between different versions of YAML, which can bite you if you are using libraries in different languages which conform to different versions of the standard.
You will almost certainly want to use a database for flexible, record based access and to take advantage of the database's ability to handle concurrent data access. If you need to track information that may need to be undone, having it in a structured format is a benefit, as is having the ability to update a row indicating when and by whom a given transaction has been undone. You likely only want to write to a file if very high performance is an issue, or if you have very unstructured or large amounts of data per record that might be unweidly to store in a database. Note that Unless your application has a very large number of transactions database speed is unlikely to be an issue. Also note that if you are working with a file you'll need to handle concurrent access (read / write / locking) very carefully which is likely not something you want to have to deal with.
[Boost documentation of unordered containers][1] The difference is in the method of how you generate the look up. In the map/set containers the `operator<` is used to generate an ordered tree. In the unordered containers, an `operator( key ) => index` is used. See hashing for a description of how that works. [1]: http://www.boost.org/doc/libs/1_36_0/doc/html/unordered.html
You sure that std::hash_map exists in *all* STL implementations? SGI STL implements it, however GNU g++ doesn't have it (it's located in the __gnu_cxx namespace) as of 4.3.1 anyway. As far as I know, hash_map has always been non-standard, and now tr1 is fixing that.
It all depends on your skill level and how much load you are getting on your servers. If you have spare (physical) resources and have the technical skills and experience to maintain production machines running different operating systems, I'd recommend going running lighttpd on either Linux or FreeBSD. A light OS install with a static file optimized server will perform faster than Apache or IIS on a heavy OS. However, unless you are extremely comfortable with these solutions, just stick to IIS on Windows. Move the static files to their own machine if you have sufficient load. If you aren't currently thinking about multiple ASP.Net frontends, there's probably no need to spin off the static files yet unless we're talking multiple gigabytes of files.
If you're serving files over the Internet, you might also consider [Amazon's S3 service][1]. I've found the rates and reliability to be better than anything I could do (or find) on my own. [1]: http://www.amazon.com/gp/browse.html?node=16427261
In C++ I use this [example code][1] to do natural sorting. The code requires the boost library. [1]: http://www.boostcookbook.com/Recipe:/1235053
I have tried both methods with a large commercial C++ application. **The better method: The trunk should be always stable.** Here are some guidelines and benefits of this method: - Code each task (or related set of tasks) in its own branch, then you will have the flexibility of when you would like to merge these tasks and perform a release. - QA should be done on each branch before it is merged to the trunk. - By doing QA on each individual branch, you will know exactly what caused the bug easier. - This solution scales to any number of developers. - This method works since branching is an almost instant operation in SVN. - Tag each release that you perform. - You can develop features that you don't plan to release for a while and decide exactly when to merge them. - For all work you do, you can have the benefit of committing your code. If you work out of the trunk only, you will probably keep your code uncommitted a lot, and hence unprotected and without automatic history. If you try to do the opposite and do all your development in the trunk you'll be plagged by: - Constant build problems for daily builds - Productivity loss when a a developer commits a problem for all other people on the project - Longer release cycles, because you need to finally get a stable version - Less stable releases You simply will not have the flexibility that you need if you try to keep a branch stable and the trunk as the development sandbox. The reason is that you can't pick and chose from the trunk what you want to put in that stable release. It would already be all mixed in together in the trunk.
For 3.5, you must install this tool: - [http://www.microsoft.com/downloads/details.aspx?FamilyID=4377f86d-c913-4b5c-b87e-ef72e5b4e065&displaylang=en][1] And for 3.0 you must use the 2.0 config tool. [Source of Answer][2]. [1]: http://www.microsoft.com/downloads/details.aspx?FamilyID=4377f86d-c913-4b5c-b87e-ef72e5b4e065&displaylang=en [2]: http://forums.msdn.microsoft.com/en-US/netfxsetup/thread/9aa72b12-3b63-493b-a7d2-596775bd66ea/
yes. If you mark a method as Sealed then it can not be overriden in a derived class.
Normally DestroyHandle is called in Dispose method. So you need to make sure that all controls are disposed to avoid handles leaks.
Normally DestroyHandle is being called in Dispose method. So you need to make sure that all controls are disposed to avoid resource leaks.
Yes, you can use the sealed keyword in the B class's implementation of Render: class B : A { public sealed override void Render() { // Prepare the object for rendering SpecialRender(); // Do some cleanup } protected virtual void SpecialRender() { } }
How sophisticated should be my Ajax code?
|ajax|
I have seen simple example Ajax source codes in many online tutorials. What I want to know is whether using the source code in the examples are perfectly alright or not? Is there anything more to be added to the code that goes into a real world application? What all steps are to be taken to make the application more robust and secure? Here is a sample source code I got from the web: function getChats() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { return; } var url="getchat.php?latest="+latest; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function GetXmlHttpObject() { var xmlHttp=null; try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; }
I have seen simple example Ajax source codes in many online tutorials. What I want to know is whether using the source code in the examples are perfectly alright or not? Is there anything more to be added to the code that goes into a real world application? What all steps are to be taken to make the application more robust and secure? Here is a sample source code I got from the web: function getChats() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { return; } var url="getchat.php?latest="+latest; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function GetXmlHttpObject() { var xmlHttp=null; try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; }
Danny is mostly right. a. unsigned decimal, minimum 4 characters, space padded<br> b. floating point, minimum 16 digits before the decimal (0 padded), 1 digit after the decimal<br> c. hex, minimum 4 characters, 0 padded, letters are printed in upper case<br> d. same as above, but minimum 2 characters<br> e. e is assumed to be an int, converted to an unsigned char and printed<br> f. same as e<br> g. This is likely a typo, the 4 has no effect. If it were "%.4s", then a maximum of 4 characters from the string would be printed. It is interesting to note that in this case, the string does not need to be null terminated.
Danny is mostly right. a. unsigned decimal, minimum 4 characters, space padded<br> b. floating point, minimum 16 digits before the decimal (0 padded), 1 digit after the decimal<br> c. hex, minimum 4 characters, 0 padded, letters are printed in upper case<br> d. same as above, but minimum 2 characters<br> e. e is assumed to be an int, converted to an unsigned char and printed<br> f. same as e<br> g. This is likely a typo, the 4 has no effect. If it were "%.4s", then a maximum of 4 characters from the string would be printed. It is interesting to note that in this case, the string does not need to be null terminated. <i>Edit: [jj33][1] points out 2 errors in b and g above [here][2]. [1]: http://stackoverflow.com/users/430/jj33 [2]: http://stackoverflow.com/questions/7981/decoding-printf-statements-in-c-printf-primer#8051
If, while writing your code, you expect this object to be in the collection, and then during runtime you find that it isn't, I would call that an exceptional case, and it is proper to use an exception. However, if you're simply testing for the existence of an object, and you find that it is not there, this is not exceptional. Using an exception in this case is not proper. The analysis of the runtime performance depends on the actual collection being used, and the method if searching for it. That shouldn't matter though. Don't let the illusion of optimization fool you into writing confusing code.
The latter is an acceptable solution. Although I would definitely catch on the specific exception (ElementNotFound?) that the collection throws in that case. Speedwise, it depends on the common case. If you're more likely to find the element than not, the exception solution will be faster. If you're more likely to fail, then it would depend on size of the collection and its iteration speed. Either way, you'd want to measure against normal use to see if this is actually a bottle neck before worrying about speed like this. Go for clarity first, and the latter solution is far more clear than the former.
> I just confrim, Replicating between > SqlServer 2005 and Compact Edition is > something that can be done? Yes it can definately be done using either Merge Replication or Sync Services
I would have to think about it more as to how much I like it... my gut instinct is, eh, not so much... EDIT: Ryan Fox's comments on the exceptional case is perfect, I concur As for performance, it depends on the indexer on the collection. C# lets you override the indexer operator, so if it is doing a for loop like the contains method you would write, then it will be just as slow (with maybe a few nanoseconds slower due to the try/catch... but nothing to worry about unless that code itself is within a huge loop). If the indexer is O(1) (or even O(log(n))... or anything faster than O(n)), then the try/catch solution would be faster of course. Also, I am assuming the indexer is throwing the exception, if it is returning null, you could of course just check for null and not use the try/catch.
What are some web-based knowledge-base solutions?
|language-agnostic|planning|