instruction stringlengths 0 30k ⌀ |
|---|
|c#|object|initialization|dataset| |
Is there a difference (performance, overhead) between these two ways of initializing an object:
MyTypedDataSet aDataSet = new MyTypedDataSet();
ds.Merge(anotherDataSet);
and
MyTypedDataSet ds = anotherDataSet;
Which do you recommend?
|
Is there a difference (performance, overhead) between these two ways of initializing an object:
MyTypedDataSet aDataSet = new MyTypedDataSet();
aDataSet .Merge(anotherDataSet);
aDataSet .Merge(yetAnotherDataSet);
and
MyTypedDataSet aDataSet = anotherDataSet;
aDataSet .Merge(yetAnotherDataSet);
Which do you recommend?
|
|c#|dataset|object|initialization| |
Formatting works correctly even without having to round:
"%.1f" % n
|
How do I make a UIDatePicker display specific dates? |
|iphone|cocoa|cocoa-touch| |
My application has a need to let the user choose a date from a list of dates conforming to a certain pattern. For instance, they may need to choose a monday from a list Monday's for a month. Is there a way to get a UIDatePicker to limit date choices to a certain subset or should I just use a UIPickerView? |
You probably want different tools for performance profiling and code coverage.
For profiling I prefer Shark on MacOSX. It is free from Apple and very good. If your app is vanilla C you should be able to use, if you can get hold of a Mac.
For profiling on Windows you can use LTProf. Cheap, but not great:
http://successfulsoftware.net/2007/12/18/optimising-your-application/
(I think Microsoft are really shooting themself in the foot for not providing a decent profiler with the cheaper versions of Visual Studio.)
For coverage I prefer Coverage Validator on Windows:
http://successfulsoftware.net/2008/03/10/coverage-validator/
It updates the coverage in real time. |
You probably want different tools for performance profiling and code coverage.
For profiling I prefer Shark on MacOSX. It is free from Apple and very good. If your app is vanilla C you should be able to use it, if you can get hold of a Mac.
For profiling on Windows you can use LTProf. Cheap, but not great:
http://successfulsoftware.net/2007/12/18/optimising-your-application/
(I think Microsoft are really shooting themself in the foot by not providing a decent profiler with the cheaper versions of Visual Studio.)
For coverage I prefer Coverage Validator on Windows:
http://successfulsoftware.net/2008/03/10/coverage-validator/
It updates the coverage in real time. |
xsl:copy-of |
round() in Python doesn't seem to be rounding properly |
|language-agnostic|styles|spartan| |
|language-agnostic|styles|spartan| |
Sounds like you're overextending regex for this purpose. What I would do is use a regex to match a few date formats and then use a separate function to validate the values of the date fields so extracted. |
Regex was not meant to validate number ranges(this number must be from 1 to 5 when the number preceding it happens to be a 2 and the number preceding that happens to be below 6).
Just look for the pattern of placement of numbers in regex. If you need to validate is qualities of a date, put it in a date object js/c#/vb, and interogate the numbers there. |
This is not an appropriate use of regular expressions. You'd be better off using
[0-9]{2}/[0-9]{2}/[0-9]{4}
and then checking ranges in a higher-level language. |
How can I retrieve the page title of a webpage using Python? |
|python|html| |
How can I retrieve the page title of a webpage (title html tag) using Python?
|
Are there any languages that implement generics _well_? |
|language-agnostic|generics| |
I liked the discussion at [Differences in Generics][1], and was wondering whether there were any languages that used this feature particularly well.
I really dislike Java's `List<? extends Foo>` for a `List` of things that are Liskov-substitutable for `Foo`. Why can't `List<Foo>` cover that?
And honestly, `Comparable<? super Bar>`?
I also can't remember for the life of my why you should never return an Array of generics:
public T[] getAll<T>() { ... }
I never liked templates in C++, but that was mostly because none of the compilers could ever spit out a remotely meaningful error message for them. One time I actually did a `make realclean && make` 17 times to get something to compile; I never did figure out why the 17th time was the charm.
So, who actually _likes_ using generics in their pet language?
[1]: http://stackoverflow.com/questions/31693/differences-in-generics |
|language-agnostic|generics| |
For subversion, there is [Assembla][1] too which comes with [Trac][2] and other useful tools. It's free or you could pay for an account if you need more space or users per project.
Kind Regards
[1]: http://www.assembla.com/
[2]: http://trac.edgewall.org/ |
I know this does not answer your question, but why don't you use a date handling routine to check if it's a valid date? Even if you modify the regexp with a negative lookahead assertion like (?!31/0?2) (ie, do not match 31/2 or 31/02) you'll still have the problem of accepting 29 02 on non leap years and about a single separator date format.
The problem is not easy if you want to really validate a date, check this [forum thread][1].
For an example or a better way, in C#, check [this link][2]
If you are using another platform/language, let us know
[1]: http://discuss.joelonsoftware.com/default.asp?joel.3.229443.10
[2]: http://www.codeguru.com/columns/dotnettips/article.php/c7547 |
I found this but can't get it to work. You're supposed to be able (according to [this][1]) to scaffold and then override the actions you want (say list) in your controller, but like I said, it doesn't work for me...
class PersonController {
def scaffold = true
def list = {
if(!params.max) params.max = 20
[ personList: Person.list( params ) ]
}
}
[1]: http://www.nabble.com/Dynamic-scaffolding-Controller-using-edited-template-td13468221.html |
There are other good reasons for entity objects besides abstraction and loose coupling. One of the things I like most is the strong typing that you can't get with a DataReader or a DataTable. Another reason is that when done well, proper entity classes can make the code more maintanable by using first-class constructs for domain-specific terms that anyone looking at the code is likely to understanbd rather than a bunch of strings with field names in them used for indexing a DataRow. Stored procedures are really orthogonal to the use of an ORM since a lot of mapping frameworks give you the ability to map to sprocs.
I wouldn't consider sprocs + datareaders a substitute for a good ORM. With stored procedures, you're still constrained by, and tightly-coupled to, the procedure's type signature, which uses a different type system than the calling code. Stored procedures can be subject to modification to acommodate additional options and schema changes. An alternative to stored procedures in the case where the schema is subject to change is to use views--you can map objects to views and then re-map views to the underlying tables when you change them.
I can understand your aversion to ORMs if your experience mainly consists of J2EE and CSLA. You might want to have a look at LINQ to SQL, which is a very lightweight framework and is primarily a one-to-one mapping with the database tables but usually only needs minor extension for them to be full-blown business objects. LINQ to SQL can also map input and output objects to stored procedures' paramaters and results.
The ADO.NET Entity framework has the added advantage that your database tables can be viewed as entity classes inheriting from each other, or as columns from multiple tables aggregated into a single entity. If you need to change the schema, you can change the mapping from the conceptual model to the storage schema without changing the actual application code. And again, stored procedures can be used here. |
There are other good reasons for entity objects besides abstraction and loose coupling. One of the things I like most is the strong typing that you can't get with a DataReader or a DataTable. Another reason is that when done well, proper entity classes can make the code more maintanable by using first-class constructs for domain-specific terms that anyone looking at the code is likely to understand rather than a bunch of strings with field names in them used for indexing a DataRow. Stored procedures are really orthogonal to the use of an ORM since a lot of mapping frameworks give you the ability to map to sprocs.
I wouldn't consider sprocs + datareaders a substitute for a good ORM. With stored procedures, you're still constrained by, and tightly-coupled to, the procedure's type signature, which uses a different type system than the calling code. Stored procedures can be subject to modification to acommodate additional options and schema changes. An alternative to stored procedures in the case where the schema is subject to change is to use views--you can map objects to views and then re-map views to the underlying tables when you change them.
I can understand your aversion to ORMs if your experience mainly consists of J2EE and CSLA. You might want to have a look at LINQ to SQL, which is a very lightweight framework and is primarily a one-to-one mapping with the database tables but usually only needs minor extension for them to be full-blown business objects. LINQ to SQL can also map input and output objects to stored procedures' paramaters and results.
The ADO.NET Entity framework has the added advantage that your database tables can be viewed as entity classes inheriting from each other, or as columns from multiple tables aggregated into a single entity. If you need to change the schema, you can change the mapping from the conceptual model to the storage schema without changing the actual application code. And again, stored procedures can be used here.
I think that more IT projects in enterprises fail because of unmaintainability of the code or poor developer productivity (which can happen from, e.g., context switching between sproc-writing and app-writing) than scalability problems of an application. |
Just last week, I used regex find/replace to convert a CSV file to an XML file.
Simple enough to do really, just chop up each field (luckily it didn't have any escaped commas) and push it back out with the appropriate tags in place of the commas. |
Here is what I'm currently doing in the application's Program.cs file.
// Sets the window to be foreground
[DllImport("User32")]
private static extern int SetForegroundWindow(IntPtr hwnd);
// Activate or minimize a window
[DllImportAttribute("User32.DLL")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SW_RESTORE = 9;
static void Main()
{
try
{
// If another instance is already running, activate it and exit
Process currentProc = Process.GetCurrentProcess();
foreach (Process proc in Process.GetProcessesByName(currentProc.ProcessName))
{
if (proc.Id != currentProc.Id)
{
ShowWindow(proc.MainWindowHandle, SW_RESTORE);
SetForegroundWindow(proc.MainWindowHandle);
return; // Exit application
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
catch (Exception ex)
{
}
}
|
Don't forget that you can't trust floating point arithmetic to be 100% accurate. If you're concerned about this, you'll want to look into the <a href="http://us2.php.net/manual/en/intro.bc.php">BCMath Arbitrary Precision Mathematics</a> functions.
$x = 22.732423423423432;
$x = bcsub(abs($x),floor(abs($x)),20);
You could also hack on the string yourself
$x = 22.732423423423432;
$x = strstr ( $x, '.' );
|
Some commands i use in my code :
- `\todo { paragraph describing what is to be done }` Useful to keep track of todos, a page will be created in final documentation containing your todo list.
- `\c <word>` Displays the argument <word> using a typewriter font. Use this to refer to a word of code. I would use it before "TRUE" and "FALSE" in your example.
- `\a , \warning , \see` : see <http://www.stack.nl/~dimitri/doxygen/commands.html#cmdc> for description |
Regex make it easy to replace whole words using word boundaries.
(\b\w+\b)
So you can replace unwanted words in your file without disturbing words like **Scunthorpe** |
Crystal Reports, because it is easy to take the same exact report file and
1 - Post it on the intranet
2 - Embed it in an application
3 - Schedule it to be emailed as an Excel output every so often to whoever needs it
Also (as I already suggested), it exports easily to Excel, PDF, and other formats. |
@Kogus: Even if i run outside debugger(standalone app. from a command prompt) it still could be preempted by OS and cause a incorrect measurement of the time consumed by my app.
Is'nt it?
-AD |
I use a similar method to ChanChan, but instead of whitespace I put a comment in the web.config to indicate when/why the config was edited. |
I use [PrettyCode.Print for .NET][1]. It does everything on your list, and more. (I use it for printing code excerpts for copyright registration paperwork, which is similar to your escrow case.)
It is a little slow to open a really big solution, but not unbearably so, and the output quality is excellent.
[1]: http://submain.com/?nav=products.pcp.net |
Our build people use Mozilla Tinderbox. It seems to have some hooks for distributed testing. I'm sorry not to know the details but I thought I would at least pass on the pointer to you.
It's also nice coz you can find out immediately when a build breaks, and what checkin might have been the culprit.
<http://www.mozilla.org/tinderbox.html> |
davex.dll is the legacy webdav component for Exchange server, which Entourage uses. Your first step should be investigating why the application pool crashes. My guess is that Entourage can't do anything when the dll isn't present because webdav is not responding to any requests. |
Don't use `int`. Files over 2 gigabytes in size are common as dirt these days
Don't use `unsigned int`. Files over 4 gigabytes in size are common as some slightly-less-common dirt
IIRC the standard library defines `off_t` as an unsigned 64 bit integer, which is what everyone should be using. We can redefine that to be 128 bits in a few years when we start having 16 exabyte files hanging around.
If you're on windows, you should use [GetFileSizeEx](http://msdn.microsoft.com/en-us/library/aa364957\(VS.85\).aspx) - it actually uses a signed 64 bit integer, so they'll start hitting problems with 8 exabyte files. Foolish Microsoft! :-) |
Don't use `int`. Files over 2 gigabytes in size are common as dirt these days
Don't use `unsigned int`. Files over 4 gigabytes in size are common as some slightly-less-common dirt
IIRC the standard library defines `off_t` as an unsigned 64 bit integer, which is what everyone should be using. We can redefine that to be 128 bits in a few years when we start having 16 exabyte files hanging around.
If you're on windows, you should use [GetFileSizeEx](http://msdn.microsoft.com/en-us/library/aa364957(VS.85).aspx) - it actually uses a signed 64 bit integer, so they'll start hitting problems with 8 exabyte files. Foolish Microsoft! :-) |
Seconding @[Matt Miller][1] on RSS feeds.
There's a useful tool called [WebSVN][2] that offers RSS feeds of every repository and individual branches/tags/folders with full commit messages. It's also a great web interface for quickly looking at file histories and commits/diffs without having to run an update and open your editor of choice.
[1]: http://stackoverflow.com/questions/7913/how-do-i-make-subversion-svn-send-email-on-checkins#7986
[2]: http://websvn.tigris.org/ |
I can't imagine drawing icons online. Nowadays icons are usually *drawn* as vectors, and I'm not aware of any online vector packages.
In case you decide to draw off-line instead, I use Xara (www.xara.com) to draw all my computer artwork, and I use Gif Movie Gear to create .ico files. The former is a superb vector package, the latter is just something I have lying around. |
I use a simple program called MyViewPad, which can convert (almost) any old image to a .ico file. It's free and easy to use. This may not be what you are looking for though. |
Otto, if you could clarify what it is that you need this for, and we are more likely to have good suggestions. Provide a use-case, and someone will probably have some advice to fit it. |
Helpful code snippet from:
windows vista \appdata\roaming shortcut problem install
ode Snippet
public class Utilities
{
public enum FolderPaths
{
CSIDL_DESKTOP = 0x0000, // <desktop>
CSIDL_INTERNET = 0x0001, // Internet Explorer (icon on desktop)
CSIDL_PROGRAMS = 0x0002, // Start Menu\Programs
CSIDL_CONTROLS = 0x0003, // My Computer\Control Panel
CSIDL_PRINTERS = 0x0004, // My Computer\Printers
CSIDL_PERSONAL = 0x0005, // My Documents
CSIDL_FAVORITES = 0x0006, // <user name>\Favorites
CSIDL_STARTUP = 0x0007, // Start Menu\Programs\Startup
CSIDL_RECENT = 0x0008, // <user name>\Recent
CSIDL_SENDTO = 0x0009, // <user name>\SendTo
CSIDL_BITBUCKET = 0x000a, // <desktop>\Recycle Bin
CSIDL_STARTMENU = 0x000b, // <user name>\Start Menu
CSIDL_MYDOCUMENTS = CSIDL_PERSONAL, // Personal was just a silly name for My Documents
CSIDL_MYMUSIC = 0x000d, // "My Music" folder
CSIDL_MYVIDEO = 0x000e, // "My Videos" folder
CSIDL_DESKTOPDIRECTORY = 0x0010, // <user name>\Desktop
CSIDL_DRIVES = 0x0011, // My Computer
CSIDL_NETWORK = 0x0012, // Network Neighborhood (My Network Places)
CSIDL_NETHOOD = 0x0013, // <user name>\nethood
CSIDL_FONTS = 0x0014, // windows\fonts
CSIDL_TEMPLATES = 0x0015,
CSIDL_COMMON_STARTMENU = 0x0016, // All Users\Start Menu
CSIDL_COMMON_PROGRAMS = 0X0017, // All Users\Start Menu\Programs
CSIDL_COMMON_STARTUP = 0x0018, // All Users\Startup
CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019, // All Users\Desktop
CSIDL_APPDATA = 0x001a, // <user name>\Application Data
CSIDL_PRINTHOOD = 0x001b, // <user name>\PrintHood
CSIDL_LOCAL_APPDATA = 0x001c // <user name>\Local Settings\Applicaiton Data (non roaming)
}
[DllImport("shfolder.dll", CharSet = CharSet.Unicode)]
public static extern int SHGetFolderPath(IntPtr owner, int folder, IntPtr token, int flags, StringBuilder path);
}
void MyFunction()
{
StringBuilder path = new StringBuilder(260);
String folderPath = "";
if (0 == Utilities.SHGetFolderPath(IntPtr.Zero, (int) Utilities.FolderPaths.CSIDL_MYVIDEO, IntPtr.Zero, 0, path))
{
folderPath = path.ToString();
}
} |
Helpful code snippet
ode Snippet
public class Utilities
{
public enum FolderPaths
{
CSIDL_DESKTOP = 0x0000, // <desktop>
CSIDL_INTERNET = 0x0001, // Internet Explorer (icon on desktop)
CSIDL_PROGRAMS = 0x0002, // Start Menu\Programs
CSIDL_CONTROLS = 0x0003, // My Computer\Control Panel
CSIDL_PRINTERS = 0x0004, // My Computer\Printers
CSIDL_PERSONAL = 0x0005, // My Documents
CSIDL_FAVORITES = 0x0006, // <user name>\Favorites
CSIDL_STARTUP = 0x0007, // Start Menu\Programs\Startup
CSIDL_RECENT = 0x0008, // <user name>\Recent
CSIDL_SENDTO = 0x0009, // <user name>\SendTo
CSIDL_BITBUCKET = 0x000a, // <desktop>\Recycle Bin
CSIDL_STARTMENU = 0x000b, // <user name>\Start Menu
CSIDL_MYDOCUMENTS = CSIDL_PERSONAL, // Personal was just a silly name for My Documents
CSIDL_MYMUSIC = 0x000d, // "My Music" folder
CSIDL_MYVIDEO = 0x000e, // "My Videos" folder
CSIDL_DESKTOPDIRECTORY = 0x0010, // <user name>\Desktop
CSIDL_DRIVES = 0x0011, // My Computer
CSIDL_NETWORK = 0x0012, // Network Neighborhood (My Network Places)
CSIDL_NETHOOD = 0x0013, // <user name>\nethood
CSIDL_FONTS = 0x0014, // windows\fonts
CSIDL_TEMPLATES = 0x0015,
CSIDL_COMMON_STARTMENU = 0x0016, // All Users\Start Menu
CSIDL_COMMON_PROGRAMS = 0X0017, // All Users\Start Menu\Programs
CSIDL_COMMON_STARTUP = 0x0018, // All Users\Startup
CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019, // All Users\Desktop
CSIDL_APPDATA = 0x001a, // <user name>\Application Data
CSIDL_PRINTHOOD = 0x001b, // <user name>\PrintHood
CSIDL_LOCAL_APPDATA = 0x001c // <user name>\Local Settings\Applicaiton Data (non roaming)
}
[DllImport("shfolder.dll", CharSet = CharSet.Unicode)]
public static extern int SHGetFolderPath(IntPtr owner, int folder, IntPtr token, int flags, StringBuilder path);
}
void MyFunction()
{
StringBuilder path = new StringBuilder(260);
String folderPath = "";
if (0 == Utilities.SHGetFolderPath(IntPtr.Zero, (int) Utilities.FolderPaths.CSIDL_MYVIDEO, IntPtr.Zero, 0, path))
{
folderPath = path.ToString();
}
} |
|python|floating-point| |
The documentation for the [round()][1] function states that you pass it a number, and the positions past the decimal to round. Thus is *should* do this:
n = 5.59
round(n, 1) # 5.6
But, in actuality, good old floating point weirdness creeps in and you get:
5.5999999999999996
For the purposes of UI, I need to display '5.6'. I poked around the Internet and found some [documentation][2] that this is dependent on my implementation of Python. Unfortunately, this occurs on both my Windows dev machine and each Linux server I've tried. [See here also][3].
Short of creating my own round library, is there any way around this?
[1]: http://docs.python.org/lib/built-in-funcs.html
[2]: http://mail.python.org/pipermail/python-list/2005-September/340383.html
[3]: http://www.python.org/doc/2.5.1/tut/node16.html |
The documentation for the [round()][1] function states that you pass it a number, and the positions past the decimal to round. Thus is *should* do this:
n = 5.59
round(n, 1) # 5.6
But, in actuality, good old floating point weirdness creeps in and you get:
5.5999999999999996
For the purposes of UI, I need to display '5.6'. I poked around the Internet and found some [documentation][2] that this is dependent on my implementation of Python. Unfortunately, this occurs on both my Windows dev machine and each Linux server I've tried. [See here also][3].
Short of creating my own round library, is there any way around this?
**Update:** Ok, string formatting. Sometimes, it's just a really simple answer. Thanks everyone.
[1]: http://docs.python.org/lib/built-in-funcs.html
[2]: http://mail.python.org/pipermail/python-list/2005-September/340383.html
[3]: http://www.python.org/doc/2.5.1/tut/node16.html |
Of course all these shortcuts are available in the menus but who has time for that when you're in the "zone".
I like the code hot swapping. |
The context connection uses the user's already established connection to the server. So you inherit things like their database context, connection options, etc.
Using localhost will connect to the server using a normal shared memory connection. This can be useful if you don't want to use the user's connection (i.e. if you want to connect to a different database, or with different options, etc).
In most cases you should use the context connection, since it doesn't create a separate connection to the server.
Also, be warned that using a separate connection means you are not part of the user's transaction and are subject to normal locking semantics. |
Calling a Web Service from Seam |
|java|seam| |
A simple question, but could someone provide sample code as to how would someone call a web service from within the JBoss Seam framework, and process the results?
I need to be able to integrate with a search platform being provided by a private vendor who is exposing his functionality as a web service. So, I'm just looking for some guidance as to what the code for calling a given web service would look like.
(Any sample web service can be chosen as an example.) |
Doesn't the [Criteria API][1] do it for you? It looks almost exactly like what you're asking for.
[1]: http://www.hibernate.org/hib_docs/v3/reference/en/html/querycriteria.html |
Can you do a partial checkout with svn? |
|subversion| |
If I had 20 directories under trunk/ with lots of files in each and only needed 3 of those directories, would it be possible to do an svn checkout with only those 3 directories under trunk? |
|svn| |
Can I have TortoiseSVN auto-add files? |
|tortoisesvn|subversion| |
Is there a way to have TortoiseSVN (or any other tool) auto-add any new .cs files I create within a directory to my working copy so I don't have to remember which files I created at the end of the day? |
|svn|tortoisesvn| |
Source Control for Everyone? |
|svn|git|subversion|version-control| |
I've got a number of non-technical users that all share a set of project files. It would be ideal to have them using version control, but I think that both subversion and git are too technical for non-technical office staff.
Is there any distributed source control software that would work well for normal people? |
|svn|git|version-control| |
How do I export (and then import) a Subversion repo? |
|version-control|versioning|subversion|import|export| |
I'm just about wrapped up on a project where I was using a commercial SVN provider to store the source code. The web host the customer ultimately picked includes a repository as part of the hosting package, so, now that the project is over, I'd like to relocate the repository to their web host and discontinue the commercial account.
How would I go about doing this? |
|svn|version-control|versioning|import|export| |
Tables are used for tabular data. If it makes since ot put it in a spreadsheet then use a table. Otherwise there is a better tag for you to be using such as div, span, ul, etc. |
There's a text progress bar library for python at <http://pypi.python.org/pypi/progressbar/2.2> that you might find useful:
>This library provides a text mode progressbar. This is tipically used to display the progress of a long running operation, providing a visual clue that processing is underway.
>The ProgressBar class manages the progress, and the format of the line is given by a number of widgets. A widget is an object that may display diferently depending on the state of the progress. There are three types of widget: - a string, which always shows itself; - a ProgressBarWidget, which may return a diferent value every time it's update method is called; and - a ProgressBarWidgetHFill, which is like ProgressBarWidget, except it expands to fill the remaining width of the line.
>The progressbar module is very easy to use, yet very powerful. And automatically supports features like auto-resizing when available. |
Hosting the CLR within SQL Server is meant to give database developers *more flexible options* in how they sought to accomplish tasks. Like others have mentioned, SQL is great for operations and modifications on *sets of data*. Anybody who has done extensive large application development with complex business/domain rules would likely tell you - trying to enforce some of these rules using pure SQL (some times into a single macro query) can get truly nightmarish.
There are just certain tasks that are better handled in a procedural or OO fashion. By having the choice of using .NET code to break down the sequence of logic, query operations can get easier to read and debug. Having used CLR stored procs I can tell you stepping through with the debugger really makes it easier to follow through with what is happening at the database level.
Just one example, we frequently use CLR stored procs here as a "gateway" for dynamic search queries. Say a search request that can have up to 30 different search parameters. Users obviously don't use all 30 of them, so the data structure passed in will have 30 parameters but mostly DBNULL. The client side has *no option* to generate a dynamic statement, for obvious security reasons. The resulting dynamic statement is generated internally without fear of external "extras". |
Hibernate makes more sense when your application works on <i>object graphs</i>, which are persisted in the RDBMS. Instead, if your application logic works on a 2-D matrix of data, fetching those via direct JDBC works better. Although Hibernate is written on top of JDBC, it has capabilities which might be non-trivial to implement in JDBC. For eg:
<ol>
<li>Say, the user views a row in the UI and changes some of the values and you want to fire an update query for only those columns that did indeed change.</li>
<li>To avoid getting into deadlocks you need to maintain a global order for SQLs in a transaction. Getting this right JDBC might not be easy</li>
<li>Easily setting up optimistic locking. When you use JDBC, you need to remember to have this in every update query.</li>
<li>Batch updates, lazy materialization of collections etc might also be non-trivial to implement in JDBC.</li>
</ol>
(I say "<i>might</i> be non-trivial", because it of course can be done - and you might be a super hacker:)
Hibernate lets you fire your own SQL queries also, in case you need to.
Hope this helps you to decide.
PS: Keeping the Session open on a remote desktop client and running into trouble is really not Hibernate's problem - you would run into the same issue if you keep the Connection to the DB open for long. |
The problem was DBNull, doing:
command.Parameters.AddWithValue("@parameter", null);
compiles OK. |
UnhandledException handler in a .Net Windows Service |
|.net|exception|windows-services| |
Is it possible to use an UnhandledException Handler in a Windows Service?
Normally I would use a custom built Exception Handling Component that does logging, phone home, etc. This component adds a handler to System.AppDomain.CurrentDomain.UnhandledException but as far as I can tell this doesn’t achieve anything win a Windows Service so I end up with this pattern in my 2 (or 4) Service entry points:
<pre>
<code>
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Try
MyServiceComponent.Start()
Catch ex As Exception
'call into our exception handler
MyExceptionHandlingComponent.ManuallyHandleException (ex)
'zero is the default ExitCode for a successfull exit, so if we set it to non-zero
ExitCode = -1
'So, we use Environment.Exit, it seems to be the most appropriate thing to use
'we pass an exit code here as well, just in case.
System.Environment.Exit(-1)
End Try
End Sub
</code>
</pre>
Is there a way my Custom Exception Handling component can deal with this better so I don't have to fill my OnStart with messy exception handling plumbing? |
The best way of doing this is a dedicated profiling tool. There are lots out there. I haven't used one for C for a few years, someone else will hopefully be able to give better advice. As you are using Visual Studio 2005 this might be a good place to start:
[AQ][1], but I've never used it.
[1]: http://www.automatedqa.com/products/aqtime/ |
I like to use regexps to reformat lists of items like this:
int item1
double item2
to
public void item1(int item1){
}
public void item2(double item2){
}
This can be a big time saver. |
I've found some benefits to makefiles with large projects, mainly related to unifying the location of the project settings. It's somewhat easier to manage the list of source files, include paths, preprocessor defines and so on, if they're all in a makefile or other build config file. With multiple configurations, adding an include path means you need to make sure you update every config manually through Visual Studio's fiddly project properties, which can get pretty tedious as a project grows in size.
Projects which use a lot of custom build tools can be easier to manage too, such as if you need to compile pixel / vertex shaders, or code in other languages without native VS support.
You'll still need to have various different project configurations however, since you'll need to differentiate the invocation of the build tool for each config (e.g. passing in different command line options to make).
Immediate downsides that spring to mind:
- Slower builds: VS isn't particularly quick at invoking external tools, or even working out whether it needs to build a project in the first place.
- Awkward inter-project dependencies: It's fiddly to set up so that a dependee causes the base project to build, and fiddlier to make sure that they get built in the right order. I've had some success getting SCons to do this, but it's always a challenge to get working well.
- Loss of some useful IDE features: Edit & Continue being the main one!
In short, you'll spend less time managing your project configurations, but more time coaxing Visual Studio to work properly with it. |
1 - Put some debug logging in your code (include timestamps of course), and run it outside of the debugger
2 - Run again *in* the debugger
3 - Repeat many times, to get statistically valid data.
4 - Compare.
If there is a significant difference in the average execution time of the standalone vs. the debugger, then you are right to be suspicious of the OS (or the overhead of the debugger hooks themselves...). If no difference, then don't sweat it.
*Edit0: Obviously the debug messages have some overhead of their own. You may want to leave those *in* the code even when you are running from the debugger. That way, both the standalone and the debugger are running the very same code.* |
1 - Put some debug logging in your code (include timestamps of course), and run it outside of the debugger
2 - Run again *in* the debugger
3 - Repeat many times, to get statistically valid data.
4 - Compare.
If there is a significant difference in the average execution time of the standalone vs. the debugger, then you are right to be suspicious of the OS (or the overhead of the debugger hooks themselves...). If no difference, then don't sweat it.
*Edit0: Obviously the debug messages have some overhead of their own. You may want to leave those in the code even when you are running from the debugger. That way, both the standalone and the debugger are running the very same code.*
*Edit1: I misunderstood the question. I thought your concern was that --while debugging--, the OS might interrupt your app more frequently than in a normal mode of execution. If you want to know how much time your app actually spent working, just compare the time taken to the "CPU Time" in the Task Manager.*
*Edit2: Compare the time returned by [GetProcessTimes][1] for your process to the actual execution time. The difference is the time spent by the CPU on somebody else.*
[1]: http://msdn.microsoft.com/en-us/library/ms683223(VS.85).aspx |
These are relatively cheap mechanisms for possibly solving the problem:
1. Keep an eye on my [heap corruption question][1] - I'm updating with the answers as they shake out. The first was balancing new[] and delete[], but you're already doing that.
2. Give valgrind more of a go; it's an excellent tool, and I only wish it was available under Windows. I only slows your program down by about half, which is pretty good compared to the Windows equivalents.
3. Think about using the [Google Performance Tools][2] as a replacement malloc/new.
4. Have you cleaned out all your object files and started over? Perhaps your make file is... "suboptimal"
5. You're not assert()ing enough in your code. How do I know that without having seen it? No-one assert()s enough in their code. Add in a validation function for your objects and call that on method start and method end.
6. Are you compiling -wall? If not, do so.
[1]: http://stackoverflow.com/questions/1069/heap-corruption-under-win32-how-to-locate
[2]: http://code.google.com/p/google-perftools/ |
These are relatively cheap mechanisms for possibly solving the problem:
1. Keep an eye on my [heap corruption question][1] - I'm updating with the answers as they shake out. The first was balancing new[] and delete[], but you're already doing that.
2. Give valgrind more of a go; it's an excellent tool, and I only wish it was available under Windows. I only slows your program down by about half, which is pretty good compared to the Windows equivalents.
3. Think about using the [Google Performance Tools][2] as a replacement malloc/new.
4. Have you cleaned out all your object files and started over? Perhaps your make file is... "suboptimal"
5. You're not assert()ing enough in your code. How do I know that without having seen it? No-one assert()s enough in their code. Add in a validation function for your objects and call that on method start and method end.
6. Are you compiling -wall? If not, do so.
7. Find yourself a lint tool like PC-Lint.
[1]: http://stackoverflow.com/questions/1069/heap-corruption-under-win32-how-to-locate
[2]: http://code.google.com/p/google-perftools/ |
These are relatively cheap mechanisms for possibly solving the problem:
1. Keep an eye on my [heap corruption question][1] - I'm updating with the answers as they shake out. The first was balancing new[] and delete[], but you're already doing that.
2. Give valgrind more of a go; it's an excellent tool, and I only wish it was available under Windows. I only slows your program down by about half, which is pretty good compared to the Windows equivalents.
3. Think about using the [Google Performance Tools][2] as a replacement malloc/new.
4. Have you cleaned out all your object files and started over? Perhaps your make file is... "suboptimal"
5. You're not assert()ing enough in your code. How do I know that without having seen it? Like flossing, no-one assert()s enough in their code. Add in a validation function for your objects and call that on method start and method end.
6. Are you compiling -wall? If not, do so.
7. Find yourself a lint tool like PC-Lint.
8. Check you're NULLing out pointers after deleteing them. Nobody likes a dangling pointer. Same gig with declared but unallocated pointers.
[1]: http://stackoverflow.com/questions/1069/heap-corruption-under-win32-how-to-locate
[2]: http://code.google.com/p/google-perftools/ |
What is a good repository layout for releases and projects in Subversion? |
|subversion| |
We have the standard Subversion trunk/branches/tags layout. We have several branches for medium- and long-term projects, but none so far for a release. This is approaching fast.
Should we:
1. Mix release branches and project branches together?
2. Create a releases folder? If so, is there a better name than releases?
3. Create a projects folder and move the current branches there? If so, is there a better name than projects? I've seen "sandbox" and "spike" in other repositories.
4. Something else altogether? |
|svn|tags|branch|release| |
I'll always use [lxml][1] for such tasks. You could use [beautifulsoup][2] as well.
import lxml.html
t = lxml.html.parse(url)
print t.find(".//title").text
[1]: http://codespeak.net/lxml/
[2]: http://www.crummy.com/software/BeautifulSoup/ |
Subversion or Adobe Version CUE 3 for Photoshop/Illustrator Files |
|versioning| |
This might seem like a stupid question I admit. But I'm in a small shop me plus two designers. Our backups are getting out of hand because they just copy/paste files if they need to make a change (version).
I was all set to try Subversion to handle all of our files my text (code) files and their photoshop/illustrator and asset files. That is until I noticed there was a new version of Adobe Version Cue v3. We've tried previously to use version cue but it got complicated and the designers quickly stopped using it.
Looking for anyone that has some experience with version 3 of Version Cue. |
This might seem like a stupid question I admit. But I'm in a small shop me plus two designers. Our backups are getting out of hand because they just copy/paste files if they need to make a change (version).
I was all set to try Subversion to handle all of our files my text (code) files and their photoshop/illustrator and asset files. That is until I noticed there was a new version of Adobe Version Cue v3. We've tried previously to use version cue but it got complicated and the designers quickly stopped using it.
Looking for anyone that has some experience with version 3 of Version Cue.
Thanks for the great feedback. Maybe I should have asked what's the best tool to use for Versioning Photoshop and related files. I did notice the binary file issue and was worried about trying to explain it and keep it "working". I signed up for the beta at Gridiron thanks for that! |
This might seem like a stupid question I admit. But I'm in a small shop me plus two designers. Our backups are getting out of hand because they just copy/paste files if they need to make a change (version).
I was all set to try Subversion to handle all of our files my text (code) files and their photoshop/illustrator and asset files. That is until I noticed there was a new version of Adobe Version Cue v3. We've tried previously to use version cue but it got complicated and the designers quickly stopped using it.
Looking for anyone that has some experience with version 3 of Version Cue.
Thanks for the great feedback. Maybe I should have asked what's the best tool to use for Versioning Photoshop and related files. I did notice the binary file issue and was worried about trying to explain it and keep it "working". I signed up for the beta at Gridiron thanks for that!
[Here][1] is the other question related to this one.
[1]: http://stackoverflow.com/questions/36186/best-versioning-tools-to-use-for-photoshopillustrator-and-related-binary-files |
Aku, that is a good resource. I answered a question similar to this one a while back. You can check my [answer here][1]. Even though this was for WPF, you can use the same logic in WinForms.
[1]: http://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-application#19326 |