instruction
stringlengths
0
30k
In C, you actually have two different choices. One, you can let the system manage the memory for you. Alternatively, you can do that by yourself. Generally, you would want to stick to the former as long as possible. However, auto-managed memory in C is extremely limited and you will need to manually manage the memory in many cases, such as: a. You want the variable to outlive the functions, and you don't want to have global variable. ex: <pre> struct pair{ int val; struct pair *next; } struct pair* new_pair(int val){ struct pair* np = malloc(sizeof(struct pair)); np->val = val; np->next = NULL; return np; } </pre> b. you want to have dynamically allocated memory. Most common example is array without fixed length: <pre> int *my_special_array; my_special_array = malloc(sizeof(int) * number_of_element); for(i=0; i< number_of_element; i++) my_special_array[i] = my_speical_value; /*using my_special_array*/ free(my_special_array); </pre> c. You want to do something REALLY dirty. For example, I would want a struct to represent many kind of data and I don't like union (union looks soooo messy): <pre> struct data{ int data_type; long data_in_mem; }; struct animal{/*something*/}; struct person{/*some other thing*/}; struct animal* read_animal(); struct person* read_person(); /*In main*/ struct data sample; sampe.data_type = input_type; switch(input_type){ case DATA_PERSON: sample.data_in_mem = read_person(); break; case DATA_ANIMAL: sample.data_in_mem = read_animal(); default: printf("Oh hoh! I warn you, that again and I will seg fault your OS"); } </pre> See, a long value is enough to hold ANYTHING. Just remember to free it, or you WILL regret. This is among my favorite tricks to have fun in C :D. However, generally, you would want to stay away from your favorite tricks (T___T). You WILL break your OS, sooner or later, if you use them too often. As long as you don't use *alloc and free, it is safe to say that you are still virgin, and that the code still looks nice.
I've learned from experience that having only one app per Tomcat instance has a very significant advantage: when a Tomcat instance dies, *you don't have to dig through logs (or guess) which app is to blame*.
NetBeans has a built-in profiler.
A tool is a big help. However, there are times when you can't use a tool: the heap dump is so huge it crashes the tool, you are trying to troubleshoot a machine in some production environment to which you only have shell access, etc. In that case, it helps to know your way around the hprof dump file. Look for SITES BEGIN. This shows you what objects are using the most memory. But the objects aren't lumped together solely by type: each entry also includes a "trace" ID. You can then search for that "TRACE nnnn" to see the top few frames of the stack where the object was allocated. Often, once I see where the object is allocated, I find a bug and I'm done. Also, note that you can control how many frames are recorded in the stack with the options to -Xrunhprof. If you check out the allocation site, and don't see anything wrong, you have to start backward chaining from some of those live objects to root objects, to find the unexpected reference chain. This is where a tool really helps, but you can do the same thing by hand (well, with grep). There is not just one root object (i.e., object not subject to garbage collection). Threads, classes, and stack frames act as root objects, and anything they reference strongly is not collectible. To do the chaining, look in the HEAP DUMP section for entries with the bad trace id. This will take you to an OBJ or ARR entry, which shows a unique object identifier in hexadecimal. Search for all occurrences of that id to find who's got a strong reference to the object. Follow each of those paths backward as they branch until you figure out where the leak is. See why a tool is so handy? Static members are a repeat offender for memory leaks. In fact, even without a tool, it'd be worth spending a few minutes looking through your code for static Map members. Can a map grow large? Does anything ever clean up its entries?
if ((testItem & FlagTest.Flag1) == FlagTest.Flag1) { // Do something }
if((testItem & FlagTest.Flag1) == FlagTest.Flag1) { ... }
Try this: <pre><code> if ((testItem & FlagTest.Flag1) == FlagTest.Flag1) { // do something } </code></pre>Basically, your code is asking if having both flags set is the same as having one flag set, which is obviously false. The code above will leave only the Flag1 bit set if it is set at all, then compares this result to Flag1.
There's a specific problem with mixing doPostback, UpdatePanel and SharePoint -- and the symptom is exactly what you're seeing: a full-page postback instead of an asynchronous postback. See this KB article for a workaround: http://support.microsoft.com/kb/941955
[List of Web Safe Fonts][1]. [1]: http://www.fonttester.com/help/list_of_web_safe_fonts.html
Good [article on Mutex's and Semaphores][1] - what makes them different, and why they might or might not be used given various conditions. -Adam [1]: http://www.netrino.com/Embedded-Systems/How-To/RTOS-Mutex-Semaphore
By just going over the features good source control brings: - ability to easily see logs of who did what, when, and in what order, to which files - keep a history of past versions of everything - easily go back and reproduce a specific version of your files from any past version, to more easily reproduce bugs reported in older versions - ability go retrieve deleted code, or remove unwanted changes, without having to worry about losing data in the process
The internet is littered with well written articles on the flaws of VSS. I would collect this as a body of evidence for moving away from VSS. Find a key requirement that VSS can't support (remote working, support on other OSs, tools integration) and use it to drive your issue. You then need to find a source control system that is a good match for your organisation's requirements - are you sure Subversion is that system? Set up a demonstration of your chosen system, and use this to prove its worth. I implemented this change at a previous employer (first to CVS, and then to SVN), and while it was successful we had to build a lot of bits around the edge and rely on a lot of (sometimes unreliable) open source projects to get all the tools we needed. With hindsight I should have considered trying to evaluate professional tools such as Perforce, Vault or even Team System. Having evaluated these, I could have made a proper value judgement on whether CVS/SVN were worth their "free" price tag.
being able to handle branching and forking is a start. Try using subversion for a while in parallel to vss you will most likely find many arguments to convince your boss. If you don't, your boss is right, no reason to switch.
Get them to google for 'vss problem', 'source safe corruption' or simply look at the Wiki page for it. That ought to convince them that it's probably not a long-term viable thing for you to be betting such a vital part of your business on. How big is your team? (ie, I mean how many members, not whether or not you're salad dodgers) Once you start to get more than half a dozen quite active users, VSS is going to give you headaches. I seriously doubt that Microsoft use it (in fact, don't they use a customised Subversion or CVS variant?) and you've got to ask yourself - if the company don't eat their own dogfood, why would you eat it?
Even if it ain't broke, there's a potential benefit to migrating from VSS. First and most trivially, you won't have to buy new VSS licenses. Second, there are many examples of deficiencies in the VSS product (some also acknowledged by MS). The learning curve for SVN is at least as low as for VSS, and if you have devs happier with their source control system, they're more likely to use it early and often. That will translate to lots less risk for your company, and that's a good benefit.
You'll probably need to create a piece of code that updates AssemblyInfo.cs according to the version number stored in the .csproj file. (The ClickOnce deploy version is stored inside an XML tag.) You'd then change your .csproj file to run this bit of code when Publish|Release build is performed. The MSBuild folks have blogged about how to perform custom actions during certain build types; check the [MSBuild team blog][1]. [1]: http://blogs.msdn.com/msbuild/
> Also, I actually fixed the std::string problem. How? By replacing it with a vector, compiling, then replacing the string again. It was consistently crashing there, and that fixed even though it...couldn't. There's something nasty there, and I'm not sure what. That sounds like you really did shake a chicken at it. If you don't know *why* it's working now, then it's still broken, and pretty much guaranteed to bite you again later (after you've added even more complexity).
Puzzle: Find largest rectangle
|algorithm|geometry|math|
What's the most efficient algorithm to find the rectangle with the largest area which will fit in the empty space? Let's say the screen looks like this ('#' represents filled area): .................... ..............###### ##.................. .................### .................### #####............... #####............... #####............... A probable solution is: .................... ..............###### ##...++++++++++++... .....++++++++++++### .....++++++++++++### #####++++++++++++... #####++++++++++++... #####++++++++++++... Normally I'd enjoy figuring out a solution. Although this time I'd like to avoid wasting time fumbling around on my own since this has a practical use for a project I'm working on. Is there a well-known solution?
|algorithm|geometry|math|language-agnostic|
Puzzle: Find largest rectangle (maximal rectangle problem)
|language-agnostic|algorithm|math|geometry|
What's the most efficient algorithm to find the rectangle with the largest area which will fit in the empty space? Let's say the screen looks like this ('#' represents filled area): .................... ..............###### ##.................. .................### .................### #####............... #####............... #####............... A probable solution is: .................... ..............###### ##...++++++++++++... .....++++++++++++### .....++++++++++++### #####++++++++++++... #####++++++++++++... #####++++++++++++... Normally I'd enjoy figuring out a solution. Although this time I'd like to avoid wasting time fumbling around on my own since this has a practical use for a project I'm working on. Is there a well-known solution? **Shog9** wrote: > Is your input an array (as implied by the other responses), or a list of occlusions in the form of arbitrarily sized, positioned rectangles (as might be the case in a windowing system when dealing with window positions)? Yes, I have a structure which keeps track of a set of windows placed on the screen. I also have a grid which keeps track of all the areas between each edge, whether they are empty or filled, and the pixel position of their left or top edge. I think there is some modified form which would take advantage of this property. Do you know of any?
It's probably the [awesome firefox3 fsync "bug"](http://shaver.off.net/diary/2008/05/25/fsyncers-and-curveballs/), which is a giant pile of fail. In summary * Firefox3 saves its bookmarks and history in an SQLite database * Every time you load a page it writes to this database several times * SQLite cares deeply that you don't lose your bookmarks, so each time it writes, instructs the kernel to flush it's database file to disk and ensure that it's fully written * Many variants of linux, when told to flush like that, flush EVERY FILE. This may take up to a minute or more if you have background tasks doing any kind of disk intensive stuff. * The kernel makes firefox wait while this flush happens, which locks up the UI.
You might or might not already know this (R# does suffer from a lack of discoverability, unless you get the one-page key-shortcut page printed out), but ALT-INS opens a box which can at least mass-generate properties for fields. Not sure if that's any use - it's not the same as a retrospective encapsulation.
C++ 0x is introducing initialization lists which will allow you to do: std::vector<std::string> v = {"Hello", "World"}; Probably doesn't help you now. Although GCC 4.4 apparently [supports this already][1]. [1]: http://gcc.gnu.org/projects/cxx0x.html
I'm not certain I fully understand the problem, but just to hack & slash at it you could try: SELECT TOP 1 FROM cteLevelOne ORDER BY CustID DESC That assumes that the CustID is also in order as in the example, and not something like a GUID.
rsync will only upload the differences. I haven't personally used it, but [Mark Pilgrim][1] wrote a long time ago about how it even [handles binary diffs brilliantly][2]. svn+rsync sounds like a fantastic solution. I'll have to try that in the future. [1]: http://diveintomark.org [2]: http://diveintomark.org/archives/2004/05/01/essentials
nmake, visualstudio, and .mak files
|visual-studio|nmake|.mak|
I was given a C++ project that was compiled using MS Visual Studio .net 2003 C++ compiler, and a .mak file that was used to compile it. I am able to build it from the command line using nmake project.mak, but the compiler complains that afxres.h was not found. I did a little searching around and the afxres.h is in the Visual Studio directory in an includes file. Where am I supposed to specify to nmake where to look for this header file?
Depending on your situation, you *might* have another option: in-license third-party code. I've consulted at a couple of companies where that would be the sensible choice, although seemingly "throwing away IP" can be a big barrier for management. At my current company, we seriously considered the viable option of using third-party code to replace our core framework, but that idea was ultimately rejected more for business reasons than technical reasons. To directly answer your question, we finally chose to rewrite the legacy framework - a decision we didn't take lightly! 14 months on, we don't regret this choice at all. Just considering the time spent fixing bugs, our new framework has nearly paid for itself. On the negative side, it is not quite feature-complete yet so we are in the unenviable position of maintaining two separate frameworks in parallel until we can port the last of our "front-end" applications.
There should be an icon in your Start menu under Programs that opens a cmd.exe instance with all the correct MSVS environment variables set up for command line building.
When you create the project you can specify whatever directory you want, you are not limited to the default.
To monitor the servers we use the free [tools from Maatkit][1] ... simple, yet efficient. The binary replication is available in 5.1, so I guess you've got some balls. We still use 5.0 and it works OK, but of course we had our share of issues with it. We use a Master-Master replication with a MySql Proxy as a load-balancer in front, and to prevent it from having errors: - we removed all unique indexes - for the few cases where we really needed unique constraints we made sure we used REPLACE instead of INSERT (MySql Proxy can be used to guard for proper usage ... it can even rewrite your queries) - scheduled scripts doing intensive reports are always accessing the same server (not the load-balancer) ... so that dangerous operations are replicated safely Yeah, I know it sounds simple and stupid, but it solved 95% of all the problems we had. [1]: http://www.maatkit.org/tools.html
I came into contact with Octal through [PDP-11](http://www.retrologic.com/jargon/P/PDP-11.html), and so, apparently, did the C language :)
If you're writing a program that will be used by many people, it's best to have some kind of mechanism to choose what will be logged and what won't. One argument in favor of .logthis() functions is that they can be an excellent replacement for inline comments in some instances (if done properly). Plus, it helps you narrow down EXACTLY where an error is occurring.
@Roddy - I've already read the links you point to, they are both referenced from Paul Tyma's presentation "Thousands of Threads and Blocking I/O - The old way to write Java Servers is New again". Some of the things that don't necessarily jump out from Paul's presentation, however, are that he specified -Xss:48k to the JVM on startup, and that he's assuming that the JVM's NIO implementation is efficient in order for it to be a valid comparison. Indy does **not** specify a similarly shrunken and tightly constrained stack size. There are no calls to BeginThread (the Delphi RTL thread creation routine, which you should use for such situations) or CreateThread (the raw WinAPI call) in the Indy codebase. The default stack size is stored in the PE, and for the Delphi compiler it defaults to 1MB of reserved address space (space is committed page by page by the OS in 4K chunks; in fact, the compiler needs to generate code to touch pages if there are >4K of locals in a function, because the extension is controlled by page faults, but only for the lowest (guard) page in the stack). That means you're going to run out of address space after max 2,000 concurrent threads handling connections. Now, you can change the default stack size in the PE using the {$M minStackSize [,maxStackSize]} directive, but that will affect **all** threads, including the main thread. I hope you don't do much recursion, because 48K or (similar) isn't a lot of space. Now, whether Paul is right about non-performance of async I/O for Windows in particular, I'm not 100% sure - I'd have to measure it to be certain. What I do know, however, is that arguments about threaded programming being easier than async event-based programming, are presenting a **false dichotomy**. Async code doesn't **need** to be event-based; it can be continuation-based, like it is in .NET, and if you specify a closure as your continuation, you get state maintained for you for free. Moreover, conversion from linear thread-style code to continuation-passing-style async code can be made mechanical by a compiler (CPS transform is mechanical), so there need be no cost in code clarity either.
Basic answer is that you have to make the case that switching meets the needs of the business. For example: 1. lower cost of development 2. shorter schedule (another shade of #1) 3. more apt for meeting process requirements (like software requirements traceability, or build reproducibility, etc). Making the case on these things also requires something quantitative, not just "we will lower costs because this is the *right* way to do it!". One thing to watch out for is that it's too easy for a developer to convince themselves that it would be beneficial to make the change without first going through the basic business filters. Once that happens, you end up with developers who are unhappy with their tools and are doubly frustrated because they think management won't listen. If you can't check off one of the things above, them you'll have no chance of persuading management of anything (unless management is incompetent, but that's for another question).
1. I use Parallels. I used Vista for 4 months then switched to XP. I prefer XP as it is faster. 2. Key bindings are quirky. Using function keys while debugging in the hosted XP will trigger events in OS X, effectively popping you out. 3. I have 3 "spaces" set up. One for OS X, one for XP VM, and the last for a RDC to my desktop. THIS IS BRILLIANTLY USEFUL. I can't live without spaces now. This technique actually killed my desire for a second monitor. peace|dewde http://dewde.com
1. I use Parallels. I used Vista for 4 months then switched to XP. I prefer XP as it is faster. 2. Key bindings are quirky. Using function keys while debugging in the hosted XP will trigger events in OS X, effectively popping you out. 3. I have 3 "spaces" set up. One for OS X, one for XP VM, and the last for a RDC to my desktop. THIS IS BRILLIANTLY USEFUL. I can't live without spaces now. This technique actually killed my desire for a second monitor. 4. Like Jason said, any files stored on the OS X partition will be seen as a network resource to the XP/Vista VM. So trying to run EXEs or storing web roots there cause trust issues. Studio doesn't like project web roots to be on network shares. peace|dewde http://dewde.com
I'm all for using static **functions**. These just make sense especially when organized into modules (`static class` in C#). However, *the moment* those functions need some kind of external (non compile-time const) data, then that function should be made an instance method and encapsulated along with its data. So in a nutshell: static functions ok, static data bad.
I'm all for using static **functions**. These just make sense especially when organized into modules (`static class` in C#). However, *the moment* those functions need some kind of external (non compile-time const) data, then that function should be made an instance method and encapsulated along with its data into a class. In a nutshell: static functions ok, static data bad.
Is there an "exists" function for jQuery
|jquery|exists|
So I know that you can do: if ($(selector).length>0) { // Do something } But is there a more elegant method?
|jquery|
|javascript|jquery|
Check following variables: - The environment variable TMPDIR - The value of the P_tmpdir macro If all fails try to use the directory `/tmp'. You can also use tempnam function to generate a unique temporary file name.
What control is this?
|.net|.net-2.0|windowscontrols|
The "Open" button on the open file dialog used in certain windows applications includes a dropdown arrow with a list of additional options -- namely "Open with..". I haven't seen this in every windows application, so you may have to try a few to get it, but SQL Server Management Studio and Visual Studio 2005 will both show the button that way if you go to the menu and choose _File->Open->File..._ I want to use a button like this with a built-in list in one of my applications, but I can't find the control they're using anywhere in visual studio. Any thoughts?
I set up an extension method to do it: [related question](http://stackoverflow.com/questions/7244/anyone-know-a-good-workaround-for-the-lack-of-an-enum-generic-constraint). Basically: public static bool IsSet( this Enum input, Enum matchTo ) { return ( Convert.ToUInt32( input ) & Convert.ToUInt32( matchTo ) ) != 0; } Then you can do: FlagTests testItem = FlagTests.Flag1 | FlagTests.Flag2; if( testItem.IsSet ( FlagTests.Flag1 ) ) //Flag1 is set ---------- Incidentally the convention I use for enums is singular for standard, plural for flags. That way you know from the enum name whether it can hold multiple values.
Yes, that'd be best, except you'd omit the `$`s on the parameter names.
Yes, that'd be best<s>, except you'd omit the `$`s on the parameter names</s>, as others have pointed out. For those interested in the rationale behind the lack of default parameter values, see @[Giovanni Galbo](#40121)'s explanation.
How to Compare Flags in C#?
|c#|.net|flags|attributes|
I have a flag enum below. [Flags] public enum FlagTest { None = 0x0, Flag1 = 0x1, Flag2 = 0x2, Flag3 = 0x4 } I cannot make the if statement evaluate to true. FlagTest testItem = FlagTest.Flag1 | FlagTest.Flag2; if (testItem == FlagTest.Flag1) { // Do something, // however This is never true. } How can I make this true?
|c#|.net|attributes|enums|flags|
GUIDs as Primary Keys - Offline OLTP
|sql-server|guid|oltp|offline|
We are working on designing an application that is typically OLTP (think: purchasing system). However, this one in particular has the need that some users will be offline, so they need to be able to download the DB to their machine, work on it, and then sync back once they're on the LAN. I would like to note that I know this has been done before, I just don't have experience with this particular model. One idea I thought about was using GUIDs as table keys. So for example, a Purchase Order would not have a number (auto-numeric) but a GUID instead, so that every offline client can generate those, and I don't have clashes when I connect back to the DB. Is this a bad idea for some reason? Will access to these tables through the GUID key be slow? Have you had experience with these type of systems? How have you solved this problem? Thanks! Daniel
|sql-server|synchronization|guid|offline|oltp|
What is the best way to migrate an existing messy webapp to elegant MVC?
|java|model-view-controller|architecture|
|java|model-view-controller|architecture|jsp|
I joined a new company about a month ago. The company is rather small in size and has pretty strong "start-up" feel to it. I'm working as a Java developer on a team of 3 others. The company primarily sells a service to for businesses/business-type people to use in communicating with each other. One of the main things I have been, and will be working on, is the main website for the company - from which the service is sold, existing users login to check their service and pay their bills, new users can sign up for a trial, etc. Currently this is a JSP application deployed on Tomcat, with access to a database done thru a persistence layer written by the company itself. A repeated and growing frustration I am having here (and I'm pretty happy with the job overall, so this isn't an "oh no I don't like my job"-type post) is the lack of any larger design or architecture for this web application. The app is made up of several dozen JSP pages, with almost no logic existing in Servlets or Beans or any other sort of framework. Many of the JSP pages are thousands of lines of code, they `jsp:include` other JSP pages, business logic is mixed in with the HTML, frequently used snippets of code (such as obtaining a web service connection) is cut and paste rather than reused, etc. In other words, the application is a mess. There have been some rumblings within the company of trying to re-architect this site so that it fits MVC better; I think that the developers and higher-ups are beginning to realize that this current pattern of spaghetti code isn't sustainable or very easily scalable to add more features for the users. The higher-ups and developers are wary of completely re-writing the thing (with good reason, since this would mean several weeks or months of work re-writing existing functionality), but we've had some discussions of (slowly) re-writing certain areas of the site into a new framework. What are some of the best strategies to enable moving the application and codebase into this direction? How can I as a developer really help move this along, and quickly, without seeming like the jerk-y new guy who comes into a job and tells everyone that what they've written is crap? Are there any proven strategies or experiences that you've used in your own job experience when you've encountered this sort of thing?
Some places to start: If you're on windows, and using visual C++6 (I hope to god nobody still uses it these days) it's implentation of std::string is not threadsafe, and can lead to this kind of thing. [Here's an article I found which explains a lot of the common causes of memory leaks and corruption.](http://www.yolinux.com/TUTORIALS/C++MemoryCorruptionAndMemoryLeaks.html) At my previous workplace we used Compuware Boundschecker to help with this. It's commercial and very expensive, so may not be an option. Here's a couple of free libraries which may be of some use <http://www.codeguru.com/cpp/misc/misc/memory/article.php/c3745/> <http://www.codeproject.com/KB/cpp/MemLeakDetect.aspx> Hope that helps. Memory corruption is a sucky place to be in!
> [Adam Haile][1] writes: >> check out the System.Web.Mail namespace By which you mean System.Net.Mail in .Net 2.0 and above :) [1]: http://stackoverflow.com/questions/6210/e-mail-notifications#6212
Some kind of task manager for JavaScript in Firefox 3?
|firefox|javascript|memory|cpu|
Recently I have been having issues with Firefox 3 on Ubuntu Hardy Heron. I will click on a link and it will hang for a while. I don't know if its a bug in Firefox 3 or whatever, but I would like to try and debug it a bit. So, my question is, is there a way to have some kind of process explorer, or task manager sort of thing for Firefox 3? I would like to be able to see what tabs are using what percent of my processor via the JavaScript on that page (or anything in the page that is causing CPU/memory usage). Does anybody know of a plugin that does this, or something similar? Has anyone else done this kind of inspection another way? I know about FireBug, but I can't imagine how I would use it to finger which tab is using a lot of resources. Any suggestions or insights?
Recently I have been having issues with Firefox 3 on Ubuntu Hardy Heron. I will click on a link and it will hang for a while. I don't know if its a bug in Firefox 3 or a page running too much client side JavaScript, but I would like to try and debug it a bit. So, my question is, is there a way to have some kind of process explorer, or task manager sort of thing for Firefox 3? I would like to be able to see what tabs are using what percent of my processor via the JavaScript on that page (or anything in the page that is causing CPU/memory usage). Does anybody know of a plugin that does this, or something similar? Has anyone else done this kind of inspection another way? I know about FireBug, but I can't imagine how I would use it to finger which tab is using a lot of resources. Any suggestions or insights?
|javascript|firefox|memory|cpu|
Recently I have been having issues with Firefox 3 on Ubuntu Hardy Heron. I will click on a link and it will hang for a while. I don't know if its a bug in Firefox 3 or a page running too much client side JavaScript, but I would like to try and debug it a bit. So, my question is, is there a way to have some kind of process explorer, or task manager sort of thing for Firefox 3? I would like to be able to see what tabs are using what percent of my processor via the JavaScript on that page (or anything in the page that is causing CPU/memory usage). Does anybody know of a plugin that does this, or something similar? Has anyone else done this kind of inspection another way? I know about FireBug, but I can't imagine how I would use it to finger which tab is using a lot of resources. Any suggestions or insights? UPDATE: Thanks Orion for the info! It doesn't really answer the question of having such a process explorer, but I think it answers my problem, so I'll mark yours as the answer! I'm still interested in some kind of mechanism to see what my various tabs are doing with respect to memory and javascript time, so any such comments are still welcome!
Adding more information to TestResult.xml file from NUnit
|unit-testing|nunit|
I would like to be able to add a "message" to a unit test, such that it actually appears within the TestResult.xml file generated by NUnit. For example, this is currently generated: <results> <test-case name="MyNamespace.Tests.MyTest" executed="True" success="True" time="0.203" asserts="4" /> </results> I would like to be able to have an additional attribute (or node as the case may be), such as: <results> <test-case name="MyNamespace.Tests.MyTest" executed="True" success="True" time="0.203" asserts="4" message="Tested that some condition was met." /> </results> The idea is that "message" above would somehow be defined within the test method itself (in my case, generated at run-time). Is there a property somewhere that I'm missing to be able to do something like this?
I agree with Andrew Peters, DRY. It should also be pointed out that you can specify your controller, action, and params to the .Form() helper and if they fit into your routing rules then no query string parameters will be used. I also understand what Will was saying about the V in MVC. In my opinion I do not think it is a problem to put code in the view **as long as it is for the view**. It is really easy to cross the line between controller and view if you are not careful. Personally I can not stand to use C# as a template engine without my eyes bleeding or getting the urge to murder someone. This helps me keep my logic separated, controller logic in C#, view logic in brail.
I use a Mac Book Pro as well but I run Vista. I set aside a little space so I could also run Leopard and just use Boot Camp. You can use Boot Camp to just boot from windows so you never have to deal with Leopard unless you want to. I would highly reccomend it because Apple makes great hardware while Microsoft makes great tools (and also great OSs, I love Vista) go ahead and downmod me for being a fangirl, but I've found what works for me.
How to ensure that the same thread is used to execute code in IIS?
|vb.net|iis|dll|multithreading|
We have a third party dll that is used in our web service hosted in IIS6. The problem is that once this dll is loaded into memory, the exception <a href="http://msdn.microsoft.com/en-us/library/system.accessviolationexception.aspx">AccessViolationException</a> gets thrown if a thread different then the one that created it tries to execute any code within the dll. The worker process is multi threaded and each call to the web service will get a random thread from the pool. We tried to unload it from memory and reload it each time we needed it, but I guess only the front end is .Net and the rest is unmanaged so it never actually gets completely unloaded from memory. We are using VB and .Net 2.0. Any suggestions?
|vb.net|iis|dll|multithreading|
We have a third party dll that is used in our web service hosted in IIS6. The problem is that once this dll is loaded into memory, the exception <a href="http://msdn.microsoft.com/en-us/library/system.accessviolationexception.aspx">AccessViolationException</a> gets thrown if a thread different then the one that created it tries to execute any code within the dll. The worker process is multi threaded and each call to the web service will get a random thread from the pool. We tried to unload it from memory and reload it each time we needed it, but I guess only the front end is .Net and the rest is unmanaged so it never actually gets completely unloaded from memory. We are using VB and .Net 2.0. Any suggestions? (Response to Rob Walker) We thought about creating a new thread and using it to call the dll, but how do we make the thread sit and wait for calls? How do you delegate the call to the thread without having the Dispatcher class supplied by .Net 3.0? Creating a hidden form and putting it in a message loop might work. And then we could call the Invoke() method of the form. But I can see many problems occurring if we create a form inside an IIS hosted web service.
I would have said that something must have updated either the LIBEAY32.dll or another dll that depends on it. You may find some helpful information using the [depends tool][1]. If you use this to open up the perl.exe then it should highlight the dependency path that produces the problem. You can compare this with other machines on which perl runs. The ordinal is effectively a function that is expected by perl or a dll, but is not present in the verision of LIBEAY32.dll that you have. The depends tool makes this quite clear. [1]: http://www.dependencywalker.com/
XML Serialization and Inherited Types
|serialization|xml|c#|inheritance|
following on from my [previous question](http://stackoverflow.com/questions/19454/enforce-attribute-decoration-of-classesmethods) I have been working on getting my object model to serialize to XML. But I have now run into a problem (quelle surprise!). The problem I have is that I have a collection, which is of a abstract base class type, which is populated by the concrete derived types. I thought it would be fine to just add the XML attributes to all of the classes involved and everything would be peachy. Sadly, thats not the case! So I have done some digging on Google and I now understand _why_ it's not working.. In that **the _XmlSerializer_ is in fact doing some clever reflection in order to serialize objects to/from XML, and since its based on the abstract type, it cannot figure out what the hell it's talking to**. Fine. I did come across [this page](http://www.codeproject.com/KB/XML/xmlserializerforunknown.aspx) on CodeProject, which looks like it may well help a lot (yet to read/consume fully), but I thought I would like to bring this problem to the StackOverflow table too, to see if you have any neat hacks/tricks in order to get this up and running in the quickest/lightest way possible :) There seems to be a lot of "Animal/Mammal", "Car/Bike/Truck" examples but not a lot of fresh ideas! Thanks a lot people :)
|c#|xml|serialization|inheritance|
following on from my [previous question](http://stackoverflow.com/questions/19454/enforce-attribute-decoration-of-classesmethods) I have been working on getting my object model to serialize to XML. But I have now run into a problem (quelle surprise!). The problem I have is that I have a collection, which is of a abstract base class type, which is populated by the concrete derived types. I thought it would be fine to just add the XML attributes to all of the classes involved and everything would be peachy. Sadly, thats not the case! So I have done some digging on Google and I now understand _why_ it's not working.. In that **the _XmlSerializer_ is in fact doing some clever reflection in order to serialize objects to/from XML, and since its based on the abstract type, it cannot figure out what the hell it's talking to**. Fine. I did come across [this page](http://www.codeproject.com/KB/XML/xmlserializerforunknown.aspx) on CodeProject, which looks like it may well help a lot (yet to read/consume fully), but I thought I would like to bring this problem to the StackOverflow table too, to see if you have any neat hacks/tricks in order to get this up and running in the quickest/lightest way possible :) There seems to be a lot of "Animal/Mammal", "Car/Bike/Truck" examples but not a lot of fresh ideas! Thanks a lot people :) ##EDIT: One thing I should also add is that I **DO NOT** want to go down the _XmlInclude_ route.. There is simply too much coupling with it, and this area of the system is under heavy development, so the it would be a real maintenence headache!
You might wanna check out [Domain Driven Design][1], by Eric Evans. DDD has this notion of a Specification: > ... explicit predicate-like VALUE > OBJECTS for specialized purposes. A > SPECIFICATION is a predicate that > determines if an object does or does > not satisfy some criteria. I think failing fast is one thing, the other is where to keep the logic for validation. The domain is the right place to keep the logic and I think a Specification Object or a validate method on your Domain objects would be a good place. [1]: http://books.google.com/books?id=7dlaMs0SECsC
<a href = "http://trolltech.com/products/qt/">Qt Cross-Platform Application Framework</a> Qt is a cross-platform application framework for desktop and embedded development. It includes an intuitive API and a rich C++ class library, integrated tools for GUI development and internationalization, and support for Java™ and C++ development They have a plug-in for Visual Studio that costs a bit of money, but it is worth every penny.
You are right. Validation should not be done during getters/setters. Accessors and mutators have a very specific job -- validation should be handled in a seperate module (a validator) or at least seperate method calls.
Validation should not be done during getters/setters, but not because of performance, but rather because you want **separation of concerns**. Getters and setters have a very specific job -- validation should be handled in a seperate module (a validator) or at least seperate method calls. In the case of the setter, you should typically have a separate call which validates the input before calling the setter. The setter itself just sets whatever is given to it. If you adhere to the above practice with setters, then you may not need to validate when calling a getter -- information stored in the object will have been validated when the setter was called, and the getter can be trusted.
Validation should be captured separately from getters or setters in a validation method. That way if the validation needs to be reused across multiple components, it is available. When the setter is called, such a validation service should be utilized to sanitize input into the object. That way you know all information stored in an object is valid at all times. You don't need any kind of validation for the getter, because information on the object is already trusted to be valid. Don't save your validation until a database update!! It is better to **fail fast**.
Not free, but [ReSharper][1] is definitely one recommendation. [1]: http://www.jetbrains.com/resharper/index.html
Xen - Can't get a Console to VMs
|ubuntu|virtualization|xen|