qid
int64 1
82.4k
| question
stringlengths 27
22.5k
| answers
stringlengths 509
252k
| date
stringlengths 10
10
| metadata
stringlengths 108
162
|
---|---|---|---|---|
76,359 |
<p>Does ADOdb do data sanitation or escaping within the same functionality by default? Or am I just confusing it with Code Igniter's built-in processes?</p>
<p>Does binding variables to parameters in ADOdb for PHP prevent SQL injection in any way? </p>
|
[{'answer_id': 76528, 'author': 'Brendon-Van-Heyzen', 'author_id': 1425, 'author_profile': 'https://Stackoverflow.com/users/1425', 'pm_score': 2, 'selected': False, 'text': '<p>yes, you pass the array of parameters.</p>\n\n<pre><code>$rs = $db->Execute(\'select * from table where val=?\', array(\'10\'));\n</code></pre>\n\n<p>Rest of their docs can be found <a href="http://adodb.sourceforge.net/#docs" rel="nofollow noreferrer">here</a>:</p>\n'}, {'answer_id': 76565, 'author': 'Peter Bailey', 'author_id': 8815, 'author_profile': 'https://Stackoverflow.com/users/8815', 'pm_score': 3, 'selected': True, 'text': '<p>Correct - bound parameters are not vulnerable to SQL injection attacks.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76359', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13320/']
|
76,395 |
<p>In what domains do each of these software architectures shine or fail?</p>
<p>Which key requirements would prompt you to choose one over the other?</p>
<p>Please assume that you have developers available who can do good object oriented code as well as good database development.</p>
<p>Also, please avoid holy wars :) all three technologies have pros and cons, I'm interested in where is most appropriate to use which.</p>
|
[{'answer_id': 76442, 'author': 'Ryan Lanciaux', 'author_id': 1385358, 'author_profile': 'https://Stackoverflow.com/users/1385358', 'pm_score': 3, 'selected': False, 'text': '<p>I agree that there are pros and cons to everything and a lot depends on your architecture. That being said, I try to use ORM\'s where it makes sense. A lot of the functionality is already there and usually they help prevent SQL Injection (plus it helps avoid re-inventing the wheel).</p>\n\n<p>Please see these other two posts on the topic (dynamic SQL vs \nstored procedures vs ORM) for more information</p>\n\n<p><strong>Dynamic SQL vs. stored procedures</strong><br>\n<a href="https://stackoverflow.com/questions/22907/which-is-better-ad-hoc-queries-or-stored-procedures">Which is better: Ad hoc queries, or stored procedures?</a></p>\n\n<p><strong>ORMs vs. stored procedures</strong><br>\n<a href="https://stackoverflow.com/questions/50346/why-is-parameterized-sql-generated-by-nhibernate-just-as-fast-as-a-stored-proce">Why is parameterized SQL generated by NHibernate just as fast as a stored procedure?</a></p>\n'}, {'answer_id': 76573, 'author': 'Nate Kohari', 'author_id': 1282, 'author_profile': 'https://Stackoverflow.com/users/1282', 'pm_score': 2, 'selected': False, 'text': '<p>ORMs and code generators are kind of on one side of the field, and stored procedures are on another. Typically, it\'s easier to use ORMs and code generators in greenfield projects, because you can tailor your database schema to match the domain model you create. It\'s much more difficult to use them with legacy projects, because once software is written with a "data-first" mindset, it\'s difficult to wrap it with a domain model.</p>\n\n<p>That being said, all three of the approaches have value. Stored procedures can be easier to optimize, but it can be tempting to put business logic in them that may be repeated in the application itself. ORMs work well if your schema matches the concept of the ORM, but can be difficult to customize if not. Code generators can be a nice middle ground, because they provide some of the benefits of an ORM but allow customization of the generated code -- however, if you get into the habit of altering the generated code, you then have two problems, because you will have to alter it each time you re-generate it.</p>\n\n<p>There is no one true answer, but I tend more towards the ORM side because I believe it makes more sense to think with an object-first mindset.</p>\n'}, {'answer_id': 76655, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Stored Procedures</strong></p>\n\n<ul>\n<li><strong>Pros:</strong> Encapsulates data access code and is application-independent</li>\n<li><strong>Cons:</strong> Can be RDBMS-specific and increase development time</li>\n</ul>\n\n<p><strong>ORM</strong></p>\n\n<p><em>At least some ORMs allow mapping to stored procedures</em></p>\n\n<ul>\n<li><strong>Pros:</strong> Abstracts data access code and allows entity objects to be written in domain-specific way</li>\n<li><strong>Cons:</strong> Possible performance overhead and limited mapping capability</li>\n</ul>\n\n<p><strong>Code generation</strong></p>\n\n<ul>\n<li><strong>Pros:</strong> Can be used to generate stored-proc based code or an ORM or a mix of both</li>\n<li><strong>Cons:</strong> Code generator layer may have to be maintained in addition to understanding generated code</li>\n</ul>\n'}, {'answer_id': 76810, 'author': 'Craig Trader', 'author_id': 12895, 'author_profile': 'https://Stackoverflow.com/users/12895', 'pm_score': 5, 'selected': True, 'text': "<p>Every one of these tools provides differing layers of abstraction, along with differing points to override behavior. These are architecture choices, and all architectural choices depend on trade-offs between technology, control, and organization, both of the application itself and the environment where it will be deployed.</p>\n\n<ul>\n<li><p>If you're dealing with a culture where DBAs 'rule the roost', then a stored-procedure-based architecture will be easier to deploy. On the other hand, it can be very difficult to manage and version stored procedures.</p></li>\n<li><p>Code generators shine when you use statically-typed languages, because you can catch errors at compile-time instead of at run-time.</p></li>\n<li><p>ORMs are ideal for integration tools, where you may need to deal with different RDBMSes and schemas on an installation-to-installation basis. Change one map and your application goes from working with PeopleSoft on Oracle to working with Microsoft Dynamics on SQL Server.</p></li>\n</ul>\n\n<p>I've seen applications where Generated Code is used to interface with Stored Procedures, because the stored procedures could be tweaked to get around limitations in the code generator.</p>\n\n<p>Ultimately the only correct answer will depend upon the problem you're trying to solve and the environment where the solution needs to execute. Anything else is arguing the correct pronunciation of 'potato'.</p>\n"}, {'answer_id': 76839, 'author': 'Sklivvz', 'author_id': 7028, 'author_profile': 'https://Stackoverflow.com/users/7028', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ll add my two cents:</p>\n\n<p><strong>Stored procedures</strong></p>\n\n<ul>\n<li>Can be easily optimized</li>\n<li>Abstract fundamental business rules, enhancing data integrity</li>\n<li>Provide a good security model (no need to grant read or write permissions to a front facing db user)</li>\n<li>Shine when you have many applications accessing the same data</li>\n</ul>\n\n<p><strong>ORMs</strong></p>\n\n<ul>\n<li>Let you concentrate only on the domain and have a more "pure" object oriented approach to development</li>\n<li>Shine when your application must be cross db compatible</li>\n<li>Shine when your application is mostly driven by behaviour instead of data</li>\n</ul>\n\n<p><strong>Code Generators</strong></p>\n\n<ul>\n<li>Provide you similar benefits as ORMs, with higher maintenance costs, but with better customizability.</li>\n<li>Are generally superior to ORMs in that ORMs tend to trade compile-time errors for runtime errors, which is generally to be avoided</li>\n</ul>\n'}, {'answer_id': 105417, 'author': 'Kevin Pauli', 'author_id': 19269, 'author_profile': 'https://Stackoverflow.com/users/19269', 'pm_score': 2, 'selected': False, 'text': '<p>You forgot a significant option that deserves a category of its own: a hybrid data mapping framework such as <a href="http://ibatis.apache.org/" rel="nofollow noreferrer">iBatis</a>.</p>\n\n<p>I have been pleased with iBatis because it lets your OO code remain OO in nature, and your database remain relational in nature, and solves the impedance mismatch by adding a third abstraction (the mapping layer between the objects and the relations) that is responsible for mapping the two, rather than trying to force fit one paradigm into the other.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76395', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7028/']
|
76,403 |
<p>I have a SQL Insert query inside a stored proc, for inserting rows into a <strong>linked server</strong> table.</p>
<p>Since the stored proc is getting called within a parent transaction, this Insert statement tries to use a DTC for inserting rows into the linked server.</p>
<p>I would like to <strong>avoid</strong> DTC from getting involved.</p>
<p>Is there any way I can do that (like a hint) for the Insert SQL statement to ignore transactional scope?</p>
|
[{'answer_id': 76688, 'author': 'AlanR', 'author_id': 7311, 'author_profile': 'https://Stackoverflow.com/users/7311', 'pm_score': 3, 'selected': True, 'text': '<p>My suggestion is that you store whatever you want to insert into a staging table, and once the procedure is over run the cross server insert. To my knowledge there is no way of ignoring the transaction you are in once you are within the SProc execution. </p>\n\n<p>In contrast, if you use .NET 2.0\'s System.Transaction namespace, you can tell specific statements not to participate in any parent scope transaction. This would require you to write some of your logic in code rather than stored procedures, but would work.</p>\n\n<p>Here\'s a <a href="http://decipherinfosys.wordpress.com/2007/02/01/simulating-autonomous-transaction-behavior-in-sql-server/" rel="nofollow noreferrer">relevant link</a>.</p>\n\n<p>Good luck,\nAlan.</p>\n'}, {'answer_id': 49511069, 'author': 'user3675542', 'author_id': 3675542, 'author_profile': 'https://Stackoverflow.com/users/3675542', 'pm_score': 0, 'selected': False, 'text': "<p>Try using openquery to call the linked server query/sp instead of direct calling\nThat worked for me</p>\n\n<p>so instead of\ninsert into ...\nselect * from mylinkedserver.pubs.dbo.authors</p>\n\n<p>e.g.\nDECLARE @TSQL varchar(8000), @VAR char(2)\nSELECT @VAR = 'CA'\nSELECT @TSQL = 'SELECT * FROM OPENQUERY(MyLinkedServer,''SELECT * FROM pubs.dbo.authors WHERE state = ''''' + @VAR + ''''''')'</p>\n\n<p>INSERT INTO .....\n EXEC (@TSQL)</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76403', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4337/']
|
76,408 |
<p>First of all, I want to avoid a flame-war on languages. The languages to choose from are Perl, Python and Ruby . I want to mention that I'm comfortable with all of them, but the problem is that I can't focus just on one. </p>
<p>If, for example, I see a cool Perl module, I have to try it out. If I see a nice Python app, I have to know how it's made. If I see a Ruby DSL or some Ruby voodoo, I'm hooked on Ruby for a while.</p>
<p>Right now I'm working as a Java developer, but plan on taking CEH in the near future. My question is: for tool writing and exploit development, which language do you find to be the most appropriate?</p>
<p>Again, I don't want to cause a flame-war or any trouble, I just want honest opinions from scripters that know what they're doing.</p>
<p>One more thing: maybe some of you will ask "Why settle on one language?". To answer this: I would like to choose only one language, in order to try to master it.</p>
|
[{'answer_id': 76441, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 2, 'selected': False, 'text': "<p>That depends on the implementation, if it will be distributed I would go with Java, seeing as you know that, because of its portability. If it is just for internal use, or will be used in semi-controlled environments, then go with whatever you are the most comfortable maintaining, and whichever has the best long-term outlook.</p>\n\n<p>Now to just answer the question, I would go with Perl, but I'm a linux guy so I may be a bit biased in this.</p>\n"}, {'answer_id': 76470, 'author': 'terminus', 'author_id': 9232, 'author_profile': 'https://Stackoverflow.com/users/9232', 'pm_score': 0, 'selected': False, 'text': "<p>Well, what kind of exploits are you thinking about? If you want to write something that needs low level stuff (ptrace, raw sockets, etc.) then you'll need to learn C. But both Perl and Python can be used. The real question is which one suits your style more?</p>\n\n<p>As for toolmaking, Perl has good string-processing abilities, is closer to the system, has good support, but IMHO it's very confusing. I prefer Python: it's a clean, easy to use, easy to learn language with good support (complete language/lib reference, 3rd party libs, etc.). And it's (strictly IMHO) cool.</p>\n"}, {'answer_id': 76495, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 1, 'selected': False, 'text': "<p>All of them should be sufficient for that. Unless you need some library that is only available in one language, I'd let personal preference guide me.</p>\n"}, {'answer_id': 76508, 'author': 'Rachel', 'author_id': 13138, 'author_profile': 'https://Stackoverflow.com/users/13138', 'pm_score': 1, 'selected': False, 'text': "<p>If you're looking for a scripting language that will play well with Java, you might want to look at Groovy. It has the flexibility and power of Perl (closures, built in regexes, associative arrays on every corner) but you can access Java code from it thus you have access to a huge number of libraries, and in particular the rest of the system you're developing. </p>\n"}, {'answer_id': 76546, 'author': 'jkramer', 'author_id': 12523, 'author_profile': 'https://Stackoverflow.com/users/12523', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.metasploit.com/" rel="nofollow noreferrer">metasploit</a> is a great framework for penetration testing. It\'s mainly written in Ruby, so if you know that language well, maybe you can hook in there. However, to <em>use</em> metasploit, you don\'t need to know any language at all. </p>\n'}, {'answer_id': 76889, 'author': '573f', 'author_id': 13699, 'author_profile': 'https://Stackoverflow.com/users/13699', 'pm_score': 2, 'selected': False, 'text': '<p>Speaking as a CEH, learn the CEH material first. This will expose you to a variety of tools and platforms used to mount various kinds of attacks. Once you understand your target well, look into the capabilities of the tools and platforms already available (the previously mentioned metasploit framework is very thorough and robust). How can they be extended to meet your needs? Once you know that, you can compare the capabilities of the languages. </p>\n\n<p>I would also recommend taking a look at the tools available on the <a href="http://www.remote-exploit.org/backtrack.html" rel="nofollow noreferrer">BackTrack</a> distro.</p>\n'}, {'answer_id': 77717, 'author': 'Aristotle Pagaltzis', 'author_id': 9410, 'author_profile': 'https://Stackoverflow.com/users/9410', 'pm_score': 3, 'selected': False, 'text': '<p>[Disclaimer: I am primarily a Perl programmer, which may be colouring my judgement. However, I am not a particularly tribal one, and I think on this particular question my argument is reasonably objective.]</p>\n\n<p>Perl was designed to blend seamlessly into the Unix landscape, and that is why it feels so alien to people with a mainly-OO background (particularly the Java school of OOP). For that reason, though, it’s incredibly widely installed on machines with any kind of Unixoid OS, and many vendor system utilities are written in it. Also for the same reason, servers that have neither Python nor Ruby installed are still likely to have Perl on them, again making it important to have some familiarity with. So if your CEH activity includes extensive activity on Unix, you will have to have some amount of familiarity with Perl anyway, and you might as well focus on it.</p>\n\n<p>That said, it is largely a matter of preference. There is not much to differentiate the languages; their expressive power is virtually identical. Some things are a little easier in one of the languages, some a little easier in another.</p>\n\n<p>In terms of libraries I do not know how Ruby and Python compare against each other – I do know that Perl has them beat by a margin. Then again, sometimes (particularly when you’re looking for libraries for common needs) the only effect of that is that you get deluged with choices. And if you are only looking to do things in some particular area which is well covered by libraries for Python or Ruby, the mass of <em>other</em> stuff on CPAN isn’t necessarily an advantage. In niche areas, however, it matters, and you never know what unforeseen need you will eventually have (err, by definition).</p>\n\n<p>For one-liner use on the command line, Python is kind of a non-starter.</p>\n\n<p>In terms of interactive interpreter environment, Perl… uhm… well, you can use the debugger, which is not that great, or you can install one from CPAN, but Perl doesn’t ship a good one itself.</p>\n\n<p>So I think Perl does have a very slight edge for your needs in particular, but only just. If you pick Ruby you’ll probably not be much worse off at all. Python might inconvenience you a little more noticeably, but it too is hardly a <em>bad</em> choice.</p>\n'}, {'answer_id': 78103, 'author': 'adrianh', 'author_id': 13165, 'author_profile': 'https://Stackoverflow.com/users/13165', 'pm_score': 2, 'selected': False, 'text': '<p>I could make an argument for all three :-)</p>\n\n<p>Perl has all of CPAN - giving you a huge advantage in pulling together functionality quickly. It also has a nice flexible testing infrastructure that means you can plug lots of different automated testing styles (including tests in other languages) in the same framework.</p>\n\n<p>Ruby is a lovely language to learn - and lacks some of the cruft in Perl 5. If you\'re doing web based testing it also has the watir library - which is trez useful (see <a href="http://wtr.rubyforge.org/" rel="nofollow noreferrer">http://wtr.rubyforge.org/</a>)</p>\n\n<p>Python - nice language and (while it\'s not to my personal preference) some folk find the way its structured easier to get to grips with.</p>\n\n<p>Any of them (and many others) would be a great language to learn.</p>\n\n<p>Instead of looking at the language - I\'d look at your working environment. It\'s always easier to learn stuff if you have other folk around who are doing similar stuff. If you current dev/testing folk are already focussed on one of the above - I\'d go for that. If not, pick the one that would be most applicable/useful to your current working environment. Chat to the rest of your team and see what they think.</p>\n'}, {'answer_id': 78106, 'author': 'QAZ', 'author_id': 14260, 'author_profile': 'https://Stackoverflow.com/users/14260', 'pm_score': 2, 'selected': False, 'text': '<p>If you plan on using Metasploit for pen-testing and exploit development I would recommend ruby as mentioned previously Metasploit is written in ruby and any exploit/module development you may wish to do will require ruby.</p>\n\n<p>If you will be using Immunity CANVAS for pen testing then for the same reasons I would recommend Python as CANVAS is written in python. Also allot of fuzzing frameworks like Peach and Sulley are written in Python.</p>\n\n<p>I would not recommend Perl as you will find very little tools/scripts/frameworks related to pen testing/fuzzing/exploits/... in Perl.</p>\n\n<p>As your question is "tool writing and exploit development" I would recommend Ruby if you choose Metasploit or python if you choose CANVAS.</p>\n\n<p>hope that helps :)</p>\n'}, {'answer_id': 78561, 'author': 'tqbf', 'author_id': 5674, 'author_profile': 'https://Stackoverflow.com/users/5674', 'pm_score': 6, 'selected': True, 'text': '<p>You probably want Ruby, because it\'s the native language for Metasploit, which is the de facto standard open source penetration testing framework. Ruby\'s going to give you:</p>\n\n<ul>\n<li><a href="http://www.metasploit.com/" rel="noreferrer">Metasploit\'s</a> framework, opcode and shellcode databases</li>\n<li>Metasploit\'s <a href="http://rubyforge.org/projects/ruby-lorcon/" rel="noreferrer">Ruby lorcon</a> bindings for raw 802.11 work.</li>\n<li>Metasploit\'s KARMA bindings for 802.11 clientside redirection.</li>\n<li><a href="http://curl.haxx.se/libcurl/ruby/" rel="noreferrer">Libcurl</a> and net/http for web tool writing.</li>\n<li><a href="http://rubyforge.org/projects/eventmachine" rel="noreferrer">EventMachine</a> for web proxy and fuzzing work (or RFuzz, which extends the well-known Mongrel webserver).</li>\n<li><a href="http://metasm.cr0.org/" rel="noreferrer">Metasm</a> for shellcode generation.</li>\n<li><a href="http://www.ragestorm.net/distorm/" rel="noreferrer">Distorm</a> for x86 disassembly.</li>\n<li><a href="http://blogfranz.blogspot.com/2008/01/bindata-for-ruby-fuzzers.html" rel="noreferrer">BinData</a> for binary file format fuzzing.</li>\n</ul>\n\n<p>Second place here goes to Python. There are more pentesting libraries available in Python than in Ruby (but not enough to offset Metasploit). Commercial tools tend to support Python as well --- if you\'re an Immunity CANVAS or CORE Impact customer, you want Python. Python gives you:</p>\n\n<ul>\n<li><a href="http://twistedmatrix.com/trac/" rel="noreferrer">Twisted</a> for network access.</li>\n<li><a href="http://www.openrce.org/downloads/details/208/PaiMei" rel="noreferrer">PaiMei</a> for program tracing and programmable debugging.</li>\n<li>CANVAS and Impact support.</li>\n<li><a href="http://www.matasano.com/log/695/windows-remote-memory-access-though-firewire/" rel="noreferrer">Dornseif\'s</a> firewire libraries for remote debugging.</li>\n<li><a href="http://pydbgeng.sourceforge.net/" rel="noreferrer">Ready integration with WinDbg</a> for remote Windows kernel debugging (there\'s still no good answer in Ruby for kernel debugging, which is why I still occasionally use Python). </li>\n<li><a href="http://peachfuzzer.com/" rel="noreferrer">Peach Fuzzer</a> and Sully for fuzzing.</li>\n<li>SpikeProxy for web penetration testing (also, <a href="http://www.owasp.org/index.php/Category:OWASP_Pantera_Web_Assessment_Studio_Project" rel="noreferrer">OWASP Pantera</a>).</li>\n</ul>\n\n<p>Unsurprisingly, a lot of web work uses Java tools. The de facto standard web pentest tool is Burp Suite, which is a Java swing app. Both Ruby and Python have Java variants you can use to get access to tools like that. Also, both Ruby and Python offer:</p>\n\n<ul>\n<li>Direct integration with libpcap for raw packet work.</li>\n<li>OpenSSL bindings for crypto.</li>\n<li>IDA Pro extensions.</li>\n<li>Mature (or at least reasonable) C foreign function interfaces for API access.</li>\n<li>WxWindows for UI work, and decent web stacks for web UIs.</li>\n</ul>\n\n<p>You\'re not going to go wrong with either language, though for mainstream pentest work, Metasploit probably edges out all the Python benefits, and at present, for x86 reversing work, Python\'s superior debugging interfaces edge out all the Ruby benefits.</p>\n\n<p>Also: it\'s 2008. They\'re not "scripting languages". They\'re programming languages. ;)</p>\n'}, {'answer_id': 3224604, 'author': 'samoz', 'author_id': 39036, 'author_profile': 'https://Stackoverflow.com/users/39036', 'pm_score': 1, 'selected': False, 'text': '<p>If you are interested in CEH, I\'d take a look at <a href="https://rads.stackoverflow.com/amzn/click/com/1593271921" rel="nofollow noreferrer" rel="nofollow noreferrer">Grey Hat Python</a>. It shows some stuff that is pretty interesting and related.</p>\n\n<p>That being said, any language should be fine.</p>\n'}, {'answer_id': 4927367, 'author': 'r3nrut', 'author_id': 373428, 'author_profile': 'https://Stackoverflow.com/users/373428', 'pm_score': 0, 'selected': False, 'text': "<p>I'm with tqbf. I've worked with Python and Ruby. Currently I'm working with JRuby. It has all the power of Ruby with access to the Java libraries so if there is something you absolutely need a low-level language to solve you can do so with a high-level language. So far I haven't needed to really use much Java as Ruby has had the ability to do everything I've needed as an API tester.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76408', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11234/']
|
76,411 |
<p>How can I create a regular expression that will grab delimited text from a string? For example, given a string like </p>
<pre><code>text ###token1### text text ###token2### text text
</code></pre>
<p>I want a regex that will pull out <code>###token1###</code>. Yes, I do want the delimiter as well. By adding another group, I can get both:</p>
<pre><code>(###(.+?)###)
</code></pre>
|
[{'answer_id': 76427, 'author': 'David Beleznay', 'author_id': 13359, 'author_profile': 'https://Stackoverflow.com/users/13359', 'pm_score': 3, 'selected': True, 'text': '<pre><code>/###(.+?)###/\n</code></pre>\n\n<p>if you want the ###\'s then you need</p>\n\n<pre><code>/(###.+?###)/\n</code></pre>\n\n<p>the <strong>?</strong> means non greedy, if you didn\'t have the <strong>?</strong>, then it would grab too much. </p>\n\n<p>e.g. <code>\'###token1### text text ###token2###\'</code> would all get grabbed. </p>\n\n<p>My initial answer had a * instead of a +. * means 0 or more. + means 1 or more. * was wrong because that would allow ###### as a valid thing to find. </p>\n\n<p>For playing around with regular expressions. I highly recommend <a href="http://www.weitz.de/regex-coach/" rel="nofollow noreferrer">http://www.weitz.de/regex-coach/</a> for windows. You can type in the string you want and your regular expression and see what it\'s actually doing. </p>\n\n<p>Your selected text will be stored in \\1 or $1 depending on where you are using your regular expression.</p>\n'}, {'answer_id': 76445, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 0, 'selected': False, 'text': '<p>Assuming you want to match ###token2### as well...</p>\n\n<pre><code>/###.+###/\n</code></pre>\n'}, {'answer_id': 76490, 'author': 'Colen', 'author_id': 13500, 'author_profile': 'https://Stackoverflow.com/users/13500', 'pm_score': 0, 'selected': False, 'text': "<p>Use () and \\x. A naive example that assumes the text within the tokens is always delimited by #:</p>\n\n<pre><code>text (#+.+#+) text text (#+.+#+) text text\n</code></pre>\n\n<p>The stuff in the () can then be grabbed by using \\1 and \\2 (\\1 for the first set, \\2 for the second in the replacement expression (assuming you're doing a search/replace in an editor). For example, the replacement expression could be:</p>\n\n<pre><code>token1: \\1, token2: \\2\n</code></pre>\n\n<p>For the above example, that should produce:</p>\n\n<pre><code>token1: ###token1###, token2: ###token2###\n</code></pre>\n\n<p>If you're using a regexp library in a program, you'd presumably call a function to get at the contents first and second token, which you've indicated with the ()s around them.</p>\n"}, {'answer_id': 76510, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Well when you are using delimiters such as this basically you just grab the first one then anything that does not match the ending delimiter followed by the ending delimiter. A special caution should be that in cases as the example above [^#] would not work as checking to ensure the end delimiter is not there since a singe # would cause the regex to fail (ie. "###foo#bar###). In the case above the regex to parse it would be the following assuming empty tokens are allowed (if not, change * to +):</p>\n\n<p>###([^#]|#[^#]|##[^#])*###</p>\n'}, {'answer_id': 76519, 'author': 'Michael Cramer', 'author_id': 1496728, 'author_profile': 'https://Stackoverflow.com/users/1496728', 'pm_score': 1, 'selected': False, 'text': '<p>In Perl, you actually want something like this:</p>\n\n<pre><code>$text = \'text ###token1### text text ###token2### text text\';\n\nwhile($text =~ m/###(.+?)###/g) {\n print $1, "\\n";\n}\n</code></pre>\n\n<p>Which will give you each token in turn within the while loop. The (.*?) ensures that you get the <em>shortest</em> bit between the delimiters, preventing it from thinking the token is \'token1### text text ###token2\'.</p>\n\n<p>Or, if you just want to save them, not loop immediately:</p>\n\n<pre><code>@tokens = $text =~ m/###(.+?)###/g;\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76411', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/410/']
|
76,412 |
<p>When developing WPF UserControls, what is the best way to expose a DependencyProperty of a child control as a DependencyProperty of the UserControl? The following example shows how I would currently expose the Text property of a TextBox inside a UserControl. Surely there is a better / simpler way to accomplish this?</p>
<pre class="lang-xml prettyprint-override"><code> <UserControl x:Class="WpfApplication3.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Background="LightCyan">
<TextBox Margin="8" Text="{Binding Text, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
</StackPanel>
</UserControl>
</code></pre>
<pre class="lang-cs prettyprint-override"><code> using System;
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication3
{
public partial class UserControl1 : UserControl
{
public static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UserControl1), new PropertyMetadata(null));
public string Text
{
get { return GetValue(TextProperty) as string; }
set { SetValue(TextProperty, value); }
}
public UserControl1() { InitializeComponent(); }
}
}
</code></pre>
|
[{'answer_id': 77094, 'author': 'user7116', 'author_id': 7116, 'author_profile': 'https://Stackoverflow.com/users/7116', 'pm_score': 5, 'selected': True, 'text': '<p>That is how we\'re doing it in our team, without the RelativeSource search, rather by naming the UserControl and referencing properties by the UserControl\'s name.</p>\n\n<pre><code><UserControl x:Class="WpfApplication3.UserControl1" x:Name="UserControl1"\n xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\n xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">\n <StackPanel Background="LightCyan">\n <TextBox Margin="8" Text="{Binding Path=Text, ElementName=UserControl1}" />\n </StackPanel>\n</UserControl>\n</code></pre>\n\n<p>Sometimes we\'ve found ourselves making too many things UserControl\'s though, and have often times scaled back our usage. I\'d also follow the tradition of naming things like that textbox along the lines of PART_TextDisplay or something, so that in the future you could template it out yet keep the code-behind the same.</p>\n'}, {'answer_id': 1995911, 'author': 'Lessneek', 'author_id': 240947, 'author_profile': 'https://Stackoverflow.com/users/240947', 'pm_score': 1, 'selected': False, 'text': '<p>You can set DataContext to this in UserControl\'s constructor, then just bind by only path.</p>\n\n<p>CS:</p>\n\n<pre><code>DataContext = this;\n</code></pre>\n\n<p>XAML:</p>\n\n<pre><code><TextBox Margin="8" Text="{Binding Text} />\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76412', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/317/']
|
76,424 |
<p>XmlElement.Attributes.Remove* methods are working fine for arbitrary attributes resulting in the removed attributes being removed from XmlDocument.OuterXml property. Xmlns attribute however is different. Here is an example:</p>
<pre><code>XmlDocument doc = new XmlDocument();
doc.InnerXml = @"<Element1 attr1=""value1"" xmlns=""http://mynamespace.com/"" attr2=""value2""/>";
doc.DocumentElement.Attributes.RemoveNamedItem("attr2");
Console.WriteLine("xmlns attr before removal={0}", doc.DocumentElement.Attributes["xmlns"]);
doc.DocumentElement.Attributes.RemoveNamedItem("xmlns");
Console.WriteLine("xmlns attr after removal={0}", doc.DocumentElement.Attributes["xmlns"]);
</code></pre>
<p>The resulting output is</p>
<pre><code>xmlns attr before removal=System.Xml.XmlAttribute
xmlns attr after removal=
<Element1 attr1="value1" xmlns="http://mynamespace.com/" />
</code></pre>
<p>The attribute seems to be removed from the Attributes collection, but it is not removed from XmlDocument.OuterXml.
I guess it is because of the special meaning of this attribute.</p>
<p>The question is how to remove the xmlns attribute using .NET XML API.
Obviously I can just remove the attribute from a String representation of this, but I wonder if it is possible to do the same thing using the API.</p>
<p>@Edit: I'm talking about .NET 2.0.</p>
|
[{'answer_id': 76513, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Yes, because its an ELEMENT name, you can't explicitly remove it. Using XmlTextWriter's WriteStartElement and WirteStartAttribute, and replacing the attribute with empty spaces will likely to get the job done. </p>\n\n<p>I'm checking it out now. will update.</p>\n"}, {'answer_id': 76716, 'author': 'MatthieuGD', 'author_id': 3109, 'author_profile': 'https://Stackoverflow.com/users/3109', 'pm_score': 0, 'selected': False, 'text': '<p>Maybe trough the XmlNamespaceManager ? <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.removenamespace.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.removenamespace.aspx</a> but it\'s just a guess.</p>\n'}, {'answer_id': 76929, 'author': 'GregK', 'author_id': 8653, 'author_profile': 'https://Stackoverflow.com/users/8653', 'pm_score': 3, 'selected': True, 'text': '<p>.NET DOM API doesn\'t support modifying element\'s namespace which is what you are essentially trying to do. So, in order to solve your problem you have to construct a new document one way or another. You can use the same .NET DOM API and create a new element without specifying its namespace. Alternatively, you can create an XSLT stylesheet that transforms your original "namespaced" document to a new one in which the elements will be not namespace-qualified.</p>\n'}, {'answer_id': 77502, 'author': 'Vin', 'author_id': 1747, 'author_profile': 'https://Stackoverflow.com/users/1747', 'pm_score': 2, 'selected': False, 'text': '<p>Wasn\'t this supposed to remove namespaces?</p>\n\n<pre><code>XmlNamespaceManager mgr = new XmlNamespaceManager("xmlnametable");\nmgr.RemoveNamespace("prefix", "uri");\n</code></pre>\n\n<p>But anyway on a tangent here, the XElement, XDocument and <a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xnamespace.aspx" rel="nofollow noreferrer">XNameSpace</a> classes from System.Xml.Linq namespace (.Net 3.0) are a better lot than the old XmlDocument model. Give it a go. I am addicted.</p>\n'}, {'answer_id': 974586, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>We can convert the xml to a string, remove the xmlns from that string, and then create another XmlDocument using this string, which will not have the namespace.</p>\n'}, {'answer_id': 1875023, 'author': 'ALI SHAH', 'author_id': 228093, 'author_profile': 'https://Stackoverflow.com/users/228093', 'pm_score': 2, 'selected': False, 'text': '<p>I saw the various options in this thread and come to solve my own solution for removing xmlns attributes in xml. This is working properly and has no issues:</p>\n\n<pre><code>\'Remove the Equifax / Transunian / Experian root node attribute that have xmlns and load xml without xmlns attributes.\nIf objXMLDom.DocumentElement.NamespaceURI <> String.Empty Then\n objXMLDom.LoadXml(objXMLDom.OuterXml.Replace(objXMLDom.DocumentElement.NamespaceURI, ""))\n objXMLDom.DocumentElement.RemoveAllAttributes()\n ResponseXML = objXMLDom.OuterXml\nEnd If\n</code></pre>\n\n<p>There is no need to do anything else to remove xmlns from xml.</p>\n'}, {'answer_id': 2251621, 'author': 'Matt Harris', 'author_id': 271817, 'author_profile': 'https://Stackoverflow.com/users/271817', 'pm_score': 2, 'selected': False, 'text': '<p>Many thanks to Ali Shah, this thread solved my problem perfectly!\nhere\'s a C# conversion:</p>\n\n<pre><code>var dom = new XmlDocument();\n dom.Load("C:/ExampleFITrade.xml));\n var loaded = new XDocument();\n if (dom.DocumentElement != null)\n if( dom.DocumentElement.NamespaceURI != String.Empty)\n {\n dom.LoadXml(dom.OuterXml.Replace(dom.DocumentElement.NamespaceURI, ""));\n dom.DocumentElement.RemoveAllAttributes();\n loaded = XDocument.Parse(dom.OuterXml);\n }\n</code></pre>\n'}, {'answer_id': 14287546, 'author': 'pcmaniak', 'author_id': 1971348, 'author_profile': 'https://Stackoverflow.com/users/1971348', 'pm_score': 1, 'selected': False, 'text': '<pre><code>public static string RemoveXmlns(string xml)\n{\n //Prepare a reader\n StringReader stringReader = new StringReader(xml);\n XmlTextReader xmlReader = new XmlTextReader(stringReader);\n xmlReader.Namespaces = false; //A trick to handle special xmlns attributes as regular\n //Build DOM\n XmlDocument xmlDocument = new XmlDocument();\n xmlDocument.Load(xmlReader);\n //Do the job\n xmlDocument.DocumentElement.RemoveAttribute("xmlns"); \n //Prepare a writer\n StringWriter stringWriter = new StringWriter();\n XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);\n //Optional: Make an output nice ;)\n xmlWriter.Formatting = Formatting.Indented;\n xmlWriter.IndentChar = \' \';\n xmlWriter.Indentation = 2;\n //Build output\n xmlDocument.Save(xmlWriter);\n return stringWriter.ToString();\n}\n</code></pre>\n'}, {'answer_id': 29321085, 'author': 'Rodrigo Serzedello', 'author_id': 2053300, 'author_profile': 'https://Stackoverflow.com/users/2053300', 'pm_score': 0, 'selected': False, 'text': '<p>here is my solution on vb.net guys!</p>\n\n<pre><code> Dim pathXmlTransformado As String = "C:\\Fisconet4\\process\\11790941000192\\2015\\3\\28\\38387-1\\38387_transformado.xml"\n Dim nfeXML As New XmlDocument\n Dim loaded As New XDocument\n\n nfeXML.Load(pathXmlTransformado)\n\n nfeXML.LoadXml(nfeXML.OuterXml.Replace(nfeXML.DocumentElement.NamespaceURI, ""))\n nfeXML.DocumentElement.RemoveAllAttributes()\n\n Dim dhCont As XmlNode = nfeXML.CreateElement("dhCont")\n Dim xJust As XmlNode = nfeXML.CreateElement("xJust")\n dhCont.InnerXml = 123\n xJust.InnerXml = 123777\n\n nfeXML.GetElementsByTagName("ide")(0).AppendChild(dhCont)\n nfeXML.GetElementsByTagName("ide")(0).AppendChild(xJust)\n\n nfeXML.Save("C:\\Fisconet4\\process\\11790941000192\\2015\\3\\28\\38387-1\\teste.xml")\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76424', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/578/']
|
76,440 |
<p>As developers and as professional engineers have you been exposed to the tenants of Extreme Programming as defined in the "version 1" by Kent Beck.
Which of those 12 core principles do you feel you have been either allowed to practice or at least be a part of in your current job or others?</p>
<pre><code>* Pair programming[5]
* Planning game
* Test driven development
* Whole team (being empowered to deliver)
* Continuous integration
* Refactoring or design improvement
* Small releases
* Coding standards
* Collective code ownership
* Simple design
* System metaphor
* Sustainable pace
</code></pre>
<p>From an engineers point of view I feel that the main engineering principles of XP arevastly superior to anything else I have been involved in. What is your opinion?</p>
|
[{'answer_id': 76543, 'author': 'pmlarocque', 'author_id': 7419, 'author_profile': 'https://Stackoverflow.com/users/7419', 'pm_score': 1, 'selected': False, 'text': '<p>I consider myself lucky, all except "Pair programming" we can do it, but only to solve big issues not on a day-to-day basis. "Collective code ownership" is hard to achieve as well, not doing pair programming we tend to keep the logical next user stories from iteration to iteration.</p>\n'}, {'answer_id': 76580, 'author': 'Yaba', 'author_id': 7524, 'author_profile': 'https://Stackoverflow.com/users/7524', 'pm_score': 2, 'selected': False, 'text': "<p>We are following these practices you've mentioned:</p>\n\n<ul>\n<li>Planning game</li>\n<li>Test driven development</li>\n<li>Whole team (being empowered to\ndeliver)</li>\n<li>Continuous integration</li>\n<li>Refactoring or design improvement</li>\n<li>Small releases</li>\n<li>Coding standards</li>\n<li>Collective code ownership</li>\n<li>Simple design</li>\n</ul>\n\n<p>And I must say that after one year I can't imagine working differently.</p>\n\n<p>As for Pair programming I must say that it makes sense in certain areas, where there is a very high difficult area or where an initial good design is essential (e.g. designing interfaces). However I don't consider this as very effective. In my opinion it is better to perform code and design reviews of smaller parts, where Pair programming would have made sense.</p>\n\n<p>As for the 'Whole team' practice I must admit that it has suffered as our team grew. It simply made the planning sessions too long, when everybody can give his personal inputs. Currently a core team is preparing the planning game by doing some initial, rough planning.</p>\n"}, {'answer_id': 77096, 'author': 'gbjbaanb', 'author_id': 13744, 'author_profile': 'https://Stackoverflow.com/users/13744', 'pm_score': 0, 'selected': False, 'text': "<ul>\n<li>Whole team (being empowered to deliver)</li>\n<li>Small releases</li>\n<li>Coding standards</li>\n<li>Collective code ownership</li>\n</ul>\n\n<p>But then, I do work in a mission-critical development team that's quite conservative. I don't necessarily thing XP is a good way to develop, you must find a way that's right for you and ignore the dogma.</p>\n"}, {'answer_id': 92758, 'author': 'Mike Reedell', 'author_id': 4897, 'author_profile': 'https://Stackoverflow.com/users/4897', 'pm_score': 0, 'selected': False, 'text': "<p>We've done everything except small releases and it's been great. I can't imagine working any other way. From my experience, the tenets I value most are:</p>\n\n<ul>\n<li>Continuous integration (with a solid test suite).</li>\n<li>Collective code ownership.</li>\n<li>TDD</li>\n<li>Team empowerment and decision making.</li>\n<li>Coding standards.</li>\n<li>Refactoring.</li>\n<li>Sustainable pace.</li>\n</ul>\n\n<p>The rest are very nice to have too, but I've found that I can live w/o pairing so long as we have TDD, collective ownership, and refactoring.</p>\n"}, {'answer_id': 36414324, 'author': 'Art Solano', 'author_id': 2321690, 'author_profile': 'https://Stackoverflow.com/users/2321690', 'pm_score': 0, 'selected': False, 'text': "<ul>\n<li>Pair programming[5]</li>\n</ul>\n\n<p>It is hard to convince management of this aspect. But I have found this is doable when an engineer gets stuck or we have an engineer who is new to a technology or effort.</p>\n\n<ul>\n<li>Planning game</li>\n</ul>\n\n<p>Yes.</p>\n\n<ul>\n<li>Test driven development</li>\n</ul>\n\n<p>Easy sell to management. However the hard part of some management is adding in more time. A lot of managers believe that Extreme and Agile programming will save them time. They don't save time to deliver you something. In fact, the testing constant requirements gathering adds effort. What it does do, is it gets the customer what they want faster.</p>\n\n<ul>\n<li>Whole team (being empowered to deliver)</li>\n</ul>\n\n<p>Definitely, this is an amazing facet to Xtreme.</p>\n\n<ul>\n<li>Continuous integration</li>\n</ul>\n\n<p>At the end of each iteration (sprint) full integration occurs. Daily full integration does not occur.</p>\n\n<ul>\n<li>Refactoring or design improvement</li>\n</ul>\n\n<p>Your first effort is rarely the best. So yes, I find Xtreme constantly yields better and better solutions.</p>\n\n<ul>\n<li>Small releases</li>\n</ul>\n\n<p>I find that given the infrastructure and resources that can lengthen the suggested length of an iteration of 1 or 2 weeks. A lot of this depends on where you are deploying to. If you system is being deployed to a production environment, formal systems and stress testing can add a lot of overhead. So in this environment, we go with iterations lasting a month or even 2 months. If the system is being deployed to a development area and has not been deployed to production, even something as tight as an iteration lasting 1 day can be doable.</p>\n\n<ul>\n<li>Coding standards</li>\n</ul>\n\n<p>Pair programming for new team members can promote this. Code reviews also can help here. A lot of this depends on how long you have been working with each other.</p>\n\n<ul>\n<li>Collective code ownership</li>\n</ul>\n\n<p>I haven't found that Xtreme really helps here. Everyone naturally falls into certain areas of the code base. So people get ownership of things they spend a lot of time with. This can actually be a good driver as good software engineers will take pride in what ever they write this way.</p>\n\n<ul>\n<li>Simple design</li>\n</ul>\n\n<p>Short iteration cycles do in fact promote a simple design. It needs to be maintainable for the short releases.</p>\n\n<ul>\n<li>System metaphor</li>\n</ul>\n\n<p>Not sure what is meant here?</p>\n\n<ul>\n<li>Sustainable pace</li>\n</ul>\n\n<p>Velocity of a team is a task that can only be acutely estimated with proper metrics. Metrics need to be kept on task estimates and task completions durations. </p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76440', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,455 |
<p>In C#.NET I am trying to programmatically change the color of the border in a group box.</p>
<p>Update: This question was asked when I was working on a winforms system before we switched to .NET.</p>
|
[{'answer_id': 5629954, 'author': 'swajak', 'author_id': 100258, 'author_profile': 'https://Stackoverflow.com/users/100258', 'pm_score': 1, 'selected': False, 'text': "<p>I'm not sure this applies to every case, but thanks to this thread, we quickly hooked into the Paint event programmatically using:</p>\n\n<pre><code>GroupBox box = new GroupBox();\n[...]\nbox.Paint += delegate(object o, PaintEventArgs p)\n{\n p.Graphics.Clear(someColorHere);\n};\n</code></pre>\n\n<p>Cheers!</p>\n"}, {'answer_id': 5827166, 'author': 'Mick Bruno', 'author_id': 730366, 'author_profile': 'https://Stackoverflow.com/users/730366', 'pm_score': 6, 'selected': True, 'text': '<p>Building on the previous answer, a better solution that includes the label for the group box:</p>\n\n<pre><code>groupBox1.Paint += PaintBorderlessGroupBox;\n\nprivate void PaintBorderlessGroupBox(object sender, PaintEventArgs p)\n{\n GroupBox box = (GroupBox)sender;\n p.Graphics.Clear(SystemColors.Control);\n p.Graphics.DrawString(box.Text, box.Font, Brushes.Black, 0, 0);\n}\n</code></pre>\n\n<p>You might want to adjust the x/y for the text, but for my use this is just right.</p>\n'}, {'answer_id': 13653500, 'author': 'Andy', 'author_id': 1867592, 'author_profile': 'https://Stackoverflow.com/users/1867592', 'pm_score': 3, 'selected': False, 'text': '<p>Just set the paint action on any object (not just buttons) to this method to draw a border.</p>\n\n<pre><code> private void UserControl1_Paint(object sender, PaintEventArgs e)\n {\n ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);\n\n }\n</code></pre>\n\n<p>It still wont be pretty and rounded like the original, but it is much simpler.</p>\n'}, {'answer_id': 20042058, 'author': 'user1944617', 'author_id': 1944617, 'author_profile': 'https://Stackoverflow.com/users/1944617', 'pm_score': 5, 'selected': False, 'text': '<p>Just add paint event.</p>\n\n<pre><code> private void groupBox1_Paint(object sender, PaintEventArgs e)\n {\n GroupBox box = sender as GroupBox;\n DrawGroupBox(box, e.Graphics, Color.Red, Color.Blue);\n }\n\n\n private void DrawGroupBox(GroupBox box, Graphics g, Color textColor, Color borderColor)\n {\n if (box != null)\n {\n Brush textBrush = new SolidBrush(textColor);\n Brush borderBrush = new SolidBrush(borderColor);\n Pen borderPen = new Pen(borderBrush);\n SizeF strSize = g.MeasureString(box.Text, box.Font);\n Rectangle rect = new Rectangle(box.ClientRectangle.X,\n box.ClientRectangle.Y + (int)(strSize.Height / 2),\n box.ClientRectangle.Width - 1,\n box.ClientRectangle.Height - (int)(strSize.Height / 2) - 1);\n\n // Clear text and border\n g.Clear(this.BackColor);\n\n // Draw text\n g.DrawString(box.Text, box.Font, textBrush, box.Padding.Left, 0);\n\n // Drawing Border\n //Left\n g.DrawLine(borderPen, rect.Location, new Point(rect.X, rect.Y + rect.Height));\n //Right\n g.DrawLine(borderPen, new Point(rect.X + rect.Width, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height));\n //Bottom\n g.DrawLine(borderPen, new Point(rect.X, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y + rect.Height));\n //Top1\n g.DrawLine(borderPen, new Point(rect.X, rect.Y), new Point(rect.X + box.Padding.Left, rect.Y));\n //Top2\n g.DrawLine(borderPen, new Point(rect.X + box.Padding.Left + (int)(strSize.Width), rect.Y), new Point(rect.X + rect.Width, rect.Y));\n }\n }\n</code></pre>\n'}, {'answer_id': 50451872, 'author': 'George', 'author_id': 5077953, 'author_profile': 'https://Stackoverflow.com/users/5077953', 'pm_score': 1, 'selected': False, 'text': '<p>I have achieved same border with something which might be simpler to understand for newbies: </p>\n\n<pre><code> private void groupSchitaCentru_Paint(object sender, PaintEventArgs e)\n {\n Pen blackPen = new Pen(Color.Black, 2);\n Point pointTopLeft = new Point(0, 7);\n Point pointBottomLeft = new Point(0, groupSchitaCentru.ClientRectangle.Height);\n Point pointTopRight = new Point(groupSchitaCentru.ClientRectangle.Width, 7);\n Point pointBottomRight = new Point(groupSchitaCentru.ClientRectangle.Width, groupSchitaCentru.ClientRectangle.Height);\n\n e.Graphics.DrawLine(blackPen, pointTopLeft, pointBottomLeft);\n e.Graphics.DrawLine(blackPen, pointTopLeft, pointTopRight);\n e.Graphics.DrawLine(blackPen, pointBottomRight, pointTopRight);\n e.Graphics.DrawLine(blackPen, pointBottomLeft, pointBottomRight);\n }\n</code></pre>\n\n<ol>\n<li>Set the Paint event on the GroupBox control. In this example the name of my control is "groupSchitaCentru". One needs this event because of its parameter e.</li>\n<li>Set up a pen object by making use of the System.Drawing.Pen class : <a href="https://msdn.microsoft.com/en-us/library/f956fzw1(v=vs.110).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/f956fzw1(v=vs.110).aspx</a></li>\n<li>Set the points which represent the corners of the rectangle represented by the control. Used the property ClientRectangle of the the control to get its dimensions.\nI used for TopLeft (0,7) because I want to respect the borders of the control, and draw the line about the its text.\nTo get more information about the coordinates system walk here : <a href="https://learn.microsoft.com/en-us/dotnet/framework/winforms/windows-forms-coordinates" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/dotnet/framework/winforms/windows-forms-coordinates</a></li>\n</ol>\n\n<p>I do not know, may be it helps someone looking to achieve this border adjustment thing.</p>\n'}, {'answer_id': 51663475, 'author': 'NetXpert', 'author_id': 1542024, 'author_profile': 'https://Stackoverflow.com/users/1542024', 'pm_score': 3, 'selected': False, 'text': '<p>FWIW, this is the implementation I used. It\'s a child of GroupBox but allows setting not only the BorderColor, but also the thickness of the border and the radius of the rounded corners. Also, you can set the amount of indent you want for the GroupBox label, and using a negative indent indents from the right side.</p>\n\n<pre><code>using System;\nusing System.Drawing;\nusing System.Windows.Forms;\n\nnamespace BorderedGroupBox\n{\n public class BorderedGroupBox : GroupBox\n {\n private Color _borderColor = Color.Black;\n private int _borderWidth = 2;\n private int _borderRadius = 5;\n private int _textIndent = 10;\n\n public BorderedGroupBox() : base()\n {\n InitializeComponent();\n this.Paint += this.BorderedGroupBox_Paint;\n }\n\n public BorderedGroupBox(int width, float radius, Color color) : base()\n {\n this._borderWidth = Math.Max(1,width);\n this._borderColor = color;\n this._borderRadius = Math.Max(0,radius);\n InitializeComponent();\n this.Paint += this.BorderedGroupBox_Paint;\n }\n\n public Color BorderColor\n {\n get => this._borderColor;\n set\n {\n this._borderColor = value;\n DrawGroupBox();\n }\n }\n\n public int BorderWidth\n {\n get => this._borderWidth;\n set\n {\n if (value > 0)\n {\n this._borderWidth = Math.Min(value, 10);\n DrawGroupBox();\n }\n }\n }\n\n public int BorderRadius\n {\n get => this._borderRadius;\n set\n { // Setting a radius of 0 produces square corners...\n if (value >= 0)\n {\n this._borderRadius = value;\n this.DrawGroupBox();\n }\n }\n }\n\n public int LabelIndent\n {\n get => this._textIndent;\n set\n {\n this._textIndent = value;\n this.DrawGroupBox();\n }\n }\n\n private void BorderedGroupBox_Paint(object sender, PaintEventArgs e) =>\n DrawGroupBox(e.Graphics);\n\n private void DrawGroupBox() =>\n this.DrawGroupBox(this.CreateGraphics());\n\n private void DrawGroupBox(Graphics g)\n {\n Brush textBrush = new SolidBrush(this.ForeColor);\n SizeF strSize = g.MeasureString(this.Text, this.Font);\n\n Brush borderBrush = new SolidBrush(this.BorderColor);\n Pen borderPen = new Pen(borderBrush,(float)this._borderWidth);\n Rectangle rect = new Rectangle(this.ClientRectangle.X,\n this.ClientRectangle.Y + (int)(strSize.Height / 2),\n this.ClientRectangle.Width - 1,\n this.ClientRectangle.Height - (int)(strSize.Height / 2) - 1);\n\n Brush labelBrush = new SolidBrush(this.BackColor);\n\n // Clear text and border\n g.Clear(this.BackColor);\n\n // Drawing Border (added "Fix" from Jim Fell, Oct 6, \'18)\n int rectX = (0 == this._borderWidth % 2) ? rect.X + this._borderWidth / 2 : rect.X + 1 + this._borderWidth / 2;\n int rectHeight = (0 == this._borderWidth % 2) ? rect.Height - this._borderWidth / 2 : rect.Height - 1 - this._borderWidth / 2;\n // NOTE DIFFERENCE: rectX vs rect.X and rectHeight vs rect.Height\n g.DrawRoundedRectangle(borderPen, rectX, rect.Y, rect.Width, rectHeight, (float)this._borderRadius);\n\n // Draw text\n if (this.Text.Length > 0)\n {\n // Do some work to ensure we don\'t put the label outside\n // of the box, regardless of what value is assigned to the Indent:\n int width = (int)rect.Width, posX;\n posX = (this._textIndent < 0) ? Math.Max(0-width,this._textIndent) : Math.Min(width, this._textIndent);\n posX = (posX < 0) ? rect.Width + posX - (int)strSize.Width : posX;\n g.FillRectangle(labelBrush, posX, 0, strSize.Width, strSize.Height);\n g.DrawString(this.Text, this.Font, textBrush, posX, 0);\n }\n }\n\n #region Component Designer generated code\n /// <summary>Required designer variable.</summary>\n private System.ComponentModel.IContainer components = null;\n\n /// <summary>Clean up any resources being used.</summary>\n /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>\n protected override void Dispose(bool disposing)\n {\n if (disposing && (components != null))\n components.Dispose();\n\n base.Dispose(disposing);\n }\n\n /// <summary>Required method for Designer support - Don\'t modify!</summary>\n private void InitializeComponent() => components = new System.ComponentModel.Container();\n #endregion\n }\n}\n</code></pre>\n\n<p>To make it work, you also have to extend the base Graphics class (Note: this is derived from some code I found on here once when I was trying to create a rounded-corners Panel control, but I can\'t find the original post to link here):</p>\n\n<pre><code>static class GraphicsExtension\n{\n private static GraphicsPath GenerateRoundedRectangle(\n this Graphics graphics,\n RectangleF rectangle,\n float radius)\n {\n float diameter;\n GraphicsPath path = new GraphicsPath();\n if (radius <= 0.0F)\n {\n path.AddRectangle(rectangle);\n path.CloseFigure();\n return path;\n }\n else\n {\n if (radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 2.0)\n return graphics.GenerateCapsule(rectangle);\n diameter = radius * 2.0F;\n SizeF sizeF = new SizeF(diameter, diameter);\n RectangleF arc = new RectangleF(rectangle.Location, sizeF);\n path.AddArc(arc, 180, 90);\n arc.X = rectangle.Right - diameter;\n path.AddArc(arc, 270, 90);\n arc.Y = rectangle.Bottom - diameter;\n path.AddArc(arc, 0, 90);\n arc.X = rectangle.Left;\n path.AddArc(arc, 90, 90);\n path.CloseFigure();\n }\n return path;\n }\n\n private static GraphicsPath GenerateCapsule(\n this Graphics graphics,\n RectangleF baseRect)\n {\n float diameter;\n RectangleF arc;\n GraphicsPath path = new GraphicsPath();\n try\n {\n if (baseRect.Width > baseRect.Height)\n {\n diameter = baseRect.Height;\n SizeF sizeF = new SizeF(diameter, diameter);\n arc = new RectangleF(baseRect.Location, sizeF);\n path.AddArc(arc, 90, 180);\n arc.X = baseRect.Right - diameter;\n path.AddArc(arc, 270, 180);\n }\n else if (baseRect.Width < baseRect.Height)\n {\n diameter = baseRect.Width;\n SizeF sizeF = new SizeF(diameter, diameter);\n arc = new RectangleF(baseRect.Location, sizeF);\n path.AddArc(arc, 180, 180);\n arc.Y = baseRect.Bottom - diameter;\n path.AddArc(arc, 0, 180);\n }\n else path.AddEllipse(baseRect);\n }\n catch { path.AddEllipse(baseRect); }\n finally { path.CloseFigure(); }\n return path;\n }\n\n /// <summary>\n /// Draws a rounded rectangle specified by a pair of coordinates, a width, a height and the radius\n /// for the arcs that make the rounded edges.\n /// </summary>\n /// <param name="brush">System.Drawing.Pen that determines the color, width and style of the rectangle.</param>\n /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to draw.</param>\n /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to draw.</param>\n /// <param name="width">Width of the rectangle to draw.</param>\n /// <param name="height">Height of the rectangle to draw.</param>\n /// <param name="radius">The radius of the arc used for the rounded edges.</param>\n public static void DrawRoundedRectangle(\n this Graphics graphics,\n Pen pen,\n float x,\n float y,\n float width,\n float height,\n float radius)\n {\n RectangleF rectangle = new RectangleF(x, y, width, height);\n GraphicsPath path = graphics.GenerateRoundedRectangle(rectangle, radius);\n SmoothingMode old = graphics.SmoothingMode;\n graphics.SmoothingMode = SmoothingMode.AntiAlias;\n graphics.DrawPath(pen, path);\n graphics.SmoothingMode = old;\n }\n\n /// <summary>\n /// Draws a rounded rectangle specified by a pair of coordinates, a width, a height and the radius\n /// for the arcs that make the rounded edges.\n /// </summary>\n /// <param name="brush">System.Drawing.Pen that determines the color, width and style of the rectangle.</param>\n /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to draw.</param>\n /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to draw.</param>\n /// <param name="width">Width of the rectangle to draw.</param>\n /// <param name="height">Height of the rectangle to draw.</param>\n /// <param name="radius">The radius of the arc used for the rounded edges.</param>\n\n public static void DrawRoundedRectangle(\n this Graphics graphics,\n Pen pen,\n int x,\n int y,\n int width,\n int height,\n int radius)\n {\n graphics.DrawRoundedRectangle(\n pen,\n Convert.ToSingle(x),\n Convert.ToSingle(y),\n Convert.ToSingle(width),\n Convert.ToSingle(height),\n Convert.ToSingle(radius));\n }\n}\n</code></pre>\n'}, {'answer_id': 68691524, 'author': 'compound eye', 'author_id': 133507, 'author_profile': 'https://Stackoverflow.com/users/133507', 'pm_score': 0, 'selected': False, 'text': "<p>This tweak to Jim Fell's code placed the borders a little better for me, but it's too long to add as a comment</p>\n<p>...</p>\n<pre><code> Rectangle rect = new Rectangle(this.ClientRectangle.X,\n this.ClientRectangle.Y + (int)(strSize.Height / 2),\n this.ClientRectangle.Width,\n this.ClientRectangle.Height - (int)(strSize.Height / 2));\n\n Brush labelBrush = new SolidBrush(this.BackColor);\n\n // Clear text and border\n g.Clear(this.BackColor);\n\n\n int drawX = rect.X;\n int drawY = rect.Y;\n int drawWidth = rect.Width;\n int drawHeight = rect.Height;\n\n if (this._borderWidth > 0)\n {\n drawX += this._borderWidth / 2;\n drawY += this._borderWidth / 2;\n\n drawWidth -= this._borderWidth;\n drawHeight -= this._borderWidth;\n \n if (this._borderWidth % 2 == 0)\n {\n drawX -= 1;\n drawWidth += 1;\n\n drawY -= 1;\n drawHeight += 1;\n }\n }\n\n g.DrawRoundedRectangle(borderPen, drawX, drawY, drawWidth, drawHeight, (float)this._borderRadius);\n</code></pre>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76455', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/300930/']
|
76,464 |
<p>I'd like to create a module in DNN that, similar to the Announcements control, offers a template that the portal admin can modify for formatting. I have a control that currently uses a Repeater control with templates. Is there a way to override the contents of the repeater ItemTemplate, HeaderTemplate, and FooterTemplate properties? </p>
|
[{'answer_id': 5629954, 'author': 'swajak', 'author_id': 100258, 'author_profile': 'https://Stackoverflow.com/users/100258', 'pm_score': 1, 'selected': False, 'text': "<p>I'm not sure this applies to every case, but thanks to this thread, we quickly hooked into the Paint event programmatically using:</p>\n\n<pre><code>GroupBox box = new GroupBox();\n[...]\nbox.Paint += delegate(object o, PaintEventArgs p)\n{\n p.Graphics.Clear(someColorHere);\n};\n</code></pre>\n\n<p>Cheers!</p>\n"}, {'answer_id': 5827166, 'author': 'Mick Bruno', 'author_id': 730366, 'author_profile': 'https://Stackoverflow.com/users/730366', 'pm_score': 6, 'selected': True, 'text': '<p>Building on the previous answer, a better solution that includes the label for the group box:</p>\n\n<pre><code>groupBox1.Paint += PaintBorderlessGroupBox;\n\nprivate void PaintBorderlessGroupBox(object sender, PaintEventArgs p)\n{\n GroupBox box = (GroupBox)sender;\n p.Graphics.Clear(SystemColors.Control);\n p.Graphics.DrawString(box.Text, box.Font, Brushes.Black, 0, 0);\n}\n</code></pre>\n\n<p>You might want to adjust the x/y for the text, but for my use this is just right.</p>\n'}, {'answer_id': 13653500, 'author': 'Andy', 'author_id': 1867592, 'author_profile': 'https://Stackoverflow.com/users/1867592', 'pm_score': 3, 'selected': False, 'text': '<p>Just set the paint action on any object (not just buttons) to this method to draw a border.</p>\n\n<pre><code> private void UserControl1_Paint(object sender, PaintEventArgs e)\n {\n ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);\n\n }\n</code></pre>\n\n<p>It still wont be pretty and rounded like the original, but it is much simpler.</p>\n'}, {'answer_id': 20042058, 'author': 'user1944617', 'author_id': 1944617, 'author_profile': 'https://Stackoverflow.com/users/1944617', 'pm_score': 5, 'selected': False, 'text': '<p>Just add paint event.</p>\n\n<pre><code> private void groupBox1_Paint(object sender, PaintEventArgs e)\n {\n GroupBox box = sender as GroupBox;\n DrawGroupBox(box, e.Graphics, Color.Red, Color.Blue);\n }\n\n\n private void DrawGroupBox(GroupBox box, Graphics g, Color textColor, Color borderColor)\n {\n if (box != null)\n {\n Brush textBrush = new SolidBrush(textColor);\n Brush borderBrush = new SolidBrush(borderColor);\n Pen borderPen = new Pen(borderBrush);\n SizeF strSize = g.MeasureString(box.Text, box.Font);\n Rectangle rect = new Rectangle(box.ClientRectangle.X,\n box.ClientRectangle.Y + (int)(strSize.Height / 2),\n box.ClientRectangle.Width - 1,\n box.ClientRectangle.Height - (int)(strSize.Height / 2) - 1);\n\n // Clear text and border\n g.Clear(this.BackColor);\n\n // Draw text\n g.DrawString(box.Text, box.Font, textBrush, box.Padding.Left, 0);\n\n // Drawing Border\n //Left\n g.DrawLine(borderPen, rect.Location, new Point(rect.X, rect.Y + rect.Height));\n //Right\n g.DrawLine(borderPen, new Point(rect.X + rect.Width, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height));\n //Bottom\n g.DrawLine(borderPen, new Point(rect.X, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y + rect.Height));\n //Top1\n g.DrawLine(borderPen, new Point(rect.X, rect.Y), new Point(rect.X + box.Padding.Left, rect.Y));\n //Top2\n g.DrawLine(borderPen, new Point(rect.X + box.Padding.Left + (int)(strSize.Width), rect.Y), new Point(rect.X + rect.Width, rect.Y));\n }\n }\n</code></pre>\n'}, {'answer_id': 50451872, 'author': 'George', 'author_id': 5077953, 'author_profile': 'https://Stackoverflow.com/users/5077953', 'pm_score': 1, 'selected': False, 'text': '<p>I have achieved same border with something which might be simpler to understand for newbies: </p>\n\n<pre><code> private void groupSchitaCentru_Paint(object sender, PaintEventArgs e)\n {\n Pen blackPen = new Pen(Color.Black, 2);\n Point pointTopLeft = new Point(0, 7);\n Point pointBottomLeft = new Point(0, groupSchitaCentru.ClientRectangle.Height);\n Point pointTopRight = new Point(groupSchitaCentru.ClientRectangle.Width, 7);\n Point pointBottomRight = new Point(groupSchitaCentru.ClientRectangle.Width, groupSchitaCentru.ClientRectangle.Height);\n\n e.Graphics.DrawLine(blackPen, pointTopLeft, pointBottomLeft);\n e.Graphics.DrawLine(blackPen, pointTopLeft, pointTopRight);\n e.Graphics.DrawLine(blackPen, pointBottomRight, pointTopRight);\n e.Graphics.DrawLine(blackPen, pointBottomLeft, pointBottomRight);\n }\n</code></pre>\n\n<ol>\n<li>Set the Paint event on the GroupBox control. In this example the name of my control is "groupSchitaCentru". One needs this event because of its parameter e.</li>\n<li>Set up a pen object by making use of the System.Drawing.Pen class : <a href="https://msdn.microsoft.com/en-us/library/f956fzw1(v=vs.110).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/f956fzw1(v=vs.110).aspx</a></li>\n<li>Set the points which represent the corners of the rectangle represented by the control. Used the property ClientRectangle of the the control to get its dimensions.\nI used for TopLeft (0,7) because I want to respect the borders of the control, and draw the line about the its text.\nTo get more information about the coordinates system walk here : <a href="https://learn.microsoft.com/en-us/dotnet/framework/winforms/windows-forms-coordinates" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/dotnet/framework/winforms/windows-forms-coordinates</a></li>\n</ol>\n\n<p>I do not know, may be it helps someone looking to achieve this border adjustment thing.</p>\n'}, {'answer_id': 51663475, 'author': 'NetXpert', 'author_id': 1542024, 'author_profile': 'https://Stackoverflow.com/users/1542024', 'pm_score': 3, 'selected': False, 'text': '<p>FWIW, this is the implementation I used. It\'s a child of GroupBox but allows setting not only the BorderColor, but also the thickness of the border and the radius of the rounded corners. Also, you can set the amount of indent you want for the GroupBox label, and using a negative indent indents from the right side.</p>\n\n<pre><code>using System;\nusing System.Drawing;\nusing System.Windows.Forms;\n\nnamespace BorderedGroupBox\n{\n public class BorderedGroupBox : GroupBox\n {\n private Color _borderColor = Color.Black;\n private int _borderWidth = 2;\n private int _borderRadius = 5;\n private int _textIndent = 10;\n\n public BorderedGroupBox() : base()\n {\n InitializeComponent();\n this.Paint += this.BorderedGroupBox_Paint;\n }\n\n public BorderedGroupBox(int width, float radius, Color color) : base()\n {\n this._borderWidth = Math.Max(1,width);\n this._borderColor = color;\n this._borderRadius = Math.Max(0,radius);\n InitializeComponent();\n this.Paint += this.BorderedGroupBox_Paint;\n }\n\n public Color BorderColor\n {\n get => this._borderColor;\n set\n {\n this._borderColor = value;\n DrawGroupBox();\n }\n }\n\n public int BorderWidth\n {\n get => this._borderWidth;\n set\n {\n if (value > 0)\n {\n this._borderWidth = Math.Min(value, 10);\n DrawGroupBox();\n }\n }\n }\n\n public int BorderRadius\n {\n get => this._borderRadius;\n set\n { // Setting a radius of 0 produces square corners...\n if (value >= 0)\n {\n this._borderRadius = value;\n this.DrawGroupBox();\n }\n }\n }\n\n public int LabelIndent\n {\n get => this._textIndent;\n set\n {\n this._textIndent = value;\n this.DrawGroupBox();\n }\n }\n\n private void BorderedGroupBox_Paint(object sender, PaintEventArgs e) =>\n DrawGroupBox(e.Graphics);\n\n private void DrawGroupBox() =>\n this.DrawGroupBox(this.CreateGraphics());\n\n private void DrawGroupBox(Graphics g)\n {\n Brush textBrush = new SolidBrush(this.ForeColor);\n SizeF strSize = g.MeasureString(this.Text, this.Font);\n\n Brush borderBrush = new SolidBrush(this.BorderColor);\n Pen borderPen = new Pen(borderBrush,(float)this._borderWidth);\n Rectangle rect = new Rectangle(this.ClientRectangle.X,\n this.ClientRectangle.Y + (int)(strSize.Height / 2),\n this.ClientRectangle.Width - 1,\n this.ClientRectangle.Height - (int)(strSize.Height / 2) - 1);\n\n Brush labelBrush = new SolidBrush(this.BackColor);\n\n // Clear text and border\n g.Clear(this.BackColor);\n\n // Drawing Border (added "Fix" from Jim Fell, Oct 6, \'18)\n int rectX = (0 == this._borderWidth % 2) ? rect.X + this._borderWidth / 2 : rect.X + 1 + this._borderWidth / 2;\n int rectHeight = (0 == this._borderWidth % 2) ? rect.Height - this._borderWidth / 2 : rect.Height - 1 - this._borderWidth / 2;\n // NOTE DIFFERENCE: rectX vs rect.X and rectHeight vs rect.Height\n g.DrawRoundedRectangle(borderPen, rectX, rect.Y, rect.Width, rectHeight, (float)this._borderRadius);\n\n // Draw text\n if (this.Text.Length > 0)\n {\n // Do some work to ensure we don\'t put the label outside\n // of the box, regardless of what value is assigned to the Indent:\n int width = (int)rect.Width, posX;\n posX = (this._textIndent < 0) ? Math.Max(0-width,this._textIndent) : Math.Min(width, this._textIndent);\n posX = (posX < 0) ? rect.Width + posX - (int)strSize.Width : posX;\n g.FillRectangle(labelBrush, posX, 0, strSize.Width, strSize.Height);\n g.DrawString(this.Text, this.Font, textBrush, posX, 0);\n }\n }\n\n #region Component Designer generated code\n /// <summary>Required designer variable.</summary>\n private System.ComponentModel.IContainer components = null;\n\n /// <summary>Clean up any resources being used.</summary>\n /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>\n protected override void Dispose(bool disposing)\n {\n if (disposing && (components != null))\n components.Dispose();\n\n base.Dispose(disposing);\n }\n\n /// <summary>Required method for Designer support - Don\'t modify!</summary>\n private void InitializeComponent() => components = new System.ComponentModel.Container();\n #endregion\n }\n}\n</code></pre>\n\n<p>To make it work, you also have to extend the base Graphics class (Note: this is derived from some code I found on here once when I was trying to create a rounded-corners Panel control, but I can\'t find the original post to link here):</p>\n\n<pre><code>static class GraphicsExtension\n{\n private static GraphicsPath GenerateRoundedRectangle(\n this Graphics graphics,\n RectangleF rectangle,\n float radius)\n {\n float diameter;\n GraphicsPath path = new GraphicsPath();\n if (radius <= 0.0F)\n {\n path.AddRectangle(rectangle);\n path.CloseFigure();\n return path;\n }\n else\n {\n if (radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 2.0)\n return graphics.GenerateCapsule(rectangle);\n diameter = radius * 2.0F;\n SizeF sizeF = new SizeF(diameter, diameter);\n RectangleF arc = new RectangleF(rectangle.Location, sizeF);\n path.AddArc(arc, 180, 90);\n arc.X = rectangle.Right - diameter;\n path.AddArc(arc, 270, 90);\n arc.Y = rectangle.Bottom - diameter;\n path.AddArc(arc, 0, 90);\n arc.X = rectangle.Left;\n path.AddArc(arc, 90, 90);\n path.CloseFigure();\n }\n return path;\n }\n\n private static GraphicsPath GenerateCapsule(\n this Graphics graphics,\n RectangleF baseRect)\n {\n float diameter;\n RectangleF arc;\n GraphicsPath path = new GraphicsPath();\n try\n {\n if (baseRect.Width > baseRect.Height)\n {\n diameter = baseRect.Height;\n SizeF sizeF = new SizeF(diameter, diameter);\n arc = new RectangleF(baseRect.Location, sizeF);\n path.AddArc(arc, 90, 180);\n arc.X = baseRect.Right - diameter;\n path.AddArc(arc, 270, 180);\n }\n else if (baseRect.Width < baseRect.Height)\n {\n diameter = baseRect.Width;\n SizeF sizeF = new SizeF(diameter, diameter);\n arc = new RectangleF(baseRect.Location, sizeF);\n path.AddArc(arc, 180, 180);\n arc.Y = baseRect.Bottom - diameter;\n path.AddArc(arc, 0, 180);\n }\n else path.AddEllipse(baseRect);\n }\n catch { path.AddEllipse(baseRect); }\n finally { path.CloseFigure(); }\n return path;\n }\n\n /// <summary>\n /// Draws a rounded rectangle specified by a pair of coordinates, a width, a height and the radius\n /// for the arcs that make the rounded edges.\n /// </summary>\n /// <param name="brush">System.Drawing.Pen that determines the color, width and style of the rectangle.</param>\n /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to draw.</param>\n /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to draw.</param>\n /// <param name="width">Width of the rectangle to draw.</param>\n /// <param name="height">Height of the rectangle to draw.</param>\n /// <param name="radius">The radius of the arc used for the rounded edges.</param>\n public static void DrawRoundedRectangle(\n this Graphics graphics,\n Pen pen,\n float x,\n float y,\n float width,\n float height,\n float radius)\n {\n RectangleF rectangle = new RectangleF(x, y, width, height);\n GraphicsPath path = graphics.GenerateRoundedRectangle(rectangle, radius);\n SmoothingMode old = graphics.SmoothingMode;\n graphics.SmoothingMode = SmoothingMode.AntiAlias;\n graphics.DrawPath(pen, path);\n graphics.SmoothingMode = old;\n }\n\n /// <summary>\n /// Draws a rounded rectangle specified by a pair of coordinates, a width, a height and the radius\n /// for the arcs that make the rounded edges.\n /// </summary>\n /// <param name="brush">System.Drawing.Pen that determines the color, width and style of the rectangle.</param>\n /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to draw.</param>\n /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to draw.</param>\n /// <param name="width">Width of the rectangle to draw.</param>\n /// <param name="height">Height of the rectangle to draw.</param>\n /// <param name="radius">The radius of the arc used for the rounded edges.</param>\n\n public static void DrawRoundedRectangle(\n this Graphics graphics,\n Pen pen,\n int x,\n int y,\n int width,\n int height,\n int radius)\n {\n graphics.DrawRoundedRectangle(\n pen,\n Convert.ToSingle(x),\n Convert.ToSingle(y),\n Convert.ToSingle(width),\n Convert.ToSingle(height),\n Convert.ToSingle(radius));\n }\n}\n</code></pre>\n'}, {'answer_id': 68691524, 'author': 'compound eye', 'author_id': 133507, 'author_profile': 'https://Stackoverflow.com/users/133507', 'pm_score': 0, 'selected': False, 'text': "<p>This tweak to Jim Fell's code placed the borders a little better for me, but it's too long to add as a comment</p>\n<p>...</p>\n<pre><code> Rectangle rect = new Rectangle(this.ClientRectangle.X,\n this.ClientRectangle.Y + (int)(strSize.Height / 2),\n this.ClientRectangle.Width,\n this.ClientRectangle.Height - (int)(strSize.Height / 2));\n\n Brush labelBrush = new SolidBrush(this.BackColor);\n\n // Clear text and border\n g.Clear(this.BackColor);\n\n\n int drawX = rect.X;\n int drawY = rect.Y;\n int drawWidth = rect.Width;\n int drawHeight = rect.Height;\n\n if (this._borderWidth > 0)\n {\n drawX += this._borderWidth / 2;\n drawY += this._borderWidth / 2;\n\n drawWidth -= this._borderWidth;\n drawHeight -= this._borderWidth;\n \n if (this._borderWidth % 2 == 0)\n {\n drawX -= 1;\n drawWidth += 1;\n\n drawY -= 1;\n drawHeight += 1;\n }\n }\n\n g.DrawRoundedRectangle(borderPen, drawX, drawY, drawWidth, drawHeight, (float)this._borderRadius);\n</code></pre>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76464', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13100/']
|
76,472 |
<p>Is there a way in Ruby to find the version of a file, specifically a .dll file?</p>
|
[{'answer_id': 76554, 'author': 'cynicalman', 'author_id': 410, 'author_profile': 'https://Stackoverflow.com/users/410', 'pm_score': 1, 'selected': False, 'text': "<p>For any file, you'd need to discover what format the file is in, and then open the file and read the necessary bytes to find out what version the file is. There is no API or common method to determine a file version in Ruby.</p>\n\n<p>Note that it would be easier if the file version were in the file name.</p>\n"}, {'answer_id': 76768, 'author': 'Erik', 'author_id': 13623, 'author_profile': 'https://Stackoverflow.com/users/13623', 'pm_score': 2, 'selected': False, 'text': '<p>If you are working on the Microsoft platform, you should be able to use the Win32 API in Ruby to call GetFileVersionInfo(), which will return the information you\'re looking for.\n<a href="http://msdn.microsoft.com/en-us/library/ms647003.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms647003.aspx</a></p>\n'}, {'answer_id': 77447, 'author': 'AShelly', 'author_id': 10396, 'author_profile': 'https://Stackoverflow.com/users/10396', 'pm_score': 4, 'selected': False, 'text': '<p>For Windows EXE\'s and DLL\'s:</p>\n\n<pre><code>require "Win32API"\nFILENAME = "c:/ruby/bin/ruby.exe" #your filename here\ns=""\nvsize=Win32API.new(\'version.dll\', \'GetFileVersionInfoSize\', \n [\'P\', \'P\'], \'L\').call(FILENAME, s)\np vsize\nif (vsize > 0)\n result = \' \'*vsize\n Win32API.new(\'version.dll\', \'GetFileVersionInfo\', \n [\'P\', \'L\', \'L\', \'P\'], \'L\').call(FILENAME, 0, vsize, result)\n rstring = result.unpack(\'v*\').map{|s| s.chr if s<256}*\'\'\n r = /FileVersion..(.*?)\\000/.match(rstring)\n puts "FileVersion = #{r ? r[1] : \'??\' }"\nelse\n puts "No Version Info"\nend\n</code></pre>\n\n<p>The \'unpack\'+regexp part is a hack, the "proper" way is the VerQueryValue API, but this should work for most files. (probably fails miserably on extended character sets.)</p>\n'}, {'answer_id': 142578, 'author': 'Tom Lahti', 'author_id': 22902, 'author_profile': 'https://Stackoverflow.com/users/22902', 'pm_score': 3, 'selected': False, 'text': '<p>What if you want to get the version info with ruby, but the ruby code isn\'t running on Windows? </p>\n\n<p>The following does just that (heeding the same extended charset warning):</p>\n\n<pre><code>#!/usr/bin/ruby\n\ns = File.read(ARGV[0])\nx = s.match(/F\\0i\\0l\\0e\\0V\\0e\\0r\\0s\\0i\\0o\\0n\\0*(.*?)\\0\\0\\0/)\n\nif x.class == MatchData\n ver=x[1].gsub(/\\0/,"")\nelse\n ver="No version"\nend\n\nputs ver\n</code></pre>\n'}, {'answer_id': 17068756, 'author': 'Pete', 'author_id': 131887, 'author_profile': 'https://Stackoverflow.com/users/131887', 'pm_score': 2, 'selected': False, 'text': '<p>As of Ruby 2.0, the <code>DL</code> module is deprecated. Here is an updated version of AShelly\'s answer, using <a href="http://www.ruby-doc.org/stdlib-2.0/libdoc/fiddle/rdoc/Fiddle.html" rel="nofollow">Fiddle</a>:</p>\n\n<pre><code>version_dll = Fiddle.dlopen(\'version.dll\')\n\ns=\'\'\nvsize = Fiddle::Function.new(version_dll[\'GetFileVersionInfoSize\'],\n [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],\n Fiddle::TYPE_LONG).call(filename, s)\n\nraise \'Unable to determine the version number\' unless vsize > 0\n\nresult = \' \'*vsize\nFiddle::Function.new(version_dll[\'GetFileVersionInfo\'],\n [Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG,\n Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP],\n Fiddle::TYPE_VOIDP).call(filename, 0, vsize, result)\n\nrstring = result.unpack(\'v*\').map{|s| s.chr if s<256}*\'\'\nr = /FileVersion..(.*?)\\000/.match(rstring)\n\nputs r[1]\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76472', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,482 |
<p>I have a file saved as UCS-2 Little Endian I want to change the encoding so I ran the following code:</p>
<pre><code>cat tmp.log -encoding UTF8 > new.log
</code></pre>
<p>The resulting file is still in UCS-2 Little Endian. Is this because the pipeline is always in that format? Is there an easy way to pipe this to a new file as UTF8?</p>
|
[{'answer_id': 76734, 'author': 'driis', 'author_id': 13627, 'author_profile': 'https://Stackoverflow.com/users/13627', 'pm_score': 5, 'selected': False, 'text': '<p>I would do it like this:</p>\n\n<pre><code>get-content tmp.log -encoding Unicode | set-content new.log -encoding UTF8\n</code></pre>\n\n<p>My understanding is that the -encoding option selects the encdoing that the file should be read or written in.</p>\n'}, {'answer_id': 76808, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 7, 'selected': True, 'text': '<p>As suggested <a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64937">here</a>:</p>\n\n<pre><code>Get-Content tmp.log | Out-File -Encoding UTF8 new.log\n</code></pre>\n'}, {'answer_id': 24057859, 'author': 'user572730', 'author_id': 572730, 'author_profile': 'https://Stackoverflow.com/users/572730', 'pm_score': 3, 'selected': False, 'text': '<p>load content from xml file with encoding.</p>\n\n<p>(Get-Content -Encoding UTF8 $fileName)</p>\n'}, {'answer_id': 31521946, 'author': 'sba923', 'author_id': 1808955, 'author_profile': 'https://Stackoverflow.com/users/1808955', 'pm_score': 1, 'selected': False, 'text': "<p>If you are reading an XML file, here's an even better way that adapts to the encoding of your XML file:</p>\n\n<pre><code>$xml = New-Object -Typename XML\n$xml.load('foo.xml')\n</code></pre>\n"}, {'answer_id': 67678498, 'author': 'Geordie', 'author_id': 796634, 'author_profile': 'https://Stackoverflow.com/users/796634', 'pm_score': 0, 'selected': False, 'text': '<p>PowerShell\'s get-content/set-content encoding flag doesn\'t handle all encoding types. You may need to use IO.File, for example to load a file using Windows-1252:</p>\n<pre><code>$myString = [IO.File]::ReadAllText($filePath, [Text.Encoding]::GetEncoding(1252))\n</code></pre>\n<p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding?view=net-5.0" rel="nofollow noreferrer">Text.Encoding::GetEncoding</a>\n<a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencodings?view=net-5.0" rel="nofollow noreferrer">Text.Encoding::GetEncodings</a></p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76482', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2582/']
|
76,484 |
<p>I have the handle of process 'A' on a Pocket PC 2003 device. I need to determine if that process is still running from process 'B'. Process 'B' is written in Embedded Visual C++ 4.0.</p>
|
[{'answer_id': 76828, 'author': 'Peter Ritchie', 'author_id': 5620, 'author_profile': 'https://Stackoverflow.com/users/5620', 'pm_score': 2, 'selected': True, 'text': '<p>GetExitCodeProcess will return STILL_ACTIVE if the process was running when the function was called.</p>\n'}, {'answer_id': 78739, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 0, 'selected': False, 'text': '<p>Process handles are waitable. They are signalled - will release any waiting thread - when the process exits. You can use them with WaitForSingleObject, WaitForMultipleObjects, etc.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76484', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3619/']
|
76,488 |
<p>Can't find anything relevant about Entity Framework/MySQL on Google so I'm hoping someone knows about it.</p>
|
[{'answer_id': 76682, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 3, 'selected': False, 'text': '<p>You would need a mapping provider for MySQL. That is an extra thing the Entity Framework needs to make the magic happen. <a href="http://blogs.msdn.com/adonet/" rel="noreferrer">This blog</a> talks about other mapping providers besides the one Microsoft is supplying. I haven\'t found any mentionings of MySQL.</p>\n'}, {'answer_id': 145819, 'author': 'Sir Code-A-Lot', 'author_id': 13148, 'author_profile': 'https://Stackoverflow.com/users/13148', 'pm_score': 3, 'selected': False, 'text': '<p>MySQL is hosting a webinar about EF in a few days... \nLook here: <a href="http://www.mysql.com/news-and-events/web-seminars/display-204.html" rel="noreferrer">http://www.mysql.com/news-and-events/web-seminars/display-204.html</a></p>\n\n<p><strong>edit:</strong> That webinar is now at <a href="http://www.mysql.com/news-and-events/on-demand-webinars/display-od-204.html" rel="noreferrer">http://www.mysql.com/news-and-events/on-demand-webinars/display-od-204.html</a></p>\n'}, {'answer_id': 679792, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>This isn\'t about MS and what they want. They have created an *open system for others to plug-in \'providers\' - postgres and sqlite have it - mysql is just laggin... but, good news for those interested, i too was looking for this and found that the MySql Connector/Net 6.0 will have it... you can check it out here: </p>\n\n<p><a href="http://www.upfromthesky.com/blog/post/2009/03/24/MySql-Supports-the-Entity-Framework.aspx" rel="noreferrer">http://www.upfromthesky.com/blog/post/2009/03/24/MySql-Supports-the-Entity-Framework.aspx</a></p>\n'}, {'answer_id': 712428, 'author': 'pattersonc', 'author_id': 82130, 'author_profile': 'https://Stackoverflow.com/users/82130', 'pm_score': 4, 'selected': False, 'text': '<p>Check out my post on this subject. </p>\n\n<p><a href="http://pattersonc.com/blog/index.php/2009/04/01/using-mysql-with-entity-framework-and-aspnet-mvc-%e2%80%93-part-i/" rel="noreferrer">http://pattersonc.com/blog/index.php/2009/04/01/using-mysql-with-entity-framework-and-aspnet-mvc-–-part-i/</a></p>\n'}, {'answer_id': 848539, 'author': 'Vin', 'author_id': 1747, 'author_profile': 'https://Stackoverflow.com/users/1747', 'pm_score': 8, 'selected': False, 'text': '<p>It\'s been released - Get the <a href="http://www.mysql.com/downloads/connector/net" rel="noreferrer">MySQL connector for .Net v6.5</a> - this has support for\n [Entity Framework]</p>\n\n<p>I was waiting for this the whole time, although the support is basic, works for most basic scenarios of db interaction. It also has basic Visual Studio integration.</p>\n\n<p><strong>UPDATE</strong>\n<a href="http://dev.mysql.com/downloads/connector/net/" rel="noreferrer">http://dev.mysql.com/downloads/connector/net/</a>\nStarting with version 6.7, Connector/Net will no longer include the MySQL for Visual Studio integration. That functionality is now available in a separate product called MySQL for Visual Studio available using the MySQL Installer for Windows (see <a href="http://dev.mysql.com/tech-resources/articles/mysql-installer-for-windows.html" rel="noreferrer">http://dev.mysql.com/tech-resources/articles/mysql-installer-for-windows.html</a>).</p>\n'}, {'answer_id': 1687051, 'author': 'aaimnr', 'author_id': 26444, 'author_profile': 'https://Stackoverflow.com/users/26444', 'pm_score': 2, 'selected': False, 'text': '<p>Vintana,</p>\n\n<p>Od course there\'s something ready now. <a href="http://www.devart.com/products.html" rel="nofollow noreferrer">http://www.devart.com/products.html</a> - it\'s commercial although (you have a 30days trial IIRC). They make a living writing providers, so I guess it should be fast and stable. I know really big companies using their Oracle provider instead of Orace and MS ones.</p>\n'}, {'answer_id': 3240257, 'author': 'Brian Frantz', 'author_id': 5117026, 'author_profile': 'https://Stackoverflow.com/users/5117026', 'pm_score': 0, 'selected': False, 'text': '<p>I didn\'t see the link here, but there\'s a beta .NET Connector for MySql. Click "Development Releases" to download 6.3.2 beta, which has EF4/VS2010 integration:</p>\n\n<p><a href="http://dev.mysql.com/downloads/connector/net/5.0.html#downloads" rel="nofollow noreferrer">http://dev.mysql.com/downloads/connector/net/5.0.html#downloads</a></p>\n'}, {'answer_id': 6241515, 'author': 'scotru', 'author_id': 298677, 'author_profile': 'https://Stackoverflow.com/users/298677', 'pm_score': 1, 'selected': False, 'text': '<p>You might also look at <a href="https://www.devart.com/dotconnect/mysql/" rel="nofollow noreferrer">https://www.devart.com/dotconnect/mysql/</a></p>\n\n<p>DevArt\'s connector supports EF and MySQL.</p>\n'}, {'answer_id': 16254132, 'author': 'oware', 'author_id': 1322781, 'author_profile': 'https://Stackoverflow.com/users/1322781', 'pm_score': 1, 'selected': False, 'text': "<p>Be careful using connector .net, Connector 6.6.5 have a bug, it is not working for inserting tinyint values as identity, for example:</p>\n\n<pre><code>create table person(\n Id tinyint unsigned primary key auto_increment,\n Name varchar(30)\n);\n</code></pre>\n\n<p>if you try to insert an object like this:</p>\n\n<pre><code>Person p;\np = new Person();\np.Name = 'Oware'\ncontext.Person.Add(p);\ncontext.SaveChanges();\n</code></pre>\n\n<p>You will get a Null Reference Exception:</p>\n\n<pre><code>Referencia a objeto no establecida como instancia de un objeto.:\n en MySql.Data.Entity.ListFragment.WriteSql(StringBuilder sql)\n en MySql.Data.Entity.SelectStatement.WriteSql(StringBuilder sql)\n en MySql.Data.Entity.InsertStatement.WriteSql(StringBuilder sql)\n en MySql.Data.Entity.SqlFragment.ToString()\n en MySql.Data.Entity.InsertGenerator.GenerateSQL(DbCommandTree tree)\n en MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)\n en System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)\n en System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)\n en System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)\n en System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)\n en System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)\n en System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)\n en System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)\n en System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)\n en System.Data.Entity.Internal.InternalContext.SaveChanges()\n en System.Data.Entity.Internal.LazyInternalContext.SaveChanges()\n en System.Data.Entity.DbContext.SaveChanges()\n</code></pre>\n\n<p>Until now I haven't found a solution, I had to change my tinyint identity to unsigned int identity, this solved the problem but this is not the right solution.</p>\n\n<p>If you use an older version of Connector.net (I used 6.4.4) you won't have this problem.</p>\n\n<p>If someone knows about the solution, please contact me.</p>\n\n<p>Cheers!</p>\n\n<p>Oware</p>\n"}, {'answer_id': 29487854, 'author': 'Igor Yalovoy', 'author_id': 790465, 'author_profile': 'https://Stackoverflow.com/users/790465', 'pm_score': 0, 'selected': False, 'text': '<p>If you interested in running Entity Framework with MySql on mono/linux/macos, this might be helpful \n<a href="https://iyalovoi.wordpress.com/2015/04/06/entity-framework-with-mysql-on-mac-os/" rel="nofollow">https://iyalovoi.wordpress.com/2015/04/06/entity-framework-with-mysql-on-mac-os/</a></p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76488', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13594/']
|
76,522 |
<p>We make infrastructure services (data retrieval and storage) and small smart client applications (fancy reporting mostly) for a commercial bank. Our team is large, 40 odd contractual employees that are C# .NET programmers. We support 50 odd applications and systems that we have developed. </p>
<p>A few members of the team began making <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation" rel="nofollow noreferrer">WPF</a>, <a href="http://en.wikipedia.org/wiki/Windows_Workflow_Foundation" rel="nofollow noreferrer">WF</a> and <a href="http://en.wikipedia.org/wiki/Windows_Communication_Foundation" rel="nofollow noreferrer">WCF</a> based applications. Given that they are the first, most members do not understand these technologies. What benefits do they convey that would overcome the cost of retraining the team?</p>
|
[{'answer_id': 76575, 'author': 'Loren Segal', 'author_id': 6436, 'author_profile': 'https://Stackoverflow.com/users/6436', 'pm_score': 5, 'selected': True, 'text': "<p>WPF UI's are easier to design implement and maintain than the current C# alternatives, so if a lot of your codebase is responsible for handling UI, migrating may serve beneficial-- as in, you'll find your team will save time in dealing with their UI layer. If most of your code is business logic, it won't help all that much. </p>\n"}, {'answer_id': 76619, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': '<p>I think the key word from your original question is "fancy". If your customers really expect a lot of glitter in the deliverable, then you probably do have something to gain from switching to WPF.</p>\n'}, {'answer_id': 76725, 'author': 'kitsune', 'author_id': 13466, 'author_profile': 'https://Stackoverflow.com/users/13466', 'pm_score': 0, 'selected': False, 'text': "<p>I was not sure at first, most applications seemed to be pretty laggy (granted, WinForms isn't lightning fast either). This seems to be fixed with .NET 3.5 SP1 where they integrated hardware acceleration for a number of techniques.</p>\n\n<p>The integrated animation / storyboard / vector capabilities are very nice and a step into the right direction. If you get a grip of Expression Blend, you will be able to prototype apps pretty quickly. These are clear benefits in my opinion.</p>\n\n<p>In the long run, I don't think WinForms and older techniques are a sustainable choice.</p>\n\n<p>There's also Adobe Flex, Adobe/Macromedia have experience in more powerful and 'exciting' GUI solutions because of their experience with Flash.</p>\n\n<p>I just hope we don't end up with 10 different VM's installed on a desktop pc just to run all those different frameworks...</p>\n\n<p>re: </p>\n\n<blockquote>\n <p>fancy reporting</p>\n</blockquote>\n\n<p>fanciness is probably one of WPF's strengths...</p>\n"}, {'answer_id': 76816, 'author': 'cranley', 'author_id': 10308, 'author_profile': 'https://Stackoverflow.com/users/10308', 'pm_score': 5, 'selected': False, 'text': '<p>We are just wrapping up a project in which myself and 4 others developed a rather successful, distributed enterprise application. We started using Win32 and then switched to WPF after the first iteration to meet the demands of our usability expert. Here is my experience.</p>\n\n<p>WPF has some really, really great features. In general, it makes the really hard things trivial (such as creating listboxes that show rich presentation data, such as images mixed with tables, copy, etc.), but in turn can make the "this used to be so easy in Win32" painfully frustrating. I\'ve been working in WPF for 6 months now, and I still find databinding a combobox to an XML dataprovider a dreaded experience.</p>\n\n<p>As I eluded to above, WPF has some great and not-so-great binding. I love how you can bind to an XML document or inline-fragment using <a href="http://en.wikipedia.org/wiki/XPath" rel="nofollow noreferrer">XPath</a>, but I hate how you can only use the built-in binding validations if your binding is two-way (and I doubly hate how you can\'t force the built-in binding validations to pass user input back to the object, even if the data falls outside the range of some business rule).</p>\n\n<p>WPF has a huge learning curve. It\'s not even a curve - it\'s a wall. It\'s a rough go. It\'s a completely different way of working with Windows presentation, and, for me anyways, it required a lot of reading and playing before I started to feel somewhat comfortable. It\'s not the easiest thing in the world, but it allows you to do some incredibly powerful stuff (e.g. In our project I created a form engine that creates full fledged XAML forms from XML using about 300 lines of <a href="http://en.wikipedia.org/wiki/XSLT" rel="nofollow noreferrer">XSLT</a> - complete with full binding and validation).</p>\n\n<p>Overall, I\'m extremely satisfied that we chose XAML, despite the learning curve, the somewhat buggy nature of it all, and some of the deep frustrations. The positives have far outweighed the negatives and it allowed us to do things I didn\'t think were possible without an enormously heavy hit to performance.</p>\n\n<p>If you decide to go the route of WPF, I would highly recommend these 2 books:</p>\n\n<ul>\n<li><p>Windows Presentation Foundation Unleashed, by Adam Nathan is a great intro, with full colour! It reads like a blog and gives you a great great intro - <a href="http://www.amazon.ca/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917/ref=pd_ys_iyr3" rel="nofollow noreferrer">http://www.amazon.ca/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917/ref=pd_ys_iyr3</a></p></li>\n<li><p>Programming WPF: Building Windows Ui with Windows Presentation Foundation, by Chris Sells. More detail and a great book to accompany the WPF Unleashed - <a href="http://www.amazon.co.uk/Programming-WPF-Building-Presentation-Foundation/dp/0596510373" rel="nofollow noreferrer">http://www.amazon.co.uk/Programming-WPF-Building-Presentation-Foundation/dp/0596510373</a></p></li>\n</ul>\n\n<p>Good luck!</p>\n'}, {'answer_id': 77490, 'author': 'Anders Rune Jensen', 'author_id': 13995, 'author_profile': 'https://Stackoverflow.com/users/13995', 'pm_score': 0, 'selected': False, 'text': '<p>WPF is a very fresh approach to designing UIs. The only problem is that it introduces a large amount of concepts, some of those only to hide the verboseness of XAML (XML). It also suffers a little from an <a href="http://www.joelonsoftware.com/articles/fog0000000018.html" rel="nofollow noreferrer">architecture astronaut</a> approach to the design but overall I\'m pretty happy with it. It makes things that you before would have said no way to, into something that is manageable to do.</p>\n'}, {'answer_id': 79171, 'author': 'AndyL', 'author_id': 9944, 'author_profile': 'https://Stackoverflow.com/users/9944', 'pm_score': 4, 'selected': False, 'text': '<p>WPF enables you to do some amazing things, and I LOVE it... but I always feel obligated to qualify my recommendations, whenever developers ask me whether I think they should be moving to the new technology.</p>\n\n<p>Are your developers willing (preferably, EAGER) to spend the time it takes to learn to use WPF effectively? I never would have thought to say this about MFC, or Windows Forms, or even unmanaged DirectX, but you probably do NOT want a team trying to "pick up" WPF over the course of a normal dev. cycle for a shipping product!</p>\n\n<p>Do at least one or two of your developers have some design sensibilities, and do individuals with final design authority have a decent understanding of development issues, so you can leverage WPF capabilities to create something which is actually BETTER, instead of just more "colorful", featuring gratuitous animation?</p>\n\n<p>Does some percentage of your target customer base run on integrated graphics chip sets that might not support the features you were planning -- or are they still running Windows 2000, which would eliminate them as customers altogether? Some people would also ask whether your customers actually CARE about enhanced visuals but, having lived through internal company "Our business customers don\'t care about colors and pictures" debates in the early 1990s, I know that well-designed solutions from your competitors will MAKE them care, and the real question is whether the conditions are right, to enable you to offer something that will make them care NOW.</p>\n\n<p>Does the project involve grounds-up development, at least for the presentation layer, to avoid the additional complexity of trying to hook into incompatible legacy scaffolding (Interoperability with Windows Forms is NOT seamless)?</p>\n\n<p>Can your manager accept (or be distracted from noticing) a significant DROP in developer productivity for four to six months?</p>\n\n<p>This last issue is due to what I like to think of as the "FizzBin" nature of WPF, with ten different ways to implement any task, and no apparent reason to prefer one approach to another, and little guidance available to help you make a choice. Not only will the shortcomings of whatever choice you make become clear only much later in the project, but you are virtually guaranteed to have every developer on your project adopting a different approach, resulting in a major maintenance headache. Most frustrating of all are the inconsistencies that constantly trip you up, as you try to learn the framework.</p>\n\n<p>You can find more in-depth WPF-related information in an entry on my blog:</p>\n\n<p><a href="http://missedmemo.com/blog/2008/09/13/WPFTheFizzBinAPI.aspx" rel="nofollow noreferrer">http://missedmemo.com/blog/2008/09/13/WPFTheFizzBinAPI.aspx</a></p>\n'}, {'answer_id': 81975, 'author': 'Hallgrim', 'author_id': 15454, 'author_profile': 'https://Stackoverflow.com/users/15454', 'pm_score': 2, 'selected': False, 'text': '<p>WPF is radically different from Windows Forms. This means a lot of training for your team.</p>\n'}, {'answer_id': 531146, 'author': 'helifreak', 'author_id': 52565, 'author_profile': 'https://Stackoverflow.com/users/52565', 'pm_score': 2, 'selected': False, 'text': '<p>WPF:</p>\n\n<ul>\n<li>Is all about graphics!</li>\n<li>Is a resolution independent framework (meaning - WPF has fully adopted the concept of vector graphics - and has also made the scaling of bitmap graphics a thoughtless process) </li>\n<li>Is hardware accelerated!!!! WPF graphics are hardware accelerated where possible through <a href="http://en.wikipedia.org/wiki/Microsoft_Direct3D" rel="nofollow noreferrer">Direct3D</a> - it is NOT <a href="http://en.wikipedia.org/wiki/Graphics_Device_Interface" rel="nofollow noreferrer">GDI</a> based!</li>\n<li>Has no <code>Paint()</code> function - WPF is based on a retained graphics mode / tree based drawing system. Finally!</li>\n<li>Is very graphically dynamic - everything can be animated - and animation is built into the framework. Remember.... there is no <code>Paint()</code>!</li>\n<li>Is extremely customizable - though getting into the nitty-gritty of <code>ControlTemplates</code> is where the complication begins. You simply add objects to the display tree and let WPF worry about updates.</li>\n<li>Is very rich in text rendering features.</li>\n<li>Is hopefully improving the designer/coder\'s workflow with the use of a declarative language (<a href="http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language" rel="nofollow noreferrer">XAML</a>) for graphic definitions and complex GUI design software (<a href="http://en.wikipedia.org/wiki/Microsoft_Expression_Blend" rel="nofollow noreferrer">Expression Blend</a>). Though it is important to realize that anything that can be done in a declarative way can also be accomplished in code. And it is also debatable that the complexity of WPF has scared away many designers - but it has put a powerful framework in the hands of coders.</li>\n</ul>\n\n<p>WPF:</p>\n\n<ul>\n<li>Is NOT <a href="http://en.wikipedia.org/wiki/Windows_Forms" rel="nofollow noreferrer">Windows Forms</a>++ - it\'s just a totally different concept all-together</li>\n<li>Is NOT Silverlight - Silverlight is a subset of WPF. Quite a light subset.</li>\n<li>Is NOT MFC - OK, this should be obvious</li>\n<li>Is not easily distributable with Windows XP - this is a shame and maybe one of its biggest failures</li>\n<li>Is not XAML. This distinction needs to be understood. XAML is an <strong>optional</strong> declarative language which can be used in the development process of WPF applications. It is absolutely not a necessary component, though once understood, it definitely improves the workflow, design, and refactoring of complex graphical frameworks.</li>\n</ul>\n'}, {'answer_id': 2171841, 'author': 'Sam Harwell', 'author_id': 138304, 'author_profile': 'https://Stackoverflow.com/users/138304', 'pm_score': 0, 'selected': False, 'text': '<p>WPF is the current "state of the art" in UI methodologies. Had it been available as people were learning to write UIs (instead of GDI, Win32, and later WinForms which is relatively similar), it wouldn\'t take so long to learn it. You can probably think of it like switching to a Dvorak keyboard - the most difficult part is changing your thinking about the parts of UI design you think you know well.</p>\n\n<p>That said, you should at least be encouraging members of your team to experiment with WPF in their spare time. Make resources available from the very beginning, maybe by the following:</p>\n\n<ul>\n<li>Have links to pages that tell about what you need to have installed to work with WPF - if it doesn\'t mention Blend then I wouldn\'t trust it.</li>\n<li>Look on here for "getting started" questions, since they\'ll probably have good answers from experienced individuals.</li>\n<li>Buy at least a few good books and let people borrow them if they want.</li>\n</ul>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76522', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,526 |
<p>Under what circumstances - if any - does adding programmers to a team actually speed development of an already late project?</p>
|
[{'answer_id': 76550, 'author': 'JosephStyons', 'author_id': 672, 'author_profile': 'https://Stackoverflow.com/users/672', 'pm_score': 3, 'selected': False, 'text': "<p>If the existing programmers are totally incompetent, then adding competent programmers may help.</p>\n\n<p>I can imagine a situation where you had a very modular system, and the existing programmer(s) hadn't even <em>started</em> on a very isolated module. In that case, assigning just that portion of the project to a new programmer might help.</p>\n\n<p>Basically the Mythical Man Month references are correct, except in contrived cases like the one I made up. Mr. Brooks did solid research to demonstrate that after a certain point, the networking and communication costs of adding new programmers to a project will outweigh any benefits you gain from their productivity.</p>\n"}, {'answer_id': 76577, 'author': 'Tom Ritter', 'author_id': 8435, 'author_profile': 'https://Stackoverflow.com/users/8435', 'pm_score': 2, 'selected': False, 'text': "<ul>\n<li>Self-contained modules that have yet to be started</li>\n<li>Lacking development tools they can integrate (like an automated build manager)</li>\n</ul>\n\n<p>Primarily I'm thinking of things that let them stay out of the currently developing people's way. I do agree with Mythical Man-Month, but I also think there are exceptions to everything.</p>\n"}, {'answer_id': 76605, 'author': 'Lost in Alabama', 'author_id': 5285, 'author_profile': 'https://Stackoverflow.com/users/5285', 'pm_score': 4, 'selected': False, 'text': "<p>Maybe if the following conditions apply:</p>\n\n<ol>\n<li>The new programmers already understand the project and don't need any ramp-up time.</li>\n<li>The new programmers already are proficient with the development environment.</li>\n<li>No adminstrative time is needed to add the developers to the team.</li>\n<li>Almost no communication is required between team members. </li>\n</ol>\n\n<p>I'll let you know the first time I see all of these at once.</p>\n"}, {'answer_id': 76613, 'author': 'Lasse V. Karlsen', 'author_id': 267, 'author_profile': 'https://Stackoverflow.com/users/267', 'pm_score': 5, 'selected': False, 'text': "<p>It only helps if you have a resource-driven project.</p>\n\n<p>For instance, consider this:</p>\n\n<p>You need to paint a large poster, say 4 by 6 meters. A poster that big, you can probably put two or three people in front of it, and have them paint in parallel. However, placing 20 people in front of it won't work. Additionally, you'll need skilled people, unless you want a crappy poster.</p>\n\n<p>However, if your project is to stuff envelopes with ready-printed letters (like <em>You MIGHT have won!</em>) then the more people you add, the faster it goes. There is some overhead in doling out stacks of work, so you can't get benefits up to the point where you have one person pr. envelope, but you can get benefits from much more than just 2 or 3 people.</p>\n\n<p>So if your project can easily be divided into small chunks, and if the team members can get up to speed quickly (like... instantaneously), then adding more people will make it go faster, up to a point.</p>\n\n<p>Sadly, not many projects are like that in our world, which is why docgnome's tip about the Mythical Man-Month book is a really good advice.</p>\n"}, {'answer_id': 76647, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 3, 'selected': False, 'text': "<ul>\n<li>If the new people focus on testing</li>\n<li>If you can isolate independent features that don't create new dependencies</li>\n<li>If you can orthogonalise some aspects of the project (especially non-coding tasks such as visual design/layout, database tuning/indexing, or server setup/network configuration) so that one person can work on that while the others carry on with application code</li>\n<li>If the people know each other, and the technology, and the business requirements, and the design, well enough to be able to do things with a knowledge of when they'll step on each other's toes and how to avoid doing so (this, of course, is pretty hard to arrange if it isn't already the case)</li>\n</ul>\n"}, {'answer_id': 76759, 'author': 'Daniel', 'author_id': 13615, 'author_profile': 'https://Stackoverflow.com/users/13615', 'pm_score': 2, 'selected': False, 'text': '<p>Only when you have at that late stage some independent (almost 0% interaction with other parts of the project) tasks not tackled yet by anybody and you can bring on the team somebody that is a specialist in that domain. The addition of a team member has to minimize the disruption for the rest of the team.</p>\n'}, {'answer_id': 76830, 'author': 'Giovanni Galbo', 'author_id': 4050, 'author_profile': 'https://Stackoverflow.com/users/4050', 'pm_score': 2, 'selected': False, 'text': "<p>I suppose the adding people toward the end of the work could speed things up if:</p>\n\n<ol>\n<li><p>The work can be done in parallel.</p></li>\n<li><p>The amount saved by added resources is more than the amount of time lost by having the people experienced with the project explain things to those that are inexperienced.</p></li>\n</ol>\n\n<p>EDIT: I forgot to mention, this kind of thing doesn't happen all too often. Usually it is fairly straight forward stuff, like admin screens that do simple CRUD to a table. These days these types of tools can be mostly autogenerated anyway.</p>\n\n<p>Be careful of managers that bank on this kind of work to hand off though. It sounds great, but it in reality there usually isn't enough of it trim any significant time off of the project.</p>\n"}, {'answer_id': 77442, 'author': 'Zach Burlingame', 'author_id': 2233, 'author_profile': 'https://Stackoverflow.com/users/2233', 'pm_score': 7, 'selected': True, 'text': '<p>The exact circumstances are obviously very specific to your project ( e.g. development team, management style, process maturity, difficulty of the subject matter, etc.). In order to scope this a bit better so we can speak about it in anything but sweeping oversimplifications, I\'m going to restate your question:</p>\n\n<blockquote>\n <p>Under what circumstances, if any, can adding team members to a software development project that is running late result in a reduction in the actual ship date with a level of quality equal to that if the existing team were allow to work until completion?</p>\n</blockquote>\n\n<p>There are a number of things that I think are <em>necessary</em>, but not sufficient, for this to occur (in no particular order):</p>\n\n<ul>\n<li><strong>The proposed individuals to be added to the project must have:</strong>\n\n<ul>\n<li>At least a reasonable understanding of the problem domain of the project</li>\n<li>Be proficient in the language of the project and the specific technologies that they would use for the tasks they would be given</li>\n<li>Their proficiency must /not/ be much less or much greater than the weakest or strongest existing member respectively. Weak members will drain your existing staff with tertiary problems while a new person who is too strong will disrupt the team with how everything they have done and are doing is wrong.</li>\n<li>Have good communication skills</li>\n<li>Be highly motivated (e.g. be able to work independently without prodding)</li>\n</ul></li>\n<li><strong>The existing team members must have:</strong>\n\n<ul>\n<li>Excellent communication skills</li>\n<li>Excellent time management skills</li>\n</ul></li>\n<li><strong>The project lead/management must have:</strong>\n\n<ul>\n<li>Good prioritization and resource allocation abilities</li>\n<li>A high level of respect from the existing team members</li>\n<li>Excellent communication skills</li>\n</ul></li>\n<li><strong>The project must have:</strong>\n\n<ul>\n<li>A good, completed, and documented software design specification</li>\n<li>Good documentation of things already implemented</li>\n<li>A modular design to allow clear chunks of responsibility to be carved out</li>\n<li>Sufficient automated processes for quality assurance for the required defect level These might include such things as: unit tests, regression tests, automated build deployments, etc.)</li>\n<li>A bug/feature tracking system that is currently in-place and in-use by the team (e.g. trac, SourceForge, FogBugz, etc).</li>\n</ul></li>\n</ul>\n\n<p>One of the first things that should be discussed is whether the ship date <em>can</em> be slipped, whether features can be cut, and if some combinations of the two will allow you to satisfy release with your existing staff. Many times its a couple features that are really hogging the resources of the team that won\'t deliver value equal to the investment. So give your project\'s priorities a serious review before anything else.</p>\n\n<p>If the outcome of the above paragraph isn\'t sufficient, then visit the list above. If you caught the schedule slip early, the addition of the right team members at the right time may save the release. Unfortunately, the closer you get to your expected ship date, the more things can go wrong with adding people. At one point, you\'ll cross the "point of no return" where no amount of change (other than shipping the current development branch) can save your release.</p>\n\n<p>I could go on and on but I think I hit the major points. Outside of the project and in terms of your career, the company\'s future success, etc. one of the things that you should definitely do is figure out why you were late, if anything could have been done alert you earlier, and what measures you need to take to prevent it in the future. A late project usually occurs because you were either:</p>\n\n<ul>\n<li>Were late before you started (more\nstuff than time) and/or </li>\n<li>slipped 1hr, 1day at time.</li>\n</ul>\n\n<p>Hope that helps!</p>\n'}, {'answer_id': 77965, 'author': 'screenglow', 'author_id': 424554, 'author_profile': 'https://Stackoverflow.com/users/424554', 'pm_score': 2, 'selected': False, 'text': "<p>Obviously every project is different but most development jobs can be assured to have a certain amount of collaboration among developers. Where this is the case my experience has been that fresh resources can actually unintentionally slow down the people they are relying on to bring them up to speed and in some cases this can be your key people (incidentally it's usually 'key' people that would take the time to educate a newb). When they <em>are</em> up to speed, there are no guarantees that their work will fit into established 'rules' or 'work culture' with the rest of the team. So again, it can do more harm than good. So that aside, these are the circumstances where it might be beneficial:</p>\n\n<p>1) The new resource has a tight task which requires a minimum of interaction with other developers and a skill set that's already been demonstrated. (ie. porting existing code to a new platform, externally refactoring a dead module that's currently locked down in the existing code base).</p>\n\n<p>2) The project is managed in such a way that other more senior team members time can be shared to assist bringing the newb up to speed and mentoring them along the way to ensure their work is compatible with what's already been done. </p>\n\n<p>3) The other team members are very patient. </p>\n"}, {'answer_id': 77983, 'author': 'apenwarr', 'author_id': 42219, 'author_profile': 'https://Stackoverflow.com/users/42219', 'pm_score': 4, 'selected': False, 'text': "<p>According to the Mythical Man-Month, the main reason adding people to a late project makes it later is the O(n^2) communication overhead.</p>\n\n<p>I've experienced one primary exception to this: if there's only <em>one</em> person on a project, it's almost always doomed. Adding a second one speeds it up almost every time. That's because communication isn't <em>overhead</em> in that case - it's a helpful opportunity to clarify your thoughts and make fewer stupid mistakes.</p>\n\n<p>Also, as you obviously knew when you posted your question, the advice from the Mythical Man-Month only applies to <em>late</em> projects. If your project isn't already late, it is quite possible that adding people won't make it later. Assuming you do it properly, of course.</p>\n"}, {'answer_id': 79686, 'author': 'Matthew Cole', 'author_id': 13348, 'author_profile': 'https://Stackoverflow.com/users/13348', 'pm_score': 2, 'selected': False, 'text': "<p>I think adding people to a team may speed up a project more than adding them to the project itself. </p>\n\n<p>I often run into the problem of having too many concurrent projects. Any one of those projects could be completed faster if I could focus on that project alone. By adding team members, I could transition off other projects.</p>\n\n<p>Of course, this assumes that you've hired capable, self-motivated developers, who are able to inherit large projects and learn independently. :-)</p>\n"}, {'answer_id': 79916, 'author': 'JackCorn', 'author_id': 14919, 'author_profile': 'https://Stackoverflow.com/users/14919', 'pm_score': 1, 'selected': False, 'text': "<p>Simply put. It comes down to comparing the time left and productivity you will get from someone excluding the amount of time it takes the additional resources to come up to speed and be productive and subtracting the time invested in teaching them by existing resources. The key factors (in order of significance):</p>\n\n<ol>\n<li>How good the resource is at picking\nit up. The best developers can walk\nonto a new site and be productive\nfixing bugs almost instantly with\nlittle assistance. This skill is\nrare but can be learnt. </li>\n<li>The segregability of tasks. They need to\nbe able to work on objects and\nfunctions without tripping over the\nexisting developers and slowing them\ndown. </li>\n<li>The complexity of the project\nand documentation available. If it's\na vanilla best practice ASP.Net\napplication and common\nwell-documented business scenarios\nthen a good developer can just get\nstuck in straight away. This factor\nmore than any will determine how\nmuch time the existing resources\nwill have to invest in teaching and\ntherefore the initial negative\nimpact of the new resources. </li>\n<li>The amount of time left. This is often\nmis-estimated too. Frequently the\nlogic will be we only have x weeks\nleft and it will take x+1 weeks to\nget someone up to speed. In reality\nthe project IS going to slip and\ndoes in fact have 2x weeks of dev\nleft to go and getting more\nresources on sooner rather than\nlater will help.</li>\n</ol>\n"}, {'answer_id': 81507, 'author': 'JXG', 'author_id': 15456, 'author_profile': 'https://Stackoverflow.com/users/15456', 'pm_score': 2, 'selected': False, 'text': '<p>Rather than adding programmers, one can think about adding administrative help. Anything that will remove distractions, improve focus, or improve motivation can be helpful. This includes both system and administration, as well as more prosaic things like getting lunches.</p>\n'}, {'answer_id': 81834, 'author': 'Bill Michell', 'author_id': 7938, 'author_profile': 'https://Stackoverflow.com/users/7938', 'pm_score': 1, 'selected': False, 'text': '<p>Where a team is already used to pair programming, then adding another developer <em>who is already skilled at pairing</em> may not slow the project down, particularly if development is proceeding with a TDD style.</p>\n\n<p>The new developer will slowly become more productive as they understand the code base more, and any misunderstandings will be caught very early either by their pair, or by the test suite that is run before every check-in (and there should ideally be a check in at least every ten minutes).</p>\n\n<p>However, the effects of the extra communication overheads need to be taken into account. It is important not to dilute the existing knowledge of the project too much.</p>\n'}, {'answer_id': 112221, 'author': 'Oskar', 'author_id': 5472, 'author_profile': 'https://Stackoverflow.com/users/5472', 'pm_score': 2, 'selected': False, 'text': '<p>If the extra resource <strong>complement</strong> your existing team it can be ideal. For example, if you are about to set up your production hardware and verify that the database is actually tuned as opposed to just returning good results (that your team knows as domain experts) borrowing time from a good dba who works on the the project next to yours can speed the team up without much training cost</p>\n'}, {'answer_id': 6795833, 'author': 'Caleb', 'author_id': 643383, 'author_profile': 'https://Stackoverflow.com/users/643383', 'pm_score': 1, 'selected': False, 'text': '<p>Adding developers makes sense when the productivity contributed by the additional developers exceeds the productivity lost to training and managing those developers.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76526', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4200/']
|
76,534 |
<p>Does the Multiview control contain the viewstate information for each of its views regardless of whether or not the view is currently visible?</p>
|
[{'answer_id': 76955, 'author': 'ssmith', 'author_id': 13729, 'author_profile': 'https://Stackoverflow.com/users/13729', 'pm_score': 0, 'selected': False, 'text': '<p>I believe so, yes. It would be quite simple to confirm using a ViewState Decoder (google it, there are tools available from Fritz Onion or as FireFox plugins).</p>\n'}, {'answer_id': 76958, 'author': 'Adam Weber', 'author_id': 9324, 'author_profile': 'https://Stackoverflow.com/users/9324', 'pm_score': 0, 'selected': False, 'text': "<p>I would have to assume that the viewstate contains information for each of a Multiview's views/controls. Otherwise, there's no way it would be able to keep track of the state of the controls in each view- unless you were using some sort of custom state management.</p>\n"}, {'answer_id': 91623, 'author': 'naspinski', 'author_id': 14777, 'author_profile': 'https://Stackoverflow.com/users/14777', 'pm_score': 3, 'selected': True, 'text': '<p>Yes it does, all the views are still there, just the inactive ones are hidden/disabled.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.multiview_properties.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.multiview_properties.aspx</a></p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76534', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13653/']
|
76,549 |
<p>An array of ints in java is stored as a block of 32-bit values in memory. How is an array of Integer objects stored? i.e.</p>
<pre><code>int[] vs. Integer[]
</code></pre>
<p>I'd imagine that each element in the Integer array is a reference to an Integer object, and that the Integer object has object storage overheads, just like any other object.</p>
<p>I'm hoping however that the JVM does some magical cleverness under the hood given that Integers are immutable and stores it just like an array of ints.</p>
<p>Is my hope woefully naive? Is an Integer array much slower than an int array in an application where every last ounce of performance matters?</p>
|
[{'answer_id': 76588, 'author': 'Will Hartung', 'author_id': 13663, 'author_profile': 'https://Stackoverflow.com/users/13663', 'pm_score': 1, 'selected': False, 'text': '<p>I think your hope is woefully naive. Specifically, it needs to deal with the issue that Integer can potentially be null, whereas int can not be. That alone is reason enough to store the object pointer.</p>\n\n<p>That said, the actual object pointer will be to a immutable int instance, notably for a select subset of integers.</p>\n'}, {'answer_id': 76596, 'author': 'cynicalman', 'author_id': 410, 'author_profile': 'https://Stackoverflow.com/users/410', 'pm_score': 0, 'selected': False, 'text': '<p>It won\'t be much slower, but because an Integer[] must accept "null" as an entry and int[] doesn\'t have to, there will be some amount of bookkeeping involved, even if Integer[] is backed by an int[].</p>\n\n<p>So if every last ounce of performance matters, user int[]</p>\n'}, {'answer_id': 76720, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>The reason that Integer can be null, whereas int cannot, is because Integer is a full-fledged Java object, with all of the overhead that includes. There's value in this since you can write</p>\n\n<pre><code>Integer foo = new Integer();\nfoo = null; \n</code></pre>\n\n<p>which is good for saying that foo will have a value, but it doesn't yet. </p>\n\n<p>Another difference is that <code>int</code> performs no overflow calculation. For instance,</p>\n\n<pre><code>int bar = Integer.MAX_VALUE;\nbar++;\n</code></pre>\n\n<p>will merrily increment bar and you end up with a very negative number, which is probably not what you intended in the first place.</p>\n\n<pre><code>foo = Integer.MAX_VALUE;\nfoo++;\n</code></pre>\n\n<p>will complain, which I think would be better behavior. </p>\n\n<p>One last point is that Integer, being a Java object, carries with it the space overhead of an object. I think that someone else may need to chime in here, but I believe that every object consumes 12 bytes for overhead, and then the space for the data storage itself. If you're after performance and space, I wonder whether Integer is the right solution.</p>\n"}, {'answer_id': 80220, 'author': 'stepancheg', 'author_id': 15018, 'author_profile': 'https://Stackoverflow.com/users/15018', 'pm_score': 2, 'selected': False, 'text': '<p>John Rose working on <a href="http://blogs.oracle.com/jrose/entry/fixnums_in_the_vm" rel="nofollow noreferrer">fixnums</a> in the JVM to fix this problem.</p>\n'}, {'answer_id': 80718, 'author': 'ralfs', 'author_id': 13107, 'author_profile': 'https://Stackoverflow.com/users/13107', 'pm_score': 5, 'selected': True, 'text': "<p>No VM I know of will store an Integer[] array like an int[] array for the following reasons:</p>\n\n<ol>\n<li>There can be <strong>null</strong> Integer objects in the array and you have no bits left for indicating this in an int array. The VM could store this 1-bit information per array slot in a hiden bit-array though.</li>\n<li>You can synchronize in the elements of an Integer array. This is much harder to overcome as the first point, since you would have to store a monitor object for each array slot.</li>\n<li>The elements of Integer[] can be compared for identity. You could for example create two Integer objects with the value 1 via <strong>new</strong> and store them in different array slots and later you retrieve them and compare them via ==. This must lead to false, so you would have to store this information somewhere. Or you keep a reference to one of the Integer objects somewhere and use this for comparison and you have to make sure one of the == comparisons is false and one true. This means the whole concept of object identity is quiet hard to handle for the <em>optimized</em> Integer array.</li>\n<li>You can cast an Integer[] to e.g. Object[] and pass it to methods expecting just an Object[]. This means all the code which handles Object[] must now be able to handle the special Integer[] object too, making it slower and larger.</li>\n</ol>\n\n<p>Taking all this into account, it would probably be possible to make a special Integer[] which saves some space in comparison to a <em>naive</em> implementation, but the additional complexity will likely affect a lot of other code, making it slower in the end.</p>\n\n<p>The overhead of using Integer[] instead of int[] can be quiet large in space and time. On a typical 32 bit VM an Integer object will consume 16 byte (8 byte for the object header, 4 for the payload and 4 additional bytes for alignment) while the Integer[] uses as much space as int[]. In 64 bit VMs (using 64bit pointers, which is not always the case) an Integer object will consume 24 byte (16 for the header, 4 for the payload and 4 for alignment). In addition a slot in the Integer[] will use 8 byte instead of 4 as in the int[]. This means you can expect an overhead of <strong>16 to 28</strong> byte per slot, which is a <strong>factor of 4 to 7</strong> compared to plain int arrays.</p>\n\n<p>The performance overhead can be significant too for mainly two reasons:</p>\n\n<ol>\n<li>Since you use more memory, you put on much more pressure on the memory subsystem, making it more likely to have cache misses in the case of Integer[]. For example if you traverse the contents of the int[] in a linear manner, the cache will have most of the entries already fetched when you need them (since the layout is linear too). But in case of the Integer array, the Integer objects itself might be scattered randomly in the heap, making it hard for the cache to guess where the next memory reference will point to.</li>\n<li>The garbage collection has to do much more work because of the additional memory used and because it has to scan and move each Integer object separately, while in the case of int[] it is just one object and the contents of the object doesn't have to be scanned (they contain no reference to other objects).</li>\n</ol>\n\n<p>To sum it up, using an int[] in performance critical work will be both much faster and memory efficient than using an Integer array in current VMs and it is unlikely this will change much in the near future.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76549', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/974/']
|
76,553 |
<p>I want to add an item into the Desktop context menu (the menu you see when you right-click on an empty space on the Windows Desktop). </p>
<p>Something like Catalyst Control Center in this screenshot:<br>
<img src="https://i361.photobucket.com/albums/oo51/Stark3000/ContextMenuExample.png" alt="Embedded Example"></p>
<p>I know how to add items to files' and folders' context menus through registry, but the Desktop seems to work differently: I didn't even find the text in the registry. </p>
<p>So, how can I add a new item into the Desktop menu and how can I associate some code with it?<br>
I think the solution is language independent, if it's not, I'd appreciate any code that helps.</p>
|
[{'answer_id': 76777, 'author': 'Peter Ritchie', 'author_id': 5620, 'author_profile': 'https://Stackoverflow.com/users/5620', 'pm_score': 1, 'selected': False, 'text': '<p>There\'s a series of articles on CodeProject that details writing Shell Extensions and is very good:</p>\n\n<p><a href="http://www.codeproject.com/KB/shell/shellextguide1.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/shell/shellextguide1.aspx</a></p>\n'}, {'answer_id': 84878, 'author': 'efotinis', 'author_id': 12320, 'author_profile': 'https://Stackoverflow.com/users/12320', 'pm_score': 2, 'selected': False, 'text': '<p>Such a handler must be registered in HKCR\\Directory\\Background, instead of usual locations like HKCR\\Directory, HKCR\\Folder, etc.</p>\n\n<p>Check out <a href="http://msdn.microsoft.com/en-us/library/cc144067(VS.85).aspx" rel="nofollow noreferrer">Creating Shell Extension Handlers</a> in MSDN.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76553', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2239/']
|
76,564 |
<p>All I want is to be able to change the color of a bullet in a list to a light gray. It defaults to black, and I can't figure out how to change it.</p>
<p>I know I could just use an image; I'd rather not do that if I can help it.</p>
|
[{'answer_id': 76603, 'author': 'Jonathan Arkell', 'author_id': 11052, 'author_profile': 'https://Stackoverflow.com/users/11052', 'pm_score': 3, 'selected': False, 'text': '<pre><code><ul>\n <li style="color: #888;"><span style="color: #000">test</span></li>\n</ul>\n</code></pre>\n\n<p>the big problem with this method is the extra markup. (the span tag)</p>\n'}, {'answer_id': 76609, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Wrap the text within the list item with a span (or some other element) and apply the bullet color to the list item and the text color to the span.</p>\n'}, {'answer_id': 76616, 'author': 'ahockley', 'author_id': 8209, 'author_profile': 'https://Stackoverflow.com/users/8209', 'pm_score': -1, 'selected': False, 'text': '<p>You\'ll want to set a "list-style" via CSS, and give it a color: value. Example:</p>\n\n<pre><code>ul.colored {list-style: color: green;}\n</code></pre>\n'}, {'answer_id': 76620, 'author': 'Diodeus - James MacFarlane', 'author_id': 12579, 'author_profile': 'https://Stackoverflow.com/users/12579', 'pm_score': -1, 'selected': False, 'text': "<p>Just use CSS:</p>\n\n<pre><code><li style='color:#e0e0e0'>something</li>\n</code></pre>\n"}, {'answer_id': 76626, 'author': 'Prestaul', 'author_id': 5628, 'author_profile': 'https://Stackoverflow.com/users/5628', 'pm_score': 8, 'selected': True, 'text': "<p>The bullet gets its color from the text. So if you want to have a different color bullet than text in your list you'll have to add some markup.</p>\n\n<p>Wrap the list text in a span:</p>\n\n<pre><code><ul>\n <li><span>item #1</span></li>\n <li><span>item #2</span></li>\n <li><span>item #3</span></li>\n</ul>\n</code></pre>\n\n<p>Then modify your style rules slightly:</p>\n\n<pre><code>li {\n color: red; /* bullet color */\n}\nli span {\n color: black; /* text color */\n}\n</code></pre>\n"}, {'answer_id': 76638, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 0, 'selected': False, 'text': '<p>As per <a href="http://www.w3.org/TR/CSS2/generate.html#lists" rel="nofollow noreferrer">W3C spec</a>, </p>\n\n<blockquote>\n <p>The list properties ... do not allow authors to specify distinct style (colors, fonts, alignment, etc.) for the list marker ...</p>\n</blockquote>\n\n<p>But the idea with a span inside the list above should work fine!</p>\n'}, {'answer_id': 76639, 'author': 'NerdFury', 'author_id': 6146, 'author_profile': 'https://Stackoverflow.com/users/6146', 'pm_score': -1, 'selected': False, 'text': '<pre><code><ul style="color: red;">\n<li>One</li>\n<li>Two</li>\n<li>Three</li>\n</ul>\n</code></pre>\n\n\n<li>One</li>\n<li>Two</li>\n<li>Three</li>\n\n'}, {'answer_id': 76707, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<pre><code><ul>\n<li style="color:#ddd;"><span style="color:#000;">List Item</span></li>\n</ul>\n</code></pre>\n'}, {'answer_id': 76942, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': '<p>You could use CSS to attain this. By specifying the list in the color and style of your choice, you can then also specify the text as a different color.</p>\n\n<p>Follow the example at <a href="http://www.echoecho.com/csslists.htm" rel="nofollow noreferrer">http://www.echoecho.com/csslists.htm</a>.</p>\n'}, {'answer_id': 1083559, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Hello maybe this answer is late but is the correct one to achieve this.</p>\n\n<p>Ok the fact is that you must specify an internal tag to make the LIst text be on the usual black (or what ever you want to get it). But is also true that you can REDEFINE any TAGS and internal tags with CSS. So the best way to do this use a SHORTER tag for the redefinition</p>\n\n<p>Usign this CSS definition:</p>\n\n<pre><code>li { color: red; }\nli b { color: black; font_weight: normal; }\n.c1 { color: red; }\n.c2 { color: blue; }\n.c3 { color: green; }\n</code></pre>\n\n<p>And this html code:</p>\n\n<pre><code><ul>\n<li><b>Text 1</b></li>\n<li><b>Text 2</b></li>\n<li><b>Text 3</b></li>\n</ul>\n</code></pre>\n\n<p>You get required result. Also you can make each disc diferent color:</p>\n\n<pre><code><ul>\n <li class="c1"><b>Text 1</b></li>\n <li class="c2"><b>Text 2</b></li>\n <li class="c3"><b>Text 3</b></li>\n </ul>\n</code></pre>\n'}, {'answer_id': 4288573, 'author': 'Marc', 'author_id': 496015, 'author_profile': 'https://Stackoverflow.com/users/496015', 'pm_score': 6, 'selected': False, 'text': '<p>I managed this without adding markup, but instead using li:before. This obviously has all the limitations of <code>:before</code> (no old IE support), but it seems to work with IE8, Firefox and Chrome after some very limited testing. It\'s working in our controller environment, wondering if anyone could check this. The bullet style is also limited by what\'s in unicode.</p>\n\n<pre><code><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html>\n<head>\n <style type="text/css">\n li {\n list-style: none;\n }\n\n li:before {\n /* For a round bullet */\n content:\'\\2022\';\n /* For a square bullet */\n /*content:\'\\25A0\';*/\n display: block;\n position: relative;\n max-width: 0px;\n max-height: 0px;\n left: -10px;\n top: -0px;\n color: green;\n font-size: 20px;\n }\n </style>\n</head>\n\n<body>\n <ul>\n <li>foo</li>\n <li>bar</li>\n </ul>\n</body>\n</html>\n</code></pre>\n'}, {'answer_id': 10237554, 'author': 'ghr', 'author_id': 387558, 'author_profile': 'https://Stackoverflow.com/users/387558', 'pm_score': 2, 'selected': False, 'text': "<p>Just do a bullet in a graphics program and use <code>list-style-image</code>:</p>\n\n<pre><code>ul {\n list-style-image:url('gray-bullet.gif');\n}\n</code></pre>\n"}, {'answer_id': 14176134, 'author': 'alaasdk', 'author_id': 501602, 'author_profile': 'https://Stackoverflow.com/users/501602', 'pm_score': 0, 'selected': False, 'text': '<p>You can use Jquery if you have lots of pages and don\'t need to go and edit the markup your self.</p>\n\n<p>here is a simple example:</p>\n\n<pre><code>$("li").each(function(){\nvar content = $(this).html();\nvar myDiv = $("<div />")\nmyDiv.css("color", "red"); //color of text.\nmyDiv.html(content);\n$(this).html(myDiv).css("color", "yellow"); //color of bullet\n});\n</code></pre>\n'}, {'answer_id': 16040621, 'author': 'Ky -', 'author_id': 453435, 'author_profile': 'https://Stackoverflow.com/users/453435', 'pm_score': 4, 'selected': False, 'text': '<p>This was impossible in 2008, but it\'s becoming possible soon (hopefully)!</p>\n\n<p>According to <a href="https://www.w3.org/TR/css-lists-3/#marker-pseudo-element" rel="nofollow">The W3C CSS3 specification</a>, you can have full control over any number, glyph, or other symbol generated before a list item with the <code>::marker</code> pseudo-element.\nTo apply this to the most voted answer\'s solution:</p>\n\n<pre><code><ul>\n <li>item #1</li>\n <li>item #2</li>\n <li>item #3</li>\n</ul>\n\nli::marker {\n color: red; /* bullet color */\n}\nli {\n color: black /* text color */\n}\n</code></pre>\n\n<p><a href="http://jsfiddle.net/9Srpq/" rel="nofollow">JSFiddle Example</a></p>\n\n<p>Note, though, that <strong>as of July 2016</strong>, this solution is only a part of the W3C Working Draft and does not work in any major browsers, yet.</p>\n\n<p>If you want this feature, do these:</p>\n\n<ul>\n<li><a href="https://code.google.com/p/chromium/issues/detail?id=457718&thanks=457718&ts=1423675756" rel="nofollow"><strong>Blink</strong> (Chrome, Opera, Vivaldi, Yandex, etc.): star Chromium\'s issue</a></li>\n<li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=205202" rel="nofollow"><strong>Gecko</strong> (Firefox, Iceweasel, etc.): Click "(vote)" on this bug</a></li>\n<li><s><a href="https://connect.microsoft.com/IE/feedbackdetail/view/1125247/support-marker-pseudo-element#tabs" rel="nofollow"><strong>Trident</strong> (IE, Windows web views): Click "I can too" under "X User(s) can reproduce this bug"</a></s><br/><sup>Trident development has ceased</sup></li>\n<li><a href="https://wpdev.uservoice.com/forums/257854-internet-explorer-platform/suggestions/7084750-css-3-marker-pseudo-element" rel="nofollow"><strong>EdgeHTML</strong> (MS Edge, Windows web views, Windows Modern apps): Click "Vote" on this prpopsal</a></li>\n<li><a href="https://bugs.webkit.org/show_bug.cgi?id=141477" rel="nofollow"><strong>Webkit</strong> (Safari, Steam, WebOS, etc.): CC yourself to this bug</a></li>\n</ul>\n'}, {'answer_id': 33908171, 'author': 'eggy', 'author_id': 1890236, 'author_profile': 'https://Stackoverflow.com/users/1890236', 'pm_score': 0, 'selected': False, 'text': '<p>For a 2008 question, I thought I might add a more recent and up-to-date answer on how you could go about changing the colour of bullets in a list.</p>\n\n<p>If you are willing to use external libraries, <a href="https://fortawesome.github.io/Font-Awesome/examples/#list" rel="nofollow">Font Awesome gives you scalable vector icons</a>, and when combined with <a href="http://getbootstrap.com/css/#helper-classes" rel="nofollow">Bootstrap\'s helper classes</a> (eg. <code>text-success</code>), you can make some pretty cool and customisable lists.</p>\n\n<p>I have expanded on the extract from <a href="https://fortawesome.github.io/Font-Awesome/examples/#list" rel="nofollow">the Font Awesome list examples page</a> below:</p>\n\n<blockquote>\n <p>Use <code>fa-ul</code> and <code>fa-li</code> to easily replace default bullets in unordered lists.</p>\n</blockquote>\n\n<p><div class="snippet" data-lang="js" data-hide="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />\r\n<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />\r\n\r\n<ul class="fa-ul">\r\n <li><i class="fa-li fa fa-circle"></i>List icons</li>\r\n <li><i class="fa-li fa fa-check-square text-success"></i>can be used</li>\r\n <li><i class="fa-li fa fa-spinner fa-spin text-primary"></i>as bullets</li>\r\n <li><i class="fa-li fa fa-square text-danger"></i>in lists</li>\r\n</ul></code></pre>\r\n</div>\r\n</div>\r\n</p>\n\n<p>Font Awesome <a href="http://getbootstrap.com/getting-started/#support-ie8-font-face" rel="nofollow">(mostly) supports IE8</a>, and only supports IE7 if you use the <a href="http://fortawesome.github.io/Font-Awesome/3.2.1/get-started/#need-ie7" rel="nofollow">older version 3.2.1</a>.</p>\n'}, {'answer_id': 44568145, 'author': 'Mohammed', 'author_id': 4657565, 'author_profile': 'https://Stackoverflow.com/users/4657565', 'pm_score': 0, 'selected': False, 'text': '<p>It works as well if we set color for each elements for example:\nI added some Margin to left now.</p>\n\n<pre><code><article class="event-item">\n <p>Black text here</p>\n</article>\n\n.event-item{\n list-style-type: disc;\n display: list-item;\n color: #ff6f9a;\n margin-left: 25px;\n}\n.event-item p {\n margin: 0;\n color: initial;\n}\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76564', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7072/']
|
76,571 |
<p>In JavaScript, using the Prototype library, the following functional construction is possible:</p>
<pre><code>var words = ["aqueous", "strength", "hated", "sesquicentennial", "area"];
words.pluck('length');
//-> [7, 8, 5, 16, 4]
</code></pre>
<p>Note that this example code is equivalent to</p>
<pre><code>words.map( function(word) { return word.length; } );
</code></pre>
<p>I wondered if something similar is possible in F#:</p>
<pre><code>let words = ["aqueous"; "strength"; "hated";"sesquicentennial"; "area"]
//val words: string list
List.pluck 'Length' words
//int list = [7; 8; 5; 16; 4]
</code></pre>
<p>without having to write:</p>
<pre><code>List.map (fun (s:string) -> s.Length) words
</code></pre>
<p>This would seem quite useful to me because then you don't have to write functions for every property to access them.</p>
|
[{'answer_id': 79511, 'author': 'Gavin', 'author_id': 2377, 'author_profile': 'https://Stackoverflow.com/users/2377', 'pm_score': 1, 'selected': False, 'text': '<p>Prototype\'s <code>pluck</code> takes advantage of that in Javascript <code>object.method()</code> is the same as <code>object[method]</code>. </p>\n\n<p>Unfortunately you can\'t call <code>String.Length</code> either because it\'s not a static method. You can however use:</p>\n\n<pre><code>#r "FSharp.PowerPack.dll" \nopen Microsoft.FSharp.Compatibility\nwords |> List.map String.length \n</code></pre>\n\n<p><a href="http://research.microsoft.com/fsharp/manual/FSharp.PowerPack/Microsoft.FSharp.Compatibility.String.html" rel="nofollow noreferrer">http://research.microsoft.com/fsharp/manual/FSharp.PowerPack/Microsoft.FSharp.Compatibility.String.html</a></p>\n\n<p>However, using <code>Compatibility</code> will probably make things more confusing to people looking at your code.</p>\n'}, {'answer_id': 86084, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': True, 'text': '<p>I saw your request on the F# mailing list. Hope I can help. </p>\n\n<p>You could use type extension and reflection to allow this. We simple extend the generic list type with the pluck function. Then we can use pluck() on any list. An unknown property will return a list with the error string as its only contents.</p>\n\n<pre><code>type Microsoft.FSharp.Collections.List<\'a> with\n member list.pluck property = \n try \n let prop = typeof<\'a>.GetProperty property \n [for elm in list -> prop.GetValue(elm, [| |])]\n with e-> \n [box <| "Error: Property \'" + property + "\'" + \n " not found on type \'" + typeof<\'a>.Name + "\'"]\n\nlet a = ["aqueous"; "strength"; "hated"; "sesquicentennial"; "area"]\n\na.pluck "Length" \na.pluck "Unknown"\n</code></pre>\n\n<p>which produces the follow result in the interactive window:</p>\n\n<pre>\n> a.pluck "Length" ;; \nval it : obj list = [7; 8; 5; 16; 4]\n\n> a.pluck "Unknown";;\nval it : obj list = ["Error: Property \'Unknown\' not found on type \'String\'"]\n</pre>\n\n<p>warm regards,</p>\n\n<p>DannyAsher</p>\n\n<p>>\n>\n>\n>\n></p>\n\n<p>NOTE: When using <code><pre</code>> the angle brackets around <pre><\'a></pre> didn\'t show though in the preview window it looked fine. The backtick didn\'t work for me. Had to resort you the colorized version which is all wrong. I don\'t think I\'ll post here again until FSharp syntax is fully supported. </p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76571', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6264/']
|
76,581 |
<p>There's an MSDN article <a href="http://msdn.microsoft.com/en-us/library/aa919730.aspx" rel="nofollow noreferrer">here</a>, but I'm not getting very far:</p>
<pre><code>p = 139;
g = 5;
CRYPT_DATA_BLOB pblob;
pblob.cbData = sizeof( ULONG );
pblob.pbData = ( LPBYTE ) &p;
CRYPT_DATA_BLOB gblob;
gblob.cbData = sizeof( ULONG );
gblob.pbData = ( LPBYTE ) &g;
HCRYPTKEY hKey;
if ( ::CryptGenKey( m_hCryptoProvider, CALG_DH_SF,
CRYPT_PREGEN, &hKey ) )
{
::CryptSetKeyParam( hKey, KP_P, ( LPBYTE ) &pblob, 0 );
</code></pre>
<p>Fails here with <code>NTE_BAD_DATA</code>. I'm using <code>MS_DEF_DSS_DH_PROV</code>. What gives?</p>
|
[{'answer_id': 78156, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 1, 'selected': False, 'text': '<p>It looks to me that <code>KP_P</code>, <code>KP_G</code>, <code>KP_Q</code> are for DSS keys (Digital Signature Standard?). For Diffie-Hellman it looks like you\'re supposed to use <code>KP_PUB_PARAMS</code> and pass a <code>DATA_BLOB</code> that points to a <code>DHPUBKEY_VER3</code> structure.</p>\n\n<p>Note that the article you\'re pointing to is from the Windows Mobile/Windows CE SDK. It wouldn\'t be the first time that CE worked differently from the desktop/server.</p>\n\n<p>EDIT: CE does not implement <code>KP_PUB_PARAMS</code>. To use this structure on the desktop, see <a href="http://msdn.microsoft.com/en-us/library/aa381974(VS.85).aspx" rel="nofollow noreferrer">Diffie-Hellman Version 3 Public Key BLOBs</a>.</p>\n'}, {'answer_id': 78537, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 3, 'selected': True, 'text': '<p>It may be that it just doesn\'t like the very short keys you\'re using.</p>\n\n<p>I found <a href="http://msdn.microsoft.com/en-us/library/aa381969.aspx" rel="nofollow noreferrer">the desktop version of that article</a> which may help, as it has a full example.</p>\n\n<p>EDIT:</p>\n\n<p>The OP realised from the example that you have to tell CryptGenKey how long the keys are, which you do by setting the top 16-bits of the flags to the number of bits you want to use. If you leave this as 0, you get the default key length. This <em>is</em> documented in the <strong>Remarks</strong> section of the device documentation, and with the <em>dwFlags</em> parameter in the <a href="http://msdn.microsoft.com/en-us/library/aa379941(VS.85).aspx" rel="nofollow noreferrer">desktop documentation</a>. </p>\n\n<p>For the Diffie-Hellman key-exchange algorithm, the Base provider defaults to 512-bit keys and the Enhanced provider (which is the default) defaults to 1024-bit keys, on Windows XP and later. There doesn\'t seem to be any documentation for the default lengths on CE.</p>\n\n<p>The code should therefore be:</p>\n\n<pre><code>BYTE p[64] = { 139 }; // little-endian, all other bytes set to 0\nBYTE g[64] = { 5 };\n\nCRYPT_DATA_BLOB pblob;\npblob.cbData = sizeof( p);\npblob.pbData = p;\n\nCRYPT_DATA_BLOB gblob;\ngblob.cbData = sizeof( g );\ngblob.pbData = g;\n\nHCRYPTKEY hKey;\nif ( ::CryptGenKey( m_hCryptoProvider, CALG_DH_SF,\n ( 512 << 16 ) | CRYPT_PREGEN, &hKey ) )\n{\n ::CryptSetKeyParam( hKey, KP_P, ( LPBYTE ) &pblob, 0 );\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76581', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,591 |
<p>I'm trying to load test data into a test DB during a maven build for integration testing. persistence.xml is being copied to <code>target/test-classes/META-INF/</code> correctly, but I get this exception when the test is run.</p>
<blockquote>
<p>javax.persistence.PersistenceException:
No Persistence provider for
EntityManager named aimDatabase</p>
</blockquote>
<p>It looks like it's not finding or loading persistence.xml.</p>
|
[{'answer_id': 78643, 'author': 'kbaribeau', 'author_id': 8085, 'author_profile': 'https://Stackoverflow.com/users/8085', 'pm_score': 2, 'selected': False, 'text': '<p>If this is on windows, you can use sysinternal\'s procmon to find out if it\'s checking the right path.</p>\n\n<p>Just filter by path -> contains -> persistence.xml. Procmon will pick up any attempts to open a file named persistenc.xml, and you can check to see the path or paths that get tried.</p>\n\n<p>See here for more detail on procmon: <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="nofollow noreferrer">http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx</a></p>\n'}, {'answer_id': 232105, 'author': 'stevemac', 'author_id': 20150, 'author_profile': 'https://Stackoverflow.com/users/20150', 'pm_score': 2, 'selected': False, 'text': "<p>I had the same problem and it wasn't that it couldn't find the persistence.xml file, but that it couldn't find the provider specified in the XML.</p>\n\n<p>Ensure that you have the correct JPA provider dependancies and the correct provider definition in your xml file.</p>\n\n<p>ie. <code><provider>oracle.toplink.essentials.PersistenceProvider</provider></code></p>\n\n<p>With maven, I had to install the 2 toplink-essentials jars locally as there were no public repositories that held the dependancies.</p>\n"}, {'answer_id': 272176, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>we got the same problem, does some tweaking on the project and finaly find following \nproblem (more clear error description):\nat oracle.toplink.essentials.ejb.cmp3.persistence.\n PersistenceUnitProcessor.computePURootURL(PersistenceUnitProcessor.java:248)</p>\n\n<p>With that information we recalled a primary rule:\nNO WHITE SPACES IN PATH NAMES!!!</p>\n\n<p>Try this. Works for us <em>smile</em>.\nMaybe some day this will be fixed.</p>\n\n<p>Hope this works for you. Good luck.</p>\n'}, {'answer_id': 1380292, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': "<p>I'm using Maven2, and I had forgotten to add this dependency in my pom.xml file:</p>\n\n<pre><code> <dependency>\n <groupId>org.hibernate</groupId>\n <artifactId>hibernate-entitymanager</artifactId>\n <version>3.4.0.GA</version>\n </dependency> \n</code></pre>\n"}, {'answer_id': 2131109, 'author': 'jhumble', 'author_id': 217829, 'author_profile': 'https://Stackoverflow.com/users/217829', 'pm_score': 4, 'selected': False, 'text': '<p>Just solved the same problem with a Maven/Eclipse based JPA project.</p>\n\n<p>I had my META-INF directory under <code>src/main/java</code> with the concequence that it was not copied to the target directory before the test phase.</p>\n\n<p>Moving this directory to <code>src/main/resources</code> solved the problem and ensured that the <code>META-INF/persistence.xml</code> file was present in <code>target/classes</code> when the tests were run.</p>\n\n<p>I <em>think</em> that the JPA facet put my <code>META-INF/persistence.xml</code> file in <code>src/main/java</code>, which turned out to be the root of my problem.</p>\n'}, {'answer_id': 3212235, 'author': 'Nils Schmidt', 'author_id': 255036, 'author_profile': 'https://Stackoverflow.com/users/255036', 'pm_score': 2, 'selected': False, 'text': '<p>Is your persistence.xml located in scr/test/resources? Cause I was facing similar problems.</p>\n\n<p>Everything is working fine as long as my <strong>persistence.xml</strong> is located in <strong>src/main/resources</strong>. </p>\n\n<p>If I move <strong>persistence.xml</strong> to <strong>src/test/resources</strong> nothing works anymore. </p>\n\n<p>The only helpful but sad answer is here: <a href="http://jira.codehaus.org/browse/SUREFIRE-427" rel="nofollow noreferrer">http://jira.codehaus.org/browse/SUREFIRE-427</a></p>\n\n<p>Seems like it is not possible right now for unclear reasons. :-(</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76591', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4893/']
|
76,595 |
<p>Is REST a better approach to doing Web Services or is SOAP? Or are they different tools for different problems? Or is it a nuanced issue - that is, is one slightly better in certain arenas than another, etc?</p>
<p>I would especially appreciate information about those concepts and their relation to the PHP-universe and also modern high-end web-applications. </p>
|
[{'answer_id': 76621, 'author': 'cynicalman', 'author_id': 410, 'author_profile': 'https://Stackoverflow.com/users/410', 'pm_score': 3, 'selected': False, 'text': '<p>It\'s nuanced.</p>\n\n<p>If you need to have other systems interface with your services, than a lot of clients will be happier with SOAP, due to the layers of "verification" you have with the contracts, WSDL, and the SOAP standard.</p>\n\n<p>For day-to-day systems calling into systems, I think that SOAP is a lot of unnecessary overhead when a simple HTML call will do.</p>\n'}, {'answer_id': 76635, 'author': 'cranley', 'author_id': 10308, 'author_profile': 'https://Stackoverflow.com/users/10308', 'pm_score': 3, 'selected': False, 'text': "<p>It's a good question... I don't want to lead you astray, so I'm open to other people's answers as much as you are. For me, it really comes down to cost of overhead and what the use of the API is. I prefer consuming web services when creating client software, however I don't like the weight of SOAP. REST, I believe, is lighter weight but I don't enjoy working with it from a client perspective nearly as much.</p>\n\n<p>I'm curious as to what others think.</p>\n"}, {'answer_id': 76709, 'author': 'neu242', 'author_id': 13365, 'author_profile': 'https://Stackoverflow.com/users/13365', 'pm_score': 2, 'selected': False, 'text': "<p>If you are looking for interoperability between different systems and languages, I would definately go for REST. I've had a lot of problems trying to get SOAP working between .NET and Java, for example.</p>\n"}, {'answer_id': 76714, 'author': 'Cruachan', 'author_id': 7315, 'author_profile': 'https://Stackoverflow.com/users/7315', 'pm_score': 3, 'selected': False, 'text': "<p>Don't overlook XML-RPC. If you're just after a lightweight solution then there's a great deal to be said for a protocol that can be defined in a couple of pages of text and implemented in a minimal amount of code. XML-RPC has been around for years but went out of fashion for a while - but the minimalist appeal seems to be giving it something of a revival of late.</p>\n"}, {'answer_id': 76740, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 5, 'selected': False, 'text': '<p><strong>SOAP</strong> currently has the advantage of better tools where they will generate a lot of the boilerplate code for both the service layer as well as generating clients from any given WSDL. </p>\n\n<p><strong>REST</strong> is simpler, can be easier to maintain as a result, lies at the heart of Web architecture, allows for better protocol visibility, and has been proven to scale at the size of the WWW itself. Some frameworks out there help you build REST services, like Ruby on Rails, and some even help you with writing clients, like ADO.NET Data Services. But for the most part, tool support is lacking.</p>\n'}, {'answer_id': 76755, 'author': 'Will Hartung', 'author_id': 13663, 'author_profile': 'https://Stackoverflow.com/users/13663', 'pm_score': 8, 'selected': False, 'text': '<p>REST is an architecture, SOAP is a protocol.</p>\n\n<p>That\'s the first problem.</p>\n\n<p>You can send SOAP envelopes in a REST application.</p>\n\n<p>SOAP itself is actually pretty basic and simple, it\'s the WSS-* standards on top of it that make it very complex.</p>\n\n<p>If your consumers are other applications and other servers, there\'s a lot of support for the SOAP protocol today, and the basics of moving data is essentially a mouse-click in modern IDEs.</p>\n\n<p>If your consumers are more likely to be RIAs or Ajax clients, you will probably want something simpler than SOAP, and more native to the client (notably JSON).</p>\n\n<p>JSON packets sent over HTTP is not necessarily a REST architecture, it\'s just messages to URLs. All perfectly workable, but there are key components to the REST idiom. It is easy to confuse the two however. But just because you\'re talking HTTP requests does not necessarily mean you have a REST architecture. You can have a REST application with no HTTP at all (mind, this is rare).</p>\n\n<p>So, if you have servers and consumers that are "comfortable" with SOAP, SOAP and WSS stack can serve you well. If you\'re doing more ad hoc things and want to better interface with web browsers, then some lighter protocol over HTTP can work well also.</p>\n'}, {'answer_id': 76811, 'author': 'toluju', 'author_id': 12457, 'author_profile': 'https://Stackoverflow.com/users/12457', 'pm_score': 7, 'selected': False, 'text': '<p>REST is a fundamentally different paradigm from SOAP. A good read on REST can be found here: <a href="http://katgleason.tumblr.com/post/37836552900/how-i-explained-rest-to-my-wife" rel="noreferrer">How I explained REST to my wife</a>. </p>\n\n<p>If you don\'t have time to read it, here\'s the short version: REST is a bit of a paradigm shift by focusing on "nouns", and restraining the number of "verbs" you can apply to those nouns. The only allowed verbs are "get", "put", "post" and "delete". This differs from SOAP where many different verbs can be applied to many different nouns (i.e. many different functions). </p>\n\n<p>For REST, the four verbs map to the corresponding HTTP requests, while the nouns are identified by URLs. This makes state management much more transparent than in SOAP, where its often unclear what state is on the server and what is on the client.</p>\n\n<p>In practice though most of this falls away, and REST usually just refers to simple HTTP requests that return results in <a href="http://www.json.org/" rel="noreferrer">JSON</a>, while SOAP is a more complex API that communicates by passing XML around. Both have their advantages and disadvantages, but I\'ve found that in my experience REST is usually the better choice because you rarely if ever need the full functionality you get from SOAP.</p>\n'}, {'answer_id': 76919, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': False, 'text': "<p>SOAP is useful from a tooling perspective because the WSDL is so easily consumed by tools. So, you can get Web Service clients generated for you in your favorite language.</p>\n\n<p>REST plays well with AJAX'y web pages. If you keep your requests simple, you can make service calls directly from your JavaScript, and that comes in very handy. Try to stay away from having any namespaces in your response XML, I've seen browsers choke on those. So, xsi:type is probably not going to work for you, no overly complex XML Schemas.</p>\n\n<p>REST tends to have better performance as well. CPU requirements of the code generating REST responses tend to be lower than what SOAP frameworks exhibit. And, if you have your XML generation ducks lined up on the server side, you can effectively stream XML out to the client. So, imagine you're reading rows of database cursor. As you read a row, you format it as an XML element, and you write that directly out to the service consumer. This way, you don't have to collect all of the database rows in memory before starting to write your XML output - you read and write at the same time. Look into novel templating engines or XSLT to get the streaming to work for REST.</p>\n\n<p>SOAP on the other hand tends to get generated by tool-generated services as a big blob and only then written. This is not an absolute truth, mind you, there are ways to get streaming characteristics out of SOAP, like by using attachments. </p>\n\n<p>My decision making process is as follows: if I want my service to be easily tooled by consumers, and the messages I write will be medium-to-small-ish (10MB or less), and I don't mind burning some extra CPU cycles on the server, I go with SOAP. If I need to serve to AJAX on web browsers, or I need the thing to stream, or my responses are gigantic, I go REST.</p>\n\n<p>Finally, there are lots of great standards built up around SOAP, like WS-Security and getting stateful Web Services, that you can plug in to if you're using the right tools. That kind of stuff really makes a difference, and can help you satisfy some hairy requirements.</p>\n"}, {'answer_id': 76954, 'author': 'gbjbaanb', 'author_id': 13744, 'author_profile': 'https://Stackoverflow.com/users/13744', 'pm_score': 4, 'selected': False, 'text': "<p>I'm sure Don Box created SOAP as a joke - 'look you <em>can</em> call RPC methods over the web' and today groans when he realises what a bloated nightmare of web standards it has become :-)</p>\n\n<p>REST is good, simple, implemented everywhere (so more a 'standard' than the standards) fast and easy. Use REST.</p>\n"}, {'answer_id': 77018, 'author': 'mdhughes', 'author_id': 6292, 'author_profile': 'https://Stackoverflow.com/users/6292', 'pm_score': 9, 'selected': False, 'text': '<p>I built one of the first SOAP servers, including code generation and WSDL generation, from the original spec as it was being developed, when I was working at Hewlett-Packard. I do NOT recommend using SOAP for anything.</p>\n\n<p>The acronym "SOAP" is a lie. It is not Simple, it is not Object-oriented, it defines no Access rules. It is, arguably, a Protocol. It is Don Box\'s worst spec ever, and that\'s quite a feat, as he\'s the man who perpetrated "COM".</p>\n\n<p>There is nothing useful in SOAP that can\'t be done with REST for transport, and JSON, XML, or even plain text for data representation. For transport security, you can use https. For authentication, basic auth. For sessions, there\'s cookies. The REST version will be simpler, clearer, run faster, and use less bandwidth.</p>\n\n<p>XML-RPC clearly defines the request, response, and error protocols, and there are good libraries for most languages. However, XML is heavier than you need for many tasks.</p>\n'}, {'answer_id': 82111, 'author': 'James Strachan', 'author_id': 2068211, 'author_profile': 'https://Stackoverflow.com/users/2068211', 'pm_score': 4, 'selected': False, 'text': '<p>I\'d recommend you go with REST first - if you\'re using Java look at JAX-RS and the <a href="http://jersey.java.net/" rel="noreferrer">Jersey</a> implementation. REST is much simpler and easy to interop in many languages. </p>\n\n<p>As others have said in this thread, the problem with SOAP is its complexity when the other WS-* specifications come in and there are countless interop issues if you stray into the wrong parts of WSDL, XSDs, SOAP, WS-Addressing etc.</p>\n\n<p>The best way to judge the REST v SOAP debate is look on the internet - pretty much all the big players in the web space, google, amazon, ebay, twitter et al - tend to use and prefer RESTful APIs over the SOAP ones.</p>\n\n<p>The other nice approach to going with REST is that you can reuse lots of code and infratructure between a web application and a REST front end. e.g. rendering HTML versus XML versus JSON of your resources is normally pretty easy with frameworks like JAX-RS and implicit views - plus its easy to work with RESTful resources using a web browser</p>\n'}, {'answer_id': 383675, 'author': 'Mark Beckwith', 'author_id': 45799, 'author_profile': 'https://Stackoverflow.com/users/45799', 'pm_score': 3, 'selected': False, 'text': '<p>Listen to <a href="http://www.se-radio.net/2008/05/episode-98-stefan-tilkov-on-rest/" rel="noreferrer">this podcast</a> to find out. If you want to know the answer without listening, then OK, its REST. But I really do recommend listening.</p>\n'}, {'answer_id': 1298850, 'author': 'John Saunders', 'author_id': 76337, 'author_profile': 'https://Stackoverflow.com/users/76337', 'pm_score': 4, 'selected': False, 'text': '<p>One thing that hasn\'t been mentioned is that a SOAP envelope can contain headers as well as body parts. This lets you use the full expressiveness of XML to send and receive out of band information. REST, as far as I know, limits you to HTTP Headers and result codes.</p>\n\n<p>(otoh, can you use cookies with a REST service to send "header"-type out of band data?)</p>\n'}, {'answer_id': 1460837, 'author': 'Travis Heseman', 'author_id': 175094, 'author_profile': 'https://Stackoverflow.com/users/175094', 'pm_score': 4, 'selected': False, 'text': "<p>Most of the applications I write are server-side C# or Java, or desktop applications in WinForms or WPF. These applications tend to need a richer service API than REST can provide. Plus, I don't want to spend any more than a couple minutes creating my web service client. The WSDL processing client generation tools allow me to implement my client and move on to adding business value.</p>\n\n<p>Now, if I were writing a web service explicitly for some javascript ajax calls, it'd probably be in REST; just for the sake knowing the client technology and leveraging JSON. In my opinion, web service APIs used from javascript probably shouldn't be very complex, as that type of complexity seems to be better handled server-side.</p>\n\n<p>With that said, there some SOAP clients for javascript; I know jQuery has one. Thus, SOAP <i>can</i> be leveraged from javascript; just not as nicely as a REST service returning JSON strings. So if I had a web service that I wanted to be complex enough that it was flexible for an arbitrary number of client technologies and uses, I'd go with SOAP.</p>\n"}, {'answer_id': 3322449, 'author': 'Josh M.', 'author_id': 374198, 'author_profile': 'https://Stackoverflow.com/users/374198', 'pm_score': 5, 'selected': False, 'text': '<p>I know this is an old question but I have to post my answer - maybe someone will find it useful. I can\'t believe how many people are recommending REST over SOAP. I can only assume these people are not developers or have never actually implemented a REST service of any reasonable size. Implementing a REST service takes a LOT longer than implementing a SOAP service. And in the end it comes out a lot messier, too. Here are the reasons I would choose SOAP 99% of the time:</p>\n\n<p>1) Implementing a REST service takes infinitely longer than implementing a SOAP service. Tools exist for all modern languages/frameworks/platforms to read in a WSDL and output proxy classes and clients. Implementing a REST service is done by hand and - get this - by reading documentation. Furthermore, while implementing these two services, you have to make "guesses" as to what will come back across the pipe as there is no real schema or reference document.</p>\n\n<p>2) Why write a REST service that returns XML anyway? The only difference is that with REST you don\'t know the types each element/attribute represents - you are on your own to implement it and hope that one day a string doesn\'t come across in a field you thought was always an int. SOAP defines the data structure using the WSDL so this is a no-brainer.</p>\n\n<p>3) I\'ve heard the complaint that with SOAP you have the "overhead" of the SOAP Envelope. In this day and age, do we really need to worry about a handful of bytes?</p>\n\n<p>4) I\'ve heard the argument that with REST you can just pop the URL into the browser and see the data. Sure, if your REST service is using simple or no authentication. The Netflix service, for instance, uses OAuth which requires you to sign things and encode things before you can even submit your request.</p>\n\n<p>5) Why do we need a "readable" URL for each resource? If we were using a tool to implement the service, do we really care about the actual URL?</p>\n\n<p>Need I go on?</p>\n'}, {'answer_id': 6389328, 'author': 'Exitos', 'author_id': 223863, 'author_profile': 'https://Stackoverflow.com/users/223863', 'pm_score': 3, 'selected': False, 'text': "<p>I am looking at the same issue. Seems to me that actually REST is quick and easy and good for lightweight calls and responses and great for debugging (what could be better than pumping a URL into a browser and seeing the response).</p>\n\n<p>However where REST seems to fall down is to do with the fact that its not a standard (although it is comprised of standards). Most programming libraries have a way of inspecting a WSDL to automatically generate the client code needed to consume a SOAP based services. Thus far consuming REST based web services seems a more adhoc approach of writing an interface to match the calls that are possible. Making a manual http request then parsing the response. This in itself can be dangerous. </p>\n\n<p>The beauty of SOAP is that once a WSDL is issued then business' can structure their logic aorund that set contract any change to the interface will change the wsdl. There isnt any room for manouvre. You can validate all requests against that WSDL. However because a WSDL doesnt properly describe a REST service then you have no defined way of agreeing on the interface for communication.</p>\n\n<p>From a business perspective this does seem to leave the communication open to interpretation and change which seems like a bad idea.</p>\n\n<p>The top 'Answer' in this thread seems to say that SOAP stands for Simple Object-oriented Access Protocol, however looking at wiki the O means Object not Object-oriented. They are different things.</p>\n\n<p>I know this post is very old but thought I should respond with my own findings.</p>\n"}, {'answer_id': 7086147, 'author': 'Chris Broski', 'author_id': 468111, 'author_profile': 'https://Stackoverflow.com/users/468111', 'pm_score': 3, 'selected': False, 'text': '<p>REST is an architecture invented by Roy Fielding and described in his dissertation <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm">Architectural Styles and the Design of Network-based Software Architectures</a>. Roy is also the main author of <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a> - the protocol that defines document transfer over the World Wide Web. HTTP is a RESTful protocol. When developers talk about "using REST Web services" it is probably more accurate to say "using HTTP."</p>\n\n<p>SOAP is a XML-based protocol that tunnels inside an HTTP request/response, so even if you use SOAP, you are using REST too. There is some debate over whether SOAP adds any significant functionality to basic HTTP.</p>\n\n<p>Before authoring a Web service, I would recommend studying HTTP. Odds are your requirements can be implemented with functionality already defined in the spec, so other protocols won\'t be needed.</p>\n'}, {'answer_id': 8214578, 'author': 'irobson', 'author_id': 567273, 'author_profile': 'https://Stackoverflow.com/users/567273', 'pm_score': 4, 'selected': False, 'text': '<p>I think that both has its own place. In my opinion:</p>\n\n<p><strong>SOAP</strong>: A better choice for integration between legacy/critical systems and a web/web-service system, on the foundation layer, where WS-* make sense (security, policy, etc.). </p>\n\n<p><strong>RESTful</strong>: A better choice for integration between websites, with public API, on the TOP of layer (VIEW, ie, javascripts taking calls to URIs). </p>\n'}, {'answer_id': 13952665, 'author': 'Peter Krauss', 'author_id': 287948, 'author_profile': 'https://Stackoverflow.com/users/287948', 'pm_score': 3, 'selected': False, 'text': '<p>Answering the 2012 refreshed (by the second bounty) question, and reviewing the today\'s results (other answers).</p>\n<hr />\n<h1>SOAP, pros and cons</h1>\n<p>About SOAP 1.2, advantages and drawbacks when comparing with "REST"... Well, since 2007\n<a href="http://www.ibm.com/developerworks/webservices/library/ws-restwsdl/" rel="nofollow noreferrer">you can describe REST Web services with WSDL</a>,\nand using SOAP protocol... That is, if you work a little harder, <strong><a href="http://en.wikipedia.org/wiki/Web_services_protocol_stack" rel="nofollow noreferrer">all W3C standards of the web services protocol stack</a> can be REST</strong>!</p>\n<p>It is a good starting point, because we can imagine a scenario in which all the philosophical and methodological discussions are temporarily avoided. We can compare technically "SOAP-REST" with "NON-SOAP-REST" in similar services,</p>\n<ul>\n<li><p><strong>SOAP-REST</strong> (="REST-SOAP"): as <a href="http://www.ibm.com/developerworks/webservices/library/ws-restwsdl/" rel="nofollow noreferrer">showed by L.Mandel</a>, WSDL2 can describe a REST webservice, and, if we suppose that exemplified XML can be enveloped in SOAP, all the implementation will be "SOAP-REST".</p>\n</li>\n<li><p><strong>NON-SOAP-REST</strong>: any REST web service that can not be SOAP... That is, "90%" of the well-knowed REST examples. Some not use XML (ex. typical AJAX RESTs use JSON instead), some use another XML strucutures, without the SOAP headers or rules. PS: to avoid informality, we can suppose <a href="http://martinfowler.com/articles/richardsonMaturityModel.html" rel="nofollow noreferrer">REST level 2</a> in the comparisons.</p>\n</li>\n</ul>\n<p>Of course, to compare more conceptually, compare "NON-REST-SOAP" with "NON-SOAP-REST", as different modeling approaches. So, completing this taxonomy of web services:</p>\n<ul>\n<li><p><strong>NON-REST-SOAP</strong>: any SOAP web service that can not be REST... That is, "90%" of the well-knowed SOAP examples.</p>\n</li>\n<li><p><strong>NON-REST-NEITHER-SOAP</strong>: yes, the universe of "web services modeling" comprises other things (ex. <a href="http://xmlrpc.scripting.com/spec" rel="nofollow noreferrer">XML-RPC</a>).</p>\n</li>\n</ul>\n<h2>SOAP in the REST condictions</h2>\n<p>Comparing comparable things: <em>SOAP-REST</em> with <em>NON-SOAP-REST</em>.</p>\n<h3>PROS</h3>\n<p>Explaining some terms,</p>\n<ul>\n<li><p><em>Contractual stability</em>: for all kinds of contracts (as "written agreements"),</p>\n<ul>\n<li><p>By the <em>use of standars</em>: all levels of the <a href="http://en.wikipedia.org/wiki/Web_services_protocol_stack" rel="nofollow noreferrer">W3C stack</a> are mutually compliant. REST, by other hand, is not a W3C or ISO standard, and have no normatized details about service\'s peripherals. So, as <a href="https://stackoverflow.com/a/13969577/287948">I</a>, @DaveWoldrich(20 votes), @cynicalman(5), @Exitos(0) said before, in a context where are NEED FOR STANDARDS, you need SOAP.</p>\n</li>\n<li><p>By the <em>use of best practices</em>: the "verbose aspect" of the <em>W3C stack</em> implementations, translates relevant human/legal/juridic agreements.</p>\n</li>\n</ul>\n</li>\n<li><p><em>Robustness</em>: the safety of SOAP structure and headers. With metada communication (with the full expressiveness of XML) and <a href="http://en.wikipedia.org/wiki/Formal_verification" rel="nofollow noreferrer">verification</a> you have an "insurance policy" against any changes or noise. <br> SOAP have "transactional reliability (...) deal with communication failures. SOAP has more controls around retry logic and thus can provide more end-to-end reliability and service guarantees", <a href="http://esj.com/Articles/2011/08/01/SOAP-and-REST-101.aspx?Page=2" rel="nofollow noreferrer">E. Terman</a>.</p>\n</li>\n</ul>\n<p>Sorting pros by popularity,</p>\n<ul>\n<li><p><strong>Better tools</strong> (~70 votes): SOAP currently has the advantage of better tools, since 2007 and still 2012, because it is a well-defined and widely accepted standard. See @MarkCidade(27 votes), @DaveWoldrich(20), @JoshM(13), @TravisHeseman(9).</p>\n</li>\n<li><p><strong>Standars compliance</strong> (25 votes): as <a href="https://stackoverflow.com/a/13969577/287948">I</a>, @DaveWoldrich(20 votes), @cynicalman(5), @Exitos(0) said before, in a context where are NEED FOR STANDARDS, you need SOAP.</p>\n</li>\n<li><p><strong>Robustness</strong>: insurance of SOAP headers, @JohnSaunders (8 votes).</p>\n</li>\n</ul>\n<h3>CONS</h3>\n<ul>\n<li><p><strong>SOAP strucuture is more complex</strong> (more than 300 votes): all answers here, and sources about "SOAP vs REST", manifest some degree of dislike with SOAP\'s redundancy and complexity. This is a natural consequence of the requirements for <em>formal verification</em> (see below), and for <em>robustness</em> (see above). "REST NON-SOAP" (and XML-RPC, the <a href="http://en.wikipedia.org/wiki/XML-RPC#History" rel="nofollow noreferrer">SOAP originator</a>) can be more simple and informal.</p>\n</li>\n<li><p><strong>The "only XML" restriction is a performance obstacle</strong> when using tiny services (~50 votes): see <a href="http://www.json.org/xml.html" rel="nofollow noreferrer">json.org/xml</a> and <a href="https://stackoverflow.com/q/4862310/287948">this question</a>, or <a href="https://stackoverflow.com/q/3951047/287948">this other one</a>. This point is showed by @toluju(41), and others. <br>PS: as <a href="https://www.rfc-editor.org/rfc/rfc4627" rel="nofollow noreferrer">JSON is not a IETF standard</a>, but we can consider a <em>de facto standard</em> for web software community.</p>\n</li>\n</ul>\n<hr />\n<h2>Modeling services with SOAP</h2>\n<p>Now, we can add <em>SOAP-NON-REST</em> with <em>NON-SOAP-REST</em> comparisons, and explain <strong>when is better to use SOAP</strong>:</p>\n<ul>\n<li><p><em>Need for standards</em> and stable contracts (see "PROS" section). PS: see a <a href="https://stackoverflow.com/a/7521548/287948">typical "B2B need for standards" described by @saille</a>.</p>\n</li>\n<li><p><em>Need for tools</em> (see "PROS" section). PS: <em>standards</em>, and the existence of <em>formal verifications</em> (see bellow), are important issues for the tools automation.</p>\n</li>\n<li><p><em>Parallel heavy processing</em> (see "Context/Foundations" section below): with bigger and/or slower processes, no matter with a bit more complexity of SOAP, reliability and stability are the best investments.</p>\n</li>\n<li><p><em>Need more security</em>: when more than HTTPS is required, and you really need additional features for protection, SOAP is a better choice (<a href="https://stackoverflow.com/a/853732/287948">see @Bell</a>, 32 votes). "Sending the message along a path more complicated than request/response or over a transport that does not involve HTTP", <a href="http://msdn.microsoft.com/en-us/library/ms977327.aspx" rel="nofollow noreferrer">S. Seely</a>. XML is a core issue, offering standards for <em>XML Encryption</em>, <em>XML Signature</em>, and <em>XML Canonicalization</em>, and, only with SOAP you can to embed these mechanisms into a message by a well-accepted standard as <em>WS-Security</em>.</p>\n</li>\n<li><p><em>Need more flexibility</em> (less restrictions): SOAP not need exact correspondence with an URI; not nedd restrict to HTTP; not need to restrict to 4 verbs. As @TravisHeseman (9 votes) says, if you wanted something "flexible for an arbitrary number of client technologies and uses", use SOAP.<br>PS: remember that XML is more universal/expressive than JSON (et al).</p>\n</li>\n<li><p><em>Need for <a href="http://en.wikipedia.org/wiki/Formal_verification" rel="nofollow noreferrer">formal verifications</a></em>: important to understand that <em>W3C stack</em> uses <a href="http://en.wikipedia.org/wiki/Formal_methods" rel="nofollow noreferrer">formal methods</a>, and REST is more informal. Your WSDL (a <a href="http://en.wikipedia.org/wiki/Specification_language" rel="nofollow noreferrer">formal language</a>) service description is a <a href="http://en.wikipedia.org/wiki/Formal_methods" rel="nofollow noreferrer">formal specification</a> of your web services interfaces, and SOAP is a robust protocol that accept all possible WSDL prescriptions.</p>\n</li>\n</ul>\n<h1>CONTEXT</h1>\n<h2>Historical</h2>\n<p>To assess trends is necessary historical perspective. For this subject, a 10 or 15 years perspective...</p>\n<p>Before the W3C standardization, there are some anarchy. Was difficult to implement interoperable services with different frameworks, and more difficult, costly, and time consuming to implement something interoperable between companys.\nThe <em>W3C stack</em> standards has been a light, a north for interoperation of sets of complex web services.</p>\n<p>For day-by-day tasks, like to implement AJAX, SOAP is heavy... So, the need for simple approaches need to elect a new theory-framework... And big "Web software players", as Google, Amazon, Yahoo, et al, elected the best alternative, that is the REST approach. Was in this context that REST concept arrived as a "competing framework", and, today (2012\'s), this alternative is a <a href="http://en.wikipedia.org/wiki/De_facto_standard" rel="nofollow noreferrer">de facto standard</a> for programmers.</p>\n<h2>Foundations</h2>\n<p>In a context of <em>Parallel Computing</em> the web services provides parallel subtasks; and protocols, like SOAP, ensures good synchronization and communication. Not "any task": web services can be classified as<br />\n<a href="http://en.wikipedia.org/wiki/Parallel_computing#Fine-grained.2C_coarse-grained.2C_and_embarrassing_parallelism" rel="nofollow noreferrer">coarse-grained and embarrassing parallelism</a>.</p>\n<p>As the task gets bigger, it becomes less significant "complexity debate", and becomes more relevant the robustness of the communication and the solidity of the contracts.</p>\n'}, {'answer_id': 14016619, 'author': 'PmanAce', 'author_id': 1867682, 'author_profile': 'https://Stackoverflow.com/users/1867682', 'pm_score': 6, 'selected': False, 'text': '<p>Quick lowdown for 2012 question:</p>\n\n<p>Areas that REST works really well for are:</p>\n\n<ul>\n<li><p><strong>Limited bandwidth and resources.</strong> Remember the return structure is really in any format (developer defined). Plus, any browser can be used because the REST approach uses the standard\xa0GET,\xa0PUT,\xa0POST, and\xa0DELETE\xa0verbs. Again, remember that REST can also use the\xa0XMLHttpRequest\xa0object that most modern browsers support today, which adds an extra bonus of AJAX.</p></li>\n<li><p><strong>Totally stateless operations.</strong>\xa0If an operation needs to be continued, then REST is not the best approach and SOAP may fit it better. However, if you need stateless CRUD (Create, Read, Update, and Delete) operations, then REST is it.</p></li>\n<li><p><strong>Caching situations.</strong>\xa0If the information can be cached because of the totally stateless operation of the REST approach, this is perfect.That covers a lot of solutions in the above three. </p></li>\n</ul>\n\n<p>So why would I even consider SOAP? Again, SOAP is fairly mature and well-defined and does come with a complete specification. The REST approach is just that, an approach and is wide open for development, so if you have the following then SOAP is a great solution:</p>\n\n<ul>\n<li><p><strong>Asynchronous processing and invocation.</strong>\xa0If your application needs a guaranteed level of reliability and security then SOAP 1.2 offers additional standards to ensure this type of operation. Things like WSRM – WS-Reliable Messaging.</p></li>\n<li><p><strong>Formal contracts.</strong>\xa0If both sides (provider and consumer) have to agree on the exchange format then SOAP 1.2 gives the rigid specifications for this type of interaction.</p></li>\n<li><p><strong>Stateful operations.</strong> If the application needs contextual information and conversational state management then SOAP 1.2 has the additional specification in the WS* structure to support those things (Security, Transactions, Coordination, etc). Comparatively, the REST approach would make the developers build this custom plumbing.</p></li>\n</ul>\n\n<p><a href="http://www.infoq.com/articles/rest-soap-when-to-use-each" rel="noreferrer">http://www.infoq.com/articles/rest-soap-when-to-use-each</a></p>\n'}, {'answer_id': 14191318, 'author': 'Vibha Sanskrityayan', 'author_id': 1954219, 'author_profile': 'https://Stackoverflow.com/users/1954219', 'pm_score': 2, 'selected': False, 'text': '<p><strong>SOAP</strong> embodies a service-oriented approach to Web services — one in which methods (or verbs) are the primary way you interact with the service. <strong>REST</strong> takes a resource-oriented approach in which the object (or the noun) takes center stage.</p>\n'}, {'answer_id': 15094993, 'author': 'shivaspk', 'author_id': 170619, 'author_profile': 'https://Stackoverflow.com/users/170619', 'pm_score': 2, 'selected': False, 'text': '<p>In sense with "PHP-universe" PHP support for any advanced SOAP sucks big time. You will end up using something like <a href="http://wso2.com/products/web-services-framework/php/" rel="nofollow">http://wso2.com/products/web-services-framework/php/</a> as soon as you cross the basic needs, even to enable WS-Security or WS-RM no inbuilt support.</p>\n\n<p>SOAP envelope creation I feel is lot messy in PHP, the way it creates namespaces, xsd:nil, xsd:anytype and old styled soap Services which use SOAP Encoding (God knows how\'s that different) with in SOAP messages. </p>\n\n<p>Avoid all this mess by sticking to REST, REST is nothing really big we have been using it since the start of WWW. We realized only when this <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm" rel="nofollow">http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm</a> paper came out it shows how can we use HTTP capabilities to implement RESTFul Services. HTTP is inherently REST, that doesn\'t mean just using HTTP makes your services RESTFul. </p>\n\n<p>SOAP neglects the core capabilities of HTTP and considers HTTP just as an transport protocol, hence it is transport protocol independent in theory (in practical it\'s not the case have you heard of SOAP Action header? if not google it now!).</p>\n\n<p>With JSON adaption increasing and HTML5 with javascript maturing REST with JSON has become the most common way of dealing with services. JSON Schema has also been defined can be used for enterprise level solutions (still in early stages) along with WADL if needed. </p>\n\n<p>PHP support for REST and JSON is definitely better than existing inbuilt SOAP support it has. </p>\n\n<p>Adding few more BUZZ words here SOA, WOA, ROA </p>\n\n<p><a href="http://blog.dhananjaynene.com/2009/06/rest-soa-woa-or-roa/" rel="nofollow">http://blog.dhananjaynene.com/2009/06/rest-soa-woa-or-roa/</a></p>\n\n<p><a href="http://www.scribd.com/doc/15657444/REST-White-Paper" rel="nofollow">http://www.scribd.com/doc/15657444/REST-White-Paper</a></p>\n\n<p>by the way I do love SOAP especially for the WS-Security spec, this is one good spec and if someone thinking in Enterprise JSON adaption definetly need to come with some thing similar for JSON, like field level encryption etc.</p>\n'}, {'answer_id': 16569278, 'author': 'Rick Sarvas', 'author_id': 1585066, 'author_profile': 'https://Stackoverflow.com/users/1585066', 'pm_score': 3, 'selected': False, 'text': "<p>My general rule is that if you want a browser web client to directly connect to a service then you should probably use REST. If you want to pass structured data between back-end services then use SOAP.</p>\n\n<p>SOAP can be a real pain to set up sometimes and is often overkill for simple web client and server data exchanges. Unfortunately, most simple programming examples I've seen (and learned from) somewhat reenforce this perception. </p>\n\n<p>That said, SOAP really shines when you start combining multiple SOAP services together as part of a larger process driven by a data workflow (think enterprise software). This is something that many of the SOAP programming examples fail to convey because a simple SOAP operation to do something, like fetch the price of a stock, is generally overcomplicated for what it does by itself unless it is presented in the context of providing a machine readable API detailing specific functions with set data formats for inputs and outputs that is, in turn, scripted by a larger process.</p>\n\n<p>This is sad, in a way, as it really gives SOAP a bad reputation because it is difficult to show the advantages of SOAP without presenting it in the full context of how the final product is used.</p>\n"}, {'answer_id': 19463402, 'author': 'kapil das', 'author_id': 2041542, 'author_profile': 'https://Stackoverflow.com/users/2041542', 'pm_score': 3, 'selected': False, 'text': "<p>I am looking at the same, and i think,\n <strong>they are different tools for different problems</strong>.</p>\n\n<p>Simple Object Access Protocol (SOAP) standard an XML language defining a message architecture and message formats, is used by Web services it contain a description of the operations. WSDL is an XML-based language for describing Web services and how to access them. will run on SMTP,HTTP,FTP etc. Requires middleware support, well defined mechanisam to define services like WSDL+XSD, WS-Policy SOAP will return XML based data SOAP provide standards for security and reliability</p>\n\n<p>Representational State Transfer (RESTful) web services. they are second generation Web Services. RESTful web services, communicate via HTTP than SOAP-based services and do not require XML messages or WSDL service-API definitions. for REST no middleware is required only HTTP support is needed.WADL Standard, REST can return XML, plain text, JSON, HTML etc</p>\n\n<p>It is easier for many types of clients to consume RESTful web services while enabling the server side to evolve and scale. Clients can choose to consume some or all aspects of the service and mash it up with other web-based services.</p>\n\n<ol>\n<li>REST uses standard HTTP so it is simplerto creating clients, developing APIs</li>\n<li>REST permits many different data formats like XML, plain text, JSON, HTML where as SOAP only permits XML.</li>\n<li>REST has better performance and scalability. </li>\n<li>Rest and can be cached and SOAP can't</li>\n<li>Built-in error handling where SOAP has No error handling</li>\n<li>REST is particularly useful PDA and other mobile devices.</li>\n</ol>\n\n<p>REST is services are easy to integrate with existing websites.</p>\n\n<p>SOAP has set of protocols, which provide standards for security and reliability, among other things, and interoperate with other WS conforming clients and servers.\nSOAP Web services (such as JAX-WS) are useful in handling asynchronous processing and invocation.</p>\n\n<p>For Complex API's SOAP will be more usefull.</p>\n"}, {'answer_id': 19928499, 'author': 'BlueChippy', 'author_id': 449156, 'author_profile': 'https://Stackoverflow.com/users/449156', 'pm_score': 2, 'selected': False, 'text': '<p>One quick point - transmission protocol and orchestration;</p>\n\n<p>I use SOAP over TCP for speed, reliability and security reasons, including orchestrated machine to machine services (ESB) and to external services. Change the service definition, the orchestration raises an error from the WSDL change and its immediately obvious and can be rebuilt/deployed.</p>\n\n<p>Not sure you can do the same with REST - I await being corrected or course!\nWith REST, change the service definition - nothing knows about it until it returns 400 (or whatever).</p>\n'}, {'answer_id': 29001048, 'author': 'Remixed123', 'author_id': 2490660, 'author_profile': 'https://Stackoverflow.com/users/2490660', 'pm_score': 0, 'selected': False, 'text': "<p>An old question but still relevant today....due to so many developers in the enterprise space still using it.</p>\n\n<p>My work involves designing and developing IoT (Internet of Things) solutions. Which includes developing code for small embedded devices that communicate with the Cloud. </p>\n\n<p>It is clear REST is now widely accepted and useful, and pretty much the defacto standard for the web, even Microsoft has REST support included throughout Azure. If I needed to rely on SOAP I could not do what I need to do, as is just too big, bulky and annoying for small embedded devices.</p>\n\n<p>REST is simple and clean and small. Making it ideal for small embedded devices. I always scream when I am working with a web developer who sends me a WSDLs. As I will have to begin an education campaign about why this just isn't going to work and why they are going to have to learn REST.</p>\n"}, {'answer_id': 32859836, 'author': 'Shalini Baranwal', 'author_id': 4763959, 'author_profile': 'https://Stackoverflow.com/users/4763959', 'pm_score': 0, 'selected': False, 'text': '<p>1.From my experience. I would say REST gives you option to access the URL which is already built. eg-> a word search in google. That URL could be used as webservice for REST. \nIn SOAP, you can create your own web service and access it through SOAP client.</p>\n\n<ol start="2">\n<li>REST supports text,JSON,XML format. Hence more versatile for communicating between two applications. While SOAP supports only XML format for message communication.</li>\n</ol>\n'}, {'answer_id': 34963114, 'author': 'Sonador', 'author_id': 5751951, 'author_profile': 'https://Stackoverflow.com/users/5751951', 'pm_score': 2, 'selected': False, 'text': '<p>i create a benchmark for find which of them are faster!\ni see this result:</p>\n\n<p>for 1000 requests :</p>\n\n<ul>\n<li>REST took 3 second</li>\n<li>SOAP took 7 second</li>\n</ul>\n\n<p>for 10,000 requests :</p>\n\n<ul>\n<li>REST took 33 second</li>\n<li>SOAP took 69 second</li>\n</ul>\n\n<p>for 1,000,000 requests :</p>\n\n<ul>\n<li>REST took 62 second</li>\n<li>SOAP took 114 second</li>\n</ul>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76595', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13276/']
|
76,601 |
<p>I've got a client that sees the "Page can not be displayed" (nothing else) whenever they perform a certain action in their website. I don't get the error, ever. I've tried IE, FF, Chrome, and I do not see the error. The client sees the error on IE.</p>
<p>The error occurs when they press a form submit button that has only hidden fields.</p>
<p>I'm thinking this could be some kind of anti-malware / virus issue. has anyone ever dealt with this issue?</p>
|
[{'answer_id': 76644, 'author': 'ADB', 'author_id': 3610, 'author_profile': 'https://Stackoverflow.com/users/3610', 'pm_score': 0, 'selected': False, 'text': '<p>It would be useful to you to figure out which error code is returned. Is it 404 - Resource not found or 503 - Forbidden Access? There are a few more, but in any case, it would help you figure out the cause of the problem. </p>\n\n<p>If your client is running IE, ask him to disable friendly error messages in the advanced options.</p>\n'}, {'answer_id': 76671, 'author': 'Loren Segal', 'author_id': 6436, 'author_profile': 'https://Stackoverflow.com/users/6436', 'pm_score': 0, 'selected': False, 'text': '<p>Check their "hosts file". The location of this file is different for XP and vista</p>\n\n<p>in XP I believe it\'s <code>C:\\windows\\hosts</code> or <code>C:\\windows\\system32\\hosts</code></p>\n\n<p>Look for any suspicious domains.. Generally speaking, there should only be ~2 definitions (besides comments) in the files defining localhost and other local ip definitions. If there\'s anything else, make sure it\'s supposed to be there.</p>\n\n<p>Otherwise, maybe the site\'s just having issues? Also, AFAIK, FF never displays "Page cannot be displayed", so are you sure this is the case in all browsers?</p>\n'}, {'answer_id': 76687, 'author': 'Charles Graham', 'author_id': 7705, 'author_profile': 'https://Stackoverflow.com/users/7705', 'pm_score': 3, 'selected': True, 'text': '<p>In IE, go to the "Anvanced" section of "Internet Options" and uncheck "Show friendly HTTP errors". This should give you the <em>real</em> error.</p>\n'}, {'answer_id': 76751, 'author': 'Olaf Kock', 'author_id': 13447, 'author_profile': 'https://Stackoverflow.com/users/13447', 'pm_score': 1, 'selected': False, 'text': '<p>Is this an IE message? Ask them to switch off "short error messages" (or whatever they are called in the english version) somewhere deep in IEs options - This will make IE display the error message your server is sending instead of its own unhelpful message.</p>\n\n<p>Also I\'ve heard that IE might be forced to show server provided error messages if only the page is long/large enough, so you might want to add a longer "&nbsp; &nbsp; " section to error messages. This information is old enough that it might have effected older versions of IE - I usually get to the root of problems with eliminating the "short error messages"</p>\n\n<p>Note: I\'m neither running IE nor Windows, therefor can only operate on memory regarding the name of the config options of IE6...</p>\n\n<p><em>Update</em>: corrected <em>&nbsp;</em> usage in the suggestion to provide longer error messages... Perhaps somebody with access to IE can approve if longer error pages still force IE to display the original error page instead of the <em>user friendly</em> (sic) one.</p>\n'}, {'answer_id': 76893, 'author': 'Jonathan Arkell', 'author_id': 11052, 'author_profile': 'https://Stackoverflow.com/users/11052', 'pm_score': 0, 'selected': False, 'text': '<p>You can try using ieHTTPHeaders to see what is going on behind the scenes.</p>\n\n<p>Do you have any events applied to your submit button? Are you doing a custom submit button that is a hyperlink with an href like "javascript:void(0)" and an event attached that submits the form?</p>\n'}, {'answer_id': 49221946, 'author': 'Webb Lu', 'author_id': 4838119, 'author_profile': 'https://Stackoverflow.com/users/4838119', 'pm_score': 0, 'selected': False, 'text': '<p>Alought this is a 2008 thread,<br>\nbut I think maybe someone still use windows xp in the virtualbox in 2018 like me. </p>\n\n<p>The issue I met in 2018 is:<br>\n1. Ping to 8.8.8.8 can get correct responses.<br>\n2. HTTP sites is working fine, but HTTPS is not.<br>\n3. I cannot connect to any site with HTTPS so I cannot download Chrome or Firefox.</p>\n\n<p>And my solution is to enable the <code>TLS 1.0</code> for secure connections<br>\nEverything is fine.</p>\n\n<p><a href="https://i.stack.imgur.com/Bhdus.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bhdus.png" alt="enter image description here"></a></p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76601', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13666/']
|
76,624 |
<p>Is there a way to have a 64 bit enum in C++? Whilst refactoring some code I came across bunch of #defines which would be better as an enum, but being greater than 32 bit causes the compiler to error.</p>
<p>For some reason I thought the following might work:</p>
<pre><code>enum MY_ENUM : unsigned __int64
{
LARGE_VALUE = 0x1000000000000000,
};
</code></pre>
|
[{'answer_id': 76661, 'author': 'Doug T.', 'author_id': 8123, 'author_profile': 'https://Stackoverflow.com/users/8123', 'pm_score': 0, 'selected': False, 'text': "<p>An enum in C++ can be any integral type. You can, for example, have an enum of chars. IE:</p>\n\n<pre><code>enum MY_ENUM\n{\n CHAR_VALUE = 'c',\n};\n</code></pre>\n\n<p>I would <em>assume</em> this includes __int64. Try just</p>\n\n<pre><code>enum MY_ENUM\n{\n LARGE_VALUE = 0x1000000000000000,\n};\n</code></pre>\n\n<p>According to my commenter, sixlettervariables, in C the base type will be an int always, while in C++ the base type is whatever is large enough to fit the largest included value. So both enums above should work.</p>\n"}, {'answer_id': 76683, 'author': 'Ferruccio', 'author_id': 4086, 'author_profile': 'https://Stackoverflow.com/users/4086', 'pm_score': 5, 'selected': True, 'text': "<p>I don't think that's possible with C++98. The underlying representation of enums is up to the compiler. In that case, you are better off using:</p>\n\n<pre><code>const __int64 LARGE_VALUE = 0x1000000000000000L;\n</code></pre>\n\n<p>As of C++11, it is possible to use enum classes to specify the base type of the enum:</p>\n\n<pre><code>enum class MY_ENUM : unsigned __int64 {\n LARGE_VALUE = 0x1000000000000000ULL\n};\n</code></pre>\n\n<p>In addition enum classes introduce a new name scope. So instead of referring to <code>LARGE_VALUE</code>, you would reference <code>MY_ENUM::LARGE_VALUE</code>.</p>\n"}, {'answer_id': 76705, 'author': 'Torlack', 'author_id': 5243, 'author_profile': 'https://Stackoverflow.com/users/5243', 'pm_score': 1, 'selected': False, 'text': '<p>Since you are working in C++, another alternative might be </p>\n\n<pre><code>const __int64 LARVE_VALUE = ...\n</code></pre>\n\n<p>This can be specified in an H file.</p>\n'}, {'answer_id': 76756, 'author': 'INS', 'author_id': 13136, 'author_profile': 'https://Stackoverflow.com/users/13136', 'pm_score': 2, 'selected': False, 'text': "<p>If the compiler doesn't support 64 bit enums by compilation flags or any other means I think there is no solution to this one.</p>\n\n<p>You could create something like in your sample something like:</p>\n\n<pre><code>namespace MyNamespace {\nconst uint64 LARGE_VALUE = 0x1000000000000000;\n};\n</code></pre>\n\n<p>and using it just like an enum using </p>\n\n<pre><code>MyNamespace::LARGE_VALUE \n</code></pre>\n\n<p>or </p>\n\n<pre><code>using MyNamespace;\n....\nval = LARGE_VALUE;\n</code></pre>\n"}, {'answer_id': 76757, 'author': 'ugasoft', 'author_id': 10120, 'author_profile': 'https://Stackoverflow.com/users/10120', 'pm_score': 1, 'selected': False, 'text': '<p>your snipplet of code is not c++ standard:</p>\n\n<blockquote>\n <p>enum MY_ENUM : unsigned __int64 </p>\n</blockquote>\n\n<p>does not make sense.</p>\n\n<p>use const __int64 instead, as Torlack suggests</p>\n'}, {'answer_id': 76980, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 4, 'selected': False, 'text': '<p>C++11 supports this, using this syntax:</p>\n\n<pre><code>enum class Enum2 : __int64 {Val1, Val2, val3};\n</code></pre>\n'}, {'answer_id': 81531, 'author': 'MSalters', 'author_id': 15416, 'author_profile': 'https://Stackoverflow.com/users/15416', 'pm_score': 2, 'selected': False, 'text': '<p>The answers refering to <code>__int64</code> miss the problem. The enum <em>is</em> valid in all C++ compilers that have a true 64 bit integral type, i.e. any C++11 compiler, or C++03 compilers with appropriate extensions. Extensions to C++03 like <code>__int64</code> work differently across compilers, including its suitability as a base type for enums. </p>\n'}, {'answer_id': 1470527, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>In MSVC++ you can do this: </p>\n\n<p>enum MYLONGLONGENUM:__int64 { BIG_KEY=0x3034303232303330, ... };</p>\n'}, {'answer_id': 2630851, 'author': 'mloskot', 'author_id': 151641, 'author_profile': 'https://Stackoverflow.com/users/151641', 'pm_score': 3, 'selected': False, 'text': '<p>The current draft of so called <a href="http://en.wikipedia.org/wiki/C%2B%2B0x" rel="noreferrer">C++0x</a>, it is <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3092.pdf" rel="noreferrer">n3092</a> says in <strong>7.2 Enumeration declarations</strong>, paragraph 6:</p>\n\n<blockquote>\n <p>It is implementation-defined which\n integral type is used as the\n underlying type except that the\n underlying type shall not be larger\n than int unless the value of an\n enumerator cannot fit in an int or\n unsigned int.</p>\n</blockquote>\n\n<p>The same paragraph also says:</p>\n\n<blockquote>\n <p>If no integral type can represent all\n the enumerator values, the enumeration\n is ill-formed.</p>\n</blockquote>\n\n<p>My interpretation of the part <strong>unless the value of an enumerator cannot fit in an int or unsigned int</strong> is that it\'s perfectly valid and safe to initialise enumerator with 64-bit integer value as long as there is 64-bit integer type provided in a particular C++ implementation.</p>\n\n<p>For example:</p>\n\n<pre><code>enum MyEnum\n{\n Undefined = 0xffffffffffffffffULL\n};\n</code></pre>\n'}, {'answer_id': 13755860, 'author': 'human.js', 'author_id': 1198898, 'author_profile': 'https://Stackoverflow.com/users/1198898', 'pm_score': 1, 'selected': False, 'text': '<p>Enum type is normally determined by the data type of the first enum initializer. If the value should exceed the range for that integral datatype then c++ compiler will make sure it fits in by using a larger integral data type.If compiler finds that it does not belong to any of the integral data type then compiler will throw error.\nRef: <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf" rel="nofollow">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf</a>\n<br>Edit: However this is purely depended on machine architecture</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76624', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9236/']
|
76,629 |
<p>I would like to call my unmanaged C++ libraries from my C# code. What are the potential pitfalls and precautions that need to be taken? Thank you for your time.</p>
|
[{'answer_id': 76696, 'author': 'Jesse C. Slicer', 'author_id': 3312, 'author_profile': 'https://Stackoverflow.com/users/3312', 'pm_score': 2, 'selected': False, 'text': '<p>There are a couple routes you can go with this - one, you can update your unmanaged C++ libraries to have a managed C++ extensions wrapper around them and have C# utilize those classes directly. This is a bit time-consuming, but it provides a nice bridge to legacy unmanaged code. But be aware that managed C++ extensions are sometimes a bit hard to navigate themselves as the syntax is similar to unmanaged C++, but close enough that a very trained eye will be able to see the differences.</p>\n\n<p>The other route to go is have your umnanaged C++ implement COM classes and have C# utilize it via an autogenerated interop assembly. This way is easier if you know your way around COM well enough.</p>\n\n<p>Hope this helps.</p>\n'}, {'answer_id': 76775, 'author': '1800 INFORMATION', 'author_id': 3146, 'author_profile': 'https://Stackoverflow.com/users/3146', 'pm_score': 0, 'selected': False, 'text': '<p>You can also call into unmanaged code via P/Invoke. This may be easier if your code doesn\'t currently use COM. I guess you would probably need to write some specific export points in your code using "C" bindings if you went this route.</p>\n\n<p>Probably the biggest thing you have to watch out for in my experience is that the lack of deterministic garbage collection means that your destructors will not run when you might have thought they would previously. You need to keep this in mind and use IDisposable or some other method to make sure your managed code is cleaned up when you want it to be.</p>\n'}, {'answer_id': 76787, 'author': 'DougN', 'author_id': 7442, 'author_profile': 'https://Stackoverflow.com/users/7442', 'pm_score': 1, 'selected': False, 'text': "<p>You're describing P/Invoke. That means your C++ library will need to expose itself via a DLL interface, and the interface will need to be simple enough to describe to P/Invoke via the call attributes. When the managed code calls into the unmanaged world, the parameters have to be marshalled, so it seems there could be a slight performance hit, but you'd have to do some testing to see if the marshalling is significant or not.</p>\n"}, {'answer_id': 76837, 'author': 'stephbu', 'author_id': 12702, 'author_profile': 'https://Stackoverflow.com/users/12702', 'pm_score': 0, 'selected': False, 'text': '<p>Of course there is always PInvoke out there too if you packaged your code as DLLs with external entrypoints. None of the options are pain free. They depend on either a) your skill at writing COM or Managed C wrappers b) chancing your arm at PInvoke. </p>\n'}, {'answer_id': 76856, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>The easiest way to start is to make sure that all the C++ functionality is exposed as \'C\' style functions. Make sure to declare the function as _stdcall.</p>\n\n<p>extern "C" __declspec(dllexport) int _stdcall Foo(int a)</p>\n\n<p>Make sure you get the marshalling right, especially things like pointers & wchar_t *. If you get it wrong, it can be difficult to debug.</p>\n\n<p>Debug it from either side, but not both. When debugging mixed native & managed, the debugger can get very slow. Debugging 1 side at a time saves lots of time.</p>\n\n<p>Getting more specific would require a more specific question.</p>\n'}, {'answer_id': 77024, 'author': 'Alan', 'author_id': 2958, 'author_profile': 'https://Stackoverflow.com/users/2958', 'pm_score': 0, 'selected': False, 'text': '<p>I would take a look at <a href="http://www.swig.org/" rel="nofollow noreferrer">swig</a>, we use this to good effect on our project to expose our C++ API to other language platforms. </p>\n\n<p>It\'s a well maintained project that effectively builds a thin wrapper around your C++ library that can allow languages such as C# to communicate directly with your native code - saving you the trouble of having to implement (and debug) glue code.</p>\n'}, {'answer_id': 77176, 'author': 'Alex Reitbort', 'author_id': 11525, 'author_profile': 'https://Stackoverflow.com/users/11525', 'pm_score': 0, 'selected': False, 'text': '<p>If you want a good PInvoke examples you can look at <a href="http://www.pinvoke.net/" rel="nofollow noreferrer">PInvoke.net</a>. It has examples of how to call most of win api functions.</p>\n\n<p>Also you can use tool from this article <a href="http://msdn.microsoft.com/en-us/magazine/cc164193.aspx" rel="nofollow noreferrer">Clr Inside Out: PInvoke</a> that will translate your .h file to c# wrappers.</p>\n'}, {'answer_id': 77348, 'author': 'Michael Burr', 'author_id': 12711, 'author_profile': 'https://Stackoverflow.com/users/12711', 'pm_score': 2, 'selected': True, 'text': '<p>This question is too broad. The only reasonable answer is P/Invoke, but that\'s kind of like saying that if you want to program for Windows you need to know the Win32 API.</p>\n\n<p>Pretty much entire books have been written about P/Invoke (<a href="https://rads.stackoverflow.com/amzn/click/com/067232170X" rel="nofollow noreferrer" rel="nofollow noreferrer">http://www.amazon.com/NET-COM-Complete-Interoperability-Guide/dp/067232170X</a>), and of course entire websites have been made: <a href="http://www.pinvoke.net/" rel="nofollow noreferrer">http://www.pinvoke.net/</a>.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76629', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13673/']
|
76,637 |
<p>I have an linux app that uses cups for printing, but I've noticed that if I print and then quit my app right away my printout never appears. So I assume that my app has to wait for it to actually come out of the printer before quitting, so does anyone know how to tell when it's finished printing??</p>
<p>I'm using libcups to print a postscript file that my app generates. So I use the command to print the file and it then returns back to my app. So my app thinks that the document is off to the printer queue when I guess it has not made it there yet. So rather than have all my users have to look on the screen for the printer icon in the system tray I would rather have a solution in code, so if they try and quit before it has really been sent off I can alert them to the fact. Also the file I generate is a temporary file so it would be nice to know when it is finished with so I can delete it.</p>
|
[{'answer_id': 76813, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Your app likely hadn't finished printing yet when you quit it. If you're using evince to print a PDF or other document, this is a known bug--there is no visual confirmation that the printing operation is underway. If the print job has been submitted, a printer icon will appear in your system tray until the actual printing has finished. You can click on the printer icon in the system tray and see what jobs are currently running and pending.</p>\n"}, {'answer_id': 82209, 'author': 'Paweł Hajdan', 'author_id': 9403, 'author_profile': 'https://Stackoverflow.com/users/9403', 'pm_score': 1, 'selected': False, 'text': '<p>As soon as your CUPS web interface (localhost:631) or some other thing to look at what CUPS sees shows you that CUPS received the job, you can quit the application.</p>\n'}, {'answer_id': 190892, 'author': 'hendry', 'author_id': 4534, 'author_profile': 'https://Stackoverflow.com/users/4534', 'pm_score': 1, 'selected': False, 'text': '<p>How about using a print spool service like <code>lpr</code> & <code>lpq</code>?</p>\n'}, {'answer_id': 3022250, 'author': 'Kurt Pfeifle', 'author_id': 359307, 'author_profile': 'https://Stackoverflow.com/users/359307', 'pm_score': 1, 'selected': False, 'text': '<p>You certainly do not need to wait till the paper is out of the printer. However, you need to wait until your temporary file is fully received by cupsd in its spooling aerea (usually <code>/var/spool/cups/</code>).</p>\n\n<p>If you printed on the commandline (using one of the CUPS <code>lp</code> or <code>lpr</code> commands) you\'d know the job is underway if the shell prompt returns (the command will even report the CUPS job ID for the job sent), and if the exit code (<code>$?</code>) is 0.</p>\n\n<p>You do not indicate which part of libcups and which function call you are using to achieve what you want. If I\'d have to do this, I\'d use the IPP function <a href="http://www.cups.org/documentation.php/doc-1.4/api-httpipp.html#cupsSendRequest" rel="nofollow noreferrer"><code>cupsSendRequest</code></a> and then <a href="http://www.cups.org/documentation.php/doc-1.4/api-httpipp.html#cupsGetResponse" rel="nofollow noreferrer"><code>cupsGetResponse</code></a> to know the result.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76637', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13676/']
|
76,650 |
<p>This has me puzzled. This code worked on another server, but it's failing on Perl v5.8.8 with <a href="http://search.cpan.org/dist/Date-Manip" rel="nofollow noreferrer">Date::Manip</a> loaded from CPAN today.</p>
<pre><code>Warning:
Use of uninitialized value in numeric lt (<) at /home/downside/lib/Date/Manip.pm line 3327.
at dailyupdate.pl line 13
main::__ANON__('Use of uninitialized value in numeric lt (<) at
/home/downsid...') called at
/home/downside/lib/Date/Manip.pm line 3327
Date::Manip::Date_SecsSince1970GMT(09, 16, 2008, 00, 21, 22) called at
/home/downside/lib/Date/Manip.pm line 1905
Date::Manip::UnixDate('today', '%Y-%m-%d') called at
TICKER/SYMBOLS/updatesymbols.pm line 122
TICKER::SYMBOLS::updatesymbols::getdate() called at
TICKER/SYMBOLS/updatesymbols.pm line 439
TICKER::SYMBOLS::updatesymbols::updatesymbol('DBI::db=HASH(0x87fcc34)',
'TICKER::SYMBOLS::symbol=HASH(0x8a43540)') called at
TICKER/SYMBOLS/updatesymbols.pm line 565
TICKER::SYMBOLS::updatesymbols::updatesymbols('DBI::db=HASH(0x87fcc34)', 1, 0, -1) called at
dailyupdate.pl line 149
EDGAR::updatesymbols('DBI::db=HASH(0x87fcc34)', 1, 0, -1) called at
dailyupdate.pl line 180
EDGAR::dailyupdate() called at dailyupdate.pl line 193
</code></pre>
<p>The code that's failing is simply:</p>
<pre><code>sub getdate()
{ my $err; ## today
&Date::Manip::Date_Init('TZ=EST5EDT');
my $today = Date::Manip::UnixDate('today','%Y-%m-%d'); ## today's date
####print "Today is ",$today,"\n"; ## ***TEMP***
return($today);
}
</code></pre>
<p>That's right; <a href="http://search.cpan.org/dist/Date-Manip" rel="nofollow noreferrer">Date::Manip</a> is failing for <code>"today"</code>.</p>
<p>The line in <a href="http://search.cpan.org/dist/Date-Manip" rel="nofollow noreferrer">Date::Manip</a> that is failing is:</p>
<pre><code> my($tz)=$Cnf{"ConvTZ"};
$tz=$Cnf{"TZ"} if (! $tz);
$tz=$Zone{"n2o"}{lc($tz)} if ($tz !~ /^[+-]\d{4}$/);
my($tzs)=1;
$tzs=-1 if ($tz<0); ### ERROR OCCURS HERE
</code></pre>
<p>So <a href="http://search.cpan.org/dist/Date-Manip" rel="nofollow noreferrer">Date::Manip</a> is assuming that <code>$Cnf</code> has been initialized with elements <code>"ConvTZ"</code> or <code>"TZ"</code>. Those are initialized in <code>Date_Init</code>, so that should have been taken care of.</p>
<p>It's only failing in my large program. If I just extract "<code>getdate()</code>" above
and run it standalone, there's no error. So there's something about the
global environment that affects this.</p>
<p>This seems to be a known, but not understood problem. If you search Google for
"Use of uninitialized value date manip" there are about 2400 hits.
This error has been reported with <a href="http://www.lemis.com/grog/videorecorder/mythsetup-sep-2006.html" rel="nofollow noreferrer">MythTV</a> and <a href="http://www.cpan.org/modules/by-module/Mail/grepmail-4.51.readme" rel="nofollow noreferrer">grepmail</a>.</p>
|
[{'answer_id': 76698, 'author': 'Darren Meyer', 'author_id': 7826, 'author_profile': 'https://Stackoverflow.com/users/7826', 'pm_score': 2, 'selected': False, 'text': "<p>It's almost certain that your host doesn't have a definition for the timezone you're specifying, which is what's causing a value to be undefined.</p>\n\n<p>Have you checked to make sure a TZ definition file of the same name actually exists on the host?</p>\n"}, {'answer_id': 76821, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Date::Manip is supposed to be self-contained. It has a list of all its time zones in its own source, following "$zonesrfc=".</p>\n'}, {'answer_id': 82146, 'author': 'Sam Kington', 'author_id': 6832, 'author_profile': 'https://Stackoverflow.com/users/6832', 'pm_score': -1, 'selected': False, 'text': '<p>Can you try single-stepping through the debugger to see what exactly is going wrong? It could easily be %Zone that is wrong - %tz may be set correctly on line 1 or 2, but then the lookup on line 3 fails, ending up with undef.</p>\n\n<p>Edit: %Date::Manip::Cnf and %Date::Manip::Zone are global variables, so you should be able to take a dump of them before and after the call to Date::Manip::Date_Init. If I read the source correctly %Cnf should contain a basic skeleton of configuration options before the call to Date_Init, and %Zone should be empty; after Date_Init, TZ should have your chosen value, and %Zone should be populated by a lookup table of time zones.</p>\n\n<p>I see a reference to .DateManip.cnf in %Cnf, which might be something to look at - is it possible that you have such a file in your home directory, or the current working directory, which is overriding the default settings?</p>\n'}, {'answer_id': 167314, 'author': 'schwerwolf', 'author_id': 7045, 'author_profile': 'https://Stackoverflow.com/users/7045', 'pm_score': 2, 'selected': False, 'text': '<p>It is a <a href="http://rt.cpan.org/Public/Bug/Display.html?id=29655" rel="nofollow noreferrer">bug</a> in Date::Manip version 5.48-5.54 for Win32. I\'ve had difficulty with using standard/daylight variants of a timezones, e.g. \'EST5EDT\', \'US/Eastern\'. The only timezones that appear to work are those without daylight savings, e.g. \'EST\'.</p>\n\n<p>It is possible to turn off timezone conversion processing in the Date::Manip module:</p>\n\n<pre><code>Date::Manip::Date_Init("ConvTZ=IGNORE");\n</code></pre>\n\n<p><strong>This will have undesired side-effects if you treat dates correctly</strong>. I would not use this workaround unless you are confident you will be never be processing dates from different timezones.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76650', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,651 |
<p>Where may one find references on implementing an algorithm for calculating a "dirty rectangle" for minimizing frame buffer updates? A display model that permits arbitrary edits and computes the minimal set of "bit blit" operations required to update the display.</p>
|
[{'answer_id': 78085, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 2, 'selected': False, 'text': "<p>To build the smallest rectangle that contains all the areas that need to be repainted:</p>\n\n<ul>\n<li>Start with a blank area (perhaps a rectangle set to 0,0,0,0 - something you can detect as 'no update required')</li>\n</ul>\n\n<p>For each dirty area added:</p>\n\n<ul>\n<li>Normalize the new area (i.e. ensure that left is less than right, top less than bottom)</li>\n<li>If the dirty rectangle is currently empty, set it to the supplied area</li>\n<li>Otherwise, set the left and top co-ordinates of the dirty rectangle to the smallest of {dirty,new}, and the right and bottom co-ordinates to the largest of {dirty,new}.</li>\n</ul>\n\n<p>Windows, at least, maintains an <em>update region</em> of the changes that it's been informed of, and any repainting that needs to be done due to the window being obscured and revealed. A <em>region</em> is an object that is made up of many possibly discontinuous rectangles, polygons and ellipses. You tell Windows about a part of the screen that needs to be repainted by calling InvalidateRect - there is also an InvalidateRgn function for more complicated areas. If you choose to do some painting before the next WM_PAINT message arrives, and you want to exclude that from the dirty area, there are ValidateRect and ValidateRgn functions.</p>\n\n<p>When you start painting with BeginPaint, you supply a PAINTSTRUCT that Windows fills with information about what needs to be painted. One of the members is the smallest rectangle that contains the invalid region. You can get the region itself using GetUpdateRgn (you must call this before BeginPaint, because BeginPaint marks the whole window as valid) if you want to minimize drawing when there are multiple small invalid areas.</p>\n\n<p>I would assume that, as minimizing drawing was important on the Mac and on X when those environments were originally written, there are equivalent mechanisms for maintaining an update region.</p>\n"}, {'answer_id': 78222, 'author': 'Martin W', 'author_id': 14199, 'author_profile': 'https://Stackoverflow.com/users/14199', 'pm_score': 2, 'selected': False, 'text': '<p>What language are you using? In Python, Pygame can do this for you. Use the RenderUpdates Group and some Sprite objects with image and rect attributes.</p>\n\n<p>For example:</p>\n\n<pre><code>#!/usr/bin/env python\nimport pygame\n\nclass DirtyRectSprite(pygame.sprite.Sprite):\n """Sprite with image and rect attributes."""\n def __init__(self, some_image, *groups):\n pygame.sprite.Sprite.__init__(self, *groups)\n self.image = pygame.image.load(some_image).convert()\n self.rect = self.image.get_rect()\n def update(self):\n pass #do something here\n\ndef main():\n screen = pygame.display.set_mode((640, 480))\n background = pygame.image.load(open("some_bg_image.png")).convert()\n render_group = pygame.sprite.RenderUpdates()\n dirty_rect_sprite = DirtyRectSprite(open("some_image.png"))\n render_group.add(dirty_rect_sprite)\n\n while True:\n dirty_rect_sprite.update()\n render_group.clear(screen, background)\n pygame.display.update(render_group.draw(screen))\n</code></pre>\n\n<p>If you\'re not using Python+Pygame, here\'s what I would do:</p>\n\n<ul>\n<li>Make a Sprite class that\'s update(),\nmove() etc. method sets a "dirty"\nflag.</li>\n<li>Keep a rect for each sprite</li>\n<li>If your API supports updating a list of rects, use that on the list of rects whose sprites are dirty. In SDL, this is SDL_UpdateRects.</li>\n<li>If your API doesn\'t support updating a list of rects (I\'ve never had the chance to use anything besides SDL so I wouldn\'t know), test to see if it\'s quicker to call the blit function multiple times or once with a big rect. I doubt that any API would be faster using one big rect, but again, I haven\'t used anything besides SDL.</li>\n</ul>\n'}, {'answer_id': 309213, 'author': 'Bob Cross', 'author_id': 5812, 'author_profile': 'https://Stackoverflow.com/users/5812', 'pm_score': 2, 'selected': False, 'text': '<p>It sounds like what you need is a bounding box for each shape that you\'re rendering to the screen. Remember that a bounding box of a polygon can be defined as a "lower left" (the minimum point) and an "upper right" (the maximum point). That is, the x-component of the minimum point is defined as the minimum of all the x-components of each point in a polygon. Use the same methodology for the y-component (in the case of 2D) and the maximal point of the bounding box. </p>\n\n<p>If it\'s sufficient to have a bounding box (aka "dirty rectangle") per polygon, you\'re done. If you need an overall composite bounding box, the same algorithm applies, except you can just populate a single box with minimal and maximal points.</p>\n\n<p>Now, if you\'re doing all this in Java, you can get your bounding box for an <code>Area</code> (which you can construct from any <code>Shape</code>) directly by using the <a href="http://java.sun.com/javase/6/docs/api/java/awt/geom/Area.html#getBounds2D()" rel="nofollow noreferrer"><code>getBound2D()</code> method</a>.</p>\n'}, {'answer_id': 322354, 'author': 'CodeAndCats', 'author_id': 26335, 'author_profile': 'https://Stackoverflow.com/users/26335', 'pm_score': 2, 'selected': False, 'text': "<p>I just recently wrote a Delphi class to calculate the difference rectangles of two images and was quite suprised by how fast it ran - fast enough to run in a short timer and after mouse/keyboard messages for recording screen activity.</p>\n\n<p>The step by step gist of how it works is by:</p>\n\n<ol>\n<li><p>Sub-dividing the image into logical 12x12 by rectangles.</p></li>\n<li><p>Looping through each pixel and if there's a difference then I tell the sub-rectangle which the pixel belongs to that there's a difference in one of it's pixels and where.</p></li>\n<li><p>Each sub-rectangle remembers the co-ordinates of it's own left-most, top-most, right-most and bottom-most difference.</p></li>\n<li><p>Once all the differences have been found, I loop through all the sub-rectangles that have differences and form bigger rectangles out of them if they are next to each other and use the left-most, top-most, right-most and bottom-most differences of those sub-rectangles to make actual difference rectangles I use.</p></li>\n</ol>\n\n<p>This seems to work quite well for me. If you haven't already implemented your own solution, let me know and I'll email you my code if you like. Also as of now, I'm a new user of StackOverflow so if you appreciate my answer then please vote it up. :)</p>\n"}, {'answer_id': 5433688, 'author': 'xan', 'author_id': 105752, 'author_profile': 'https://Stackoverflow.com/users/105752', 'pm_score': 2, 'selected': False, 'text': '<p>Look into <a href="http://en.wikipedia.org/wiki/R-tree" rel="nofollow">R-tree</a> and <a href="http://en.wikipedia.org/wiki/Quadtree" rel="nofollow">quadtree</a> data structures.</p>\n'}, {'answer_id': 6520903, 'author': 'Charles Goodwin', 'author_id': 546060, 'author_profile': 'https://Stackoverflow.com/users/546060', 'pm_score': 2, 'selected': False, 'text': '<p>Vexi is a reference implementation of this. The class is <a href="http://vexi.svn.sourceforge.net/viewvc/vexi/trunk/org.vexi-core.main/src/main/java/org/vexi/util/DirtyList.java?revision=4163&view=markup" rel="nofollow">org.vexi.util.DirtyList</a> (Apache License), and is used as part of production systems i.e. thoroughly tested, and is well commented.</p>\n\n<p>A caveat, the currently class description is a bit inaccurate, <em>"A general-purpose data structure for holding a list of rectangular regions that need to be repainted, with intelligent coalescing."</em> Actually it does not currently do the coalescing. Therefore you can consider this a basic DirtyList implementation in that it only intersects dirty() requests to make sure there are no overlapping dirty regions.</p>\n\n<p>The one nuance to this implementation is that, instead of using Rect or another similar region object, the regions are stored in an array of ints i.e. in blocks of 4 ints in a 1-dimensional array. This is done for run time efficiency although in retrospect I\'m not sure whether there\'s much merit to this. (Yes, I implemented it.) It should be simple enough to substitute Rect for the array blocks in use.</p>\n\n<p>The purpose of the class is to be <em>fast</em>. With Vexi, dirty may be called thousands of times per frame, so intersections of the dirty regions with the dirty request has to be as quick as possible. No more than 4 number comparisons are used to determine the relative position of two regions.</p>\n\n<p>It is not entirely optimal due to the missing coalescing. Whilst it does ensure no overlaps between dirty/painted regions, you might end up with regions that line up and could be merged into a larger region - and therefore reducing the number of paint calls.</p>\n\n<p>Code snippet. Full code <a href="http://vexi.svn.sourceforge.net/viewvc/vexi/trunk/org.vexi-core.main/src/main/java/org/vexi/util/DirtyList.java?revision=4163&view=markup" rel="nofollow">online here</a>.</p>\n\n<pre><code>public class DirtyList {\n\n /** The dirty regions (each one is an int[4]). */\n private int[] dirties = new int[10 * 4]; // gets grown dynamically\n\n /** The number of dirty regions */\n private int numdirties = 0;\n\n ...\n\n /** \n * Pseudonym for running a new dirty() request against the entire dirties list\n * (x,y) represents the topleft coordinate and (w,h) the bottomright coordinate \n */\n public final void dirty(int x, int y, int w, int h) { dirty(x, y, w, h, 0); }\n\n /** \n * Add a new rectangle to the dirty list; returns false if the\n * region fell completely within an existing rectangle or set of\n * rectangles (i.e. did not expand the dirty area)\n */\n private void dirty(int x, int y, int w, int h, int ind) {\n int _n;\n if (w<x || h<y) {\n return;\n }\n for (int i=ind; i<numdirties; i++) {\n _n = 4*i;\n // invalid dirties are marked with x=-1\n if (dirties[_n]<0) {\n continue;\n }\n\n int _x = dirties[_n];\n int _y = dirties[_n+1];\n int _w = dirties[_n+2];\n int _h = dirties[_n+3];\n\n if (x >= _w || y >= _h || w <= _x || h <= _y) {\n // new region is outside of existing region\n continue;\n }\n\n if (x < _x) {\n // new region starts to the left of existing region\n\n if (y < _y) {\n // new region overlaps at least the top-left corner of existing region\n\n if (w > _w) {\n // new region overlaps entire width of existing region\n\n if (h > _h) {\n // new region contains existing region\n dirties[_n] = -1;\n continue;\n }// else {\n // new region contains top of existing region\n dirties[_n+1] = h;\n continue;\n\n } else {\n // new region overlaps to the left of existing region\n\n if (h > _h) {\n // new region contains left of existing region\n dirties[_n] = w;\n continue;\n }// else {\n // new region overlaps top-left corner of existing region\n dirty(x, y, w, _y, i+1);\n dirty(x, _y, _x, h, i+1);\n return;\n\n }\n } else {\n // new region starts within the vertical range of existing region\n\n if (w > _w) {\n // new region horizontally overlaps existing region\n\n if (h > _h) {\n // new region contains bottom of existing region\n dirties[_n+3] = y;\n continue;\n }// else {\n // new region overlaps to the left and right of existing region\n dirty(x, y, _x, h, i+1);\n dirty(_w, y, w, h, i+1);\n return;\n\n } else {\n // new region ends within horizontal range of existing region\n\n if (h > _h) {\n // new region overlaps bottom-left corner of existing region\n dirty(x, y, _x, h, i+1);\n dirty(_x, _h, w, h, i+1);\n return;\n }// else {\n // existing region contains right part of new region\n w = _x;\n continue;\n }\n }\n } else {\n // new region starts within the horizontal range of existing region\n\n if (y < _y) {\n // new region starts above existing region\n\n if (w > _w) {\n // new region overlaps at least top-right of existing region\n\n if (h > _h) {\n // new region contains the right of existing region\n dirties[_n+2] = x;\n continue;\n }// else {\n // new region overlaps top-right of existing region\n dirty(x, y, w, _y, i+1);\n dirty(_w, _y, w, h, i+1);\n return;\n\n } else {\n // new region is horizontally contained within existing region\n\n if (h > _h) {\n // new region overlaps to the above and below of existing region\n dirty(x, y, w, _y, i+1);\n dirty(x, _h, w, h, i+1);\n return;\n }// else {\n // existing region contains bottom part of new region\n h = _y;\n continue;\n }\n } else {\n // new region starts within existing region\n\n if (w > _w) {\n // new region overlaps at least to the right of existing region\n\n if (h > _h) {\n // new region overlaps bottom-right corner of existing region\n dirty(x, _h, w, h, i+1);\n dirty(_w, y, w, _h, i+1);\n return;\n }// else {\n // existing region contains left part of new region\n x = _w;\n continue;\n } else {\n // new region is horizontally contained within existing region\n\n if (h > _h) {\n // existing region contains top part of new region\n y = _h;\n continue;\n }// else {\n // new region is contained within existing region\n return;\n }\n }\n }\n }\n\n // region is valid; store it for rendering\n _n = numdirties*4;\n size(_n);\n dirties[_n] = x;\n dirties[_n+1] = y;\n dirties[_n+2] = w;\n dirties[_n+3] = h;\n numdirties++;\n }\n\n ...\n}\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76651', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,680 |
<p>I want to maintain a list of global messages that will be displayed to all users of a web app. I want each user to be able to mark these messages as read individually. I've created 2 tables; <code>messages (id, body)</code> and <code>messages_read (user_id, message_id)</code>.</p>
<p>Can you provide an sql statement that selects the unread messages for a single user? Or do you have any suggestions for a better way to handle this?</p>
<p>Thanks!</p>
|
[{'answer_id': 76702, 'author': 'cynicalman', 'author_id': 410, 'author_profile': 'https://Stackoverflow.com/users/410', 'pm_score': 3, 'selected': False, 'text': '<p>Well, you could use</p>\n\n<pre><code>SELECT id FROM messages m WHERE m.id NOT IN(\n SELECT message_id FROM messages_read WHERE user_id = ?)\n</code></pre>\n\n<p>Where ? is passed in by your app.</p>\n'}, {'answer_id': 76733, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 0, 'selected': False, 'text': "<p>Something like:</p>\n\n<pre><code>SELECT id, body FROM messages LEFT JOIN\n (SELECT message_id FROM messages_read WHERE user_id = ?)\n ON id=message_id WHERE message_id IS NULL \n</code></pre>\n\n<p>Slightly tricky and I'm not sure how the performance will scale up, but it should work.</p>\n"}, {'answer_id': 78715, 'author': 'Bennor McCarthy', 'author_id': 14451, 'author_profile': 'https://Stackoverflow.com/users/14451', 'pm_score': 3, 'selected': True, 'text': '<p>If the table definitions you mentioned are complete, you might want to include a date for each message, so you can order them by date.</p>\n\n<p>Also, this might be a slightly more efficient way to do the select:</p>\n\n<pre><code>SELECT id, message\nFROM messages\nLEFT JOIN messages_read\n ON messages_read.message_id = messages.id\n AND messages_read.[user_id] = @user_id\nWHERE\n messages_read.message_id IS NULL\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76680', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13636/']
|
76,689 |
<p>I'm in the process of designing a PHP-based content management system for personal use and eventually to be distributed. I know there are a lot of CMS's already out there, but I really haven't found one that meets my all of my needs and I also would like to have the learning experience. Security is a large focus, as are extensibility and ease of use. For those of you out there who have built your own CMS, what advice can you offer? What features are essential for a core? What are must have add-ons? What did you wish you knew before starting? What's the biggest potential roadblock/problem? Any and all advice is welcome.</p>
<p>Edit: Any advice on marketing do's and don't's would also be appreciated.</p>
|
[{'answer_id': 76894, 'author': 'toluju', 'author_id': 12457, 'author_profile': 'https://Stackoverflow.com/users/12457', 'pm_score': 0, 'selected': False, 'text': '<p>I know this isn\'t a direct answer to what you\'re looking for but if you haven\'t looked at it yet I\'d recommend checking out <a href="http://www.cmsmadesimple.org/" rel="nofollow noreferrer">CMS made simple</a>. It has much less bloat than other CMS\'s and is fast and efficient. It\'s open source so it may be a good reference point for any questions you will run into.</p>\n'}, {'answer_id': 76899, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 3, 'selected': False, 'text': "<p>In building a few iterations of CMSs, some of the key things turned out to be:</p>\n\n<ul>\n<li>Having a good rich text editor - end-users really don't want to do HTML. Consensus seems to be that FCKEditor is the best - there have been a couple of questions on this here recently</li>\n<li>Allowing people to add new pages and easily create a menu/tab structure or cross-link between pages</li>\n<li>Determining how to fit content into a template and/or allowing users to develop the templates themselves</li>\n<li>Figuring out how (and whether) to let people paste content from Microsoft Word - converting magic quotes, emdashes and the weirdish Wordish HTML</li>\n<li>Including a spellchecking feature (though Firefox has something built-in and iespell may do the job for IE)</li>\n</ul>\n\n<p>Some less critical but useful capabilities are:\n - Ability to dynamically create readable and SEO-friendly URLs (the StackOverflow way is not bad)\n - Ability to show earlier versions of content after it's modified\n - Ability to have a sandbox for content to let it be proofread or checked before release\n - Handling of multiple languages and non-English/non-ASCII characters</p>\n"}, {'answer_id': 76915, 'author': 'ahockley', 'author_id': 8209, 'author_profile': 'https://Stackoverflow.com/users/8209', 'pm_score': 2, 'selected': False, 'text': '<p>If you ask 100 different CMS users about the most important thing about their CMS, you\'ll probably get 80+ different answers.</p>\n\n<p>The biggest roadblock is probably going to be people asking you why you built a new CMS from scratch.\n If you don\'t know the answer to that question, I\'m not sure why you\'re going down this path.</p>\n\n<p>One thing to keep in mind is that for an internet CMS, folks are going to want integration points with many of the "usual" services. Leverage existing services such as photo sharing sites, Twitter, OpenID and the like before building your own proprietary solutions.</p>\n'}, {'answer_id': 76916, 'author': 'Carl Camera', 'author_id': 12804, 'author_profile': 'https://Stackoverflow.com/users/12804', 'pm_score': 2, 'selected': False, 'text': '<p>well i wrote a CMS for personal use and released it to the biggest chorus of chirping crickets ever! no biggie, though. i did learn a lot and i encourage you to move forward. my clients use it and like it and it\'s holding up fine. </p>\n\n<p>but if i were to start over (and i might) here\'s the advice i would give myself:</p>\n\n<ol>\n<li>scrub everything <em>everything</em> <strong>everything</strong> entered from the user</li>\n<li>user administration is a product differentiator. bonus points for being able to handle someone copy/pasting from WORD.</li>\n<li>extensibility. 90% of the comments i get are from developers who want to use the cms to host "some" of the website pages but not others. or they want to embed their custom scripts into the page among the content. my next cms will be as modular as i possibly can handle.</li>\n<li>many folks are absolutely fanatic about clean urls.</li>\n</ol>\n'}, {'answer_id': 78554, 'author': 'Gaurav', 'author_id': 13492, 'author_profile': 'https://Stackoverflow.com/users/13492', 'pm_score': 1, 'selected': False, 'text': '<p>From marketing point of view:</p>\n\n<p>1) Make it template<em>able</em>.</p>\n\n<p>2) Make CMS SEF and have SEOed URLs.</p>\n'}, {'answer_id': 81056, 'author': 'Slavo', 'author_id': 1801, 'author_profile': 'https://Stackoverflow.com/users/1801', 'pm_score': 3, 'selected': True, 'text': "<p>Well, building your own CMS actually implies that it is not an enterprise-level product. What this means is that you will not be able to actually implement all features that make CMS users happy. Not even most features. I want to clarify that by CMS I actually mean a platform for creating web applications or web sites, not a blogging platform or a scaled-down version. From personal experience I can tell you the things I want most in a CMS.<br>\n1. Extensible - provide a clean and robust API so that a programmer can do most things through code, instead of using the UI<br>\n2. Easy page creation and editing - use templates, have several URLs for a single page, provide options for URL rewriting<br>\n3. Make it component-based. Allow users to add custom functionality. Make it easy for someone to add his code to do something<br>\n4. Make it SEO-friendly. This includes metadata, again URL rewriting, good sitemap, etc.</p>\n\n<p>Now there are these enterprise features that I also like, but i doubt you'll have the desire to dive into their implementation from the beginning. They include workflow (an approval process for content-creation, customizable), Built-in modules for common functionality (blogs, e-commerce, news), ability to write own modules, permissions for different users, built-in syndication, etc.</p>\n\n<p>After all I speak from a developer's point of view and my opinion might not be mainstream, so you have to decide on your own in the end. Just as ahockley said - you have to know why you need to build your own CMS.</p>\n"}, {'answer_id': 3608145, 'author': 'Richard', 'author_id': 435821, 'author_profile': 'https://Stackoverflow.com/users/435821', 'pm_score': -1, 'selected': False, 'text': '<p>Just use Drupal.</p>\n\n<p>Out of the box it is very light and fast. You add modules for virtually everything, so that can be daunting but it is fantastic.</p>\n\n<p>Its secure (NASA and The White House use it), its modular, its open-source, it is well supported, has a reputation for clean APIs, and has hundreds of modules from SEO to Wysiwyg....</p>\n'}, {'answer_id': 6295933, 'author': 'DLo', 'author_id': 749298, 'author_profile': 'https://Stackoverflow.com/users/749298', 'pm_score': 1, 'selected': False, 'text': '<p>If you need to build custom functionality where your CMS is really a window to the rest of your business layers, then use something like PyroCMS or FuelCMS which are based off of CodeIgniter framework.</p>\n\n<p>Developers usually get lost in the weeds with Drupal and Joomla! / Wordpress quickly become spaghetti code-laced doozies over time. Its how much you have already drank from the Kool-aid punch bowl.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76689', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13281/']
|
76,700 |
<p>I'm looking for a little shell script that will take anything piped into it, and dump it to a file.. for email debugging purposes. Any ideas?</p>
|
[{'answer_id': 76719, 'author': 'JBB', 'author_id': 12332, 'author_profile': 'https://Stackoverflow.com/users/12332', 'pm_score': 2, 'selected': False, 'text': '<p>Use Procmail. Procmail is your friend. Procmail is made for this sort of thing.</p>\n'}, {'answer_id': 76721, 'author': 'Stephen Deken', 'author_id': 7154, 'author_profile': 'https://Stackoverflow.com/users/7154', 'pm_score': 6, 'selected': True, 'text': '<p>The unix command tee does this.</p>\n\n<pre><code>man tee\n</code></pre>\n'}, {'answer_id': 76731, 'author': 'Commodore Jaeger', 'author_id': 4659, 'author_profile': 'https://Stackoverflow.com/users/4659', 'pm_score': 4, 'selected': False, 'text': '<pre><code>cat > FILENAME\n</code></pre>\n'}, {'answer_id': 76735, 'author': 'Brian Mitchell', 'author_id': 13716, 'author_profile': 'https://Stackoverflow.com/users/13716', 'pm_score': 3, 'selected': False, 'text': '<p>The standard unix tool tee can do this. It copies input to output, while also logging it to a file.</p>\n'}, {'answer_id': 76736, 'author': 'Isak Savo', 'author_id': 8521, 'author_profile': 'https://Stackoverflow.com/users/8521', 'pm_score': 3, 'selected': False, 'text': '<p>You\'re not alone in needing something similar... in fact, someone wanted that functionality decades ago and developed <a href="http://linux.die.net/man/1/tee" rel="nofollow noreferrer">tee</a> :-)</p>\n\n<p>Of course, you can redirect stdout directly to a file in any shell using the > character:</p>\n\n<pre><code>echo "hello, world!" > the-file.txt\n</code></pre>\n'}, {'answer_id': 76741, 'author': 'Mo.', 'author_id': 1870, 'author_profile': 'https://Stackoverflow.com/users/1870', 'pm_score': 0, 'selected': False, 'text': '<p>Huh? I guess, I don\'t get the question?</p>\n\n<p>Can\'t you just end your pipe into a <code>>> ~file</code></p>\n\n<p>For example</p>\n\n<pre><code>echo "Foobar" >> /home/mo/dumpfile\n</code></pre>\n\n<p>will append Foobar to the dumpfile (and create dumpfile if necessary). No need for a shell script... Is that what you were looking for?</p>\n'}, {'answer_id': 76742, 'author': 'terminus', 'author_id': 9232, 'author_profile': 'https://Stackoverflow.com/users/9232', 'pm_score': 1, 'selected': False, 'text': "<p>If you want to analyze it in the script:</p>\n\n<pre><code>while /bin/true; do\n read LINE\n echo $LINE > $OUTPUT\ndone\n</code></pre>\n\n<p>But you can simply use cat. If cat gets something on the stdin, it will echo it to the stdout, so you'll have to pipe it to cat >$OUTPUT. These will do the same. The second works for binary data also.</p>\n"}, {'answer_id': 76748, 'author': 'BCS', 'author_id': 1343, 'author_profile': 'https://Stackoverflow.com/users/1343', 'pm_score': 0, 'selected': False, 'text': "<p>if you don't care about outputting the result</p>\n\n<pre><code>cat - > filename\n</code></pre>\n\n<p>or</p>\n\n<pre><code>cat > filename\n</code></pre>\n"}, {'answer_id': 76754, 'author': 'sirprize', 'author_id': 12902, 'author_profile': 'https://Stackoverflow.com/users/12902', 'pm_score': 1, 'selected': False, 'text': '<p>If you want a shell script, try this:</p>\n\n<pre><code>#!/bin/sh\nexec cat >/path/to/file\n</code></pre>\n'}, {'answer_id': 76763, 'author': 'Liudvikas Bukys', 'author_id': 5845, 'author_profile': 'https://Stackoverflow.com/users/5845', 'pm_score': 1, 'selected': False, 'text': "<p>If exim or sendmail is what's writing into the pipe, then procmail is a good answer because it'll give you file locking/serialization and you can put it all in the same file.</p>\n\n<p>If you just want to write into a file, then\n - tee > /tmp/log.$$\nor\n - cat > /tmp/log.$$\nmight be good enough.</p>\n"}, {'answer_id': 78515, 'author': 'Scott', 'author_id': 7399, 'author_profile': 'https://Stackoverflow.com/users/7399', 'pm_score': 1, 'selected': False, 'text': '<p>Use <code><<command>> | tee <<file>></code> for piping a command <code><<command>></code> into a file <code><<file>></code>. </p>\n\n<p>This will also show the output.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76700', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12624/']
|
76,712 |
<p>PHP stores its session information on the file system of the host of the server establishing that session. In a multiple-host PHP environment, where load is unintelligently distributed amongst each host, PHP session variables are not available to each request (unless by chance the request is assigned to the same host -- assume we have no control over the load balancer).</p>
<p><a href="http://porteightyeight.com/archives/121-The-Hitchhikers-Guide-to-PHP-Load-Balancing.html" rel="noreferrer">This site, dubbed "The Hitchhikers Guide to PHP Load Balancing"</a> suggests overriding PHPs session handler and storing session information in the shared database.</p>
<p>What, in your humble opinion, is the <em>best</em> way to maintain session information in a multiple PHP host environment?</p>
<p><strong>UPDATE:</strong> Thanks for the great feedback. For anyone looking for example code, we found a <a href="http://www.devshed.com/c/a/PHP/Storing-PHP-Sessions-in-a-Database/" rel="noreferrer">useful tutorial on writing a Session Manager class for MySQL</a> which I recommend checking out.</p>
|
[{'answer_id': 76800, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 1, 'selected': False, 'text': '<p>Storing the session data in a shared db works, but can be slow. If it\'s a really big site, <a href="http://en.wikipedia.org/wiki/Memcached" rel="nofollow noreferrer">memcache</a> is probably a better option.</p>\n'}, {'answer_id': 76881, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': True, 'text': '<p>Database, or Database+Memcache. Generally speaking sessions should not be written to very often. Start with a database solution that only writes to the db when the session data has <em>changed</em>. Memcache should be added later as a performance enhancement. A db solution will be very fast because you are only ever looking up primary keys. Make sure the db has row locking, not table locking (myISAM). MemCache only is a bad idea... If it overflows, crashes, or is restarted, the users will be logged out.</p>\n'}, {'answer_id': 76947, 'author': 'Peter Bailey', 'author_id': 8815, 'author_profile': 'https://Stackoverflow.com/users/8815', 'pm_score': 1, 'selected': False, 'text': "<p>Depending on your project's budget, you may also consider Zend Platform for your production machines, which in addition to a bunch of other great features, includes configurable session clustering, which works sort of like a CDN does.</p>\n"}, {'answer_id': 77192, 'author': 'Jilles', 'author_id': 13864, 'author_profile': 'https://Stackoverflow.com/users/13864', 'pm_score': 2, 'selected': False, 'text': "<p>Whatever you do, do not store it on the server itself (even if you're only using one server, or in a 1+1 failover scenario). It'll put you on a dead end.</p>\n\n<p>I would say, use Database+Memcache for storage/retrieval, it'll keep you out of Zend's grasp (and believe me things do break down at some point with Zend). Since you will be able to easily partition by UserID or SessionID even going with MySQL will leave things quite scalable.</p>\n\n<p>(Edit: additionally, going with DB+Memcache does not bind you to a comercial party, it does not bind you to PHP either -- something you might be happy for down the road)</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76712', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4330/']
|
76,718 |
<p>I saw a question on reverse projecting 4 2D points to derive the corners of a rectangle in 3D space. I have a kind of more general version of the same problem:</p>
<p>Given either a focal length (which can be solved to produce arcseconds / pixel) or the intrinsic camera matrix (a 3x2 matrix that defines the properties of the pinhole camera model being used - it's directly related to focal length), compute the camera ray that goes through each pixel.</p>
<p>I'd like to take a series of frames, derive the candidate light rays from each frame, and use some sort of iterative solving approach to derive the camera pose from each frame (given a sufficiently large sample, of course)... All of that is really just massively-parallel implementations of a generalized Hough algorithm... it's getting the candidate rays in the first place that I'm having the problem with...</p>
|
[{'answer_id': 76807, 'author': 'Matt Cruikshank', 'author_id': 8643, 'author_profile': 'https://Stackoverflow.com/users/8643', 'pm_score': 1, 'selected': False, 'text': "<p>A friend of mine found the source code from a university for the camera matching in PhotoSynth. I'd Google around for it, if I were you.</p>\n"}, {'answer_id': 76995, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>That\'s a good suggestion... and I will definitely look into it (photosynth kind of resparked my interest in this subject - but I\'ve been working on it for months for robochamps) - but it\'s a sparse implementation - it looks for "good" features (points in the image that should be easily identifiable in other views of the same image), and while I certainly plan to score each match based on how good the feature it\'s matching is, I want the full dense algorithm to derive every pixel... or should I say voxel lol?</p>\n'}, {'answer_id': 84026, 'author': 'Matt Cruikshank', 'author_id': 8643, 'author_profile': 'https://Stackoverflow.com/users/8643', 'pm_score': 0, 'selected': False, 'text': "<p>After a little poking around, isn't it the extrinsic matrix that tells you where the camera actually is in 3-space?</p>\n\n<p>I worked at a company that did a lot of this, but I always used the tools that the algorithm guys wrote. :)</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76718', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,724 |
<p>I need to return a list of record id's from a table that may/may not have multiple entries with that record id on the same date. The same date criteria is key - if a record has three entries on 09/10/2008, then I need all three returned. If the record only has one entry on 09/12/2008, then I don't need it.</p>
|
[{'answer_id': 76783, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 3, 'selected': False, 'text': '<pre><code>SELECT id, datefield, count(*) FROM tablename GROUP BY datefield\n HAVING count(*) > 1\n</code></pre>\n'}, {'answer_id': 76785, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p><code>GROUP BY</code> with <code>HAVING</code> is your friend:</p>\n\n<pre><code>select id, count(*) from records group by date having count(*) > 1\n</code></pre>\n'}, {'answer_id': 76798, 'author': 'Manu', 'author_id': 2133, 'author_profile': 'https://Stackoverflow.com/users/2133', 'pm_score': 1, 'selected': False, 'text': '<pre><code>select id from tbl where date in\n(select date from tbl group by date having count(*)>1)\n</code></pre>\n'}, {'answer_id': 76799, 'author': 'easeout', 'author_id': 10906, 'author_profile': 'https://Stackoverflow.com/users/10906', 'pm_score': 1, 'selected': False, 'text': '<p>For matching on just the date part of a Datetime:</p>\n\n<pre><code>select * from Table\nwhere id in (\n select alias1.id from Table alias1, Table alias2\n where alias1.id != alias2.id\n and datediff(day, alias1.date, alias2.date) = 0\n)\n</code></pre>\n\n<p>I think. This is based on my assumption that you need them on the same day month and year, but not the same time of day, so I did not use a Group by clause. From the other posts it looks like I could have more cleverly used a Having clause. Can you use a having or group by on a datediff expression?</p>\n'}, {'answer_id': 76815, 'author': 'Travis', 'author_id': 7316, 'author_profile': 'https://Stackoverflow.com/users/7316', 'pm_score': 1, 'selected': False, 'text': "<p>If I understand your question correctly you could do something similar to:</p>\n\n<pre><code>select\n recordID\nfrom\n tablewithrecords as a\n left join (\n select\n count(recordID) as recordcount\n from\n tblwithrecords\n where\n recorddate='9/10/08'\n ) as b on a.recordID=b.recordID\nwhere\n b.recordcount>1\n</code></pre>\n"}, {'answer_id': 76825, 'author': 'JBB', 'author_id': 12332, 'author_profile': 'https://Stackoverflow.com/users/12332', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.sql-server-performance.com/articles/dba/delete_duplicates_p1.aspx" rel="nofollow noreferrer">http://www.sql-server-performance.com/articles/dba/delete_duplicates_p1.aspx</a> will get you going. Also, <a href="http://en.allexperts.com/q/MS-SQL-1450/2008/8/SQL-query-fetch-duplicate.htm" rel="nofollow noreferrer">http://en.allexperts.com/q/MS-SQL-1450/2008/8/SQL-query-fetch-duplicate.htm</a></p>\n\n<p>I found these by searching Google for \'sql duplicate data\'. You\'ll see this isn\'t an unusual problem.</p>\n'}, {'answer_id': 76840, 'author': 'Sparr', 'author_id': 13675, 'author_profile': 'https://Stackoverflow.com/users/13675', 'pm_score': 1, 'selected': False, 'text': '<pre><code>SELECT * FROM the_table WHERE ROW(record_id,date) IN \n ( SELECT record_id, date FROM the_table \n GROUP BY record_id, date WHERE COUNT(*) > 1 )\n</code></pre>\n'}, {'answer_id': 76849, 'author': 'Scott Nichols', 'author_id': 4299, 'author_profile': 'https://Stackoverflow.com/users/4299', 'pm_score': 2, 'selected': False, 'text': "<p>Since you mentioned needing all three records, I am assuming you want the data as well. If you just need the id's, you can just use the group by query. To return the data, just join to that as a subquery</p>\n\n<pre><code>select * from table\ninner join (\n select id, date\n from table \n group by id, date \n having count(*) > 1) grouped \n on table.id = grouped.id and table.date = grouped.date\n</code></pre>\n"}, {'answer_id': 76875, 'author': 'jkramer', 'author_id': 12523, 'author_profile': 'https://Stackoverflow.com/users/12523', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m not sure I understood your question, but maybe you want something like this:</p>\n\n<pre><code>SELECT id, COUNT(*) AS same_date FROM foo GROUP BY id, date HAVING same_date = 3;\n</code></pre>\n\n<p>This is just written from my mind and not tested in any way. Read the GROUP BY and HAVING section <a href="http://dev.mysql.com/doc/refman/5.0/en/select.html" rel="nofollow noreferrer">here</a>. If this is not what you meant, please ignore this answer.</p>\n'}, {'answer_id': 76879, 'author': 'Chris Wuestefeld', 'author_id': 10082, 'author_profile': 'https://Stackoverflow.com/users/10082', 'pm_score': 1, 'selected': False, 'text': "<p>Note that there's some extra processing necessary if you're using a SQL DateTime field. If you've got that extra time data in there, then you can't just use that column as-is. You've got to normalize the DateTime to a single value for all records contained within the day. </p>\n\n<p>In SQL Server here's a little trick to do that:</p>\n\n<pre><code>SELECT CAST(FLOOR(CAST(CURRENT_TIMESTAMP AS float)) AS DATETIME)\n</code></pre>\n\n<p>You cast the DateTime into a float, which represents the Date as the integer portion and the Time as the fraction of a day that's passed. Chop off that decimal portion, then cast that back to a DateTime, and you've got midnight at the beginning of that day.</p>\n"}, {'answer_id': 76884, 'author': 'Eduardo Campañó', 'author_id': 12091, 'author_profile': 'https://Stackoverflow.com/users/12091', 'pm_score': 1, 'selected': False, 'text': '<pre>\nSELECT id, count(*)\nINTO #tmp\nFROM tablename\nWHERE date = @date\nGROUP BY id\nHAVING count(*) > 1\n\nSELECT *\nFROM tablename t\nWHERE EXISTS (SELECT 1 FROM #tmp WHERE id = t.id)\n\nDROP TABLE tablename\n</pre>\n'}, {'answer_id': 76901, 'author': 'Dave Lievense', 'author_id': 13679, 'author_profile': 'https://Stackoverflow.com/users/13679', 'pm_score': 1, 'selected': False, 'text': "<p>Without knowing the exact structure of your tables or what type of database you're using it's hard to answer. However if you're using MS SQL and if you have a true date/time field that has different times that the records were entered on the same date then something like this should work:</p>\n\n<pre><code>select record_id, \n convert(varchar, date_created, 101) as log date, \n count(distinct date_created) as num_of_entries\nfrom record_log_table\ngroup by convert(varchar, date_created, 101), record_id\nhaving count(distinct date_created) > 1\n</code></pre>\n\n<p>Hope this helps.</p>\n"}, {'answer_id': 77304, 'author': 'Bob Probst', 'author_id': 12424, 'author_profile': 'https://Stackoverflow.com/users/12424', 'pm_score': 2, 'selected': False, 'text': "<p>The top post (Leigh Caldwell) will not return duplicate records and needs to be down modded. It will identify the duplicate keys. Furthermore, it will not work if your database doesn't allows the group by to not include all select fields (many do not).</p>\n\n<p>If your date field includes a time stamp then you'll need to truncate that out using one of the methods documented above ( I prefer: dateadd(dd,0, datediff(dd,0,@DateTime)) ).</p>\n\n<p>I think Scott Nichols gave the correct answer and here's a script to prove it:</p>\n\n<pre><code>declare @duplicates table (\nid int,\ndatestamp datetime,\nipsum varchar(200))\n\ninsert into @duplicates (id,datestamp,ipsum) values (1,'9/12/2008','ipsum primis in faucibus')\ninsert into @duplicates (id,datestamp,ipsum) values (1,'9/12/2008','Vivamus consectetuer. ')\ninsert into @duplicates (id,datestamp,ipsum) values (2,'9/12/2008','condimentum posuere, quam.')\ninsert into @duplicates (id,datestamp,ipsum) values (2,'9/13/2008','Donec eu sapien vel dui')\ninsert into @duplicates (id,datestamp,ipsum) values (3,'9/12/2008','In velit nulla, faucibus sed')\n\nselect a.* from @duplicates a\ninner join (select id,datestamp, count(1) as number\n from @duplicates\n group by id,datestamp\n having count(1) > 1) b\n on (a.id = b.id and a.datestamp = b.datestamp)\n</code></pre>\n"}, {'answer_id': 98368, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<pre><code>SELECT RecordID\nFROM aTable\nWHERE SameDate IN\n (SELECT SameDate\n FROM aTable\n GROUP BY SameDate\n HAVING COUNT(SameDate) > 1)\n</code></pre>\n'}, {'answer_id': 98536, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>TrickyNixon writes;</p>\n\n<blockquote>\n <p>The top post (Leigh Caldwell) will not return duplicate records and needs to be down modded.</p>\n</blockquote>\n\n<p>Yet the question doesn\'t ask about duplicate records. It asks about duplicate record-ids on the same date...</p>\n\n<p>GROUP-BY,HAVING seems good to me. I\'ve used it in production before.</p>\n\n<p>.</p>\n\n<p>Something to watch out for:</p>\n\n<p>SELECT ... FROM ... GROUP BY ... HAVING count(*)>1</p>\n\n<p>Will, on most database systems, run in O(NlogN) time. It\'s a good solution. (Select is O(N), sort is O(NlogN), group by is O(N), having is O(N) -- Worse case. Best case, date is indexed and the sort operation is more efficient.)</p>\n\n<p>.</p>\n\n<p>Select ... from ..., .... where a.data = b.date</p>\n\n<p>Granted only idiots do a Cartesian join. But you\'re looking at O(N^2) time. For some databases, this also creates a "temporary" table. It\'s all insignificant when your table has only 10 rows. But it\'s gonna hurt when that table grows!</p>\n\n<p>Ob link: <a href="http://en.wikipedia.org/wiki/Join_(SQL)" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Join_(SQL)</a></p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76724', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,760 |
<p>fellow anthropoids and lily pads and paddlewheels!</p>
<p>I'm developing a Windows desktop app in C#/.NET/WPF, using VS 2008. The app is required to install and run on Vista and XP machines. I'm working on a Setup/Windows Installer Project to install the app.</p>
<p>My app requires read/modify/write access to a SQLCE database file (.sdf) and some other database-type files related to a third-party control I'm using. These files should be shared among all users/log-ins on the PC, none of which can be required to be an Administrator. This means, of course, that the files can't go in the program's own installation directory (as such things often did before the arrival of Vista, yes, yes!).</p>
<p>I had expected the solution to be simple. <strong>Vista and XP both have shared-application-data folders intended for this purpose.</strong> ("\ProgramData" in Vista, "\Documents and Settings\All Users\Application Data" in XP.) The .NET Environment.GetFolderPath(SpecialFolder.CommonApplicationData) call exists to find the paths to these folders on a given PC, yes, yes!</p>
<p><strong>But I can't figure out how to specify the shared-application-data folder as a target in the Setup project.</strong></p>
<p>The Setup project offers a "Common Files" folder, but that's intended for shared program components (not data files), is usually located under "\Program Files," and has the same security restrictions anything else in "\Program files" does, yes, yes!</p>
<p>The Setup project offers a "User's Application Data" folder, but that's a per-user folder, which is exactly what I'm trying to avoid, yes, yes!</p>
<p>Is it possible to add files to the shared-app-data folder in a robust, cross-Windows-version way from a VS 2008 setup project? Can anyone tell me how?</p>
|
[{'answer_id': 159451, 'author': 'Lyman Enders Knowles', 'author_id': 13726, 'author_profile': 'https://Stackoverflow.com/users/13726', 'pm_score': 5, 'selected': True, 'text': '<p>I have learned the answer to my question through other sources, yes, yes! Sadly, it didn\'t fix my problem! What\'s that make me -- a fixer-upper? Yes, yes!</p>\n\n<p>To put stuff in a sub-directory of the Common Application Data folder from a VS2008 Setup project, here\'s what you do:</p>\n\n<ol>\n<li><p>Right-click your setup project in the Solution Explorer and pick "View -> File System".</p></li>\n<li><p>Right-click "File system on target machine" and pick "Add Special Folder -> Custom Folder".</p></li>\n<li><p>Rename the custom folder to "Common Application Data Folder." (This isn\'t the name that will be used for the resulting folder, it\'s just to help you keep it straight.)</p></li>\n<li><p>Change the folder\'s DefaultLocation property to "[CommonAppDataFolder][Manufacturer]\\[ProductName]". Note the similarity with the DefaultLocation property of the Application Folder, including the odd use of a single backslash.</p></li>\n<li><p>Marvel for a moment at the ridiculous (yet undeniable) fact that there is a folder property named "Property." </p></li>\n<li><p>Change the folder\'s Property property to "COMMONAPPDATAFOLDER".</p></li>\n</ol>\n\n<p>Data files placed in the "Common Application Data" folder will be copied to "\\ProgramData\\Manufacturer\\ProductName" (on Vista) or "\\Documents and Settings\\All Users\\Application Data\\Manufacturer\\ProductName" (on XP) when the installer is run.</p>\n\n<p>Now it turns out that under Vista, non-Administrators don\'t get modify/write access to the files in here. So all users get to read the files, but they get that in "\\Program Files" as well. So what, I wonder, is the point of the Common Application Data folder?</p>\n'}, {'answer_id': 285082, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I'm not sure if this will help in your case or not.</p>\n\n<p>But if you add a private section to your app's config file</p>\n\n<p>\n \n \n \n \n</p>\n\n<p>You can specify extra folders to check in your app.</p>\n\n<p>If what you are saying is that you want to be able to install\ninto other folders on the machine, then that is a problem.\nEssentially the whole reason that MS has restricted this stuff\nis to keep malicious code off machines where the user is unaware \nof what they are installing.</p>\n\n<p>So, this won't work if you need another directory.\nWhat this fix does is allow you to specify where\nwithin your app to search for files......</p>\n"}, {'answer_id': 374293, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>This worked for me using VS2005 but I had to change the DefaultLocation, I added a '\\' to separate the CommonAppDataFolder.</p>\n<p><code>[CommonAppDataFolder]\\[Manufacturer]\\[ProductName]</code></p>\n<p>Don't know if this was a typo but Lyman did refer to the odd use of a single backslash but this does not seem correct.</p>\n"}, {'answer_id': 490449, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>I solved it this way. I kept the database file (.sdf) in the same folder as where the application is installed (Application Folder). On the security tab in the properties window for the main project, i checked the "Enable ClickOnce Security Settings" and selected "This is a full trust application", rebuilt and ran the setup. After that no security problem</p>\n\n<p>I am using Visual Studio 2008 and Windows Vista</p>\n'}, {'answer_id': 741763, 'author': 'cdonner', 'author_id': 58880, 'author_profile': 'https://Stackoverflow.com/users/58880', 'pm_score': 1, 'selected': False, 'text': '<p>I had the same issue. The setup project gives the user the option to install the app "for the current user only" or "for all users:. Consequently, the database file would end up in either the current user\'s or the All Users application data folder. The setup would have to write this information somewhere so that the application can later retrieve it, when it comes to accessing the database. How else would it know which application data folder to look in?</p>\n\n<p>To avoid this issue, I just want to install the database in the All Users/Application Data folder, regardless if the application was installed for one user or for all users. I realize, of course, that two users could not install the application on the same computer without overwriting each other\'s data. This is such a remote possibility, though, that I don\'t want to consider it.</p>\n\n<p>The first piece of the puzzle I got <a href="http://snipplr.com/view/10502/set-the-directory-connection-string-for-an-sql-server-database-connection/" rel="nofollow noreferrer">here</a>: </p>\n\n<pre><code>Form_Load(object sender, EventArgs e)\n{\n // Set the db directory to the common app data folder\n AppDomain.CurrentDomain.SetData("DataDirectory", \n System.Environment.GetFolderPath\n (System.Environment.SpecialFolder.CommonApplicationData));\n}\n</code></pre>\n\n<p>Now we need to make sure that the data source contains the DataDirectory placeholder. This piece came from <a href="http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/d18724a8-0be2-4d8e-8311-3a08b87ec10e" rel="nofollow noreferrer">here</a>. In the DataSet designer, find the DataSet\'s properties, open the Connection node and edit the ConnectionString property to look as follows:</p>\n\n<pre><code>Data Source=|DataDirectory|\\YourDatabase.sdf\n</code></pre>\n\n<p>Then I followed Lyman Enders Knowles\' instructions from above for how to add the Common Application Data Folder to the setup project and placed the database file in that folder.</p>\n\n<p>I then followed Ove\'s suggestion from above, i.e. I checked the "Enable ClickOnce Security Settings" and selected "This is a full trust application.</p>\n\n<p>After that, the application deployed fine on Vista and the database file was accessible for both reads and writes.</p>\n'}, {'answer_id': 4392394, 'author': 'ejwipp', 'author_id': 171655, 'author_profile': 'https://Stackoverflow.com/users/171655', 'pm_score': 3, 'selected': False, 'text': '<p>Instead of checking "Enable ClickOnce Security Settings" and selecting "This is a full trust application", it is possible to change the permissions of your app\'s CommonAppDataDirectory with a Custom Action under the "install" section of a setup project. Here\'s what I did:</p>\n\n<ol>\n<li>Added a custom action to call the app being installed (alternately you could create a separate program/dll and call that instead)</li>\n<li>Set the Arguments property to "Install"</li>\n<li>Modified Main in Program.cs to check for that arg:\n<pre><code><br>\nstatic void Main(string[] args)\n{\n if (args != null && args.Length > 0 && args[0] == "Install")\n {\n ApplicationData.SetPermissions();\n }\n else\n {\n // Execute app "normally"\n }\n}\n</pre></code></li>\n<li>Wrote the SetPermissions function to programmatically change permissions\n<pre><code><br>\npublic static void SetPermissions()\n{\n String path = GetPath();\n try\n {\n // Create security idenifier for all users (WorldSid)\n SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);\n DirectoryInfo di = new DirectoryInfo(path);\n DirectorySecurity ds = di.GetAccessControl();\n // add a new file access rule w/ write/modify for all users to the directory security object<br>\n ds.AddAccessRule(new FileSystemAccessRule(sid, \n FileSystemRights.Write | FileSystemRights.Modify,\n InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, // all sub-dirs to inherit\n PropagationFlags.None,\n AccessControlType.Allow)); // Turn write and modify on\n // Apply the directory security to the directory\n di.SetAccessControl(ds);\n }\n catch (Exception ex)\n {\n MessageBox.Show(ex.Message);\n }\n}\n</pre></code></li>\n</ol>\n\n<p>Since the installer runs with admin rights, the program will be able to change the permissions. I read somewhere that the "Enable ClickOnce Security" can cause the user to see an undesired prompt at app startup. Doing it as described above will prevent this from happening. I hope this helps someone. I know I could have benefited from seeing something like this a few days ago!</p>\n'}, {'answer_id': 10657695, 'author': 'Ahmad', 'author_id': 1404032, 'author_profile': 'https://Stackoverflow.com/users/1404032', 'pm_score': 1, 'selected': False, 'text': '<p>i like below concept, some stuff taken from above</p>\n\n<ol>\n<li><p>Right-click your setup project in the Solution Explorer and pick "View -> File System".</p></li>\n<li><p>Right-click "File system on target machine" and pick "Add Special Folder -> Custom Folder".</p></li>\n<li><p>Rename the custom folder to "Common Application Data Folder." (This isn\'t the name that will be used for the resulting folder, it\'s just to help you keep it straight.)</p></li>\n<li><p>Change the folder\'s DefaultLocation property to "[CommonAppDataFolder][Manufacturer][ProductName]". Note the similarity with the DefaultLocation property of the Application Folder, including the odd use of a single backslash.</p></li>\n<li><p>Marvel for a moment at the ridiculous (yet undeniable) fact that there is a folder property named "Property." Babies full of rabies, who comes up with this shit?</p></li>\n<li><p>Change the folder\'s Property property to "COMMONAPPDATAFOLDER".</p></li>\n</ol>\n\n<pre class="lang-cs prettyprint-override"><code>string userAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);\nstring commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); \n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76760', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13726/']
|
76,762 |
<p>How cheap can MySQL be compared to MS SQL when you have tons of data (and joins/search)? Consider a site like stackoverflow full of Q&As already and after getting dugg. </p>
<p>My ASP.NET sites are currently on SQL Server Express so I don't have any idea how cost compares in the long run. Although after a quick research, I'm starting to envy the savings MySQL folks get.</p>
|
[{'answer_id': 76841, 'author': 'George Mauer', 'author_id': 5056, 'author_profile': 'https://Stackoverflow.com/users/5056', 'pm_score': 2, 'selected': False, 'text': "<p>I know that stackoverflow has had problems with deadlocks from reads/writes coming at odd intervals but they're claiming their architecture (MSSQL) is holding up fine. This was before the public beta of course and according to Jeff's twitter earlier today:</p>\n\n<blockquote>\n <p>the range of top 32 newest/modified\n questions was about 20 minutes in the\n private beta; now it's about 2\n minutes.</p>\n</blockquote>\n\n<p>That the site hasn't crashed yet is a testament to the database (as well as good coding and testing).</p>\n\n<p>But why not post some specific numbers about your site?</p>\n"}, {'answer_id': 76842, 'author': 'japollock', 'author_id': 1210318, 'author_profile': 'https://Stackoverflow.com/users/1210318', 'pm_score': 2, 'selected': False, 'text': '<p>The performance benefits of MS SQL over MySQL are fairly negligible, especially if you mitigate them with server and client side optimzations like server caching (in RAM), client caching (cache and expires headers) and gzip compression.</p>\n'}, {'answer_id': 76873, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 4, 'selected': True, 'text': "<p>MSSQL Standard Edition (32 or 64 bit) will cost around $5K <em>per CPU socket</em>. 64 bit will allow you to use as much RAM as you need. Enterprise Edition is not really necessary for most deployments, so don't worry about the $20K you would need for that license.</p>\n\n<p>MySQL is only free if you forego a lot of the useful tools offered with the licenses, and it's probably (at least as of 2008) going to be a little more work to get it to scale like Sql Server.</p>\n\n<p>In the long run I think you will spend much more on hardware and people than you will on just the licenses. If you need to scale, then you will probably have the cash flow to handle $5K here and there.</p>\n"}, {'answer_id': 87520, 'author': 'Willem', 'author_id': 15447, 'author_profile': 'https://Stackoverflow.com/users/15447', 'pm_score': 1, 'selected': False, 'text': "<p>MySQL is extremely cheap when you have the distro (or staff to build) that carries MySQL Enterprise edition. This is a High Availability version which offers multi-master replication over many servers.</p>\n\n<p>Pros are low (license-) costs after initial purchase of hardware (Gigs of RAM needed!) and time to set up. </p>\n\n<p>The drawbacks are suboptimal performance with many joins, no full-text indexing, stored procesures (I think) and one need to replicate grants to every master node. </p>\n\n<p>Yet it's easier to run than the replication/proxy balancing setup that's available for PostgreSQL.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76762', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13594/']
|
76,781 |
<p>I need to create a custom membership user and provider for an ASP.NET mvc app and I'm looking to use TDD. I have created a User class which inherits from the MembershipUser class, but when I try to test it I get an error that I can't figure out. How do I give it a valid provider name? Do I just need to add it to web.config? But I'm not even testing the web app at this point.</p>
<p>[failure] UserTests.SetUp.UserShouldHaveMembershipUserProperties
TestCase 'UserTests.SetUp.UserShouldHaveMembershipUserProperties'
failed: The membership provider name specified is invalid.
Parameter name: providerName
System.ArgumentException
Message: The membership provider name specified is invalid.
Parameter name: providerName
Source: System.Web</p>
|
[{'answer_id': 76883, 'author': 'ssmith', 'author_id': 13729, 'author_profile': 'https://Stackoverflow.com/users/13729', 'pm_score': 1, 'selected': False, 'text': "<p>Yes, you need to configure it in your configuration file (probably not web.config for a test library, but app.config). You still use the section and within that the section to do the configuration. Once you have that in place, you'll be able to instantiate your user and go about testing it. At which point you'll likely encounter new problems, which you should post as separate questions, I think.</p>\n"}, {'answer_id': 243844, 'author': 'ddc0660', 'author_id': 16027, 'author_profile': 'https://Stackoverflow.com/users/16027', 'pm_score': 4, 'selected': True, 'text': '<p>The configuration to add to your unit test project configuration file would look something like this:</p>\n\n<pre><code> <connectionStrings>\n <remove name="LocalSqlServer"/>\n <add name="LocalSqlServer" connectionString="<connection string>" providerName="System.Data.SqlClient"/>\n </connectionStrings>\n <system.web>\n <membership defaultProvider="provider">\n <providers>\n <add name="provider" applicationName="MyApp" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="false" maxInvalidPasswordAttempts="3" passwordAttemptWindow="15"/>\n </providers>\n </membership>\n </system.web>\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76781', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9938/']
|
76,793 |
<p>I'm working on a set of classes that will be used to serialize to XML. The XML is not controlled by me and is organized rather well. Unfortunately, there are several sets of nested nodes, the purpose of some of them is just to hold a collection of their children. Based on my current knowledge of XML Serialization, those nodes require another class.</p>
<p>Is there a way to make a class serialize to a set of XML nodes instead of just one. Because I feel like I'm being as clear as mud, say we have the xml:</p>
<pre><code><root>
<users>
<user id="">
<firstname />
<lastname />
...
</user>
<user id="">
<firstname />
<lastname />
...
</user>
</users>
<groups>
<group id="" groupname="">
<userid />
<userid />
</group>
<group id="" groupname="">
<userid />
<userid />
</group>
</groups>
</root>
</code></pre>
<p>Ideally, 3 classes would be best. A class <code>root</code> with collections of <code>user</code> and <code>group</code> objects. However, best I can figure is that I need a class for <code>root</code>, <code>users</code>, <code>user</code>, <code>groups</code> and <code>group</code>, where <code>users</code> and <code>groups</code> contain only collections of <code>user</code> and <code>group</code> respectively, and <code>root</code> contains a <code>users</code>, and <code>groups</code> object.</p>
<p>Anyone out there who knows better than me? (don't lie, I know there are).</p>
|
[{'answer_id': 76826, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 4, 'selected': True, 'text': '<p>Are you not using the <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx" rel="nofollow noreferrer">XmlSerializer</a>? It\'s pretty damn good and makes doing things like this real easy (I use it quite a lot!).</p>\n\n<p>You can simply decorate your class properties with some attributes and the rest is all done for you..</p>\n\n<p>Have you considered using XmlSerializer or is there a particular reason why not?</p>\n\n<p>Heres a code snippet of all the work required to get the above to serialize (both ways):</p>\n\n<pre><code>[XmlArray("users"),\nXmlArrayItem("user")]\npublic List<User> Users\n{\n get { return _users; }\n}\n</code></pre>\n'}, {'answer_id': 76868, 'author': 'paulwhit', 'author_id': 7301, 'author_profile': 'https://Stackoverflow.com/users/7301', 'pm_score': 0, 'selected': False, 'text': '<p>You would only need to have Users defined as an array of User objects. The XmlSerializer will render it appropriately for you.</p>\n\n<p>See this link for an example:\n<a href="http://www.informit.com/articles/article.aspx?p=23105&seqNum=4" rel="nofollow noreferrer">http://www.informit.com/articles/article.aspx?p=23105&seqNum=4</a></p>\n\n<p>Additionally, I would recommend using Visual Studio to generate an XSD and using the commandline utility XSD.EXE to spit out the class hierarchy for you, as per <a href="http://quickstart.developerfusion.co.uk/quickstart/howto/doc/xmlserialization/XSDToCls.aspx" rel="nofollow noreferrer">http://quickstart.developerfusion.co.uk/quickstart/howto/doc/xmlserialization/XSDToCls.aspx</a></p>\n'}, {'answer_id': 77259, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I wrote this class up back in the day to do what I think, is similar to what you are trying to do. You would use methods of this class on objects that you wish to serialize to XML. For instance, given an employee...</p>\n\n<p>using Utilities;\nusing System.Xml.Serialization;</p>\n\n<p>[XmlRoot("Employee")]\npublic class Employee\n{\n private String name = "Steve";</p>\n\n<pre><code> [XmlElement("Name")]\n public string Name { get { return name; } set{ name = value; } }\n\n public static void Main(String[] args)\n {\n Employee e = new Employee();\n XmlObjectSerializer.Save("c:\\steve.xml", e);\n }\n</code></pre>\n\n<p>}</p>\n\n<p>this code should output:</p>\n\n<pre><code><Employee>\n <Name>Steve</Name>\n</Employee>\n</code></pre>\n\n<p>The object type (Employee) must be serializable. Try [Serializable(true)].\nI have a better version of this code someplace, I was just learning when I wrote it.\nAnyway, check out the code below. I\'m using it in some project, so it definitly works.</p>\n\n<pre><code>using System;\nusing System.IO;\nusing System.Xml.Serialization;\n\nnamespace Utilities\n{\n /// <summary>\n /// Opens and Saves objects to Xml\n /// </summary>\n /// <projectIndependent>True</projectIndependent>\n public static class XmlObjectSerializer\n {\n /// <summary>\n /// Serializes and saves data contained in obj to an XML file located at filePath <para></para> \n /// </summary>\n /// <param name="filePath">The file path to save to</param>\n /// <param name="obj">The object to save</param>\n /// <exception cref="System.IO.IOException">Thrown if an error occurs while saving the object. See inner exception for details</exception>\n public static void Save(String filePath, Object obj)\n {\n // allows access to the file\n StreamWriter oWriter = null;\n\n try\n {\n // Open a stream to the file path\n oWriter = new StreamWriter(filePath);\n\n // Create a serializer for the object\'s type\n XmlSerializer oSerializer = new XmlSerializer(obj.GetType());\n\n // Serialize the object and write to the file\n oSerializer.Serialize(oWriter.BaseStream, obj);\n }\n catch (Exception ex)\n {\n // throw any errors as IO exceptions\n throw new IOException("An error occurred while saving the object", ex);\n }\n finally\n {\n // if a stream is open\n if (oWriter != null)\n {\n // close it\n oWriter.Close();\n }\n }\n }\n\n /// <summary>\n /// Deserializes saved object data of type T in an XML file\n /// located at filePath \n /// </summary>\n /// <typeparam name="T">Type of object to deserialize</typeparam>\n /// <param name="filePath">The path to open the object from</param>\n /// <returns>An object representing the file or the default value for type T</returns>\n /// <exception cref="System.IO.IOException">Thrown if the file could not be opened. See inner exception for details</exception>\n public static T Open<T>(String filePath)\n {\n // gets access to the file\n StreamReader oReader = null;\n\n // the deserialized data\n Object data;\n\n try\n {\n // Open a stream to the file\n oReader = new StreamReader(filePath);\n\n // Create a deserializer for the object\'s type\n XmlSerializer oDeserializer = new XmlSerializer(typeof(T));\n\n // Deserialize the data and store it\n data = oDeserializer.Deserialize(oReader.BaseStream);\n\n //\n // Return the deserialized object\n // don\'t cast it if it\'s null\n // will be null if open failed\n //\n if (data != null)\n {\n return (T)data;\n }\n else\n {\n return default(T);\n }\n }\n catch (Exception ex)\n {\n // throw error\n throw new IOException("An error occurred while opening the file", ex);\n }\n finally\n {\n // Close the stream\n oReader.Close();\n }\n }\n }\n}\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76793', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13611/']
|
76,796 |
<p>What are some general tips to make sure I don't leak memory in C++ programs? How do I figure out who should free memory that has been dynamically allocated?</p>
|
[{'answer_id': 76814, 'author': 'DougN', 'author_id': 7442, 'author_profile': 'https://Stackoverflow.com/users/7442', 'pm_score': 2, 'selected': False, 'text': '<p>User smart pointers everywhere you can! Whole classes of memory leaks just go away.</p>\n'}, {'answer_id': 76820, 'author': 'Doug T.', 'author_id': 8123, 'author_profile': 'https://Stackoverflow.com/users/8123', 'pm_score': 5, 'selected': False, 'text': '<p>You\'ll want to look at smart pointers, such as <a href="http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/shared_ptr.htm" rel="noreferrer">boost\'s smart pointers</a>.</p>\n\n<p>Instead of </p>\n\n<pre><code>int main()\n{ \n Object* obj = new Object();\n //...\n delete obj;\n}\n</code></pre>\n\n<p>boost::shared_ptr will automatically delete once the reference count is zero:</p>\n\n<pre><code>int main()\n{\n boost::shared_ptr<Object> obj(new Object());\n //...\n // destructor destroys when reference count is zero\n}\n</code></pre>\n\n<p>Note my last note, "when reference count is zero, which is the coolest part. So If you have multiple users of your object, you won\'t have to keep track of whether the object is still in use. Once nobody refers to your shared pointer, it gets destroyed.</p>\n\n<p>This is not a panacea, however. Though you can access the base pointer, you wouldn\'t want to pass it to a 3rd party API unless you were confident with what it was doing. Lots of times, your "posting" stuff to some other thread for work to be done AFTER the creating scope is finished. This is common with PostThreadMessage in Win32:</p>\n\n<pre><code>void foo()\n{\n boost::shared_ptr<Object> obj(new Object()); \n\n // Simplified here\n PostThreadMessage(...., (LPARAM)ob.get());\n // Destructor destroys! pointer sent to PostThreadMessage is invalid! Zohnoes!\n}\n</code></pre>\n\n<p>As always, use your thinking cap with any tool...</p>\n'}, {'answer_id': 76838, 'author': 'Seth Morris', 'author_id': 13434, 'author_profile': 'https://Stackoverflow.com/users/13434', 'pm_score': 2, 'selected': False, 'text': '<p>Share and know memory ownership rules across your project. Using the COM rules makes for the best consistency ([in] parameters are owned by the caller, callee must copy; [out] params are owned by the caller, callee must make a copy if keeping a reference; etc.)</p>\n'}, {'answer_id': 76844, 'author': 'Andri Möll', 'author_id': 13719, 'author_profile': 'https://Stackoverflow.com/users/13719', 'pm_score': 6, 'selected': True, 'text': '<p>Instead of managing memory manually, try to use smart pointers where applicable.<br />\nTake a look at the <a href="http://www.boost.org/" rel="noreferrer">Boost lib</a>, <a href="http://en.wikipedia.org/wiki/Technical_Report_1" rel="noreferrer">TR1</a>, and <a href="http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/smart_ptr.htm" rel="noreferrer">smart pointers</a>.<br />\nAlso smart pointers are now a part of C++ standard called <a href="http://en.wikipedia.org/wiki/Smart_pointer" rel="noreferrer">C++11</a>.<br /></p>\n'}, {'answer_id': 76850, 'author': 'Hank', 'author_id': 7610, 'author_profile': 'https://Stackoverflow.com/users/7610', 'pm_score': 4, 'selected': False, 'text': '<p>Read up on <a href="http://en.wikipedia.org/wiki/Resource_acquisition_is_initialization" rel="noreferrer">RAII</a> and make sure you understand it.</p>\n'}, {'answer_id': 76852, 'author': 'Justin Rudd', 'author_id': 12968, 'author_profile': 'https://Stackoverflow.com/users/12968', 'pm_score': 1, 'selected': False, 'text': "<p>If you can, use boost shared_ptr and standard C++ auto_ptr. Those convey ownership semantics.</p>\n\n<p>When you return an auto_ptr, you are telling the caller that you are giving them ownership of the memory.</p>\n\n<p>When you return a shared_ptr, you are telling the caller that you have a reference to it and they take part of the ownership, but it isn't solely their responsibility.</p>\n\n<p>These semantics also apply to parameters. If the caller passes you an auto_ptr, they are giving you ownership.</p>\n"}, {'answer_id': 76859, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p><strong>valgrind</strong> is a good tool to check your programs memory leakages at runtime, too.</p>\n\n<p>It is available on most flavors of Linux (including Android) and on Darwin.</p>\n\n<p>If you use to write unit tests for your programs, you should get in the habit of systematicaly running valgrind on tests. It will potentially avoid many memory leaks at an early stage. It is also usually easier to pinpoint them in simple tests that in a full software. </p>\n\n<p>Of course this advice stay valid for any other memory check tool.</p>\n'}, {'answer_id': 76866, 'author': 'Jason Dagit', 'author_id': 5113, 'author_profile': 'https://Stackoverflow.com/users/5113', 'pm_score': 3, 'selected': False, 'text': '<p>One technique that has become popular with memory management in C++ is <a href="http://en.wikipedia.org/wiki/Resource_acquisition_is_initialization" rel="noreferrer">RAII</a>. Basically you use constructors/destructors to handle resource allocation. Of course there are some other obnoxious details in C++ due to exception safety, but the basic idea is pretty simple.</p>\n\n<p>The issue generally comes down to one of ownership. I highly recommend reading the Effective C++ series by Scott Meyers and Modern C++ Design by Andrei Alexandrescu.</p>\n'}, {'answer_id': 76876, 'author': 'Seth Morris', 'author_id': 13434, 'author_profile': 'https://Stackoverflow.com/users/13434', 'pm_score': 2, 'selected': False, 'text': "<p>If you can't/don't use a smart pointer for something (although that should be a huge red flag), type in your code with:</p>\n\n<pre><code>allocate\nif allocation succeeded:\n{ //scope)\n deallocate()\n}\n</code></pre>\n\n<p>That's obvious, but make sure you type it <em>before</em> you type any code in the scope</p>\n"}, {'answer_id': 76878, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>Also, don't use manually allocated memory if there's a std library class (e.g. vector). Make sure if you violate that rule that you have a virtual destructor.</p>\n"}, {'answer_id': 76906, 'author': 'Seth Morris', 'author_id': 13434, 'author_profile': 'https://Stackoverflow.com/users/13434', 'pm_score': -1, 'selected': False, 'text': "<p>Exactly one return from any function. That way you can do deallocation there and never miss it.</p>\n\n<p>It's too easy to make a mistake otherwise:</p>\n\n<pre><code>new a()\nif (Bad()) {delete a; return;}\nnew b()\nif (Bad()) {delete a; delete b; return;}\n... // etc.\n</code></pre>\n"}, {'answer_id': 76931, 'author': 'Null303', 'author_id': 13787, 'author_profile': 'https://Stackoverflow.com/users/13787', 'pm_score': 1, 'selected': False, 'text': '<p>If you are going to manage your memory manually, you have two cases:</p>\n\n<ol>\n<li>I created the object (perhaps indirectly, by calling a function that allocates a new object), I use it (or a function I call uses it), then I free it.</li>\n<li>Somebody gave me the reference, so I should not free it.</li>\n</ol>\n\n<p>If you need to break any of these rules, please document it.</p>\n\n<p>It is all about pointer ownership.</p>\n'}, {'answer_id': 76961, 'author': 'INS', 'author_id': 13136, 'author_profile': 'https://Stackoverflow.com/users/13136', 'pm_score': 0, 'selected': False, 'text': '<p>You can intercept the memory allocation functions and see if there are some memory zones not freed upon program exit (though it is not suitable for <em>all</em> the applications).</p>\n\n<p>It can also be done at compile time by replacing operators new and delete and other memory allocation functions.</p>\n\n<p>For example check in this <a href="http://www.scs.cs.nyu.edu/~dm/c++-new.html" rel="nofollow noreferrer">site</a> [Debugging memory allocation in C++]\nNote: There is a trick for delete operator also something like this:</p>\n\n<pre><code>#define DEBUG_DELETE PrepareDelete(__LINE__,__FILE__); delete\n#define delete DEBUG_DELETE\n</code></pre>\n\n<p>You can store in some variables the name of the file and when the overloaded delete operator will know which was the place it was called from. This way you can have the trace of every delete and malloc from your program. At the end of the memory checking sequence you should be able to report what allocated block of memory was not \'deleted\' identifying it by filename and line number which is I guess what you want.</p>\n\n<p>You could also try something like <a href="http://www.compuware.com/products/devpartner/visualc.htm" rel="nofollow noreferrer">BoundsChecker</a> under Visual Studio which is pretty interesting and easy to use.</p>\n'}, {'answer_id': 77035, 'author': 'DarenW', 'author_id': 10468, 'author_profile': 'https://Stackoverflow.com/users/10468', 'pm_score': 4, 'selected': False, 'text': '<p>Bah, you young kids and your new-fangled garbage collectors...</p>\n\n<p>Very strong rules on "ownership" - what object or part of the software has the right to delete the object. Clear comments and wise variable names to make it obvious if a pointer "owns" or is "just look, don\'t touch". To help decide who owns what, follow as much as possible the "sandwich" pattern within every subroutine or method.</p>\n\n<pre><code>create a thing\nuse that thing\ndestroy that thing\n</code></pre>\n\n<p>Sometimes it\'s necessary to create and destroy in widely different places; i think hard to avoid that. </p>\n\n<p>In any program requiring complex data structures, i create a strict clear-cut tree of objects containing other objects - using "owner" pointers. This tree models the basic hierarchy of application domain concepts. Example a 3D scene owns objects, lights, textures. At the end of the rendering when the program quits, there\'s a clear way to destroy everything. </p>\n\n<p>Many other pointers are defined as needed whenever one entity needs access another, to scan over arays or whatever; these are the "just looking". For the 3D scene example - an object uses a texture but does not own; other objects may use that same texture. The destruction of an object does <em>not</em> invoke destruction of any textures. </p>\n\n<p>Yes it\'s time consuming but that\'s what i do. I rarely have memory leaks or other problems. But then i work in the limited arena of high-performance scientific, data acquisition and graphics software. I don\'t often deal transactions like in banking and ecommerce, event-driven GUIs or high networked asynchronous chaos. Maybe the new-fangled ways have an advantage there!</p>\n'}, {'answer_id': 77040, 'author': 'screenglow', 'author_id': 424554, 'author_profile': 'https://Stackoverflow.com/users/424554', 'pm_score': 0, 'selected': False, 'text': '<p>We wrap all our allocation functions with a layer that appends a brief string at the front and a sentinel flag at the end. So for example you\'d have a call to "myalloc( pszSomeString, iSize, iAlignment ); or new( "description", iSize ) MyObject(); which internally allocates the specified size plus enough space for your header and sentinel. Of course, don\'t forget to comment this out for non-debug builds! It takes a little more memory to do this but the benefits far outweigh the costs. </p>\n\n<p>This has three benefits - first it allows you to easily and quickly track what code is leaking, by doing quick searches for code allocated in certain \'zones\' but not cleaned up when those zones should have freed. It can also be useful to detect when a boundary has been overwritten by checking to ensure all sentinels are intact. This has saved us numerous times when trying to find those well-hidden crashes or array missteps. The third benefit is in tracking the use of memory to see who the big players are - a collation of certain descriptions in a MemDump tells you when \'sound\' is taking up way more space than you anticipated, for example. </p>\n'}, {'answer_id': 77148, 'author': 'fabiopedrosa', 'author_id': 2731698, 'author_profile': 'https://Stackoverflow.com/users/2731698', 'pm_score': 3, 'selected': False, 'text': '<p>There\'s already a lot about how to not leak, but if you need a tool to help you track leaks take a look at:</p>\n\n<ul>\n<li><a href="http://www.compuware.com/products/devpartner/visualc.htm" rel="noreferrer">BoundsChecker</a> under VS </li>\n<li>MMGR C/C++ lib from FluidStudio\n<a href="http://www.paulnettle.com/pub/FluidStudios/MemoryManagers/Fluid_Studios_Memory_Manager.zip" rel="noreferrer">http://www.paulnettle.com/pub/FluidStudios/MemoryManagers/Fluid_Studios_Memory_Manager.zip</a> (its overrides the allocation methods and creates a report of the allocations, leaks, etc)</li>\n</ul>\n'}, {'answer_id': 77182, 'author': 'artificialidiot', 'author_id': 7988, 'author_profile': 'https://Stackoverflow.com/users/7988', 'pm_score': 0, 'selected': False, 'text': '<p>C++ is designed RAII in mind. There is really no better way to manage memory in C++ I think.\nBut be careful not to allocate very big chunks (like buffer objects) on local scope. It can cause stack overflows and, if there is a flaw in bounds checking while using that chunk, you can overwrite other variables or return addresses, which leads to all kinds security holes.</p>\n'}, {'answer_id': 77234, 'author': 'eli', 'author_id': 5105, 'author_profile': 'https://Stackoverflow.com/users/5105', 'pm_score': 1, 'selected': False, 'text': '<p>Others have mentioned ways of avoiding memory leaks in the first place (like smart pointers). But a profiling and memory-analysis tool is often the only way to track down memory problems once you have them.</p>\n\n<p><a href="http://valgrind.org/info/tools.html#memcheck" rel="nofollow noreferrer">Valgrind memcheck</a> is an excellent free one.</p>\n'}, {'answer_id': 77893, 'author': 'paercebal', 'author_id': 14089, 'author_profile': 'https://Stackoverflow.com/users/14089', 'pm_score': 7, 'selected': False, 'text': '<h2>Use <a href="http://en.wikipedia.org/wiki/RAII" rel="noreferrer">RAII</a></h2>\n\n<ul>\n<li><strong>Forget Garbage Collection</strong> (Use RAII instead). Note that even the Garbage Collector can leak, too (if you forget to "null" some references in Java/C#), and that Garbage Collector won\'t help you to dispose of resources (if you have an object which acquired a handle to a file, the file won\'t be freed automatically when the object will go out of scope if you don\'t do it manually in Java, or use the "dispose" pattern in C#).</li>\n<li><strong>Forget the "one return per function" rule</strong>. This is a good C advice to avoid leaks, but it is outdated in C++ because of its use of exceptions (use RAII instead).</li>\n<li>And while <strong>the "Sandwich Pattern"</strong> is a good C advice, it <strong>is outdated in C++</strong> because of its use of exceptions (use RAII instead).</li>\n</ul>\n\n<p>This post seem to be repetitive, but in C++, the most basic pattern to know is <a href="http://en.wikipedia.org/wiki/RAII" rel="noreferrer">RAII</a>.</p>\n\n<p>Learn to use smart pointers, both from boost, TR1 or even the lowly (but often efficient enough) auto_ptr (but you must know its limitations).</p>\n\n<p>RAII is the basis of both exception safety and resource disposal in C++, and no other pattern (sandwich, etc.) will give you both (and most of the time, it will give you none).</p>\n\n<p>See below a comparison of RAII and non RAII code:</p>\n\n<pre><code>void doSandwich()\n{\n T * p = new T() ;\n // do something with p\n delete p ; // leak if the p processing throws or return\n}\n\nvoid doRAIIDynamic()\n{\n std::auto_ptr<T> p(new T()) ; // you can use other smart pointers, too\n // do something with p\n // WON\'T EVER LEAK, even in case of exceptions, returns, breaks, etc.\n}\n\nvoid doRAIIStatic()\n{\n T p ;\n // do something with p\n // WON\'T EVER LEAK, even in case of exceptions, returns, breaks, etc.\n}\n</code></pre>\n\n<h2>About <a href="http://en.wikipedia.org/wiki/RAII" rel="noreferrer">RAII</a></h2>\n\n<p>To summarize (after the comment from <i>Ogre Psalm33</i>), RAII relies on three concepts:</p>\n\n<ul>\n<li><b>Once the object is constructed, it just works!</b> Do acquire resources in the constructor.</li>\n<li><b>Object destruction is enough!</b> Do free resources in the destructor.</li>\n<li><b>It\'s all about scopes!</b> Scoped objects (see doRAIIStatic example above) will be constructed at their declaration, and will be destroyed the moment the execution exits the scope, no matter how the exit (return, break, exception, etc.).</li>\n</ul>\n\n<p>This means that in correct C++ code, most objects won\'t be constructed with <code>new</code>, and will be declared on the stack instead. And for those constructed using <code>new</code>, all will be somehow <i>scoped</i> (e.g. attached to a smart pointer).</p>\n\n<p>As a developer, this is very powerful indeed as you won\'t need to care about manual resource handling (as done in C, or for some objects in Java which makes intensive use of <code>try</code>/<code>finally</code> for that case)...</p>\n\n<h2>Edit (2012-02-12)</h2>\n\n<blockquote>\n <p>"scoped objects ... will be destructed ... no matter the exit" that\'s not entirely true. there are ways to cheat RAII. any flavour of terminate() will bypass cleanup. exit(EXIT_SUCCESS) is an oxymoron in this regard.</p>\n \n <p>– <a href="https://stackoverflow.com/users/456/wilhelmtell">wilhelmtell</a></p>\n</blockquote>\n\n<p><a href="https://stackoverflow.com/users/456/wilhelmtell">wilhelmtell</a> is quite right about that: There are <em>exceptional</em> ways to cheat RAII, all leading to the process abrupt stop.</p>\n\n<p>Those are <strong>exceptional</strong> ways because C++ code is not littered with terminate, exit, etc., or in the case with exceptions, we do want an <a href="https://stackoverflow.com/questions/1104136/c-raii-not-working">unhandled exception</a> to crash the process and core dump its memory image as is, and not after cleaning.</p>\n\n<p>But we must still know about those cases because, while they rarely happen, they can still happen.</p>\n\n<p><i>(who calls <code>terminate</code> or <code>exit</code> in casual C++ code?... I remember having to deal with that problem when playing with <a href="http://www.opengl.org/resources/libraries/glut/" rel="noreferrer">GLUT</a>: This library is very C-oriented, going as far as actively designing it to make things difficult for C++ developers like not caring about <a href="http://www.opengl.org/resources/faq/technical/glut.htm#glot0070" rel="noreferrer">stack allocated data</a>, or having "interesting" decisions about <a href="http://www.opengl.org/resources/faq/technical/glut.htm#glot0090" rel="noreferrer">never returning from their main loop</a>... I won\'t comment about that)</i>.</p>\n'}, {'answer_id': 78019, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 8, 'selected': False, 'text': "<p>I thoroughly endorse all the advice about RAII and smart pointers, but I'd also like to add a slightly higher-level tip: the easiest memory to manage is the memory you never allocated. Unlike languages like C# and Java, where pretty much everything is a reference, in C++ you should put objects on the stack whenever you can. As I've see several people (including Dr Stroustrup) point out, the main reason why garbage collection has never been popular in C++ is that well-written C++ doesn't produce much garbage in the first place.</p>\n\n<p>Don't write</p>\n\n<pre><code>Object* x = new Object;\n</code></pre>\n\n<p>or even</p>\n\n<pre><code>shared_ptr<Object> x(new Object);\n</code></pre>\n\n<p>when you can just write</p>\n\n<pre><code>Object x;\n</code></pre>\n"}, {'answer_id': 81039, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>One of the only examples about allocating and destroying in different places is thread creation (the parameter you pass).\nBut even in this case is easy.\nHere is the function/method creating a thread:</p>\n\n<pre><code>struct myparams {\nint x;\nstd::vector<double> z;\n}\n\nstd::auto_ptr<myparams> param(new myparams(x, ...));\n// Release the ownership in case thread creation is successfull\nif (0 == pthread_create(&th, NULL, th_func, param.get()) param.release();\n...\n</code></pre>\n\n<p>Here instead the thread function</p>\n\n<pre><code>extern "C" void* th_func(void* p) {\n try {\n std::auto_ptr<myparams> param((myparams*)p);\n ...\n } catch(...) {\n }\n return 0;\n}\n</code></pre>\n\n<p>Pretty easyn isn\'t it? In case the thread creation fails the resource will be free\'d (deleted) by the auto_ptr, otherwise the ownership will be passed to the thread.\nWhat if the thread is so fast that after creation it releases the resource before the</p>\n\n<pre><code>param.release();\n</code></pre>\n\n<p>gets called in the main function/method? Nothing! Because we will \'tell\' the auto_ptr to ignore the deallocation.\nIs C++ memory management easy isn\'t it?\nCheers,</p>\n\n<p>Ema!</p>\n'}, {'answer_id': 81082, 'author': 'Rob', 'author_id': 9236, 'author_profile': 'https://Stackoverflow.com/users/9236', 'pm_score': 1, 'selected': False, 'text': "<p>For MSVC only, add the following to the top of each .cpp file:</p>\n\n<pre><code>#ifdef _DEBUG\n#define new DEBUG_NEW\n#endif\n</code></pre>\n\n<p>Then, when debugging with VS2003 or greater, you will be told of any leaks when your program exits (it tracks new/delete). It's basic, but it has helped me in the past.</p>\n"}, {'answer_id': 81141, 'author': 'ugasoft', 'author_id': 10120, 'author_profile': 'https://Stackoverflow.com/users/10120', 'pm_score': 3, 'selected': False, 'text': '<p>Great question!</p>\n\n<p>if you are using c++ and you are developing real-time CPU-and-memory boud application (like games) you need to write your own Memory Manager.</p>\n\n<p>I think the better you can do is merge some interesting works of various authors, I can give you some hint:</p>\n\n<ul>\n<li><p>Fixed size allocator is heavily discussed, everywhere in the net</p></li>\n<li><p>Small Object Allocation was introduced by Alexandrescu in 2001 in his perfect book "Modern c++ design"</p></li>\n<li><p>A great advancement (with source code distributed) can be found in an amazing article in Game Programming Gem 7 (2008) named "High Performance Heap allocator" written by Dimitar Lazarov</p></li>\n<li><p>A great list of resources can be found in <a href="http://entland.homelinux.com/blog/2008/08/19/practical-efficient-memory-management/" rel="noreferrer">this</a> article</p></li>\n</ul>\n\n<p>Do not start writing a noob unuseful allocator by yourself... DOCUMENT YOURSELF first.</p>\n'}, {'answer_id': 81146, 'author': 'Jonathan', 'author_id': 14850, 'author_profile': 'https://Stackoverflow.com/users/14850', 'pm_score': 2, 'selected': False, 'text': "<p>A frequent source of these bugs is when you have a method that accepts a reference or pointer to an object but leaves ownership unclear. Style and commenting conventions can make this less likely.</p>\n\n<p>Let the case where the function takes ownership of the object be the special case. In all situations where this happens, be sure to write a comment next to the function in the header file indicating this. You should strive to make sure that in most cases the module or class which allocates an object is also responsible for deallocating it.</p>\n\n<p>Using const can help a lot in some cases. If a function will not modify an object, and does not store a reference to it that persists after it returns, accept a const reference. From reading the caller's code it will be obvious that your function has not accepted ownership of the object. You could have had the same function accept a non-const pointer, and the caller may or may not have assumed that the callee accepted ownership, but with a const reference there's no question.</p>\n\n<p>Do not use non-const references in argument lists. It is very unclear when reading the caller code that the callee may have kept a reference to the parameter.</p>\n\n<p>I disagree with the comments recommending reference counted pointers. This usually works fine, but when you have a bug and it doesn't work, especially if your destructor does something non-trivial, such as in a multithreaded program. Definitely try to adjust your design to not need reference counting if it's not too hard.</p>\n"}, {'answer_id': 81538, 'author': 'Robert Gould', 'author_id': 15124, 'author_profile': 'https://Stackoverflow.com/users/15124', 'pm_score': 2, 'selected': False, 'text': '<p>Tips in order of Importance:</p>\n\n<p>-Tip#1 Always remember to declare your destructors "virtual".</p>\n\n<p>-Tip#2 Use RAII</p>\n\n<p>-Tip#3 Use boost\'s smartpointers</p>\n\n<p>-Tip#4 Don\'t write your own buggy Smartpointers, use boost (on a project I\'m on right now I can\'t use boost, and I\'ve suffered having to debug my own smart pointers, I would definately not take the same route again, but then again right now I can\'t add boost to our dependencies)</p>\n\n<p>-Tip#5 If its some casual/non-performance critical (as in games with thousands of objects) work look at Thorsten Ottosen\'s boost pointer container</p>\n\n<p>-Tip#6 Find a leak detection header for your platform of choice such as Visual Leak Detection\'s "vld" header</p>\n'}, {'answer_id': 83353, 'author': 'Nemanja Trifunovic', 'author_id': 8899, 'author_profile': 'https://Stackoverflow.com/users/8899', 'pm_score': 0, 'selected': False, 'text': '<p>Manage memory the same way you manage other resources (handles, files, db connections, sockets...). GC would not help you with them either.</p>\n'}, {'answer_id': 83373, 'author': 'Ronny Brendel', 'author_id': 14114, 'author_profile': 'https://Stackoverflow.com/users/14114', 'pm_score': 1, 'selected': False, 'text': '<p>valgrind (only avail for *nix platforms) is a very nice memory checker</p>\n'}, {'answer_id': 103563, 'author': 'Jeroen Dirks', 'author_id': 7743, 'author_profile': 'https://Stackoverflow.com/users/7743', 'pm_score': 4, 'selected': False, 'text': "<p>Most memory leaks are the result of not being clear about object ownership and lifetime.</p>\n\n<p>The first thing to do is to allocate on the Stack whenever you can. This deals with most of the cases where you need to allocate a single object for some purpose.</p>\n\n<p>If you do need to 'new' an object then most of the time it will have a single obvious owner for the rest of its lifetime. For this situation I tend to use a bunch of collections templates that are designed for 'owning' objects stored in them by pointer. They are implemented with the STL vector and map containers but have some differences:</p>\n\n<ul>\n<li>These collections can not be copied or assigned to. (once they contain objects.)</li>\n<li>Pointers to objects are inserted into them.</li>\n<li>When the collection is deleted the destructor is first called on all objects in the collection. (I have another version where it asserts if destructed and not empty.)</li>\n<li>Since they store pointers you can also store inherited objects in these containers.</li>\n</ul>\n\n<p>My beaf with STL is that it is so focused on Value objects while in most applications objects are unique entities that do not have meaningful copy semantics required for use in those containers.</p>\n"}, {'answer_id': 426351, 'author': 'mh.', 'author_id': 44134, 'author_profile': 'https://Stackoverflow.com/users/44134', 'pm_score': 1, 'selected': False, 'text': '<ul>\n<li>Try to avoid allocating objects dynamically. As long as classes have appropriate constructors and destructors, use a variable of the class type, not a pointer to it, and you avoid dynamical allocation and deallocation because the compiler will do it for you.<br>\nActually that\'s also the mechanism used by "smart pointers" and referred to as RAII by some of the other writers ;-) . \n<li>When you pass objects to other functions, prefer reference parameters over pointers. This avoids some possible errors.\n<li>Declare parameters const, where possible, especially pointers to objects. That way objects can\'t be freed "accidentially" (except if you cast the const away ;-))). \n<li>Minimize the number of places in the program where you do memory allocation and deallocation. E. g. if you do allocate or free the same type several times, write a function for it (or a factory method ;-)).<br>\nThis way you can create debug output (which addresses are allocated and deallocated, ...) easily, if required.\n<li>Use a factory function to allocate objects of several related classes from a single function. \n<li>If your classes have a common base class with a virtual destructor, you can free all of them using the same function (or static method).\n<li>Check your program with tools like purify (unfortunately many $/€/...). \n</ul>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76796', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,809 |
<p>Is anyone out there* using <a href="http://web2py.com/" rel="noreferrer">web2py</a>?</p>
<p>Specifically:</p>
<ul>
<li>In production?</li>
<li>With what database?</li>
<li><p>With Google Application Engine?</p>
<ul>
<li>by "out there" I mean at stackoverflow.</li>
</ul></li>
</ul>
|
[{'answer_id': 76982, 'author': 'benefactual', 'author_id': 6445, 'author_profile': 'https://Stackoverflow.com/users/6445', 'pm_score': 3, 'selected': False, 'text': '<p>There are some users listed here: <a href="http://mdp.cti.depaul.edu/who" rel="noreferrer">http://mdp.cti.depaul.edu/who</a>.</p>\n'}, {'answer_id': 148321, 'author': 'sparklewhiskers', 'author_id': 23402, 'author_profile': 'https://Stackoverflow.com/users/23402', 'pm_score': 3, 'selected': False, 'text': "<p>I'm starting to use it with Postgresql. But a long way off production... I've also played with Zope V2 and Ruby on Rails and really love the approach of web2py.</p>\n"}, {'answer_id': 159804, 'author': 'Armin Ronacher', 'author_id': 19990, 'author_profile': 'https://Stackoverflow.com/users/19990', 'pm_score': 3, 'selected': False, 'text': "<p>I am not using web2py. But I had a look at the source code and it's horrible for so many reasons. For one the database definitions as well as the views and models and I don't know what, are evaluated against a global dictionary of values. It feels like PHP in that regard (it's bypassing Python semantics in name behaviour) and is very inefficient and I could imagine that it's hard to maintain.</p>\n\n<p>I have no idea where all that fuzz about web2py is coming from lately, but I really can't see a reason why anyone would want to use it.</p>\n\n<p>What's wrong with Django or Pylons? What does web2py do that you can't do with Django in a few lines of code with a better performance, code that's easier to read and on an established platform where tons of developers will jump in and fix problems in no time if they appear. (Well, there are exceptions I must admit, but in general the developers fix problems quickly)</p>\n"}, {'answer_id': 178937, 'author': 'Andre Bossard', 'author_id': 21027, 'author_profile': 'https://Stackoverflow.com/users/21027', 'pm_score': 4, 'selected': False, 'text': "<p>I started using web2py about 6 month ago. I choose it, because I wanted to move from PHP to Python, to have a more object-oriented approch because of the language featrues of python.</p>\n\n<p>The all-in-one approach of web2py is really amazing and makes the start very fast.</p>\n\n<p>As a former symfony user I soon started to miss Components and Forms that aren't dependend on table structure.</p>\n\n<p>Just with a simple registration form, I could not find a way to do the Form DRY. For me the real bugger was the form validation. I forgot the details, but I ended up with having form validation in the forms itself. Because some thing just didn't work else. </p>\n\n<p>Also the naming concept of capitalised words with that lot of repeated chars is just not my thing.</p>\n\n<pre><code>dba.users.name.requires=IS_NOT_EMPTY()\ndba.users.email.requires=[IS_EMAIL(), IS_NOT_IN_DB(dba,'users.email')]\ndba.dogs.owner_id.requires=IS_IN_DB(dba,'users.id','users.name')\ndba.dogs.name.requires=IS_NOT_EMPTY()\ndba.dogs.type.requires=IS_IN_SET(['small','medium','large'])\ndba.purchases.buyer_id.requires=IS_IN_DB(dba,'users.id','users.name')\ndba.purchases.product_id.requires=IS_IN_DB(dba,'products.id','products.name')\ndba.purchases.quantity.requires=IS_INT_IN_RANGE(0,10)\n</code></pre>\n\n<p>Sometimes the names have to be in quotes, sometimes not ... and if I looked at the examples or sites already made with web2py, I really didn't see that big step forward from using php. </p>\n\n<p>I recommend you: Look if web2py works for you. It would be nice, because the community and especially massimo (the creator) are very helpful and nice. </p>\n\n<p>Also you have a much quicker start, than with django, easier deployment and less hassle if you change your database models.</p>\n"}, {'answer_id': 196705, 'author': 'massimo', 'author_id': 24489, 'author_profile': 'https://Stackoverflow.com/users/24489', 'pm_score': 7, 'selected': False, 'text': '<p>You are welcome to ask the same question on the <a href="http://groups.google.com/group/web2py" rel="noreferrer">google group</a>. You will find more than 500 users there and some of them are development companies building projects for their clients.</p>\n\n<p>My impression is that most of them use postgresql (that\'s what I do to) and some others use the Google App Engine. In fact web2py is the only framework that allows you to write code once and the same code will run on GAE, SQLite, MySQL, PostgreSQL, Oracle, MSSQL and FireBird (with the limitations imposed by GAE).</p>\n\n<p>You can find the Reddish (reddit clone) appliance with source code for GAE <a href="http://mdp.cti.depaul.edu/appliances" rel="noreferrer">here</a></p>\n\n<p><a href="http://mdp.cti.depaul.edu/who" rel="noreferrer">Here</a> you can find links to some productions app. Some are running on GAE.</p>\n\n<p>@Armin:</p>\n\n<p>Nothing is wrong with Django or Pylons. They are excellent frameworks. I have used them before developing web2py. There are a few things you can do with web2py that you cannot with them. For example: </p>\n\n<ul>\n<li>web2py does distributed transactions with Postgresql, Armin requested this feature.</li>\n<li>the Django ORM does not do migrations natively (see <a href="http://south.aeracode.org/" rel="noreferrer">South</a>), web2py does. </li>\n<li>the Django ORM does not allow partial sums (count(field)) and group by, web2py does. </li>\n<li>web2py can connect to multiple databases at once, <strike>Django and</strike> Pylons need to be hacked to do that, and </li>\n<li>web2py has a configuration file at the app, not at the project level, like them.</li>\n<li>webp2y logs all tracebacks server side for the administrator, Django and Pylons do not.</li>\n<li>web2py programs often run on GAE unmodified. </li>\n<li>web2py has built-in xmlrpc web services.</li>\n<li>web2py comes with jQuery.</li>\n</ul>\n\n<p>There are many things that web2py does better (using a more coherent API) and faster (processing templates and generating SQL for example). web2py is also very compact (all modules fit in 265K bytes) and therefore it is much easier to maintain than those competing projects.</p>\n\n<p>You only have to learn Python and 81 new function/classes (50 of which have the same names and attributes as corresponding HTML tags, <code>BR</code>, <code>DIV</code>, <code>SPAN</code>, etc. and 19 are validators, <code>IS_IN_SET</code>, <code>IS_INT_IN_RANGE</code>, etc.).</p>\n\n<p>Anyway, the most important issue is that web2py is easier than Django, Pylons, PHP and Rails.</p>\n\n<p>You will also notice that web2py is hosted on both Google Code and Launchpad and there are not open tickets. All past issues have been resolved in less than 24 hours.</p>\n\n<p>You can also check on the google mailing list that all threads (10056 messages today) ended up with an answer from me or one of the other developers within 24 hours.</p>\n\n<p>You can find a book on web2py on Amazon.</p>\n\n<p>Armin, I know you are the developer of Jinja. I like Jinja but have different design philosophies. Both Django and Jinja define their own template languages (and Jinja in particular has excellent documentation) but I do prefer to use pure Python in templates so that my users do no need to learn a template language at all. I am well aware of the pros and cons of each approach. Let\'s the users decide what they prefer. No need to criticize each other.</p>\n\n<p>@Andre: db.table.field refers to the field object. \'table.field\' is a field name. You can always pass a field object when a field name is required because str(db.table.field) is \'table.field\'. The only case you are required to use a string instead of an object is when you need to reference by name a field that has not already been defined... perhaps we should move this discussion to the proper place. ;-)</p>\n\n<p>I hope you will decide to give web2py a try and, whether you like it or not, I would love to hear your opinion. </p>\n'}, {'answer_id': 320130, 'author': 'Snaky Love', 'author_id': 40960, 'author_profile': 'https://Stackoverflow.com/users/40960', 'pm_score': 4, 'selected': False, 'text': '<p>I am evaluating web frameworks for a long time now. I wrote my own (not open) frameworks in Perl and in PHP. Well, PHP has a builtin deadend and the whole infrastructure is still quite poor, but I did not want to go back to Perl, so I checked Python and the Python Web Frameworks like Django, Turbogears, Pylon and web2py. There are many things to think about, if you want to choose a codestack that is not your own and you will often scratch your head because there is still no "right way" to program things. However, web2py is my current favourite, because the author, despite beeing a "real programmer", keeps things easy! Just look at the comparison on web2py site - I was wondering why python frameworks like django or turbogears had to introduce such redundance and complicated syntax in their code - web2py shows, that it IS in fact possible to keep your syntax clean and easy!</p>\n\n<p>@Armin: could you please specify you criticism? Where exactly do you see web2py "bypassing Python semantics"? I can not understand, what you mean. I must admit that I am not that deep into python right now, but I see no problem with the web2py code - in fact, I think it is brilliant and one of the best frameworks available today.</p>\n'}, {'answer_id': 353933, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>Actually it's using MySQL, but it could switch to postgresql at a moments notice as web2py is so diverse :)</p>\n"}, {'answer_id': 1224002, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>I vote for Web2py. I only have time to develop small but useful stuff for my own use. </p>\n\n<p>Hopefully next month I will have an oppty to create an app that is perfect for Web2py and run on Google app engine. </p>\n\n<p>Web2py = breath of fresh air!</p>\n'}, {'answer_id': 1325446, 'author': 'toomim', 'author_id': 100183, 'author_profile': 'https://Stackoverflow.com/users/100183', 'pm_score': 4, 'selected': False, 'text': "<p>I'm using web2py for a small web app. It's running the HITs on a Mechanical Turk project, and giving me an interface to control and visualize them. I started on Google App Engine, but then got sick of the little annoyances of not having direct database access and having to wait forever each time I want to upload my code, and moved to a local server with postgres. GAE makes most things harder in order to make a few scaling things easier... stay away from it unless you really need their scaling help.</p>\n\n<p>I like web2py a lot. Compared to Django and Ruby on Rails, it's WAY easier to learn and get going. Everything is simple. You get stuff done fast. Massimo is everywhere solving your problems (even on this board haha).</p>\n"}, {'answer_id': 1360810, 'author': 'hoju', 'author_id': 105066, 'author_profile': 'https://Stackoverflow.com/users/105066', 'pm_score': 2, 'selected': False, 'text': '<p>I am using web2py in production with postgres on webfaction, and also on the GAE.</p>\n'}, {'answer_id': 1507369, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>I have been evaluating web frameworks for sometime now. I prefer web2py because it's easy to follow, compact yet powerful.</p>\n"}, {'answer_id': 2077327, 'author': 'Zhe Li', 'author_id': 241870, 'author_profile': 'https://Stackoverflow.com/users/241870', 'pm_score': 2, 'selected': False, 'text': '<p>I like it because it is so tiny that I can easily distribute with my application.</p>\n'}, {'answer_id': 3749813, 'author': 'Jose de Soto Garcia', 'author_id': 452496, 'author_profile': 'https://Stackoverflow.com/users/452496', 'pm_score': 2, 'selected': False, 'text': '<p>We started to use Web2py 7 months ago. We already have one application in production in El Prado (National Museum in Spain). We developed a app to check and automate all the systems, to make servers statistics, access statistics, etc.</p>\n'}, {'answer_id': 3826962, 'author': 'David Watson', 'author_id': 173308, 'author_profile': 'https://Stackoverflow.com/users/173308', 'pm_score': 4, 'selected': False, 'text': '<p>As Massimo points out above, the team at tenthrow uses web2py for <a href="http://www.tenthrow.com/" rel="noreferrer">tenthrow.com</a></p>\n\n<p>We did most of our development work during 2009. Our stack uses cherokee, web2py, postgresql, and amazon s3. We had done many python web implementations prior to this on a variety of frameworks and backends. To say that we simply could not have done tenthrow so quickly and easily without web2py is an understatement. It\'s the best kept secret in web development.</p>\n'}, {'answer_id': 6401123, 'author': 'uolter', 'author_id': 805132, 'author_profile': 'https://Stackoverflow.com/users/805132', 'pm_score': 2, 'selected': False, 'text': '<p>I used web2py for small projects so far, but I hope to introduce it in my company. It\'s my favorite web framework.</p>\n\n<p><a href="http://uolter-blog.appspot.com/" rel="nofollow">My blog</a> is running on GAE with web2py.</p>\n\n<p>I also have a facebook apps running on top of web2py: <a href="http://apps.facebook.com/mytop_ten_gift/" rel="nofollow">My Top 10 Gift</a></p>\n'}, {'answer_id': 7623450, 'author': 'Farshid Ashouri', 'author_id': 895659, 'author_profile': 'https://Stackoverflow.com/users/895659', 'pm_score': 1, 'selected': False, 'text': '<p>Well, I am using Web2Py professionally, with PostgreSQL, and on linux. I am working on my Social network named "<a href="http://www.ourway.ir" rel="nofollow">Ourway</a>". You may like some features of it like "<a href="http://www.ourway.ir/pages/blog" rel="nofollow">Blog</a>" part.</p>\n'}, {'answer_id': 8844281, 'author': 'Chris Hawkes', 'author_id': 836277, 'author_profile': 'https://Stackoverflow.com/users/836277', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.noobmusic.com" rel="nofollow">http://www.noobmusic.com</a> is using the Google App Engine. </p>\n'}, {'answer_id': 14213052, 'author': 'sharkguto', 'author_id': 1926761, 'author_profile': 'https://Stackoverflow.com/users/1926761', 'pm_score': 3, 'selected': False, 'text': '<p>I am using web2py for 2 years, this web frameworks is great and unique. Easy to use, accept a lot of DB\'s but the best DB supported is postgres.\nI have created 2 projects with web2py and a really like how easy it is. 1 project is a financial management and other a mail tracker, both in production systems (4 linux lpar with postgres) running fine.\nweb2py is a good choice </p>\n\n<p>[small application created with web2py 2.5.1]\nupdated</p>\n\n<p><a href="http://freitasmgustavo.pythonanywhere.com/calculoST/" rel="nofollow">http://freitasmgustavo.pythonanywhere.com/calculoST/</a></p>\n'}, {'answer_id': 17802514, 'author': 'user2566926', 'author_id': 2566926, 'author_profile': 'https://Stackoverflow.com/users/2566926', 'pm_score': 3, 'selected': False, 'text': '<p>We are using it with our website that teachers Chinese, <a href="http://www.dominochinese.com" rel="noreferrer">www.dominochinese.com</a>. Our host is <a href="http://www.pythonanywhere.com" rel="noreferrer">pythonanywhere.com</a> and we love the simplicity of it. I work on building stuff instead of wishing I could get stuff working. I worked with django for 1.5 years and I hated it. In a sense I feel web2py is the PHP but in python. It makes people quickly do stuff without going into object oriented programming, which can be really confusing for beginners to intermediate programmers.</p>\n'}, {'answer_id': 18194034, 'author': 'Ryan Cori', 'author_id': 1709126, 'author_profile': 'https://Stackoverflow.com/users/1709126', 'pm_score': 1, 'selected': False, 'text': "<p>I am using web2py in production. Currently while in early production we are developing with SQLite because it is easy and it comes out of the box but later we will probably switch to MySQL. I don' think there are any plans to use Google App Engine.</p>\n"}, {'answer_id': 19884509, 'author': 'Luca', 'author_id': 410354, 'author_profile': 'https://Stackoverflow.com/users/410354', 'pm_score': 2, 'selected': False, 'text': '<p>I use it in production on Google Appengine for <a href="http://www.crowdgrader.org" rel="nofollow">www.crowdgrader.org</a>.\nI store data as follows:</p>\n\n<ul>\n<li>The core metadata, where I need ACID, is stored in Google Cloud SQL, which is working very well for me. For big text fields, I store in Google Cloud SQL the key, and in the Datastore the key-value. </li>\n<li>The text typed by users is stored in the Google Datastore, see above, with the key stored in Cloud SQL. </li>\n<li>File uploads go in the blobstore. </li>\n</ul>\n\n<p>I am slowly migrating more storage to the Datastore, to get more write bandwidth for things that do not require complex queries and can deal with a bit of eventual consistency.</p>\n\n<p>I am very happy about web2py + appengine + Google Cloud SQL + Datastore + Blobstore.</p>\n'}, {'answer_id': 29195667, 'author': 'Alexey Gorozhanov', 'author_id': 1921715, 'author_profile': 'https://Stackoverflow.com/users/1921715', 'pm_score': 3, 'selected': False, 'text': '<p>I use web2py for academic purposes. About a year ago I published on pythonanywhere a digital <a href="https://alexgoro.pythonanywhere.com/well" rel="noreferrer">text book for german grammar</a>.</p>\n\n<p>The resource requires authentication and looks like a little LMS with roles, activities and grades. It was my first experience of this kind. And it was a success because PHP was to difficult for me, and only web2py could provide a clear way to handle a database. With Python I could easily solve my problems as e. g. text analysis and downloading reports. As for database so SQLite was completely enough.</p>\n\n<p>My students like the design and the way everything is functioning. So I am very satisfied with the results and going to develop other interesting applications for my university.</p>\n\n<p>I think web2py is very good for applied linguists and L2 teachers, who are not as experienced in computer science as programmers. So that was my humble opinion.</p>\n'}, {'answer_id': 42184458, 'author': 'Harold Sarmiento', 'author_id': 4263031, 'author_profile': 'https://Stackoverflow.com/users/4263031', 'pm_score': 2, 'selected': False, 'text': '<p>I am using web2py with gae and google datastore in production of <a href="http://softqrate.appspot.com" rel="nofollow noreferrer">custom application</a> , it is a very good framework.</p>\n\n<p>I did made some minor fixes for work good on GAE, work fast and stable, i have published the Web2Py version changes uses on my github soyharso.</p>\n\n<p>The uploads to GAE are fast, the version control app engine is secure, the free tier offer google for tuning your code is excellent, the monthly cost is adequate</p>\n'}, {'answer_id': 53719430, 'author': 'Aravindan RS', 'author_id': 5114024, 'author_profile': 'https://Stackoverflow.com/users/5114024', 'pm_score': 2, 'selected': False, 'text': '<p>I use Web2py with Google App Engine in production. See <a href="https://www.nittiolearn.com" rel="nofollow noreferrer">https://www.nittiolearn.com</a>. </p>\n\n<p>For storing data, Google Datastore (accessed via web2py DAL) is used except for storing large resources where Google Cloud Storage is used. I have done multiple web2py version upgrades on the production environment in the last 5 years without any major issues.</p>\n\n<p>Google app engine has also been mostly friction-free over the years.</p>\n\n<p>But neither Web2py nor Google app engine has been adopted widely as I had thought 5-6 years ago. If I\'m starting a new project, I\'m unlikely to go with web2py or app engine as the number of developers who will be excited to work on these technologies is limited.</p>\n'}, {'answer_id': 55915364, 'author': 'Ljudva', 'author_id': 11430958, 'author_profile': 'https://Stackoverflow.com/users/11430958', 'pm_score': 1, 'selected': False, 'text': '<p>This are quite old responses but I will chip in anyway. In the year 2008 maybe it was excellent choice, as well as Django/Flask. And it still might be good.\nBut this days people want instant results, with a way less learning curve. </p>\n\n<p>The web2py is not that intuitive to be fair. </p>\n\n<p>Do I need to study MVC concepts for working with MS Access? I could not care less for URL routing, just need to display a few tables on the web, preferably with some validation. Plus some authentication. </p>\n\n<p>This is where framework like <a href="http://jam-py.com/" rel="nofollow noreferrer">http://jam-py.com/</a> shines! Not only that you wont be lost, but it does remind of Access which ruled the offices for like decades. And still rules in 2019. Why? Almost no learning curve.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76809', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/479/']
|
76,812 |
<p>What factors determine which approach is more appropriate?</p>
|
[{'answer_id': 76832, 'author': 'Loren Segal', 'author_id': 6436, 'author_profile': 'https://Stackoverflow.com/users/6436', 'pm_score': 0, 'selected': False, 'text': '<p>Not nearly enough information here. It depends if your language even supports the construct "Thing.something" or equivalent (ie. it\'s an OO language). If so, it\'s far more appropriate because that\'s the OO paradigm (members should be associated with the object they act on). In a procedural style, of course, DoSomethingtoThing() is your only choice... or ThingDoSomething()</p>\n'}, {'answer_id': 76834, 'author': 'benefactual', 'author_id': 6445, 'author_profile': 'https://Stackoverflow.com/users/6445', 'pm_score': 3, 'selected': False, 'text': '<p>To be object-oriented, tell, don\'t ask : <a href="http://www.pragmaticprogrammer.com/articles/tell-dont-ask" rel="nofollow noreferrer">http://www.pragmaticprogrammer.com/articles/tell-dont-ask</a>.</p>\n\n<p>So, Thing.DoSomething() rather than DoSomethingToThing(Thing n).</p>\n'}, {'answer_id': 76835, 'author': 'Bryan Roth', 'author_id': 299, 'author_profile': 'https://Stackoverflow.com/users/299', 'pm_score': 0, 'selected': False, 'text': '<p>DoSomethingToThing(Thing n) would be more of a functional approach whereas Thing.DoSomething() would be more of an object oriented approach.</p>\n'}, {'answer_id': 76836, 'author': 'Guido', 'author_id': 12388, 'author_profile': 'https://Stackoverflow.com/users/12388', 'pm_score': 0, 'selected': False, 'text': '<p>That is the Object Oriented versus Procedural Programming choice :)</p>\n\n<p>I think the well documented OO advantages apply to the Thing.DoSomething()</p>\n'}, {'answer_id': 76869, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 2, 'selected': False, 'text': "<p>If you're dealing with internal state of a thing, Thing.DoSomething() makes more sense, because even if you change the internal representation of Thing, or how it works, the code talking to it doesn't have to change. If you're dealing with a collection of Things, or writing some utility methods, procedural-style DoSomethingToThing() might make more sense or be more straight-forward; but still, can usually be represented as a method on the object representing that collection: for instance</p>\n\n<pre><code>GetTotalPriceofThings();\n</code></pre>\n\n<p>vs</p>\n\n<pre><code>Cart.getTotal();\n</code></pre>\n\n<p>It really depends on how object oriented your code is.</p>\n"}, {'answer_id': 76877, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 0, 'selected': False, 'text': '<p>This has been asked <a href="https://stackoverflow.com/questions/68617/design-question-does-the-phone-dial-the-phonenumber-or-does-the-phonenumber-dia">Design question: does the Phone dial the PhoneNumber, or does the PhoneNumber dial itself on the Phone?</a></p>\n'}, {'answer_id': 76904, 'author': 'Chris Comeaux', 'author_id': 2748, 'author_profile': 'https://Stackoverflow.com/users/2748', 'pm_score': 0, 'selected': False, 'text': '<p>Here are a couple of factors to consider:</p>\n\n<ul>\n<li>Can you modify or extend the <code>Thing</code> class. If not, use the former</li>\n<li>Can <code>Thing</code> be instantiated. If not, use the later as a static method</li>\n<li>If <code>Thing</code> actually get modified (i.e. has properties that change), prefer the latter. If <code>Thing</code> is not modified the latter is just as acceptable.</li>\n<li>Otherwise, as objects are meant to map on to real world object, choose the method that seems more grounded in reality.</li>\n</ul>\n'}, {'answer_id': 76907, 'author': 'Ken Ray', 'author_id': 12253, 'author_profile': 'https://Stackoverflow.com/users/12253', 'pm_score': 0, 'selected': False, 'text': '<p>Even if you aren\'t working in an OO language, where you would have Thing.DoSomething(), for the overall readability of your code, having a set of functions like:</p>\n\n<p>ThingDoSomething()\nThingDoAnotherTask()\nThingWeDoSomethingElse()</p>\n\n<p>then</p>\n\n<p>AnotherThingDoSomething()</p>\n\n<p>and so on is far better.</p>\n\n<p>All the code that works on "Thing" is on the one location. Of course, the "DoSomething" and other tasks should be named consistently - so you have a ThingOneRead(), a ThingTwoRead()... by now you should get point. When you go back to work on the code in twelve months time, you will appreciate taking the time to make things logical.</p>\n'}, {'answer_id': 76909, 'author': 'killdash10', 'author_id': 7621, 'author_profile': 'https://Stackoverflow.com/users/7621', 'pm_score': 0, 'selected': False, 'text': '<p>In general, if "something" is an action that "thing" naturally knows how to do, then you should use thing.doSomething(). That\'s good OO encapsulation, because otherwise DoSomethingToThing(thing) would have to access potential internal information of "thing".</p>\n\n<p>For example invoice.getTotal()</p>\n\n<p>If "something" is not naturally part of "thing\'s" domain model, then one option is to use a helper method. </p>\n\n<p>For example: Logger.log(invoice)</p>\n'}, {'answer_id': 76946, 'author': 'digiguru', 'author_id': 5055, 'author_profile': 'https://Stackoverflow.com/users/5055', 'pm_score': 0, 'selected': False, 'text': "<p>If DoingSomething to an object is likely to produce a different result in another scenario, then i'd suggest you oneThing.DoSomethingToThing(anotherThing). </p>\n\n<p>For example you may have two was of saving thing in you program so you might adopt a DatabaseObject.Save(thing) SessionObject.Save(thing) would be more advantageous than thing.Save() or thing.SaveToDatabase or thing.SaveToSession().</p>\n\n<p>I rarely pass no parameters to a class, unless I'm retrieving public properties.</p>\n"}, {'answer_id': 76960, 'author': 'David Arno', 'author_id': 7122, 'author_profile': 'https://Stackoverflow.com/users/7122', 'pm_score': 0, 'selected': False, 'text': "<p>To add to Aeon's answer, it depends on the the thing and what you want to do to it. So if you are writing Thing, and DoSomething alters the internal state of Thing, then the best approach is Thing.DoSomething. However, if the action does more than change the internal state, then DoSomething(Thing) makes more sense. For example:</p>\n\n<pre><code>Collection.Add(Thing)\n</code></pre>\n\n<p>is better than</p>\n\n<pre><code>Thing.AddSelfToCollection(Collection)\n</code></pre>\n\n<p>And if you didn't write Thing, and cannot create a derived class, then you have no chocie but to do DoSomething(Thing)</p>\n"}, {'answer_id': 76977, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 5, 'selected': True, 'text': '<p>I think both have their places.</p>\n\n<p>You shouldn\'t simply use <code>DoSomethingToThing(Thing n)</code> just because you think "Functional programming is good". Likewise you shouldn\'t simply use <code>Thing.DoSomething()</code> because "Object Oriented programming is good".</p>\n\n<p>I think it comes down to what you are trying to convey. Stop thinking about your code as a series of instructions, and start thinking about it like a paragraph or sentence of a story. Think about which parts are the most important from the point of view of the task at hand.</p>\n\n<p>For example, if the part of the \'sentence\' you would like to stress is the object, you should use the OO style.</p>\n\n<p>Example:</p>\n\n<pre><code>fileHandle.close();\n</code></pre>\n\n<p>Most of the time when you\'re passing around file handles, the main thing you are thinking about is keeping track of the file it represents.</p>\n\n<p>CounterExample:</p>\n\n<pre><code>string x = "Hello World";\nsubmitHttpRequest( x );\n</code></pre>\n\n<p>In this case submitting the HTTP request is far more important than the string which is the body, so <code>submitHttpRequst(x)</code> is preferable to <code>x.submitViaHttp()</code></p>\n\n<p>Needless to say, these are not mutually exclusive. You\'ll probably actually have</p>\n\n<pre><code>networkConnection.submitHttpRequest(x)\n</code></pre>\n\n<p>in which you mix them both. The important thing is that you think about what parts are emphasized, and what you will be conveying to the future reader of the code.</p>\n'}, {'answer_id': 76997, 'author': 'easeout', 'author_id': 10906, 'author_profile': 'https://Stackoverflow.com/users/10906', 'pm_score': 2, 'selected': False, 'text': '<ol>\n<li><strong>Thing.DoSomething</strong> is appropriate if Thing is the subject of your sentence.\n\n<ul>\n<li><strong>DoSomethingToThing(Thing n)</strong> is appropriate if Thing is the object of your sentence.</li>\n<li><strong>ThingA.DoSomethingToThingB(ThingB m)</strong> is an unavoidable combination, since in all the languages I can think of, functions belong to one class and are not mutually owned. But this makes sense because you can have a subject and an object.</li>\n</ul></li>\n</ol>\n\n<p>Active voice is more straightforward than passive voice, so make sure your sentence has a subject that isn\'t just "the computer". This means, use form 1 and form 3 frequently, and use form 2 rarely.</p>\n\n<p>For clarity:</p>\n\n<pre><code>// Form 1: "File handle, close."\nfileHandle.close(); \n\n// Form 2: "(Computer,) close the file handle."\nclose(fileHandle);\n\n// Form 3: "File handle, write the contents of another file handle."\nfileHandle.writeContentsOf(anotherFileHandle);\n</code></pre>\n'}, {'answer_id': 77014, 'author': 'Nikolai Prokoschenko', 'author_id': 6460, 'author_profile': 'https://Stackoverflow.com/users/6460', 'pm_score': 0, 'selected': False, 'text': "<p>Even in object oriented programming it might be useful to use a function call instead of a method (or for that matter calling a method of an object other than the one we call it on). Imagine a simple database persistence framework where you'd like to just call save() on an object. Instead of including an SQL statement in every class you'd like to have saved, thus complicating code, spreading SQL all across the code and making changing the storage engine a PITA, you could create an Interface defining save(Class1), save(Class2) etc. and its implementation. Then you'd actually be calling databaseSaver.save(class1) and have everything in one place.</p>\n"}, {'answer_id': 77091, 'author': 'Daniel', 'author_id': 13615, 'author_profile': 'https://Stackoverflow.com/users/13615', 'pm_score': 0, 'selected': False, 'text': '<p>I have to agree with <a href="https://stackoverflow.com/users/10906/kevin-conner">Kevin Conner</a></p>\n\n<p>Also keep in mind the caller of either of the 2 forms. The caller is probably a method of some other object that definitely does something to your Thing :)</p>\n'}, {'answer_id': 77303, 'author': 'Tyler', 'author_id': 3561, 'author_profile': 'https://Stackoverflow.com/users/3561', 'pm_score': 1, 'selected': False, 'text': '<p>I agree with Orion, but I\'m going to rephrase the decision process.</p>\n\n<p>You have a noun and a verb / an object and an action.</p>\n\n<ul>\n<li>If many objects of this type will use this action, try to make the action part of the object.</li>\n<li>Otherwise, try to group the action separately, but with related actions.</li>\n</ul>\n\n<p>I like the File / string examples. There are many string operations, such as "SendAsHTTPReply", which won\'t happen for your average string, but do happen often in a certain setting. However, you basically will always close a File (hopefully), so it makes perfect sense to put the Close action in the class interface.</p>\n\n<p>Another way to think of this is as buying part of an entertainment system. It makes sense to bundle a TV remote with a TV, because you always use them together. But it would be strange to bundle a power cable for a specific VCR with a TV, since many customers will never use this. The key idea is <strong>how often will this action be used on this object</strong>?</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76812', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/337/']
|
76,817 |
<p>Flex uses by default UTF-8. I have not fount a way to specify a different encoding/charset on the actionscript WebService class.</p>
|
[{'answer_id': 80749, 'author': 'Juan Delgado', 'author_id': 5908, 'author_profile': 'https://Stackoverflow.com/users/5908', 'pm_score': 2, 'selected': True, 'text': '<p>Ummm, look here:</p>\n\n<p><a href="http://www.adobe.com/devnet/flex/articles/struts_06.html" rel="nofollow noreferrer">http://www.adobe.com/devnet/flex/articles/struts_06.html</a></p>\n\n<p>I think that sample implies that declaring your mxml file as iso-8859-1 might do the trick, but I really don\'t think so.</p>\n\n<p>I might be wrong but as far as I know the Flash player only handles UTF-8 encoding. I\'ve searched for a link to an official page saying so, but couldn\'t find it.</p>\n\n<p>If that\'s the case you either:</p>\n\n<p>a) update the webservice to handle UTF-8 encoding</p>\n\n<p>b) if that\'s not possible, proxy your call to your own webservice that accepts UTF-8 and then call the actual one.</p>\n\n<p>You might want to give a go to the old system.useCodepage=true trick BUT that didn\'t use to work when the user was on Linux or Mac, USE WITH CARE!</p>\n'}, {'answer_id': 81341, 'author': 'Alexandre Victoor', 'author_id': 11897, 'author_profile': 'https://Stackoverflow.com/users/11897', 'pm_score': 0, 'selected': False, 'text': '<p>There is also a way to specify an encoding to the flex compiler but that does not seem to work.\nRight now the only solution I have found is to re-encode the incomming requests on the server side.\nI am surprised this limitation is not written black on white in the flex reference documentation.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76817', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11897/']
|
76,854 |
<p>I build websites for a small-ish media company. Unfortunately, around 45-50% of our client base uses IE6, while the other half are pretty much equally split between Firefox and Webkit-based browsers, with a sprinkling of Opera users.</p>
<p>I start every one of my sites with a reset stylesheet similar to Eric Meyer's, with a few modificaions. I've been using the Blueprint CSS "framework" a lot recently, and it's made my life a lot easier, though I am not especially attached to it.</p>
<p>Roughly 60% of my development time is spent making sure the sites I create don't look incredibly different in each browser. I code for Firefox 3 then tweak from there.</p>
<p>Does anyone know of any stylesheets/frameworks out there that attempt to preemptively account for all of those stupid little browser quirks? I know that nothing out there can totally account for all the browser weirdness, but it would be nice to have something a little more solid to start with.</p>
<p>I'm working on creating my own, but it would be nice to have something to start with.</p>
|
[{'answer_id': 76871, 'author': 'Will Hartung', 'author_id': 13663, 'author_profile': 'https://Stackoverflow.com/users/13663', 'pm_score': 0, 'selected': False, 'text': '<p>Have you looked at the Yahoo YUI stuff? They have a cross-browser CSS Framework.</p>\n'}, {'answer_id': 76922, 'author': 'japollock', 'author_id': 1210318, 'author_profile': 'https://Stackoverflow.com/users/1210318', 'pm_score': 2, 'selected': False, 'text': '<p>The Yahoo YUI library helps deal with a cross browser rendering issues. Namely, the Reset component (<a href="http://developer.yahoo.com/yui/reset/" rel="nofollow noreferrer">http://developer.yahoo.com/yui/reset/</a>) will revert all browser specific rendering (margin and padding on certain elements for instance), creating a level playing field to start from when designing your site.</p>\n'}, {'answer_id': 76928, 'author': 'JRoppert', 'author_id': 6777, 'author_profile': 'https://Stackoverflow.com/users/6777', 'pm_score': 3, 'selected': True, 'text': '<p>Take a look at <a href="http://www.yaml.de/en/home.html" rel="nofollow noreferrer">YAML</a>.</p>\n'}, {'answer_id': 76985, 'author': 'Bill Michell', 'author_id': 7938, 'author_profile': 'https://Stackoverflow.com/users/7938', 'pm_score': 1, 'selected': False, 'text': '<p>Dean Edwards\' <a href="http://dean.edwards.name/IE7/" rel="nofollow noreferrer">IE7 library</a> copes with some of the Internet Explorer quirks.</p>\n'}, {'answer_id': 77492, 'author': 'Bill Michell', 'author_id': 7938, 'author_profile': 'https://Stackoverflow.com/users/7938', 'pm_score': 2, 'selected': False, 'text': '<p>Read and inwardly digest <a href="http://www.transcendingcss.com/" rel="nofollow noreferrer">Transcending CSS</a> by Andy Clarke, Molly E. Holzschlag, Aaron Gustafson, and Mark Boulton.</p>\n\n<p>It gives a set of techniques for dealing with those quirks you can deal with, and advice on making web sites accessible to older or less capable browsers, or those using other technologies, such as screen readers.</p>\n\n<p>The fundamental thrust is on making sites that degrade gracefully.</p>\n\n<p>It contains lots of links to resources that deal with these issues.</p>\n'}, {'answer_id': 91492, 'author': 'Buzz', 'author_id': 13113, 'author_profile': 'https://Stackoverflow.com/users/13113', 'pm_score': 1, 'selected': False, 'text': '<p>Blueprint was one of the early appearances in this space, and is considered to be quite mature. </p>\n\n<p><a href="http://code.google.com/p/blueprintcss/" rel="nofollow noreferrer">http://code.google.com/p/blueprintcss/</a></p>\n\n<p>Here\'s a huge list of available frameworks:</p>\n\n<p><a href="http://www.cssnolanche.com.br/css-frameworks/" rel="nofollow noreferrer">http://www.cssnolanche.com.br/css-frameworks/</a></p>\n\n<p>There was a lot of interesting debate in the web dev community about css frameworks at the time. Many were worried this violated some stucture/presentation seperation, and introduced non semantic class names and structure. </p>\n\n<p>Some views:</p>\n\n<p><a href="http://jeffcroft.com/blog/2007/nov/17/whats-not-love-about-css-frameworks/" rel="nofollow noreferrer">http://jeffcroft.com/blog/2007/nov/17/whats-not-love-about-css-frameworks/</a></p>\n\n<p><a href="http://playgroundblues.com/posts/2007/aug/10/blueprints-are-not-final/" rel="nofollow noreferrer">http://playgroundblues.com/posts/2007/aug/10/blueprints-are-not-final/</a></p>\n\n<p><a href="http://www.markboulton.co.uk/journal/comments/blueprint_a_css_framework/" rel="nofollow noreferrer">http://www.markboulton.co.uk/journal/comments/blueprint_a_css_framework/</a></p>\n\n<p><a href="http://peter.mapledesign.co.uk/weblog/archives/blueprint-semantics-markup-frameworks" rel="nofollow noreferrer">http://peter.mapledesign.co.uk/weblog/archives/blueprint-semantics-markup-frameworks</a></p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76854', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13419/']
|
76,855 |
<p>Each of our production web servers maintains its own cache for separate web sites (ASP.NET Web Applications). Currently to clear a cache we log into the server and "touch" the web.config file. </p>
<p>Does anyone have an example of a safe/secure way to <strong>remotely</strong> reset the cache for a specific web application? Ideally we'd be able to say "clear the cache for app X running on all servers" but also "clear the cache for app X running on server Y".</p>
<p>Edits/Clarifications: </p>
<ul>
<li><p>I should probably clarify that doing this via the application itself isn't really an option (i.e. some sort of log in to the application, surf to a specific page or handler that would clear the cache). In order to do something like this we'd need to disable/bypass logging and stats tracking code, or mess up our stats.</p></li>
<li><p>Yes, the cache expires regularly. What I'd like to do though is setup something so I can expire a specific cache on demand, usually after we change something in the database (we're using SQL 2000). We can do this now but only by logging in to the servers themselves.</p></li>
</ul>
|
[{'answer_id': 77158, 'author': 'Adam Weber', 'author_id': 9324, 'author_profile': 'https://Stackoverflow.com/users/9324', 'pm_score': 0, 'selected': False, 'text': '<p>This may not be "elegant", but you could setup a scheduled task that executes a batch script. The script would essentially "touch" the web.config (or some other file that causes a re-compile) for you.</p>\n\n<p>Otherwise, is your application cache not set to expire after N minutes?</p>\n'}, {'answer_id': 77860, 'author': 'Oli', 'author_id': 12870, 'author_profile': 'https://Stackoverflow.com/users/12870', 'pm_score': 2, 'selected': False, 'text': '<p>For each application, you could write a little cache-dump.aspx script to kill the cache/application data. Copy it to all your applications and write a hub script to manage the calling.</p>\n\n<p>For security, you could add all sorts of authentication-lookups or IP-checking.</p>\n\n<p>Here the way I do the actual app-dumping:</p>\n\n<pre><code>Context.Application.Lock()\nContext.Session.Abandon()\nContext.Application.RemoveAll()\nContext.Application.UnLock()\n</code></pre>\n'}, {'answer_id': 82594, 'author': 'Sean Gough', 'author_id': 12842, 'author_profile': 'https://Stackoverflow.com/users/12842', 'pm_score': 2, 'selected': True, 'text': '<p>Found a <a href="http://archive.devx.com/dotnet/articles/rj060502/rj060502-1.asp" rel="nofollow noreferrer">DevX</a> article regarding a touch utility that look useful. </p>\n\n<p>I\'m going to try combining that with either a table in the database (add a record and the touch utility finds it and updates the appropriate web.config file) or a web service (make a call and the touch utility gets called to update the appropriate web.config file)</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76855', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12842/']
|
76,864 |
<p>In some languages you can override the "new" keyword to control how types are instantiated. You can't do this directly in .NET. However, I was wondering if there is a way to, say, handle a "Type not found" exception and manually resolve a type before whoever "new"ed up that type blows up?</p>
<p>I'm using a serializer that reads in an xml-based file and instantiates types described within it. I don't have any control over the serializer, but I'd like to interact with the process, hopefully without writing my own appdomain host.</p>
<p>Please don't suggest alternative serialization methods. </p>
|
[{'answer_id': 76902, 'author': 'MagicKat', 'author_id': 8505, 'author_profile': 'https://Stackoverflow.com/users/8505', 'pm_score': -1, 'selected': False, 'text': '<p>You should check out Reflection and the Activator class. They will allow you to create objects from strings. Granted, the object has to be in one of the assemblies that you have access to.</p>\n'}, {'answer_id': 76912, 'author': 'Abe Heidebrecht', 'author_id': 9268, 'author_profile': 'https://Stackoverflow.com/users/9268', 'pm_score': 4, 'selected': True, 'text': '<p>You can attach an event handler to AppDomain.CurrentDomain.AssemblyResolve to take part in the process.</p>\n\n<p>Your EventHandler should return the assembly that is responsible for the type passed in the ResolveEventArgs.</p>\n\n<p>You can read more about it at <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx" rel="nofollow noreferrer">MSDN</a></p>\n'}, {'answer_id': 76956, 'author': 'Peter Ritchie', 'author_id': 5620, 'author_profile': 'https://Stackoverflow.com/users/5620', 'pm_score': 1, 'selected': False, 'text': '<p>There\'s also the <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.typeresolve(VS.80).aspx" rel="nofollow noreferrer">AppDomain.TypeResolve</a> event that you can override.</p>\n'}, {'answer_id': 76978, 'author': 'Anthony', 'author_id': 5599, 'author_profile': 'https://Stackoverflow.com/users/5599', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://lingpipe-blog.com/2007/06/27/select-isnt-broken-or-horses-not-zebras/" rel="nofollow noreferrer">select isn\'t broken</a> discusses how to look at it differently - the fault may be in your design not your tooling.</p>\n\n<p>I think that trying to get "new" to do something else is going to be the wrong approach.</p>\n\n<p>Think of why operator overloading has to be used with caution - it\'s counter-intuitive and hard to debug when there are hidden changes in the language semantics.</p>\n\n<p>Step back and look at the design in a larger context, try to find a more sensible way to solve the problem.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76864', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,870 |
<p>I want to load a different properties file based upon one variable.</p>
<p>Basically, if doing a dev build use this properties file, if doing a test build use this other properties file, and if doing a production build use yet a third properties file.</p>
|
[{'answer_id': 77099, 'author': 'Andy Whitfield', 'author_id': 4805, 'author_profile': 'https://Stackoverflow.com/users/4805', 'pm_score': 0, 'selected': False, 'text': '<p>The way I\'ve done this kind of thing is to include seperate build files depending on the type of build using the <a href="http://nant.sourceforge.net/release/latest/help/tasks/nant.html" rel="nofollow noreferrer">nant task</a>. A possible alternative might be to use the <a href="http://nantcontrib.sourceforge.net/release/latest/help/tasks/iniread.html" rel="nofollow noreferrer">iniread task in nantcontrib</a>.</p>\n'}, {'answer_id': 78583, 'author': 'Tim', 'author_id': 10363, 'author_profile': 'https://Stackoverflow.com/users/10363', 'pm_score': 3, 'selected': False, 'text': '<p>You can use the <a href="http://nant.sourceforge.net/release/latest/help/tasks/include.html" rel="nofollow noreferrer"><code>include</code></a> task to include another build file (containing your properties) within the main build file. The <code>if</code> attribute of the <code>include</code> task can test against a variable to determine whether the build file should be included:</p>\n\n<pre><code><include buildfile="devPropertyFile.build" if="${buildEnvironment == \'DEV\'}"/>\n<include buildfile="testPropertyFile.build" if="${buildEnvironment == \'TEST\'}"/>\n<include buildfile="prodPropertyFile.build" if="${buildEnvironment == \'PROD\'}"/>\n</code></pre>\n'}, {'answer_id': 87752, 'author': 'scott.caligan', 'author_id': 14814, 'author_profile': 'https://Stackoverflow.com/users/14814', 'pm_score': 6, 'selected': True, 'text': '<p><strong>Step 1</strong>: Define a property in your NAnt script to track the environment you\'re building for (local, test, production, etc.).</p>\n\n<pre><code><property name="environment" value="local" />\n</code></pre>\n\n<p><strong>Step 2</strong>: If you don\'t already have a configuration or initialization target that all targets depends on, then create a configuration target, and make sure your other targets depend on it.</p>\n\n<pre><code><target name="config">\n <!-- configuration logic goes here -->\n</target>\n\n<target name="buildmyproject" depends="config">\n <!-- this target builds your project, but runs the config target first -->\n</target>\n</code></pre>\n\n<p><strong>Step 3</strong>: Update your configuration target to pull in an appropriate properties file based on the environment property.</p>\n\n<pre><code><target name="config">\n <property name="configFile" value="${environment}.config.xml" />\n <if test="${file::exists(configFile)}">\n <echo message="Loading ${configFile}..." />\n <include buildfile="${configFile}" />\n </if>\n <if test="${not file::exists(configFile) and environment != \'local\'}">\n <fail message="Configuration file \'${configFile}\' could not be found." />\n </if>\n</target>\n</code></pre>\n\n<p>Note, I like to allow team members to define their own local.config.xml files that don\'t get committed to source control. This provides a nice place to store local connection strings or other local environment settings.</p>\n\n<p><strong>Step 4</strong>: Set the environment property when you invoke NAnt, e.g.:</p>\n\n<ul>\n<li>nant -D:environment=dev</li>\n<li>nant -D:environment=test</li>\n<li>nant -D:environment=production</li>\n</ul>\n'}, {'answer_id': 180438, 'author': 'Ryan Taylor', 'author_id': 19977, 'author_profile': 'https://Stackoverflow.com/users/19977', 'pm_score': 3, 'selected': False, 'text': '<p>I had a similar problem which the answer from scott.caligan partially solved, however I wanted people to be able to set the environment and load the appropriate properties file just by specifying a target like so:</p>\n\n<ul>\n<li>nant dev</li>\n<li>nant test</li>\n<li>nant stage</li>\n</ul>\n\n<p>You can do this by adding a target that sets the environment variable. For instance:</p>\n\n<pre><code><target name="dev">\n <property name="environment" value="dev"/>\n <call target="importProperties" cascade="false"/>\n</target>\n\n<target name="test">\n <property name="environment" value="test"/>\n <call target="importProperties" cascade="false"/>\n</target>\n\n<target name="stage">\n <property name="environment" value="stage"/>\n <call target="importProperties" cascade="false"/>\n</target>\n\n<target name="importProperties">\n <property name="propertiesFile" value="properties.${environment}.build"/>\n <if test="${file::exists(propertiesFile)}">\n <include buildfile="${propertiesFile}"/>\n </if>\n <if test="${not file::exists(propertiesFile)}">\n <fail message="Properties file ${propertiesFile} could not be found."/>\n </if>\n</target>\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76870', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9052/']
|
76,882 |
<p>I have written a lot of code in Python, and I am very used to the syntax, object structure, and so forth of Python because of it.</p>
<p>What is the best online guide or resource site to provide me with the basics, as well as a comparison or lookup guide with equivalent functions/features in VBA versus Python.</p>
<p>For example, I am having trouble equating a simple List in Python to VBA code. I am also have issues with data structures, such as dictionaries, and so forth. </p>
<p>What resources or tutorials are available that will provide me with a guide to porting python functionality to VBA, or just adapting to the VBA syntax from a strong OOP language background?</p>
|
[{'answer_id': 76950, 'author': 'Jiaaro', 'author_id': 2908, 'author_profile': 'https://Stackoverflow.com/users/2908', 'pm_score': 2, 'selected': False, 'text': '<p>This tutorial isn\'t \'for python programmers\' but I thinkit\'s a pretty good vba resource:</p>\n\n<p><a href="http://www.vbtutor.net/VBA/vba_tutorial.html" rel="nofollow noreferrer">http://www.vbtutor.net/VBA/vba_tutorial.html</a></p>\n\n<p>This site goes over a real-world example using lists:</p>\n\n<p><a href="http://www.ozgrid.com/VBA/count-of-list.htm" rel="nofollow noreferrer">http://www.ozgrid.com/VBA/count-of-list.htm</a></p>\n'}, {'answer_id': 76984, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Probably not exactly what you are looking for but this is a decent VBA site if you have some programming background. It\'s not a list of this = that but more of a problem/solution</p>\n\n<p><a href="http://www.mvps.org/access/toc.htm" rel="nofollow noreferrer">http://www.mvps.org/access/toc.htm</a></p>\n'}, {'answer_id': 76989, 'author': 'Sam Corder', 'author_id': 2351, 'author_profile': 'https://Stackoverflow.com/users/2351', 'pm_score': 2, 'selected': False, 'text': "<p>VBA as in what was implemented as part of Office 2000, 2003 and VB6 have been deprecated in favor of .Net technologies. Unless you are maintaining old code stick to python or maybe even go with IronPython for .Net. If you go IronPython, you may have to write some C#/VB.Net helper classes here and there when working with various COM objects such as ones in Office but otherwise it is supposed to be pretty functional and nice. Just about all of the Python goodness is over in IronPython. If you are just doing some COM scripting take a look at what ActiveState puts out. I've used it in the past to do some COM work. Specifically using Python as an Active Scripting language (classic ASP).</p>\n"}, {'answer_id': 78708, 'author': 'S.Lott', 'author_id': 10661, 'author_profile': 'https://Stackoverflow.com/users/10661', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n <p>"I\'m having trouble equating a simple\n List in Python with something in\n VBA..."</p>\n</blockquote>\n\n<p>This isn\'t the best way to learn the language. In a way, you\'re giving up large pieces of Python because there isn\'t something like it in VBA.</p>\n\n<p>If there\'s nothing like a Python list in VBA, then -- well -- it\'s something new. And new would be the significant value in parts of Python.</p>\n\n<p>The first parts of the Python <a href="http://docs.python.org/lib/types.html" rel="nofollow noreferrer">Built-in Types</a> may not map well to VBA. That makes learning appear daunting. But limiting yourself to just things that appear in VBA tends to prevent learning.</p>\n'}, {'answer_id': 185390, 'author': 'molasses', 'author_id': 11293, 'author_profile': 'https://Stackoverflow.com/users/11293', 'pm_score': 1, 'selected': False, 'text': '<p>I think the equivalent of lists would be arrays in terms of common usage.\nWhere it is common to use a list in Python you would normally use an array in VB.\nHowever, VB arrays are very inflexible compared to Python lists and are more like arrays in C.</p>\n\n<pre><code>\' An array with 3 elements\n\'\' The number inside the brackets represents the upper bound index\n\'\' ie. the last index you can access\n\'\' So a(2) means you can access a(0), a(1), and a(2) \'\n\nDim a(2) As String\na(0) = "a"\na(1) = "b"\na(2) = "c"\n\nDim i As Integer\nFor i = 0 To UBound(a)\n MsgBox a(i)\nNext\n</code></pre>\n\n<p>Note that arrays in VB cannot be resized if you declare the initial number of elements.</p>\n\n<pre><code>\' Declare a "dynamic" array \'\n\nDim a() As Variant\n\n\' Set the array size to 3 elements \'\n\nReDim a(2)\na(0) = 1\na(1) = 2\n\n\' Set the array size to 2 elements\n\'\' If you dont use Preserve then you will lose\n\'\' the existing data in the array \'\n\nReDim Preserve a(1)\n</code></pre>\n\n<p>You will also come across various collections in VB.\neg. <a href="http://devguru.com/technologies/vbscript/14045.asp" rel="nofollow noreferrer">http://devguru.com/technologies/vbscript/14045.asp</a></p>\n\n<p>Dictionaries in VB can be created like this:</p>\n\n<pre><code>Set cars = CreateObject("Scripting.Dictionary")\ncars.Add "a", "Alvis"\ncars.Add "b", "Buick"\ncars.Add "c", "Cadillac" \n</code></pre>\n\n<p><a href="http://devguru.com/technologies/vbscript/13992.asp" rel="nofollow noreferrer">http://devguru.com/technologies/vbscript/13992.asp</a></p>\n'}, {'answer_id': 186583, 'author': 'tzot', 'author_id': 6899, 'author_profile': 'https://Stackoverflow.com/users/6899', 'pm_score': 5, 'selected': False, 'text': '<p>VBA is quite different from Python, so you should read at least the "Microsoft Visual Basic Help" as provided by the application you are going to use (Excel, Access…).</p>\n\n<p>Generally speaking, VBA has the equivalent of Python modules; they\'re called "Libraries", and they are not as easy to create as Python modules. I mention them because Libraries will provide you with higher-level types that you can use.</p>\n\n<p>As a start-up nudge, there are two types that can be substituted for <code>list</code> and <code>dict</code>.</p>\n\n<h2><code>list</code></h2>\n\n<p>VBA has the type <code>Collection</code>. It\'s available by default (it\'s in the library <code>VBA</code>). So you just do a<br>\n<code>dim alist as New Collection</code><br>\nand from then on, you can use its methods/properties:</p>\n\n<ul>\n<li><code>.Add(item)</code> ( list.append(item) ),</li>\n<li><code>.Count</code> ( len(list) ),</li>\n<li><code>.Item(i)</code> ( list[i] ) and</li>\n<li><code>.Remove(i)</code> ( del list[i] ). Very primitive, but it\'s there.</li>\n</ul>\n\n<p>You can also use the VBA Array type, which like python arrays are lists of same-type items, and unlike python arrays, you need to do <code>ReDim</code> to change their size (i.e. you can\'t just append and remove items)</p>\n\n<h2><code>dict</code></h2>\n\n<p>To have a dictionary-like object, you should add the Scripting library to your VBA project¹. Afterwards, you can<br>\n<code>Dim adict As New Dictionary</code><br>\nand then use its properties/methods:</p>\n\n<ul>\n<li><code>.Add(key, item)</code> ( dict[key] = item ),</li>\n<li><code>.Exists(key)</code> ( dict.has_key[key] ),</li>\n<li><code>.Items()</code> ( dict.values() ),</li>\n<li><code>.Keys()</code> ( dict.keys() ),<br>\nand others which you will find in the Object Browser².</li>\n</ul>\n\n<p>¹ Open VBA editor (Alt+F11). Go to Tools→References, and check the "Microsoft Scripting Runtime" in the list.</p>\n\n<p>² To see the Object Browser, in VBA editor press F2 (or View→Object Browser).</p>\n'}, {'answer_id': 186641, 'author': 'CtrlDot', 'author_id': 19487, 'author_profile': 'https://Stackoverflow.com/users/19487', 'pm_score': 0, 'selected': False, 'text': '<p>This may sound weird, but since I learned data structures in C++, I had a really hard time figuring out how to create them without pointers. There\'s something about VB6/VBA that makes them feel unnatural to me. Anyway, I came across this section of MSDN that has several data structure examples written in VBA. I found it useful.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/aa227473(VS.60).aspx" rel="nofollow noreferrer">Creating Dynamic Data Structures Using Class Modules</a></p>\n'}, {'answer_id': 189311, 'author': 'JonnyGold', 'author_id': 2665, 'author_profile': 'https://Stackoverflow.com/users/2665', 'pm_score': 2, 'selected': False, 'text': "<p>While I'm not a Python programmer, you might be able to run VSTO with Iron Python and Visual Studio. At least that way, you won't have to learn VBA syntax.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76882', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,891 |
<p>I have some curious behavior that I'm having trouble figuring out why is occurring. I'm seeing intermittent timeout exceptions. I'm pretty sure it's related to volume because it's not reproducible in our development environment. As a bandaid solution, I tried upping the sql command timeout to sixty seconds, but as I've found, this doesn't seem to help. Here's the strange part, when I check my logs on the process that is failing, here are the start and end times:</p>
<ul>
<li>09/16/2008 16:21:49</li>
<li>09/16/2008 16:22:19</li>
</ul>
<p>So how could it be that it's timing out in thirty seconds when I've set the command timeout to sixty??</p>
<p>Just for reference, here's the exception being thrown:</p>
<pre><code>System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at SetClear.DataAccess.SqlHelper.ExecuteReader(CommandType commandType, String commandText, SqlParameter[] commandArgs)
</code></pre>
|
[{'answer_id': 76911, 'author': 'Danimal', 'author_id': 2757, 'author_profile': 'https://Stackoverflow.com/users/2757', 'pm_score': 1, 'selected': False, 'text': "<p>Try changing the SqlConnection's timeout property, rather than that of the command</p>\n"}, {'answer_id': 76921, 'author': 'blowdart', 'author_id': 2525, 'author_profile': 'https://Stackoverflow.com/users/2525', 'pm_score': 1, 'selected': False, 'text': '<p>Because the timeout is happening on the connection, not the command. You need to set the <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx" rel="nofollow noreferrer">connection.TimeOut</a> property</p>\n'}, {'answer_id': 76941, 'author': 'Charles Graham', 'author_id': 7705, 'author_profile': 'https://Stackoverflow.com/users/7705', 'pm_score': 2, 'selected': False, 'text': "<p>This may sound stupid, but just hear me out. Check all the indexes and primary keys involved in your query. Do they exist? Are they fragmented? I've had a problem where, so some reason, running the script outright worked just find, but then when I did it through the application, it was slow as dirt. The reader's basically act like cursors, so indexing is extremely important.</p>\n\n<p>It might not be this, but it's always the first thing that I check.</p>\n"}, {'answer_id': 76994, 'author': 'The Digital Gabeg', 'author_id': 12782, 'author_profile': 'https://Stackoverflow.com/users/12782', 'pm_score': 1, 'selected': False, 'text': "<p>I had this problem once, and I tracked it to some really inefficient SQL code in one of my database's views. Someone had put a complex condition with a subquery into the ON clause for a table join, instead of into the WHERE clause where it belonged. Once I corrected this error, the problem went away.</p>\n"}, {'answer_id': 78698, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 3, 'selected': True, 'text': "<p>SQL commands time out because the query you're using takes longer than that to execute. Execute it in Query Analyzer or Management Studio, <em>with a representative amount of data in the database</em>, and look at the execution plan to find out what's slow.</p>\n\n<p>If something is taking a large percentage of the time and is described as a 'table scan' or 'clustered index scan', look at whether you can create an index that would turn that operation into a key lookup (an index seek or clustered index seek).</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76891', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5416/']
|
76,905 |
<p>For some reason the combination of swfobject.js and script.aculo.us Ajax.Autocompleter on the same page causes the latter to fail. Autocompleter doesn't make its Ajax request. A separate Ajax control on the same page that uses Ajax.Updater doesn't seem to have the same problem.</p>
|
[{'answer_id': 76972, 'author': 'Alexandre Victoor', 'author_id': 11897, 'author_profile': 'https://Stackoverflow.com/users/11897', 'pm_score': 0, 'selected': False, 'text': "<p>prototype.js (used by scriptaculous) and swfobject.js might be incompatible.\nWhat are the versions of theses tools you are using ?\nDid you try to switch the order of the 'script' import tags in order to import swfobject first ?</p>\n"}, {'answer_id': 77221, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Bah, I should have included versions tried in the original question. </p>\n\n<p>I've tried a combination of swfobject 1.5, 2.0, and 2.1 (current) and both the 1.7.x and 1.8.x versions of scriptaculous, which rely on 1.5.x and 1.6.x of prototype.js, respectively. I've tried loading swfobject both before and after the protoype/scriptaculous libraries, to no avail.</p>\n\n<p>I'm led to believe that there's a fundamental incompatibility lurking somewhere, but haven't been able to find anything about it on the googles, which seems a bit odd in itself.</p>\n"}, {'answer_id': 208640, 'author': 'Chris MacDonald', 'author_id': 18146, 'author_profile': 'https://Stackoverflow.com/users/18146', 'pm_score': 1, 'selected': False, 'text': '<p>If you\'re using Firefox on a local machine, AJAX requests don\'t work for security reasons.</p>\n\n<p>Either upload to a server, or try something like <a href="http://www.apachefriends.org/en/xampp.html" rel="nofollow noreferrer">xampp</a> to easily get a webserver running on your own machine.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76905', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,925 |
<p>DOING THE POST IS NOT THE PROBLEM! Formatting the message so that I get a response is the problem.</p>
<p>Ideally I'd be able to construct a message and use WinHTTP to perform a post to a WCF service (hosted in IIS) and get a response, but so far I've been unable to construct something that works properly.</p>
<p>Does anyone have an example of doing this that is straightforward?</p>
<p>In the 2.0 Web Service world this was as easy as putting a setting in the web.config to get the service to respond to a post and then calling the appropriate web method with the right parameters. There seems to be no analogue for this in the WCF world.</p>
<p>As of now there is no option for me to convert the consumer (the vbscript end) into .NET.</p>
<p>Assume at this point that at the endpoint I can convert to using whatever bindings are available right up to whatever is supported in .NET 3.5, but at the same time if this can be done using WsHttpBinding or BasicHttpBinding then the proper answer to this would be to describe how to format the message for either of those bindings in the context of VBScript or if there is no way to do that then just say, you can't do it. If this can be done using WebHTTPBinding then I have not found a way to make it happen as I've already investigated the WebInvoke attribute and been unable to create a test from VBScript to WCF that worked properly.</p>
<p>Assume that the posted data type is a string and the response is also a string.</p>
<p>Also this question is not WinHTTP related. I already know how to perform the post using WinHTTP it's the construction of the message that the WCF service will respond to that is the problem.</p>
<p>While I could use something other than WinHTTP to perform the post from ASP over to the WCF service such as XMLHTTP I still have the problem of constructing an XML message that the WCF service will respond to. I've tried variations on this and still am unable to fathom what sort of format I need to use to make this happen.</p>
<p>I know theoretically that all the WCF service needs is a properly formatted message. I'm just unable to construct the message properly and usually while everyone has some suggestion on how to send the message I have yet to see someone give an actual example of what the proper message format would be in this situation since everyone is so used to using .NET to send the message and it's all done for you in that context.</p>
|
[{'answer_id': 77115, 'author': 'Spike', 'author_id': 13111, 'author_profile': 'https://Stackoverflow.com/users/13111', 'pm_score': 0, 'selected': False, 'text': '<p>I wote some code a while ago for an excel macro which reads a XML file, posts the contents to a URL then saves the result.</p>\n\n<pre><code>Sub ExportToHTTPPOST()\nDim sURL, sExtraParams\nConst ForReading = 1, ForWriting = 2, ForAppending = 3\n\nSet rs = CreateObject("Scripting.FileSystemObject")\nSet r = rs.OpenTextFile("y:\\test.xml", ForReading)\n\nSet Ws = CreateObject("Scripting.FileSystemObject")\nSet w = Ws.OpenTextFile("Y:\\test2.xml", ForWriting, True)\n\nDo Until r.AtEndOfStream\n\n sData = sData & r.readline\n\nLoop\n\nsURL = "http://MyServer/MyWebApp.asp"\n\nsData = "payload=" & sData\n\n Set objHTTP = New WinHttp.WinHttpRequest\n\n objHTTP.Open "POST", sURL, False\n objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"\n objHTTP.send sData\n w.writeline objHTTP.ResponseText\n Set objHTTP = Nothing\n w.Close\n r.Close\nEnd Sub\n</code></pre>\n'}, {'answer_id': 78907, 'author': 'tomasr', 'author_id': 10292, 'author_profile': 'https://Stackoverflow.com/users/10292', 'pm_score': 2, 'selected': True, 'text': '<p>You don\'t specify one thing: What binding are you exposing your service as? If you\'re using WsHttpBinding or BasicHttpBinding, then there\'s no simple "http post" you can do, because you need to include at the very least the entire SOAP envelope (with the right SOAP version and potentially security headers and so forth).</p>\n\n<p>If you\'re using (or can migrate to) .NET 3.5, then there\'s a new binding explicitly created to support scenarios like this, where you want your service to be exposed not as a SOAP service but as fully REST-like service, or simply as XML/JSON over HTTP. It\'s called the WebHttpBinding.</p>\n\n<p>There are many options you can tweak, but it\'s very likely you might just be able to add a new endpoint with webHttpBinding and have that working almost right away.</p>\n\n<p>This might give you a head-start on the new programming model: <a href="http://msdn.microsoft.com/en-us/library/bb412169.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb412169.aspx</a></p>\n'}, {'answer_id': 95307, 'author': 'Skyhigh', 'author_id': 13387, 'author_profile': 'https://Stackoverflow.com/users/13387', 'pm_score': 1, 'selected': False, 'text': '<p>This is the simplest code I\'ve got for doing a background HTTP post in ASP</p>\n\n<pre><code>Set objXML = CreateObject("MSXML2.ServerXMLHTTP.6.0")\nobjXML.open "POST", url, false\nobjXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"\nobjXML.send("key="& Server.URLEncode(xmlvalue))\nSet responseXML = objXML.responseXML\nSet objXML = nothing\n</code></pre>\n\n<p>This just requires that you have the MSXML objects installed on your server. I use this for all kinds of things including an XML-RPC server/client in ASP.</p>\n\n<p>edit: Re-read your question and if you are set on that specific way then this won\'t help, but if you are really just looking for a way to access your webservice this would work as long as you construct your XML to post correctly.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76925', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10004/']
|
76,930 |
<p><strong>Scenario:</strong> Several people go on holiday together, armed with digital cameras, and snap away. Some people remembered to adjust their camera clocks to local time, some left them at their home time, some left them at local time of the country they were born in, and some left their cameras on factory time.</p>
<p><strong>The Problem:</strong> Timestamps in the EXIF metadata of photos will not be synchronised, making it difficult to aggregate all the photos into one combined collection.</p>
<p><strong>The Question:</strong> Assuming that you have discovered the deltas between all of the camera clocks, What is the <em>simplest</em> way to correct these timestamp differences in Windows Vista?</p>
|
[{'answer_id': 77037, 'author': 'flxkid', 'author_id': 13036, 'author_profile': 'https://Stackoverflow.com/users/13036', 'pm_score': 1, 'selected': False, 'text': '<p>Easiest, probably a small python script that will use something like os.walk to go through all the files below a folder and then use <a href="http://tilloy.net/dev/pyexiv2/index.htm" rel="nofollow noreferrer">pyexiv2</a> to actually read and then modify the EXIF data. A tutorial on pyexiv2 can be found <a href="http://tilloy.net/dev/pyexiv2/tutorial.htm" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 77123, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>use exiftool. open source, written in perl, but also available as standalone .exe file. author seems to have though of <em>everything</em> exif related. mature code.</p>\n\n<p>examples:</p>\n\n<pre><code>exiftool "-DateTimeOriginal+=5:10:2 10:48:0" DIR\n\nexiftool -AllDates-=1 DIR\n</code></pre>\n\n<p>refs:</p>\n\n<ul>\n<li><a href="http://www.sno.phy.queensu.ca/~phil/exiftool/" rel="nofollow noreferrer">http://www.sno.phy.queensu.ca/~phil/exiftool/</a></li>\n<li><a href="http://www.sno.phy.queensu.ca/~phil/exiftool/#shift" rel="nofollow noreferrer">http://www.sno.phy.queensu.ca/~phil/exiftool/#shift</a></li>\n</ul>\n'}, {'answer_id': 87093, 'author': 'Iain', 'author_id': 5993, 'author_profile': 'https://Stackoverflow.com/users/5993', 'pm_score': 3, 'selected': True, 'text': '<p>Windows Live Photo Gallery Wave 3 Beta includes this feature. From the help:</p>\n\n<blockquote>\n <p>If you change the date and time\n settings for more than one photo at\n the same time, each photo\'s time stamp\n is changed by the same amount, so that\n the time stamps of all the selected\n photos remain in their original\n chronological order.</p>\n</blockquote>\n\n<p><strong>Instructions:</strong></p>\n\n<ol>\n<li>Select Photos to change (you can use the search feature to limit by camera model, etc).</li>\n<li>Right-Click and select \'Change Time Taken...\'.</li>\n<li>Select a new time and click OK.</li>\n</ol>\n\n<p>Current download location is from <a href="http://www.liveside.net/main/archive/2008/09/16/windows-live-wave-3-betas-download-now.aspx" rel="nofollow noreferrer">LiveSide.net</a>.</p>\n'}, {'answer_id': 20418903, 'author': 'Fr0sT', 'author_id': 1497831, 'author_profile': 'https://Stackoverflow.com/users/1497831', 'pm_score': 0, 'selected': False, 'text': '<p>I\'d dare to advice my software for this purpose: <a href="https://github.com/Fr0sT-Brutal/App_EXIFTimeEdit" rel="nofollow">EXIFTimeEdit</a>. Open-source and simple, it supports all the possible variants I could imagine:</p>\n\n<ul>\n<li>Shifting date part (year/month/day/hour/minute) by any value</li>\n<li>Setting date part to any value</li>\n<li>Determining necessary shift value</li>\n<li>Copying resulting timestamp to EXIF DateTime field and last modified property</li>\n</ul>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76930', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5975/']
|
76,933 |
<p>I have a small app which references the Microsoft.SqlServer.Smo assembly (so I can display to the user a list of servers & databases to which they can connect).</p>
<p>My application originally referenced Microsoft.SqlServer.Smo and Microsoft.SqlServer.ConnectionInfo. Things worked as expected on my dev box.</p>
<p>When I installed the application on a test machine, I received a <strong>System.IO.FileNotFoundException</strong>. The details of the message included the following:
<strong>Could not load file or assembly Microsoft.SqlServer.SmoEnum</strong></p>
<p>I eventually resolved the issue by referencing the following assemblies in addition to the ones mentioned above: </p>
<ul>
<li>Microsoft.SqlServer.SmoEnum</li>
<li>Microsoft.SqlServer.SqlEnum</li>
<li>Microsoft.SqlServer.BatchParser</li>
<li>Microsoft.SqlServer.Replication</li>
</ul>
<p>Can anyone confirm that I do indeed need to include each of these additional assemblies in my application (and therefore install them on user's machines) even though the app builds fine on my development box without them referenced?</p>
|
[{'answer_id': 77343, 'author': 'Omer van Kloeten', 'author_id': 4979, 'author_profile': 'https://Stackoverflow.com/users/4979', 'pm_score': 0, 'selected': False, 'text': "<p>Since JIT links to external assemblies at run-time, this question can't be answered without analyzing your code and seeing what you call and in turn, what those calls call, etc.</p>\n\n<p>If you want to analyze this yourself, your best bet would be to reference only the assembly you need and then to learn from the exceptions and inner-exceptions what happened.</p>\n\n<p>Another thing you should look into is why the four assemblies you mention aren't in the GAC. It sure seems like they should be.</p>\n"}, {'answer_id': 77366, 'author': 'David J. Sokol', 'author_id': 1390, 'author_profile': 'https://Stackoverflow.com/users/1390', 'pm_score': 3, 'selected': True, 'text': '<p>Yes, they do need to be included. On the development machine you probably have SQL Server installed, which places those assemblies into the Global Assembly Cache. Whenever you build, Visual Studio just pulls from them from the GAC. It also assumes that the GAC of whatever computer it will be deployed on will also have those files. If not, it throws the FileNotFound exception.</p>\n'}, {'answer_id': 5808451, 'author': 'ebol2000', 'author_id': 407188, 'author_profile': 'https://Stackoverflow.com/users/407188', 'pm_score': 0, 'selected': False, 'text': '<p>For me this answer turned out not to be true. I added the above references but with no resolution. Ultimately I found that I only needed the reference:</p>\n\n<p>Microsoft.SqlServer.Smo</p>\n\n<p>... and the following resolution:</p>\n\n<p><a href="https://stackoverflow.com/questions/41449/i-get-a-an-attempt-was-made-to-load-a-program-with-an-incorrect-format-error-on/2926982#2926982">I get a "An attempt was made to load a program with an incorrect format" error on a SQL Server replication project</a></p>\n\n<p>To summarize, I needed to enable my IIS 6 to enable 32bit application on IIS App pool. This is because I had Win 7 x64 but a SQL x86 install. Too bad the error message can\'t be more specific huh?</p>\n'}, {'answer_id': 23634105, 'author': 'Erti-Chris Eelmaa', 'author_id': 1936622, 'author_profile': 'https://Stackoverflow.com/users/1936622', 'pm_score': 2, 'selected': False, 'text': '<p>You need to install two MSI files on a target machine, namely:</p>\n\n<p>1) SQLSysClrTypes.msi [this one is needed for C# -> SMO GAC]</p>\n\n<p>2) SharedManagementObjects.msi</p>\n\n<p>For SQL Server 2014 you can dowload these <a href="http://www.microsoft.com/en-us/download/details.aspx?id=42295" rel="nofollow">here</a>.</p>\n\n<p>Also, you must make sure that the version is correct. These two files can be found with a little bit of googling. This way you don\'t copy anything to local & they will be resolved from GAC. </p>\n\n<p>I know that this is old question, but the answers weren\'t satisfactory. </p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76933', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2833/']
|
76,934 |
<p>I have been hired to help write an application that manages certain information for the end user. It is intended to manage a few megabytes of information, but also manage scanned images in full resolution. Should this project use a database, and why or why not?</p>
|
[{'answer_id': 76952, 'author': 'Tom Leys', 'author_id': 11440, 'author_profile': 'https://Stackoverflow.com/users/11440', 'pm_score': 1, 'selected': False, 'text': '<p>Any question "Should I use a certain tool?" comes down to asking exactly what you want to do. You should ask yourself - "Do I want to write my own storage for this data?"</p>\n\n<p>Most web based applications are written against a database because most databases support many "free" features - you can have multiple webservers. You can use standard tools to edit, verify and backup your data. You can have a robust storage solution with transactions. </p>\n'}, {'answer_id': 76965, 'author': 'ahockley', 'author_id': 8209, 'author_profile': 'https://Stackoverflow.com/users/8209', 'pm_score': 0, 'selected': False, 'text': '<p>My gut reaction is "why not?" A database is going to provide a framework for storing information, with all of the input/output/optimization functions provided in a documented format. You can go with a server-side solution, or a local database such as SQLite or the local version of SQL Server. Either way you have a robust, documented data management framework.</p>\n'}, {'answer_id': 76968, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 0, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay">This post</a> should give you most of the opinions you need about storing images in the database. Do you also mean \'should I use a database for the other information?\' or are you just asking about the images?</p>\n'}, {'answer_id': 76970, 'author': 'Matt Everson', 'author_id': 7300, 'author_profile': 'https://Stackoverflow.com/users/7300', 'pm_score': 0, 'selected': False, 'text': '<p>Our CMS stores all of the check images we process. It uses a database for metadata and lets the file system handle the scanned images. </p>\n\n<p>A simple database like SQLite sounds appropriate - it will let you store file metadata in a consistent, transactional way. Then store the path to each image in the database and let the file system do what it does best - manage files.</p>\n\n<p>SQL Server 2008 has a new data type built for in-database files, but before that BLOB was the way to store files inside the database. On a small scale that would work too.</p>\n'}, {'answer_id': 76973, 'author': 'nsayer', 'author_id': 13757, 'author_profile': 'https://Stackoverflow.com/users/13757', 'pm_score': 1, 'selected': False, 'text': "<p>The database won't help you much in dealing with the image data itself, but anything that manages a bunch of images is going to have meta-data about the images that you'll be dealing with. Depending on the meta-data and what you want to do with it, a database can be quite helpful indeed with that.</p>\n\n<p>And just because the database doesn't help you much with the image data, that doesn't mean you can't store the images in the database. You would store them in a BLOB column of a SQL database.</p>\n"}, {'answer_id': 77004, 'author': 'NerdFury', 'author_id': 6146, 'author_profile': 'https://Stackoverflow.com/users/6146', 'pm_score': 1, 'selected': False, 'text': '<p>If the amount of data is small, or installed on many client machines, you might not want the overhead of a database.</p>\n\n<p>Is it intended to be installed on many users machines? Adding the overhead of ensuring you can run whatever database engine you choose on a client installed app is not optimal. Since the amount of data is small, I think XML would be adequate here. You could Base64 encode the images and store them as CDATA.</p>\n\n<p>Will the application be run on a server? If you have concurrent users, then databases have concepts for handling these scenarios (transactions), and that can be helpful. And the scanned image data would be appropriate for a BLOB.</p>\n'}, {'answer_id': 77016, 'author': 'japollock', 'author_id': 1210318, 'author_profile': 'https://Stackoverflow.com/users/1210318', 'pm_score': 0, 'selected': False, 'text': "<p>A database is meant to manage large volumes of data, and are supposed to give you fast access to read and write that data in spite of the size. Put simply, they manage scale for data - scale that you don't want to deal with. If you have only a few users (hundreds?), you could just as easily manage the data on disk (say XML?) and keep the data in memory. The images should clearly not go in to the database so the question is how much data, or for how many users are you maintaining this database instance?</p>\n"}, {'answer_id': 77019, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>If you want to have a structured way to store and retrieve information, a database is most definitely the way to go. It makes your application flexible and more powerful, and lets you focus on the actual application rather than incidentals like trying to write your own storage system. </p>\n\n<p>For individual applications, <a href="http://www.sqlite.org/" rel="nofollow noreferrer" title="SQLite">SQLite</a> is great. It fits right in an app as a file; no need for a whole DRBMS juggernaut. </p>\n'}, {'answer_id': 77031, 'author': 'Charles Graham', 'author_id': 7705, 'author_profile': 'https://Stackoverflow.com/users/7705', 'pm_score': 0, 'selected': False, 'text': "<p>There are a lot of factors to this. But, being a database weenie, I would err on the side of having a database. It just makes life easier when things changes. and things <em>will</em> change.</p>\n\n<p>Depending on the images, you might store them on the file system or actually blob them and put them in the database (Not supported in all DBMS's). If the files are very small, then I would blob them. If they are big, then I would keep them on he file system and manage them yourself.</p>\n\n<p>There are so many free or cheap DBMS's out there that there really is no excuse not to use one. I'm a SQL Server guy, but f your application is that simple, then the free version of mysql should do the job. In fact, it has some pretty cool stuff in there.</p>\n"}, {'answer_id': 77061, 'author': 'Seibar', 'author_id': 357, 'author_profile': 'https://Stackoverflow.com/users/357', 'pm_score': 1, 'selected': False, 'text': '<p>You shouldn\'t store images in the database, as is the general consensus <a href="https://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay">here</a>.</p>\n\n<p>The file system is just much better at storing images than your database is.</p>\n\n<p>You should use a database to store meta information about those images, such as a title, description, etc, and just store a URL or path to the images.</p>\n'}, {'answer_id': 77231, 'author': 'LizB', 'author_id': 13616, 'author_profile': 'https://Stackoverflow.com/users/13616', 'pm_score': 1, 'selected': False, 'text': '<p>When it comes to storing images in a database I try to avoid it. In your case from what I can gather of your question there is a possibilty for a subsantial number of fairly large images, so I would probably strong oppose it.</p>\n\n<p>If this is a web application I would use a database for quick searching and indexing of images using keywords and other parameters. Then have a column pointing to the location of the image in a filesystem if possible with some kind of folder structure to help further decrease the image load time.</p>\n\n<p>If you need greater security due to the directory being available (network share) and the application is local then you should probably bite the bullet and store the images in the database.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76934', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13790/']
|
76,939 |
<p>Is it possible to install the x86 Remote Debugger as a Service on a 64bit machine? I need to attach a debugger to managed code in a Session 0 process. The process runs 32bit but the debugger service that gets installed is 64bit and wont attach to the 32bit process. </p>
<p>I tried creating the Service using the SC command, and was able to get the service to start, and verified that it was running in Task manager processes. However, when I tried to connect to it with visual studio, it said that the remote debugger monitor wasn't enabled. When I stopped the x86 service, and started the x64 service and it was able to find the monitor, but still got an error.</p>
<p>Here is the error when I try to use the remote debugger:
Unable to attach to the process. The 64-bit version of the Visual Studio Remote Debugging Monitor (MSVSMON.EXE) cannot debug 32-bit processes or 32-bit dumps. Please use the 32-bit version instead.</p>
<p>Here is the error when I try to attach locally:
Attaching to a process in a different terminal server session is not supported on this computer. Try remote debugging to the machine and running the Microsoft Visual Studio Remote Debugging Monitor in the process's session.</p>
<p>If I try to run the 32bit remote debugger as an application, it wont work attach b/c the Remote Debugger is running in my session and not in session 0.</p>
|
[{'answer_id': 77920, 'author': 'Michael Burr', 'author_id': 12711, 'author_profile': 'https://Stackoverflow.com/users/12711', 'pm_score': 2, 'selected': False, 'text': '<p>I haven\'t tried this, but here\'s a suggestion anyway:</p>\n\n<p>Try installing the x86 remote debugger service manually.</p>\n\n<pre><code>sc create "Remote Debugger" binpath= "C:\\use\\short\\filename\\in\\the\\path\\x86\\msvsmon.exe /service msvsmon90"\n</code></pre>\n\n<p>Two notes:</p>\n\n<ul>\n<li>You\'ll need to use short filenames\nin the path to msvsmon.exe to\nprevent having to quote the path\n(since the whole command needs to be\nquoted)</li>\n<li>there must be a space after the\n"binpath=" (and no space before the\n\'=\' character). Whoever wrote the\ncommand line parser for the sc\ncommand should be cursed.</li>\n</ul>\n\n<p>Then you can use the services.msc control panel applet to get it running with the right credentials.</p>\n\n<p>You\'ll probably have to stop or maybe even delete the existing x64 remote debugger service.</p>\n'}, {'answer_id': 445514, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': True, 'text': '<p>This works on my machine(TM) after installing rdbgsetup_x64.exe and going through the configuration wizard:</p>\n\n<pre><code>sc stop msvsmon90\nsc config msvsmon90 binPath= "C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\Remote Debugger\\x86\\msvsmon.exe /service msvsmon90"\nsc start msvsmon90\n</code></pre>\n'}, {'answer_id': 445540, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I can confirm that what you want to do will indeed work. I often connect my 32 bit xp worstation to a x64 win2003 server with VS2008 remote debugger.</p>\n'}, {'answer_id': 1866531, 'author': 'Andras Zoltan', 'author_id': 157701, 'author_profile': 'https://Stackoverflow.com/users/157701', 'pm_score': 3, 'selected': False, 'text': '<p>We had the same problem when trying to remote debug a website that is running as 32 bit inside 64 bit IIS.</p>\n\n<p>You can also do this:</p>\n\n<ul>\n<li>Stop the default debugging service\n(which will be x64 as the installer\nwill have been clever and configured\nthat one to run).</li>\n<li>Navigate to the Remote Debugger start\nmenu folder and run the x86 debugging\nservice. Ignore the warning about<br>\n32bit/64bit.</li>\n<li>Open the Tools->Options window of the\nremote debugger app window and make<br>\nnote of the value in the \'Server<br>\nName\' text box.</li>\n<li>Now you can attach your visual studio\nto it by copying the \'Server Name\'<br>\nvalue into the \'Qualifier\' text/combo\nbox on the Attach To Process dialog<br>\nof Visual Studio.</li>\n</ul>\n\n<p>On a related note, there is also a low-level bug with Kerberos authentication if you are attaching from Windows 2008/7/Vista to a 2003 machine, reported to MS (and then closed as \'external\') via Connect here: <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=508455" rel="nofollow noreferrer">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=508455</a></p>\n'}, {'answer_id': 26037339, 'author': 'GreatDane', 'author_id': 1796802, 'author_profile': 'https://Stackoverflow.com/users/1796802', 'pm_score': 0, 'selected': False, 'text': '<p>Worked for me without installing additional software. I just copied the <code>C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\Remote Debugger</code> folder on the VM and started the <code>msvsmon.exe</code> from the <code>x86</code> folder. Both my guest and host are <code>x64</code>.</p>\n'}, {'answer_id': 43326533, 'author': 'Mike Grimm', 'author_id': 1913997, 'author_profile': 'https://Stackoverflow.com/users/1913997', 'pm_score': 1, 'selected': False, 'text': '<p>1) Install the x64 version. This also installs the x86 debugger but does not create a shortcut.</p>\n\n<p>2) You can find the executable for x86 process debugging here... C:\\Program Files\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Remote Debugger\\x86\\msvsmon.exe</p>\n\n<p>3) If you want to, pin it to the task bar.</p>\n'}, {'answer_id': 48541210, 'author': 'SeyedPooya Soofbaf', 'author_id': 866761, 'author_profile': 'https://Stackoverflow.com/users/866761', 'pm_score': 0, 'selected': False, 'text': '<p>Sometimes this error occurred, I just close visual studio and open it again, everything is OK!</p>\n\n<p>Very strange behavior from vs</p>\n'}, {'answer_id': 59494652, 'author': 'Mukus', 'author_id': 1497565, 'author_profile': 'https://Stackoverflow.com/users/1497565', 'pm_score': 0, 'selected': False, 'text': '<p>I ran into this issue today (64 bit OS and VS 2019). I changed Configuration to use x64 for the project, IISExpress to use 64 bit and Platform target to be x64. It still used the 32 bit debugger and complained. Finally, when I enabled Script Debugging it started using the 64 bit debugger. So I would say the combination of all did the trick.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76939', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3291/']
|
76,945 |
<p>What's the best library to use to generate RSS for a webserver written in Common Lisp?</p>
|
[{'answer_id': 77184, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.cliki.net/xml-emitter" rel="nofollow noreferrer">xml-emitter</a> says it has an RSS 2.0 emitter built in.</p>\n'}, {'answer_id': 78878, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>CL-WHO can generate XML pretty easily.</p>\n'}, {'answer_id': 81145, 'author': 'HD.', 'author_id': 6525, 'author_profile': 'https://Stackoverflow.com/users/6525', 'pm_score': 1, 'selected': False, 'text': '<p>I am not aware of any specific RSS library. But the format is fairly simple so any library that can write xml will do at that level.</p>\n\n<p>You could have e.g. a look at the nuclblog (<a href="http://cyrusharmon.org/projects?project=nuclblog" rel="nofollow noreferrer">http://cyrusharmon.org/projects?project=nuclblog</a>) project as that has the capability to generate an RSS feed for the blog entries it maintains.</p>\n'}, {'answer_id': 92025, 'author': 'Matthias Benkard', 'author_id': 15517, 'author_profile': 'https://Stackoverflow.com/users/15517', 'pm_score': 3, 'selected': True, 'text': '<p>Most anything will probably do. Personally, I\'ve been using xml-emitter for my blog\'s Atom feed, which has worked out well so far.</p>\n\n<p>Just choose whichever XML generation library you like and hack away, I\'d say. As others have remarked, RSS is simple; it\'s little work to generate it manually.</p>\n\n<p>That said, I recommend not generating plain strings directly. Having to deal with quoting data is more of a hassle than installing an XML library, and it\'s also <a href="http://en.wikipedia.org/wiki/Cross-site_scripting" rel="nofollow noreferrer" title="Cross-site scripting">insecure</a> in case your feed contains data submitted by visitors of your website.</p>\n'}, {'answer_id': 11061966, 'author': 'Luka Ramishvili', 'author_id': 324220, 'author_profile': 'https://Stackoverflow.com/users/324220', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.cliki.net/cl-rss-gen" rel="nofollow">cl-rss-gen</a> is a tiny library (LGPL, depends on CL-WHO) that does some boilerplate work for you (supports generating RSS entries directly from CLOS class instances by specifying which slot maps to which attribute). </p>\n\n<p>Take a look at the code before using it, it may give you the idea how it\'s working and whether you need it or not (as other posters said, you can generate RSS yourself with CL-WHO or any XML generation library).</p>\n\n<p>Oh, and sorry for resurrecting a four years old thread, but if anyone searches for similar library, he/she will find the answer here.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76945', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10019/']
|
76,963 |
<p>I am a MFC programmer who is new to C# and am looking for a simple control that will allow number entry and range validation.</p>
|
[{'answer_id': 77008, 'author': 'Adam Hawkes', 'author_id': 6703, 'author_profile': 'https://Stackoverflow.com/users/6703', 'pm_score': 4, 'selected': True, 'text': '<p>Look at the "NumericUpDown" control. It has range validation, the input will always be numeric, and it has those nifty increment/decrement buttons.</p>\n'}, {'answer_id': 77011, 'author': 'paulwhit', 'author_id': 7301, 'author_profile': 'https://Stackoverflow.com/users/7301', 'pm_score': 0, 'selected': False, 'text': '<p>You can use a regular textbox and a Validator control to control input.</p>\n'}, {'answer_id': 77116, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>Try using an error provider control to validate the textbox. You can use int.TryParse() or double.TryParse() to check if it's numeric and then validate the range.</p>\n"}, {'answer_id': 77219, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 0, 'selected': False, 'text': '<p>You can use a combination of the RequiredFieldValidator and CompareValidator (Set to DataTypeCheck for the operator and Type set to Integer)</p>\n\n<p>That will get it with a normal textbox if you would like, otherwise the recommendation above is good.</p>\n'}, {'answer_id': 77853, 'author': 'Ricardo Amores', 'author_id': 10136, 'author_profile': 'https://Stackoverflow.com/users/10136', 'pm_score': 1, 'selected': False, 'text': '<p>I had to implement a Control which only accepted numbers, integers or reals.\nI build the control as a specialization of (read: derived from) TextBox control, and using input control and a regular expresión for the validation. \nAdding range validation is terribly easy.</p>\n\n<p>This is the code for building the regex. _numericSeparation is a string with characters accepted as decimal comma values\n(for example, a \'.\' or a \',\': $10.50 10,50€</p>\n\n<pre><code>private string ComputeRegexPattern()\n{\n StringBuilder builder = new StringBuilder();\n if (this._forcePositives)\n {\n builder.Append("([+]|[-])?");\n }\n builder.Append(@"[\\d]*((");\n if (!this._useIntegers)\n {\n for (int i = 0; i < this._numericSeparator.Length; i++)\n {\n builder.Append("[").Append(this._numericSeparator[i]).Append("]");\n if ((this._numericSeparator.Length > 0) && (i != (this._numericSeparator.Length - 1)))\n {\n builder.Append("|");\n }\n }\n }\n builder.Append(@")[\\d]*)?");\n return builder.ToString();\n}\n</code></pre>\n\n<p>The regular expression matches any number (i.e. any string with numeric characters) with only one character as a numeric separation, and a \'+\' or a \'-\' optional character at the beginning of the string.\nOnce you create the regex (when instanciating the Control), you check if the value is correct overriding the OnValidating method. \nCheckValidNumber() just applies the Regex to the introduced text. If the regex match fails, activates an error provider with an specified error (set with ValidationError public property) and raises a ValidationError event.\nHere you could do the verification to know if the number is in the requiered range.</p>\n\n<pre><code>private bool CheckValidNumber()\n{\n if (Regex.Match(this.Text, this.RegexPattern).Value != this.Text)\n {\n this._errorProvider.SetError(this, this.ValidationError);\n return false;\n }\n this._errorProvider.Clear();\n return true;\n}\n\nprotected override void OnValidating(CancelEventArgs e)\n{\n bool flag = this.CheckValidNumber();\n if (!flag)\n {\n e.Cancel = true;\n this.Text = "0";\n }\n base.OnValidating(e);\n if (!flag)\n {\n this.ValidationFail(this, EventArgs.Empty);\n }\n}\n</code></pre>\n\n<p>As I said, i also prevent the user from input data in the text box other than numeric characteres overriding the OnKeyPress methdod:</p>\n\n<pre><code>protected override void OnKeyPress(KeyPressEventArgs e)\n{\n if ((!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) && (!this._numberSymbols.Contains(e.KeyChar.ToString()) && !this._numericSeparator.Contains(e.KeyChar.ToString())))\n {\n e.Handled = true;\n }\n if (this._numberSymbols.Contains(e.KeyChar.ToString()) && !this._forcePositives)\n {\n e.Handled = true;\n }\n if (this._numericSeparator.Contains(e.KeyChar.ToString()) && this._useIntegers)\n {\n e.Handled = true;\n }\n base.OnKeyPress(e);\n}\n</code></pre>\n\n<p>The elegant touch: I check if the number valid every time the user releases a key, so the user can get feedback as he/she types. (But remember that you must be carefull with the ValidationFail event ;))</p>\n\n<pre><code>protected override void OnKeyUp(KeyEventArgs e)\n{\n this.CheckValidNumber();\n base.OnKeyUp(e);\n}\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76963', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,967 |
<p>I know that that is not a question... erm anyway HERE is the question.</p>
<p>I have inherited a database that has 1(one) table in that looks much like this. Its aim is to record what species are found in the various (200 odd) countries.</p>
<pre><code>ID
Species
Afghanistan
Albania
Algeria
American Samoa
Andorra
Angola
....
Western Sahara
Yemen
Zambia
Zimbabwe
</code></pre>
<p>A sample of the data would be something like this</p>
<pre><code>id Species Afghanistan Albania American Samoa
1 SP1 null null null
2 SP2 1 1 null
3 SP3 null null 1
</code></pre>
<p>It seems to me this is a typical many to many situation and I want 3 tables.
Species, Country, and SpeciesFoundInCountry</p>
<p>The link table (SpeciesFoundInCountry) would have foreign keys in both the species and Country tables.</p>
<p>(It is hard to draw the diagram!)</p>
<pre><code>Species
SpeciesID SpeciesName
Country
CountryID CountryName
SpeciesFoundInCountry
CountryID SpeciesID
</code></pre>
<p>Is there a magic way I can generate an insert statement that will get the CountryID from the new Country table based on the column name and the SpeciesID where there is a 1 in the original mega table?</p>
<p>I can do it for one Country (this is a select to show what I want out)</p>
<pre><code>SELECT Species.ID, Country.CountryID
FROM Country, Species
WHERE (((Species.Afghanistan)=1)) AND (((Country.Country)="Afghanistan"));
</code></pre>
<p>(the mega table is called species)</p>
<p>But using this strategy I would need to do the query for each column in the original table. </p>
<p>Is there a way of doing this in sql?</p>
<p>I guess I can OR a load of my where clauses together and write a script to make the sql, seems inelegant though!</p>
<p>Any thoughts (or clarification required)?</p>
|
[{'answer_id': 76999, 'author': 'Sarien', 'author_id': 1994377, 'author_profile': 'https://Stackoverflow.com/users/1994377', 'pm_score': 3, 'selected': False, 'text': '<p>Why do you want to do it in SQL? Just write a little script that does the conversion.</p>\n'}, {'answer_id': 77017, 'author': 'nsayer', 'author_id': 13757, 'author_profile': 'https://Stackoverflow.com/users/13757', 'pm_score': 1, 'selected': False, 'text': "<p>You're probably going to want to create replacement tables in place. The script sort of depends on the scripting language you have available to you, but you should be able to create the country ID table simply by listing the columns of the table you have now. Once you've done that, you can do some string substitutions to go through all of the unique country names and insert into the speciesFoundInCountry table where the given country column is not null.</p>\n"}, {'answer_id': 77028, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 4, 'selected': True, 'text': "<p>I would use a script to generate all the individual queries, since this is a one-off import process.</p>\n\n<p>Some programs such as Excel are good at mixing different dimensions of data (comparing column names to data inside rows) but relational databases rarely are.</p>\n\n<p>However, you might find that some systems (such as Microsoft Access, surprisingly) have convenient tools which you can use to normalise the data. Personally I'd find it quicker to write the script but your relative skills with Access and scripting might be different to mine.</p>\n"}, {'answer_id': 77038, 'author': 'StubbornMule', 'author_id': 13341, 'author_profile': 'https://Stackoverflow.com/users/13341', 'pm_score': 2, 'selected': False, 'text': '<p>When I run into these I write a script to do the conversion rather than trying to do it in SQL. It is typically much faster and easier for me. Pick any language you are comfortable with.</p>\n'}, {'answer_id': 77039, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 1, 'selected': False, 'text': "<p>You could probably get clever and query the system tables for the column names, and then build a dynamic query string to execute, but honestly that will probably be uglier than a quick script to generate the SQL statements for you.</p>\n\n<p>Hopefully you don't have too much dynamic SQL code that accesses the old tables buried in your codebase. That could be the <em>really</em> hard part.</p>\n"}, {'answer_id': 77054, 'author': 'Tom Ritter', 'author_id': 8435, 'author_profile': 'https://Stackoverflow.com/users/8435', 'pm_score': 1, 'selected': False, 'text': '<p>In SQL Server this will generate your custom select you demonstrate. You can extrapolate to an insert</p>\n\n<blockquote>\n<pre><code>select \n \'SELECT Species.ID, Country.CountryID FROM Country, Species WHERE (((Species.\' + \n c.name + \n \')=1)) AND (((Country.Country)="\' +\n c.name + \n \'"))\'\nfrom syscolumns c\ninner join sysobjects o\non o.id = c.id\nwhere o.name = \'old_table_name\'\n</code></pre>\n</blockquote>\n'}, {'answer_id': 77068, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 1, 'selected': False, 'text': "<p>As with the others I would most likely just do it as a one time quick fix in whatever manner works for you.</p>\n\n<p>With these types of conversions, they are one off items, quick fixes, and the code doesn't have to be elegant, it just has to work. For these types of things I have done it many ways.</p>\n"}, {'answer_id': 77070, 'author': 'eulerfx', 'author_id': 13855, 'author_profile': 'https://Stackoverflow.com/users/13855', 'pm_score': 1, 'selected': False, 'text': '<p>If this is SQL Server, you can use the sys.columns table to find all of the columns of the original table. Then you can use dynamic SQL and the pivot command to do what you want. Look those up online for syntax.</p>\n'}, {'answer_id': 77149, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>I would definitely agree with your suggestion of writing a small script to produce your SQL with a query for every column.</p>\n\n<p>In fact your script could have already been finished in the time you've spent thinking about this magical query (that you would use only one time and then throw away, so what's the use in making it all magicy and perfect)</p>\n"}, {'answer_id': 77283, 'author': 'digiguru', 'author_id': 5055, 'author_profile': 'https://Stackoverflow.com/users/5055', 'pm_score': 2, 'selected': False, 'text': '<p>If this was SQL Server, you\'d use the Unpivot commands, but looking at the tag you assigned it\'s for access - am I right?</p>\n\n<p>Although there is a <a href="http://www.blueclaw-db.com/accessquerysql/pivot_query.htm" rel="nofollow noreferrer">pivoting command in access</a>, there is no reverse statement.</p>\n\n<p>Looks like it can be done with a complex join. Check this <a href="http://weblogs.sqlteam.com/jeffs/archive/2008/04/23/unpivot.aspx" rel="nofollow noreferrer">interesting article</a> for a lowdown on how to unpivot in a select command.</p>\n'}, {'answer_id': 77610, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>I would make it a three step process with a slight temporary modification to your SpeciesFoundInCountry table. I would add a column to that table to store the Country name. Then the steps would be as follows.</p>\n\n<p>1) Create/Run a script that walks columns in the source table and creates a record in SpeciesFoundInCountry for each column that has a true value. This record would contain the country name.\n2) Run a SQL statement that updates the SpeciesFoundInCountry.CountryID field by joining to the Country table on Country Name.\n3) Cleanup the SpeciesFoundInCountry table by removing the CountryName column.</p>\n\n<p>Here is a little MS Access VB/VBA pseudo code to give you the gist</p>\n\n<pre><code>Public Sub CreateRelationshipRecords()\n\n Dim rstSource as DAO.Recordset\n Dim rstDestination as DAO.Recordset\n Dim fld as DAO.Field\n dim strSQL as String\n Dim lngSpeciesID as Long\n\n strSQL = "SELECT * FROM [ORIGINALTABLE]"\n Set rstSource = CurrentDB.OpenRecordset(strSQL)\n set rstDestination = CurrentDB.OpenRecordset("SpeciesFoundInCountry")\n\n rstSource.MoveFirst\n\n \' Step through each record in the original table\n Do Until rstSource.EOF\n lngSpeciesID = rstSource.ID\n \' Now step through the fields(columns). If the field\n \' value is one (1), then create a relationship record\n \' using the field name as the Country Name\n For Each fld in rstSource.Fields\n If fld.Value = 1 then\n with rstDestination\n .AddNew\n .Fields("CountryID").Value = Null\n .Fields("CountryName").Value = fld.Name\n .Fields("SpeciesID").Value = lngSpeciesID\n .Update\n End With\n End IF\n Next fld \n rstSource.MoveNext\n Loop\n\n \' Clean up\n rstSource.Close\n Set rstSource = nothing\n ....\n\nEnd Sub\n</code></pre>\n\n<p>After this you could run a simple SQL statement to update the CountryID values in the SpeciesFoundInCountry table.</p>\n\n<p>UPDATE SpeciesFoundInCountry INNER JOIN Country ON SpeciesFoundInCountry.CountryName = Country.CountryName SET SpeciesFoundInCountry.CountryID = Country.CountryID;</p>\n\n<p>Finally, all you have to do is cleanup the SpeciesFoundInCountry table by removing the CountryName column.</p>\n\n<p>****SIDE NOTE: I have found it usefull to have country tables that also include the ISO abbreviations (country codes). Occassionally they are used as Foreign Keys in other tables so that a join to the Country table does not have to be included in queries.</p>\n\n<p>For more info: <a href="http://en.wikipedia.org/wiki/Iso_country_codes" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Iso_country_codes</a></p>\n'}, {'answer_id': 77633, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Sorry, but the bloody posting parser removed the whitespace and formatting on my post. It makes it a log harder to read.</p>\n'}, {'answer_id': 78130, 'author': 'CindyH', 'author_id': 12897, 'author_profile': 'https://Stackoverflow.com/users/12897', 'pm_score': 1, 'selected': False, 'text': '<p>@stomp:</p>\n\n<p>Above the box where you type the answer, there are several buttons. The one that is 101010 is a code sample. You select all your text that is code, and then click that button. Then it doesn\'t get messed with much.</p>\n\n<pre><code>cout>>"I don\'t know C"\ncout>>"Hello World"\n</code></pre>\n'}, {'answer_id': 78249, 'author': 'Fionnuala', 'author_id': 2548, 'author_profile': 'https://Stackoverflow.com/users/2548', 'pm_score': 1, 'selected': False, 'text': '<p>I would use a Union query, very roughly:</p>\n\n<pre><code>Dim db As Database\nDim tdf As TableDef\n\nSet db = CurrentDb\n\nSet tdf = db.TableDefs("SO")\n\nstrSQL = "SELECT ID, Species, """ & tdf.Fields(2).Name _\n & """ AS Country, [" & tdf.Fields(2).Name & "] AS CountryValue FROM SO "\n\nFor i = 3 To tdf.Fields.Count - 1\n strSQL = strSQL & vbCrLf & "UNION SELECT ID, Species, """ & tdf.Fields(i).Name _\n & """ AS Country, [" & tdf.Fields(i).Name & "] AS CountryValue FROM SO "\nNext\n\ndb.CreateQueryDef "UnionSO", strSQL\n</code></pre>\n\n<p>You would then have a view that could be appended to your new design.</p>\n'}, {'answer_id': 78348, 'author': 'Gaurav', 'author_id': 13492, 'author_profile': 'https://Stackoverflow.com/users/13492', 'pm_score': 1, 'selected': False, 'text': "<p>When I read the title 'bad BAD database design', I was curious to find out how bad it is. You didn't disappoint me :)</p>\n\n<p>As others mentioned, a script would be the easiest way. This can be accomplished by writing about 15 lines of code in PHP.</p>\n\n<pre><code>SELECT * FROM ugly_table;\nwhile(row)\nforeach(row as field => value)\nif(value == 1)\nSELECT country_id from country_table WHERE country_name = field;\n\nif(field == 'Species')\nSELECT species_id from species_table WHERE species_name = value;\n\nINSERT INTO better_table (...)\n</code></pre>\n\n<p>Obviously this is pseudo code and will not work as it is. You can also populate the countries and species table on the fly by adding insert statements here.</p>\n"}, {'answer_id': 78464, 'author': 'user14336', 'author_id': 14336, 'author_profile': 'https://Stackoverflow.com/users/14336', 'pm_score': 1, 'selected': False, 'text': "<p>Sorry, I've done very little Access programming but I can offer some guidance which should help.</p>\n\n<p>First lets walk through the problem.\nIt is assumed that you will typically need to generate multiple rows in SpeciesFoundInCountry for every row in the original table. In other words species tend to be in more then one country. This is actually easy to do with a Cartesian product, a join with no join criteria. </p>\n\n<p>To do a Cartesian product you will need to create the Country table. The table should have the country_id from 1 to N (N being the number of unique countries, 200 or so) and country name. To make life easy just use the numbers 1 to N in column order. That would make Afghanistan 1 and Albania 2 ... Zimbabwe N. You should be able to use the system tables to do this.</p>\n\n<p>Next create a table or view from the original table which contains the species and a sting with a 0 or 1 for each country. You will need to convert the null, not null to a text 0 or 1 and concatenate all of the values into a single string. A description of the table and a text editor with regular expressions should make this easy. Experiment first with a single column and once that's working edit the create view/insert with all of the columns.</p>\n\n<p>Next join the two tables together with no join criteria. This will give you a record for every species in every country, you're almost there.</p>\n\n<p>Now all you have to do is filter out the records which are not valid, they will have a zero in the corresponding location in the string. Since the country table's country_code column has the substring location all you need to do is filter out the records where it's 0.</p>\n\n<pre><code>where substring(new_column,country_code) = '1'\n</code></pre>\n\n<p>You will still need to create the species table and join to that </p>\n\n<pre><code>where a.species_name = b.species_name\n</code></pre>\n\n<p>a and b are table aliases.</p>\n\n<p>Hope this help</p>\n"}, {'answer_id': 78505, 'author': 'user14336', 'author_id': 14336, 'author_profile': 'https://Stackoverflow.com/users/14336', 'pm_score': 1, 'selected': False, 'text': '<p>OBTW,</p>\n\n<p>If you have queries that already run against the old table you will need to create a view which replicates the old tables using the new tables. You will need to do a group by to denormalize the tables. </p>\n\n<p>Tell your users that the old table/view will not be supported in the future and all new queries or updates to older queries will have to use the new tables.</p>\n'}, {'answer_id': 119036, 'author': 'Glenn M', 'author_id': 61669, 'author_profile': 'https://Stackoverflow.com/users/61669', 'pm_score': 1, 'selected': False, 'text': '<p>If I ever have to create a truckload of similar SQL statements and execute all of them, I often find Excel is very handy. Take your original query. If you have a country list in column A and your SQL statement in column B, formated as text (in quotes) with cell references inserted where the country appears in the sql</p>\n\n<p>e.g. ="INSERT INTO new_table SELECT ... (species." & A1 & ")= ... ));"</p>\n\n<p>then just copy the formula down to create 200 different SQL statements, copy/paste the column to your editor and hit F5. You can of course do this with as many variables as you want.</p>\n'}, {'answer_id': 197683, 'author': 'AJ.', 'author_id': 7211, 'author_profile': 'https://Stackoverflow.com/users/7211', 'pm_score': 1, 'selected': False, 'text': '<p>This is (hopefully) a one-off exercise, so an inelegant solution might not be as bad as it sounds. </p>\n\n<p>The problem (as, I\'m sure you\'re only too aware!) is that at some point in your query you\'ve got to list all those columns. :( The question is, what is the most elegant way to do this? Below is my attempt. It looks unwieldy because there are so many columns, but it might be what you\'re after, or at least it might point you in the right direction. </p>\n\n<h2>Possible SQL Solution:</h2>\n\n<pre><code>/* if you have N countries */\nCREATE TABLE Country\n(id int, \n name varchar(50)) \n\nINSERT Country\n SELECT 1, \'Afghanistan\'\nUNION SELECT 2, \'Albania\', \nUNION SELECT 3, \'Algeria\' ,\nUNION SELECT 4, \'American Samoa\' ,\nUNION SELECT 5, \'Andorra\' ,\nUNION SELECT 6, \'Angola\' ,\n...\nUNION SELECT N-3, \'Western Sahara\', \nUNION SELECT N-2, \'Yemen\', \nUNION SELECT N-1, \'Zambia\', \nUNION SELECT N, \'Zimbabwe\', \n\n\n\nCREATE TABLE #tmp\n(key varchar(N), \n country_id int) \n/* "key" field needs to be as long as N */ \n\n\nINSERT #tmp \nSELECT \'1________ ... _\', \'Afghanistan\' \n/* \'1\' followed by underscores to make the length = N */\n\nUNION SELECT \'_1_______ ... ___\', \'Albania\'\nUNION SELECT \'__1______ ... ___\', \'Algeria\'\n...\nUNION SELECT \'________ ... _1_\', \'Zambia\'\nUNION SELECT \'________ ... __1\', \'Zimbabwe\'\n\nCREATE TABLE new_table\n(country_id int, \nspecies_id int) \n\nINSERT new_table\nSELECT species.id, country_id\nFROM species s , \n #tmp t\nWHERE isnull( s.Afghanistan, \' \' ) + \n isnull( s.Albania, \' \' ) + \n ... + \n isnull( s.Zambia, \' \' ) + \n isnull( s.Zimbabwe, \' \' ) like t.key \n</code></pre>\n\n<h2>My Suggestion</h2>\n\n<p>Personally, I would not do this. I would do a quick and dirty solution like the one to which you allude, except that I would hard-code the country ids (because you\'re only going to do this once, right? And you can do it right after you create the country table, so you know what all the IDs are): </p>\n\n<pre><code>INSERT new_table SELECT Species.ID, 1 FROM Species WHERE Species.Afghanistan = 1 \nINSERT new_table SELECT Species.ID, 2 FROM Species WHERE Species.Albania= 1 \n...\nINSERT new_table SELECT Species.ID, 999 FROM Species WHERE Species.Zambia= 1 \nINSERT new_table SELECT Species.ID, 1000 FROM Species WHERE Species.Zimbabwe= 1 \n</code></pre>\n'}, {'answer_id': 225462, 'author': 'Walter Mitty', 'author_id': 19937, 'author_profile': 'https://Stackoverflow.com/users/19937', 'pm_score': 1, 'selected': False, 'text': '<p>When I\'ve been faced with similar problems, I\'ve found it convenient to generate a script that generates SQL scripts. Here\'s the sample you gave, abstracted to use %PAR1% in place of Afghanistan.</p>\n\n<pre><code>SELECT Species.ID, Country.CountryID\nFROM Country, Species\nWHERE (((Species.%PAR1%)=1)) AND (((Country.Country)="%PAR1%"))\nUNION\n</code></pre>\n\n<p>Also the key word union has been added as a way to combine all the selects.</p>\n\n<p>Next, you need a list of countries, generated from your existing data:</p>\n\n<p>Afghanistan\nAlbania\n.\n,\n.</p>\n\n<p>Next you need a script that can iterate through the country list, and for each iteration,\nproduce an output that substitutes Afghanistan for %PAR1% on the first iteration, Albania for the second iteration and so on. The algorithm is just like mail-merge in a word processor. It\'s a little work to write this script. But, once you have it, you can use it in dozens of one-off projects like this one.</p>\n\n<p>Finally, you need to manually change the last "UNION" back to a semicolon. </p>\n\n<p>If you can get Access to perform this giant union, you can get the data you want in the form you want, and insert it into your new table.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76967', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5552/']
|
76,976 |
<p>Is it possible to get the progress of an XMLHttpRequest (bytes uploaded, bytes downloaded)? </p>
<p>This would be useful to show a progress bar when the user is uploading a large file. The standard API doesn't seem to support it, but maybe there's some non-standard extension in any of the browsers out there? It seems like a pretty obvious feature to have after all, since the client knows how many bytes were uploaded/downloaded.</p>
<p>note: I'm aware of the "poll the server for progress" alternative (it's what I'm doing right now). the main problem with this (other than the complicated server-side code) is that typically, while uploading a big file, the user's connection is completely hosed, because most ISPs offer poor upstream. So making extra requests is not as responsive as I'd hoped. I was hoping there'd be a way (maybe non-standard) to get this information, which the browser has at all times.</p>
|
[{'answer_id': 77075, 'author': 'Sean McMains', 'author_id': 2041950, 'author_profile': 'https://Stackoverflow.com/users/2041950', 'pm_score': 3, 'selected': False, 'text': '<p>One of the most promising approaches seems to be opening a second communication channel back to the server to ask it how much of the transfer has been completed.</p>\n'}, {'answer_id': 77098, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 1, 'selected': False, 'text': '<p>If you have access to your apache install and trust third-party code, you can use the <a href="http://drogomir.com/blog/2008/6/18/upload-progress-bar-with-mod_passenger-and-apache" rel="nofollow noreferrer">apache upload progress module</a> (if you use apache; there\'s also a <a href="http://wiki.codemongers.com/NginxHttpUploadProgressModule" rel="nofollow noreferrer">nginx upload progress module</a>). </p>\n\n<p>Otherwise, you\'d have to write a script that you can hit out of band to request the status of the file (checking the filesize of the tmp file for instance). </p>\n\n<p>There\'s some work going on in firefox 3 I believe to add upload progress support to the browser, but that\'s not going to get into all the browsers and be widely adopted for a while (more\'s the pity).</p>\n'}, {'answer_id': 77163, 'author': 'Orclev', 'author_id': 13739, 'author_profile': 'https://Stackoverflow.com/users/13739', 'pm_score': 2, 'selected': False, 'text': "<p>For the total uploaded there doesn't seem to be a way to handle that, but there's something similar to what you want for download. Once readyState is 3, you can periodically query responseText to get all the content downloaded so far as a String (this doesn't work in IE), up until all of it is available at which point it will transition to readyState 4. The total bytes downloaded at any given time will be equal to the total bytes in the string stored in responseText.</p>\n\n<p>For a all or nothing approach to the upload question, since you have to pass a string for upload (and it's possible to determine the total bytes of that) the total bytes sent for readyState 0 and 1 will be 0, and the total for readyState 2 will be the total bytes in the string you passed in. The total bytes both sent and received in readyState 3 and 4 will be the sum of the bytes in the original string plus the total bytes in responseText.</p>\n"}, {'answer_id': 77284, 'author': 'Alexandre Victoor', 'author_id': 11897, 'author_profile': 'https://Stackoverflow.com/users/11897', 'pm_score': -1, 'selected': False, 'text': '<p>The only way to do that with pure javascript is to implement some kind of polling mechanism.\nYou will need to send ajax requests at fixed intervals (each 5 seconds for example) to get the number of bytes received by the server.</p>\n\n<p>A more efficient way would be to use flash. The flex component <a href="http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html" rel="nofollow noreferrer">FileReference</a> dispatchs periodically a \'progress\' event holding the number of bytes already uploaded. \nIf you need to stick with javascript, bridges are available between actionscript and javascript. \nThe good news is that this work has been already done for you :)</p>\n\n<p><a href="http://www.swfupload.org" rel="nofollow noreferrer"><strong>swfupload</strong></a></p>\n\n<p>This library allows to register a javascript handler on the flash progress event.</p>\n\n<p>This solution has the hudge advantage of not requiring aditionnal resources on the server side.</p>\n'}, {'answer_id': 3360576, 'author': 'Markus Peröbner', 'author_id': 404522, 'author_profile': 'https://Stackoverflow.com/users/404522', 'pm_score': 3, 'selected': False, 'text': '<p>Firefox supports <a href="https://developer.mozilla.org/en/using_xmlhttprequest#Monitoring_progress" rel="nofollow noreferrer">XHR download progress events</a>.</p>\n<p><strong>EDIT 2021-07-08 10:30 PDT</strong></p>\n<p>The above link is dead. Doing a search on the Mozilla WebDev site turned up the following link:</p>\n<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent</a></p>\n<p>It describes how to use the progress event with XMLHttpRequest and provides an example. I\'ve included the example below:</p>\n<pre><code>var progressBar = document.getElementById("p"),\n client = new XMLHttpRequest()\nclient.open("GET", "magical-unicorns")\nclient.onprogress = function(pe) {\n if(pe.lengthComputable) {\n progressBar.max = pe.total\n progressBar.value = pe.loaded\n }\n}\nclient.onloadend = function(pe) {\n progressBar.value = pe.loaded\n}\nclient.send()\n</code></pre>\n<p>I also found this link as well which is what I think the original link pointed to.</p>\n<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/progress_event" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/progress_event</a></p>\n'}, {'answer_id': 3694435, 'author': 'albanx', 'author_id': 354881, 'author_profile': 'https://Stackoverflow.com/users/354881', 'pm_score': 7, 'selected': False, 'text': '<p>For the bytes uploaded it is quite easy. Just monitor the <code>xhr.upload.onprogress</code> event. The browser knows the size of the files it has to upload and the size of the uploaded data, so it can provide the progress info.</p>\n\n<p>For the bytes downloaded (when getting the info with <code>xhr.responseText</code>), it is a little bit more difficult, because the browser doesn\'t know how many bytes will be sent in the server request. The only thing that the browser knows in this case is the size of the bytes it is receiving. </p>\n\n<p>There is a solution for this, it\'s sufficient to set a <code>Content-Length</code> header on the server script, in order to get the total size of the bytes the browser is going to receive. </p>\n\n<p>For more go to <a href="https://developer.mozilla.org/en/Using_XMLHttpRequest" rel="noreferrer">https://developer.mozilla.org/en/Using_XMLHttpRequest</a> .</p>\n\n<p>Example:\nMy server script reads a zip file (it takes 5 seconds):</p>\n\n<pre><code>$filesize=filesize(\'test.zip\');\n\nheader("Content-Length: " . $filesize); // set header length\n// if the headers is not set then the evt.loaded will be 0\nreadfile(\'test.zip\');\nexit 0;\n</code></pre>\n\n<p>Now I can monitor the download process of the server script, because I know it\'s total length:</p>\n\n<pre><code>function updateProgress(evt) \n{\n if (evt.lengthComputable) \n { // evt.loaded the bytes the browser received\n // evt.total the total bytes set by the header\n // jQuery UI progress bar to show the progress on screen\n var percentComplete = (evt.loaded / evt.total) * 100; \n $(\'#progressbar\').progressbar( "option", "value", percentComplete );\n } \n} \nfunction sendreq(evt) \n{ \n var req = new XMLHttpRequest(); \n $(\'#progressbar\').progressbar(); \n req.onprogress = updateProgress;\n req.open(\'GET\', \'test.php\', true); \n req.onreadystatechange = function (aEvt) { \n if (req.readyState == 4) \n { \n //run any callback here\n } \n }; \n req.send(); \n}\n</code></pre>\n'}, {'answer_id': 35080857, 'author': 'Forums Lover', 'author_id': 5283607, 'author_profile': 'https://Stackoverflow.com/users/5283607', 'pm_score': 2, 'selected': False, 'text': '<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>\r\n<html>\r\n<body>\r\n<p id="demo">result</p>\r\n<button type="button" onclick="get_post_ajax();">Change Content</button>\r\n<script type="text/javascript">\r\n function update_progress(e)\r\n {\r\n if (e.lengthComputable)\r\n {\r\n var percentage = Math.round((e.loaded/e.total)*100);\r\n console.log("percent " + percentage + \'%\' );\r\n }\r\n else \r\n {\r\n console.log("Unable to compute progress information since the total size is unknown");\r\n }\r\n }\r\n function transfer_complete(e){console.log("The transfer is complete.");}\r\n function transfer_failed(e){console.log("An error occurred while transferring the file.");}\r\n function transfer_canceled(e){console.log("The transfer has been canceled by the user.");}\r\n function get_post_ajax()\r\n {\r\n var xhttp;\r\n if (window.XMLHttpRequest){xhttp = new XMLHttpRequest();}//code for modern browsers} \r\n else{xhttp = new ActiveXObject("Microsoft.XMLHTTP");}// code for IE6, IE5 \r\n xhttp.onprogress = update_progress;\r\n xhttp.addEventListener("load", transfer_complete, false);\r\n xhttp.addEventListener("error", transfer_failed, false);\r\n xhttp.addEventListener("abort", transfer_canceled, false); \r\n xhttp.onreadystatechange = function()\r\n {\r\n if (xhttp.readyState == 4 && xhttp.status == 200)\r\n {\r\n document.getElementById("demo").innerHTML = xhttp.responseText;\r\n }\r\n };\r\n xhttp.open("GET", "http://it-tu.com/ajax_test.php", true);\r\n xhttp.send();\r\n }\r\n</script>\r\n</body>\r\n</html></code></pre>\r\n</div>\r\n</div>\r\n</p>\n\n<p><a href="https://i.stack.imgur.com/K0f91.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K0f91.jpg" alt="Result"></a></p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76976', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,983 |
<p>At my house I have about 10 computers all different processors and speeds (all x86 compatible). I would like to cluster these. I have looked at openMosix but since they stopped development on it I am deciding against using it. I would prefer to use the latest or next to latest version of a mainstream distribution of Linux (Suse 11, Suse 10.3, Fedora 9 etc). </p>
<p>Does anyone know any good sites (or books) that explain how to get a cluster up and running using free open source applications that are common on most mainstream distributions?</p>
<p>I would like a load balancing cluster for custom software I would be writing. I can not use something like Folding@home because I need constant contact with every part of the application. For example if I was running a simulation and one computer was controlling where rain was falling, and another controlling what my herbivores are doing in the simulation.</p>
|
[{'answer_id': 77063, 'author': 'Jonathan Mueller', 'author_id': 13832, 'author_profile': 'https://Stackoverflow.com/users/13832', 'pm_score': 3, 'selected': True, 'text': '<p>I recently set up an OpenMPI cluster using Ubuntu. Some existing write up is at <a href="https://wiki.ubuntu.com/MpichCluster" rel="nofollow noreferrer">https://wiki.ubuntu.com/MpichCluster</a> .</p>\n'}, {'answer_id': 77103, 'author': 'MarkR', 'author_id': 13724, 'author_profile': 'https://Stackoverflow.com/users/13724', 'pm_score': 1, 'selected': False, 'text': '<p>You only need a cluster if you know what you want to do. Come back with an actual requirement, and someone will suggest a solution.</p>\n'}, {'answer_id': 77118, 'author': 'Flimzy', 'author_id': 13860, 'author_profile': 'https://Stackoverflow.com/users/13860', 'pm_score': 2, 'selected': False, 'text': '<p>Your question is too vague. What cluster application do you want to use?</p>\n\n<p>By far the easiest way to set up a "cluster" is to install Folding@Home on each of your machines. But I doubt that\'s really what you\'re asking for.</p>\n\n<p>I have set up clusters for music/video transcoding using simple bash scripts and ssh shared keys before.</p>\n\n<p>I manage mail server clusters at work.</p>\n'}, {'answer_id': 77849, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I think he's looking for something similar with openMosix, some kind of a general cluster on top of which any application can run distributed among the nodes. AFAIK there's nothing like that available. MPI based clusters are the closest thing you can get, but I think you can only run MPI applications on them.</p>\n"}, {'answer_id': 225320, 'author': 'Daniel Silveira', 'author_id': 1100, 'author_profile': 'https://Stackoverflow.com/users/1100', 'pm_score': 0, 'selected': False, 'text': '<p>Linux Virtual Server</p>\n\n<p><a href="http://www.linuxvirtualserver.org/" rel="nofollow noreferrer">http://www.linuxvirtualserver.org/</a></p>\n'}, {'answer_id': 234927, 'author': 'HeMan', 'author_id': 5145, 'author_profile': 'https://Stackoverflow.com/users/5145', 'pm_score': 1, 'selected': False, 'text': '<p>Take a look at <a href="http://www.rocksclusters.org" rel="nofollow noreferrer">Rocks</a>. It\'s a fullblown cluster "distribution" based on CentOS 5.1. It installs all you need (libs, applications and tools) to run a cluster and is dead simple to install and use. You do all the tweaking and configuration on the master node and it helps you with kickstarting all your other nodes. I\'ve recently been installing a 1200+ nodes (over 10.000 cores!) cluster with it! And would not hesitate to install it on a 4 node cluster since the workload to install the master is none!</p>\n\n<p>You could either run applications written for cluster libs such as MPI or PVM or you could use the queue system (Sun Grid Engine) to distribute any type of jobs. Or distcc to compile code of choice on all nodes!</p>\n\n<p>And it\'s open source, gpl, free, everything that you like! </p>\n'}, {'answer_id': 234952, 'author': 'stephanea', 'author_id': 8776, 'author_profile': 'https://Stackoverflow.com/users/8776', 'pm_score': 0, 'selected': False, 'text': '<p>I use pvm and it works. But even with a nice ssh setup, allowing for login without entering passwd to the machine, you can easily remotely launch commands on your different computing nodes.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76983', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
76,988 |
<p>I have seen another program provide traceroute functionality within it but without needing root (superuser) privileges? I've always assumed that raw sockets need to be root, but is there some other way? (I think somebody mentioned "supertrace" or "tracepath"?) Thanks!</p>
|
[{'answer_id': 77029, 'author': 'moonshadow', 'author_id': 11834, 'author_profile': 'https://Stackoverflow.com/users/11834', 'pm_score': 2, 'selected': False, 'text': '<p>Ping the target, gradually increasing the TTL and watching where the "TTL exceeded" responses originate.</p>\n'}, {'answer_id': 77045, 'author': 'akraut', 'author_id': 3971, 'author_profile': 'https://Stackoverflow.com/users/3971', 'pm_score': 1, 'selected': False, 'text': '<p>Rather than using raw sockets, some applications use a higher numbered tcp or udp port. By directing that tcp port at port 80 on a known webserver, you could traceroute to that server. The downside is that you need to know what ports are open on a destination device to tcpping it.</p>\n'}, {'answer_id': 77060, 'author': 'Ferruccio', 'author_id': 4086, 'author_profile': 'https://Stackoverflow.com/users/4086', 'pm_score': 0, 'selected': False, 'text': "<p>You don't need to use raw sockets to send and receive ICMP packets. At least not on Windows.</p>\n"}, {'answer_id': 77205, 'author': 'James Antill', 'author_id': 10314, 'author_profile': 'https://Stackoverflow.com/users/10314', 'pm_score': -1, 'selected': False, 'text': "<p>If you have a modern Linux distro you can look at the source for traceroute (or tracepath, which came about before traceroute went no setuid) and tcptraceroute. None of those require RAW sockets -- checked on Fedora 9, they aren't setuid and work with default options for the normal user.</p>\n\n<p>Using the code that tcptraceroute does might be esp. useful, as ICMP packets to an address will not necessarily end up at the same place as a TCP connection to port 80, for example.</p>\n\n<p>Doing an strace of traceroute (as a normal user) shows it doing something like:</p>\n\n<pre><code>\nint opt_on = 1;\nint opt_off = 0;\n\nfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)\nsetsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &opt_off, sizeof int)\nsetsockopt(fd, SOL_SOCKET, SO_TIMESTAMP, &opt_on, sizeof int)\nsetsockopt(fd, SOL_IP, IP_RECVTTL, &opt_on, sizeof int)\n</code></pre>\n\n<p>...and then reading the data out of the CMSG results.</p>\n"}, {'answer_id': 77310, 'author': 'Andrew Johnson', 'author_id': 5109, 'author_profile': 'https://Stackoverflow.com/users/5109', 'pm_score': 1, 'selected': False, 'text': '<p><strong>ping</strong> and <strong>traceroute</strong> use the ICMP protocol. Like UDP and TCP this is accessible through the normal sockets API. Only UDP and TCP port numbers less than 1024 are protected from use, other than by root. ICMP is freely available to all users.</p>\n\n<p>If you really want to see how ping and traceroute work you can download an example C code implementation for them from <a href="http://www.codeproject.com/KB/IP/Ping_and_Traceroute.aspx" rel="nofollow noreferrer">CodeProject</a>.</p>\n\n<p>In short, they simple open an ICMP socket, and traceroute alters the increments the TTL using setsockopt until the target is reached.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76988', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13817/']
|
76,993 |
<p>How can I set the protected <code>DoubleBuffered</code> property of the controls on a form that are suffering from flicker?</p>
|
[{'answer_id': 77023, 'author': 'Arno', 'author_id': 13685, 'author_profile': 'https://Stackoverflow.com/users/13685', 'pm_score': 4, 'selected': False, 'text': '<pre><code>public void EnableDoubleBuffering()\n{\n this.SetStyle(ControlStyles.DoubleBuffer | \n ControlStyles.UserPaint | \n ControlStyles.AllPaintingInWmPaint,\n true);\n this.UpdateStyles();\n}\n</code></pre>\n'}, {'answer_id': 77041, 'author': 'dummy', 'author_id': 6297, 'author_profile': 'https://Stackoverflow.com/users/6297', 'pm_score': 4, 'selected': False, 'text': '<pre><code>System.Reflection.PropertyInfo aProp = typeof(System.Windows.Forms.Control)\n .GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic |\n System.Reflection.BindingFlags.Instance);\naProp.SetValue(ListView1, true, null);\n</code></pre>\n\n<p><a href="https://stackoverflow.com/questions/76993/how-to-double-buffer-net-controls-on-a-form#77233">Ian</a> has some more information about using this on a terminal server.</p>\n'}, {'answer_id': 77055, 'author': 'MagicKat', 'author_id': 8505, 'author_profile': 'https://Stackoverflow.com/users/8505', 'pm_score': 1, 'selected': False, 'text': '<p>You can also inherit the controls into your own classes, and set the property in there. This method is also nice if you tend to be doing a lot of set up that is the same on all of the controls.</p>\n'}, {'answer_id': 77071, 'author': 'Jeff Hubbard', 'author_id': 8844, 'author_profile': 'https://Stackoverflow.com/users/8844', 'pm_score': 3, 'selected': False, 'text': "<p>One way is to extend the specific control you want to double buffer and set the DoubleBuffered property inside the control's ctor.</p>\n\n<p>For instance:</p>\n\n<pre><code>class Foo : Panel\n{\n public Foo() { DoubleBuffered = true; }\n}\n</code></pre>\n"}, {'answer_id': 77084, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': False, 'text': '<p>Before you try double buffering, see if SuspendLayout()/ResumeLayout() solve your problem. </p>\n'}, {'answer_id': 77233, 'author': 'Ian Boyd', 'author_id': 12597, 'author_profile': 'https://Stackoverflow.com/users/12597', 'pm_score': 8, 'selected': True, 'text': '<p>Here\'s a more generic version of <a href="https://stackoverflow.com/questions/76993/how-to-double-buffer-net-controls-on-a-form#77041">Dummy\'s solution</a>. </p>\n\n<p>We can use reflection to get at the protected <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx" rel="noreferrer">DoubleBuffered</a> property, and then it can be set to <strong>true</strong>.</p>\n\n<p><strong>Note</strong>: You should <a href="https://devblogs.microsoft.com/oldnewthing/20050822-11/?p=34483" rel="noreferrer">pay your developer taxes</a> and not <a href="https://devblogs.microsoft.com/oldnewthing/20060103-12/?p=32793" rel="noreferrer">use double-buffering if the user is running in a terminal services session</a> (e.g. Remote Desktop) This helper method will not turn on double buffering if the person is running in remote desktop.</p>\n\n<pre><code>public static void SetDoubleBuffered(System.Windows.Forms.Control c)\n{\n //Taxes: Remote Desktop Connection and painting\n //http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx\n if (System.Windows.Forms.SystemInformation.TerminalServerSession)\n return;\n\n System.Reflection.PropertyInfo aProp = \n typeof(System.Windows.Forms.Control).GetProperty(\n "DoubleBuffered", \n System.Reflection.BindingFlags.NonPublic | \n System.Reflection.BindingFlags.Instance);\n\n aProp.SetValue(c, true, null); \n}\n</code></pre>\n'}, {'answer_id': 77331, 'author': 'ljs', 'author_id': 3394, 'author_profile': 'https://Stackoverflow.com/users/3394', 'pm_score': 0, 'selected': False, 'text': '<p>I have found that simply setting the DoubleBuffered setting on the form automatically sets all the properties listed here.</p>\n'}, {'answer_id': 89125, 'author': 'Hans Passant', 'author_id': 17034, 'author_profile': 'https://Stackoverflow.com/users/17034', 'pm_score': 6, 'selected': False, 'text': '<p>Check <a href="http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/aaed00ce-4bc9-424e-8c05-c30213171c2c" rel="noreferrer">this thread</a></p>\n\n<p>Repeating the core of that answer, you can turn on the WS_EX_COMPOSITED style flag on the window to get both the form and all of its controls double-buffered. The style flag is available since XP. It doesn\'t make painting faster but the entire window is drawn in an off-screen buffer and blitted to the screen in one whack. Making it look instant to the user\'s eyes without visible painting artifacts. It is not entirely trouble-free, some visual styles renderers can glitch on it, particularly TabControl when its has too many tabs. YMMV.</p>\n\n<p>Paste this code into your form class:</p>\n\n<pre><code>protected override CreateParams CreateParams {\n get {\n var cp = base.CreateParams;\n cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED\n return cp;\n } \n}\n</code></pre>\n\n<p>The big difference between this technique and Winform\'s double-buffering support is that Winform\'s version only works on one control at at time. You will still see each individual control paint itself. Which can look like a flicker effect as well, particularly if the unpainted control rectangle contrasts badly with the window\'s background.</p>\n'}, {'answer_id': 1643053, 'author': 'Chris S', 'author_id': 21574, 'author_profile': 'https://Stackoverflow.com/users/21574', 'pm_score': 3, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/questions/76993/how-to-double-buffer-net-controls-on-a-form/89125#89125">nobugz</a> gets the credit for the method in his link, I\'m just reposting. Add this override to the Form:</p>\n\n<pre><code>protected override CreateParams CreateParams\n{\n get\n {\n CreateParams cp = base.CreateParams;\n cp.ExStyle |= 0x02000000;\n return cp;\n }\n}\n</code></pre>\n\n<p>This worked best for me, on Windows 7 I was getting large black blocks appearing when I resize a control heavy form. The control now bounce instead! But it\'s better.</p>\n'}, {'answer_id': 14282267, 'author': 'MajesticRa', 'author_id': 548894, 'author_profile': 'https://Stackoverflow.com/users/548894', 'pm_score': 3, 'selected': False, 'text': '<p><strong>Extension method</strong> to turn double buffering on or off for controls</p>\n\n<pre><code>public static class ControlExtentions\n{\n /// <summary>\n /// Turn on or off control double buffering (Dirty hack!)\n /// </summary>\n /// <param name="control">Control to operate</param>\n /// <param name="setting">true to turn on double buffering</param>\n public static void MakeDoubleBuffered(this Control control, bool setting)\n {\n Type controlType = control.GetType();\n PropertyInfo pi = controlType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);\n pi.SetValue(control, setting, null);\n }\n}\n</code></pre>\n\n<p>Usage (for example how to make DataGridView DoubleBuffered):</p>\n\n<pre><code>DataGridView _grid = new DataGridView();\n// ...\n_grid.MakeDoubleBuffered(true);\n</code></pre>\n'}, {'answer_id': 17279923, 'author': 'dnennis', 'author_id': 2386550, 'author_profile': 'https://Stackoverflow.com/users/2386550', 'pm_score': 2, 'selected': False, 'text': '<p>This caused me a <strong>lot</strong> of grief for two days with a third party control until I tracked it down.</p>\n\n<pre><code>protected override CreateParams CreateParams\n{\n get\n {\n CreateParams cp = base.CreateParams;\n cp.ExStyle |= 0x02000000;\n return cp;\n }\n}\n</code></pre>\n\n<p>I recently had a lot of holes (droppings) when re-sizing / redrawing a control containing several other controls.</p>\n\n<p>I tried WS_EX_COMPOSITED and WM_SETREDRAW but nothing worked until I used this:</p>\n\n<pre><code>private void myPanel_SizeChanged(object sender, EventArgs e)\n{\n Application.DoEvents();\n}\n</code></pre>\n\n<p>Just wanted to pass it on.</p>\n'}, {'answer_id': 39343123, 'author': 'Flip70', 'author_id': 6799147, 'author_profile': 'https://Stackoverflow.com/users/6799147', 'pm_score': 2, 'selected': False, 'text': '<p>vb.net version of this fine solution....:</p>\n\n<pre><code>Protected Overrides ReadOnly Property CreateParams() As CreateParams\n Get\n Dim cp As CreateParams = MyBase.CreateParams\n cp.ExStyle = cp.ExStyle Or &H2000000\n Return cp\n End Get\nEnd Property\n</code></pre>\n'}, {'answer_id': 67273198, 'author': 'Gregor y', 'author_id': 4496560, 'author_profile': 'https://Stackoverflow.com/users/4496560', 'pm_score': -1, 'selected': False, 'text': '<h2>FWIW</h2>\n<p>building on the work of those who\'ve come before me:<br>\n<a href="https://stackoverflow.com/a/77041/4496560">Dummy\'s Solution</a>, <a href="https://stackoverflow.com/a/77233/4496560">Ian Boyd\'s Solution</a>, <a href="https://stackoverflow.com/a/77023/4496560">Amo\'s Solution</a></p>\n<p>here is a version that sets double buffering via <code>SetStyle</code> in PowerShell using reflection</p>\n<pre><code>function Set-DoubleBuffered{\n<#\n.SYNOPSIS\nTurns on double buffering for a [System.Windows.Forms.Control] object\n.DESCRIPTION\nUses the Non-Public method \'SetStyle\' on the control to set the three\nstyle flags recomend for double buffering: \n UserPaint\n AllPaintingInWmPaint\n DoubleBuffer\n.INPUTS\n[System.Windows.Forms.Control]\n.OUTPUTS\nNone\n.COMPONENT \nSystem.Windows.Forms.Control\n.FUNCTIONALITY\nSet Flag, DoubleBuffering, Graphics\n.ROLE\nWinForms Developer\n.NOTES\nThrows an exception when trying to double buffer a control on a terminal \nserver session becuase doing so will cause lots of data to be sent across \nthe line\n.EXAMPLE\n#A simple WinForm that uses double buffering to reduce flicker\nAdd-Type -AssemblyName System.Windows.Forms\n[System.Windows.Forms.Application]::EnableVisualStyles()\n\n$Pen = [System.Drawing.Pen]::new([System.Drawing.Color]::FromArgb(0xff000000),3)\n\n$Form = New-Object System.Windows.Forms.Form\nSet-DoubleBuffered $Form\n$Form.Add_Paint({\n param(\n [object]$sender,\n [System.Windows.Forms.PaintEventArgs]$e\n )\n [System.Windows.Forms.Form]$f = $sender\n $g = $e.Graphics\n $g.SmoothingMode = \'AntiAlias\'\n $g.DrawLine($Pen,0,0,$f.Width/2,$f.Height/2)\n})\n$Form.ShowDialog()\n\n.LINK\nhttps://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.setstyle?view=net-5.0\n.LINK\nhttps://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.controlstyles?view=net-5.0\n#>\n param(\n [parameter(mandatory=$true,ValueFromPipeline=$true)]\n [ValidateScript({$_ -is [System.Windows.Forms.Control]})]\n #The WinForms control to set to double buffered\n $Control,\n \n [switch]\n #Override double buffering on a terminal server session(not recomended)\n $Force\n )\n begin{try{\n if([System.Windows.Forms.SystemInformation]::TerminalServerSession -and !$Force){\n throw \'Double buffering not set on terminal server session.\'\n }\n \n $SetStyle = ([System.Windows.Forms.Control]).GetMethod(\'SetStyle\',\n [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance\n )\n $UpdateStyles = ([System.Windows.Forms.Control]).GetMethod(\'UpdateStyles\',\n [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance\n )\n }catch {$PSCmdlet.ThrowTerminatingError($PSItem)}\n }process{try{\n $SetStyle.Invoke($Control,@(\n ([System.Windows.Forms.ControlStyles]::UserPaint -bor\n [System.Windows.Forms.ControlStyles]::AllPaintingInWmPaint -bor\n [System.Windows.Forms.ControlStyles]::DoubleBuffer\n ),\n $true\n ))\n $UpdateStyles.Invoke($Control,@())\n }catch {$PSCmdlet.ThrowTerminatingError($PSItem)}}\n}\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/76993', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12597/']
|
77,005 |
<p>I am working on Linux with the GCC compiler. When my C++ program crashes I would like it to automatically generate a stacktrace.</p>
<p>My program is being run by many different users and it also runs on Linux, Windows and Macintosh (all versions are compiled using <code>gcc</code>).</p>
<p>I would like my program to be able to generate a stack trace when it crashes and the next time the user runs it, it will ask them if it is ok to send the stack trace to me so I can track down the problem. I can handle the sending the info to me but I don't know how to generate the trace string. Any ideas?</p>
|
[{'answer_id': 76867, 'author': 'mana', 'author_id': 12016, 'author_profile': 'https://Stackoverflow.com/users/12016', 'pm_score': 3, 'selected': False, 'text': '<pre><code>ulimit -c unlimited\n</code></pre>\n\n<p>is a system variable, wich will allow to create a core dump after your application crashes. In this case an unlimited amount. Look for a file called core in the very same directory. Make sure you compiled your code with debugging informations enabled!</p>\n\n<p>regards</p>\n'}, {'answer_id': 76924, 'author': 'Stephen Deken', 'author_id': 7154, 'author_profile': 'https://Stackoverflow.com/users/7154', 'pm_score': 3, 'selected': False, 'text': '<p>Some versions of libc contain functions that deal with stack traces; you might be able to use them:</p>\n\n<p><a href="http://www.gnu.org/software/libc/manual/html_node/Backtraces.html" rel="noreferrer">http://www.gnu.org/software/libc/manual/html_node/Backtraces.html</a></p>\n\n<p>I remember using <a href="http://www.nongnu.org/libunwind/" rel="noreferrer">libunwind</a> a long time ago to get stack traces, but it may not be supported on your platform.</p>\n'}, {'answer_id': 76937, 'author': 'Brian Mitchell', 'author_id': 13716, 'author_profile': 'https://Stackoverflow.com/users/13716', 'pm_score': 5, 'selected': False, 'text': "<p>You did not specify your operating system, so this is difficult to answer. If you are using a system based on gnu libc, you might be able to use the libc function <code>backtrace()</code>.</p>\n\n<p>GCC also has two builtins that can assist you, but which may or may not be implemented fully on your architecture, and those are <code>__builtin_frame_address</code> and <code>__builtin_return_address</code>. Both of which want an immediate integer level (by immediate, I mean it can't be a variable). If <code>__builtin_frame_address</code> for a given level is non-zero, it should be safe to grab the return address of the same level.</p>\n"}, {'answer_id': 76962, 'author': 'Stéphane', 'author_id': 13022, 'author_profile': 'https://Stackoverflow.com/users/13022', 'pm_score': 3, 'selected': False, 'text': '<p>Look at:</p>\n\n<p>man 3 backtrace</p>\n\n<p>And:</p>\n\n<pre><code>#include <exeinfo.h>\nint backtrace(void **buffer, int size);\n</code></pre>\n\n<p>These are GNU extensions.</p>\n'}, {'answer_id': 76986, 'author': 'Benson', 'author_id': 13816, 'author_profile': 'https://Stackoverflow.com/users/13816', 'pm_score': 4, 'selected': False, 'text': '<p>It\'s important to note that once you generate a core file you\'ll need to use the gdb tool to look at it. For gdb to make sense of your core file, you must tell gcc to instrument the binary with debugging symbols: to do this, you compile with the -g flag:</p>\n\n<pre><code>$ g++ -g prog.cpp -o prog\n</code></pre>\n\n<p>Then, you can either set "ulimit -c unlimited" to let it dump a core, or just run your program inside gdb. I like the second approach more: </p>\n\n<pre><code>$ gdb ./prog\n... gdb startup output ...\n(gdb) run\n... program runs and crashes ...\n(gdb) where\n... gdb outputs your stack trace ...\n</code></pre>\n\n<p>I hope this helps. </p>\n'}, {'answer_id': 77030, 'author': 'Jim Buck', 'author_id': 2666, 'author_profile': 'https://Stackoverflow.com/users/2666', 'pm_score': 2, 'selected': False, 'text': '<p>I would use the code that generates a stack trace for leaked memory in <a href="http://www.codeproject.com/KB/applications/visualleakdetector.aspx" rel="nofollow noreferrer">Visual Leak Detector</a>. This only works on Win32, though.</p>\n'}, {'answer_id': 77033, 'author': 'terminus', 'author_id': 9232, 'author_profile': 'https://Stackoverflow.com/users/9232', 'pm_score': 3, 'selected': False, 'text': '<p>I can help with the Linux version: the function backtrace, backtrace_symbols and backtrace_symbols_fd can be used. See the corresponding manual pages.</p>\n'}, {'answer_id': 77142, 'author': 'INS', 'author_id': 13136, 'author_profile': 'https://Stackoverflow.com/users/13136', 'pm_score': 2, 'selected': False, 'text': '<p>*nix: \nyou can intercept <a href="http://en.wikipedia.org/wiki/SIGSEGV" rel="nofollow noreferrer">SIGSEGV</a> (usualy this signal is raised before crashing) and keep the info into a file. (besides the core file which you can use to debug using gdb for example).</p>\n\n<p>win:\nCheck <a href="http://msdn.microsoft.com/en-us/library/ms680659(VS.85).aspx" rel="nofollow noreferrer">this</a> from msdn.</p>\n\n<p>You can also look at the google\'s chrome code to see how it handles crashes. It has a nice exception handling mechanism.</p>\n'}, {'answer_id': 77224, 'author': 'Kasprzol', 'author_id': 5957, 'author_profile': 'https://Stackoverflow.com/users/5957', 'pm_score': 1, 'selected': False, 'text': '<p>On Linux/unix/MacOSX use core files (you can enable them with ulimit or <a href="http://www.opengroup.org/onlinepubs/009695399/functions/setrlimit.html" rel="nofollow noreferrer">compatible system call</a>). On Windows use Microsoft error reporting (you can become a partner and get access to your application crash data).</p>\n'}, {'answer_id': 77272, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p><code>ulimit -c <value></code> sets the core file size limit on unix. By default, the core file size limit is 0. You can see your <code>ulimit</code> values with <code>ulimit -a</code>.</p>\n\n<p>also, if you run your program from within gdb, it will halt your program on "segmentation violations" (<code>SIGSEGV</code>, generally when you accessed a piece of memory that you hadn\'t allocated) or you can set breakpoints.</p>\n\n<p>ddd and nemiver are front-ends for gdb which make working with it much easier for the novice.</p>\n'}, {'answer_id': 77289, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I forgot about the GNOME tech of "apport", but I don\'t know much about using it. It is used to generate stacktraces and other diagnostics for processing and can automatically file bugs. It\'s certainly worth checking in to.</p>\n'}, {'answer_id': 77336, 'author': 'Todd Gamblin', 'author_id': 9122, 'author_profile': 'https://Stackoverflow.com/users/9122', 'pm_score': 10, 'selected': True, 'text': '<p>For Linux and I believe Mac OS X, if you\'re using gcc, or any compiler that uses glibc, you can use the backtrace() functions in <code>execinfo.h</code> to print a stacktrace and exit gracefully when you get a segmentation fault. Documentation can be found <a href="http://www.gnu.org/software/libc/manual/html_node/Backtraces.html" rel="noreferrer">in the libc manual</a>.</p>\n\n<p>Here\'s an example program that installs a <code>SIGSEGV</code> handler and prints a stacktrace to <code>stderr</code> when it segfaults. The <code>baz()</code> function here causes the segfault that triggers the handler:</p>\n\n<pre><code>#include <stdio.h>\n#include <execinfo.h>\n#include <signal.h>\n#include <stdlib.h>\n#include <unistd.h>\n\n\nvoid handler(int sig) {\n void *array[10];\n size_t size;\n\n // get void*\'s for all entries on the stack\n size = backtrace(array, 10);\n\n // print out all the frames to stderr\n fprintf(stderr, "Error: signal %d:\\n", sig);\n backtrace_symbols_fd(array, size, STDERR_FILENO);\n exit(1);\n}\n\nvoid baz() {\n int *foo = (int*)-1; // make a bad pointer\n printf("%d\\n", *foo); // causes segfault\n}\n\nvoid bar() { baz(); }\nvoid foo() { bar(); }\n\n\nint main(int argc, char **argv) {\n signal(SIGSEGV, handler); // install our handler\n foo(); // this will call foo, bar, and baz. baz segfaults.\n}\n</code></pre>\n\n<p>Compiling with <code>-g -rdynamic</code> gets you symbol info in your output, which glibc can use to make a nice stacktrace:</p>\n\n<pre><code>$ gcc -g -rdynamic ./test.c -o test\n</code></pre>\n\n<p>Executing this gets you this output:</p>\n\n<pre><code>$ ./test\nError: signal 11:\n./test(handler+0x19)[0x400911]\n/lib64/tls/libc.so.6[0x3a9b92e380]\n./test(baz+0x14)[0x400962]\n./test(bar+0xe)[0x400983]\n./test(foo+0xe)[0x400993]\n./test(main+0x28)[0x4009bd]\n/lib64/tls/libc.so.6(__libc_start_main+0xdb)[0x3a9b91c4bb]\n./test[0x40086a]\n</code></pre>\n\n<p>This shows the load module, offset, and function that each frame in the stack came from. Here you can see the signal handler on top of the stack, and the libc functions before <code>main</code> in addition to <code>main</code>, <code>foo</code>, <code>bar</code>, and <code>baz</code>.</p>\n'}, {'answer_id': 78543, 'author': 'Adam Mitz', 'author_id': 2574, 'author_profile': 'https://Stackoverflow.com/users/2574', 'pm_score': 3, 'selected': False, 'text': '<p>See the Stack Trace facility in <a href="http://www.cs.wustl.edu/~schmidt/ACE.html" rel="noreferrer">ACE</a> (ADAPTIVE Communication Environment). It\'s already written to cover all major platforms (and more). The library is BSD-style licensed so you can even copy/paste the code if you don\'t want to use ACE.</p>\n'}, {'answer_id': 82192, 'author': 'Simon Steele', 'author_id': 4591, 'author_profile': 'https://Stackoverflow.com/users/4591', 'pm_score': 5, 'selected': False, 'text': '<p>Might be worth looking at <a href="https://chromium.googlesource.com/breakpad/breakpad" rel="noreferrer">Google Breakpad</a>, a cross-platform crash dump generator and tools to process the dumps.</p>\n'}, {'answer_id': 89601, 'author': 'Gregory', 'author_id': 14351, 'author_profile': 'https://Stackoverflow.com/users/14351', 'pm_score': 4, 'selected': False, 'text': '<p>Ive been looking at this problem for a while.</p>\n\n<p>And buried deep in the Google Performance Tools README</p>\n\n<p><a href="http://code.google.com/p/google-perftools/source/browse/trunk/README" rel="noreferrer">http://code.google.com/p/google-perftools/source/browse/trunk/README</a></p>\n\n<p>talks about libunwind</p>\n\n<p><a href="http://www.nongnu.org/libunwind/" rel="noreferrer">http://www.nongnu.org/libunwind/</a></p>\n\n<p>Would love to hear opinions of this library.</p>\n\n<p>The problem with -rdynamic is that it can increase the size of the binary relatively significantly in some cases</p>\n'}, {'answer_id': 1925461, 'author': 'jschmier', 'author_id': 203667, 'author_profile': 'https://Stackoverflow.com/users/203667', 'pm_score': 7, 'selected': False, 'text': '<h2>Linux</h2>\n<p>While the use of the backtrace() functions in execinfo.h to print a stacktrace and exit gracefully when you get a segmentation fault has <a href="https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes/77336#77336">already been suggested</a>, I see no mention of the intricacies necessary to ensure the resulting backtrace points to the actual location of the fault (at least for some architectures - x86 & ARM).</p>\n<p>The first two entries in the stack frame chain when you get into the signal handler contain a return address inside the signal handler and one inside sigaction() in libc. The stack frame of the last function called before the signal (which is the location of the fault) is lost.</p>\n<h2>Code</h2>\n<pre><code>#ifndef _GNU_SOURCE\n#define _GNU_SOURCE\n#endif\n#ifndef __USE_GNU\n#define __USE_GNU\n#endif\n\n#include <execinfo.h>\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <ucontext.h>\n#include <unistd.h>\n\n/* This structure mirrors the one found in /usr/include/asm/ucontext.h */\ntypedef struct _sig_ucontext {\n unsigned long uc_flags;\n ucontext_t *uc_link;\n stack_t uc_stack;\n sigcontext_t uc_mcontext;\n sigset_t uc_sigmask;\n} sig_ucontext_t;\n\nvoid crit_err_hdlr(int sig_num, siginfo_t * info, void * ucontext)\n{\n void * array[50];\n void * caller_address;\n char ** messages;\n int size, i;\n sig_ucontext_t * uc;\n\n uc = (sig_ucontext_t *)ucontext;\n\n /* Get the address at the time the signal was raised */\n#if defined(__i386__) // gcc specific\n caller_address = (void *) uc->uc_mcontext.eip; // EIP: x86 specific\n#elif defined(__x86_64__) // gcc specific\n caller_address = (void *) uc->uc_mcontext.rip; // RIP: x86_64 specific\n#else\n#error Unsupported architecture. // TODO: Add support for other arch.\n#endif\n\n fprintf(stderr, "signal %d (%s), address is %p from %p\\n", \n sig_num, strsignal(sig_num), info->si_addr, \n (void *)caller_address);\n\n size = backtrace(array, 50);\n\n /* overwrite sigaction with caller\'s address */\n array[1] = caller_address;\n\n messages = backtrace_symbols(array, size);\n\n /* skip first stack frame (points here) */\n for (i = 1; i < size && messages != NULL; ++i)\n {\n fprintf(stderr, "[bt]: (%d) %s\\n", i, messages[i]);\n }\n\n free(messages);\n\n exit(EXIT_FAILURE);\n}\n\nint crash()\n{\n char * p = NULL;\n *p = 0;\n return 0;\n}\n\nint foo4()\n{\n crash();\n return 0;\n}\n\nint foo3()\n{\n foo4();\n return 0;\n}\n\nint foo2()\n{\n foo3();\n return 0;\n}\n\nint foo1()\n{\n foo2();\n return 0;\n}\n\nint main(int argc, char ** argv)\n{\n struct sigaction sigact;\n\n sigact.sa_sigaction = crit_err_hdlr;\n sigact.sa_flags = SA_RESTART | SA_SIGINFO;\n\n if (sigaction(SIGSEGV, &sigact, (struct sigaction *)NULL) != 0)\n {\n fprintf(stderr, "error setting signal handler for %d (%s)\\n",\n SIGSEGV, strsignal(SIGSEGV));\n\n exit(EXIT_FAILURE);\n }\n\n foo1();\n\n exit(EXIT_SUCCESS);\n}\n</code></pre>\n<h2>Output</h2>\n<pre><code>signal 11 (Segmentation fault), address is (nil) from 0x8c50\n[bt]: (1) ./test(crash+0x24) [0x8c50]\n[bt]: (2) ./test(foo4+0x10) [0x8c70]\n[bt]: (3) ./test(foo3+0x10) [0x8c8c]\n[bt]: (4) ./test(foo2+0x10) [0x8ca8]\n[bt]: (5) ./test(foo1+0x10) [0x8cc4]\n[bt]: (6) ./test(main+0x74) [0x8d44]\n[bt]: (7) /lib/libc.so.6(__libc_start_main+0xa8) [0x40032e44]\n</code></pre>\n<p>All the hazards of calling the backtrace() functions in a signal handler still exist and should not be overlooked, but I find the functionality I described here quite helpful in debugging crashes.</p>\n<p>It is important to note that the example I provided is developed/tested on Linux for x86. I have also successfully implemented this on ARM using <code>uc_mcontext.arm_pc</code> instead of <code>uc_mcontext.eip</code>.</p>\n<p>Here\'s a link to the article where I learned the details for this implementation:\n<a href="http://www.linuxjournal.com/article/6391" rel="noreferrer">http://www.linuxjournal.com/article/6391</a></p>\n'}, {'answer_id': 2526298, 'author': 'jschmier', 'author_id': 203667, 'author_profile': 'https://Stackoverflow.com/users/203667', 'pm_score': 7, 'selected': False, 'text': '<p>Even though a <a href="https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes/77336#77336">correct answer</a> has been provided that describes how to use the GNU libc <code>backtrace()</code> function<sup>1</sup> and I provided <a href="https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes/1925461#1925461">my own answer</a> that describes how to ensure a backtrace from a signal handler points to the actual location of the fault<sup>2</sup>, I don\'t see any mention of <a href="http://en.wikipedia.org/wiki/Name_mangling" rel="noreferrer">demangling</a> C++ symbols output from the backtrace.</p>\n\n<p>When obtaining backtraces from a C++ program, the output can be run through <code>c++filt</code><sup>1</sup> to demangle the symbols or by using <a href="http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html" rel="noreferrer"><code>abi::__cxa_demangle</code></a><sup>1</sup> directly.</p>\n\n<ul>\n<li><sup>1</sup> Linux & OS X\n<sub>Note that <code>c++filt</code> and <code>__cxa_demangle</code> are GCC specific</sub></li>\n<li><sup>2</sup> Linux</li>\n</ul>\n\n<hr>\n\n<p>The following C++ Linux example uses the same signal handler as my <a href="https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes/1925461#1925461">other answer</a> and demonstrates how <code>c++filt</code> can be used to demangle the symbols.</p>\n\n<p><strong>Code</strong>:</p>\n\n<pre><code>class foo\n{\npublic:\n foo() { foo1(); }\n\nprivate:\n void foo1() { foo2(); }\n void foo2() { foo3(); }\n void foo3() { foo4(); }\n void foo4() { crash(); }\n void crash() { char * p = NULL; *p = 0; }\n};\n\nint main(int argc, char ** argv)\n{\n // Setup signal handler for SIGSEGV\n ...\n\n foo * f = new foo();\n return 0;\n}\n</code></pre>\n\n<p><strong>Output</strong> (<code>./test</code>):</p>\n\n<pre><code>signal 11 (Segmentation fault), address is (nil) from 0x8048e07\n[bt]: (1) ./test(crash__3foo+0x13) [0x8048e07]\n[bt]: (2) ./test(foo4__3foo+0x12) [0x8048dee]\n[bt]: (3) ./test(foo3__3foo+0x12) [0x8048dd6]\n[bt]: (4) ./test(foo2__3foo+0x12) [0x8048dbe]\n[bt]: (5) ./test(foo1__3foo+0x12) [0x8048da6]\n[bt]: (6) ./test(__3foo+0x12) [0x8048d8e]\n[bt]: (7) ./test(main+0xe0) [0x8048d18]\n[bt]: (8) ./test(__libc_start_main+0x95) [0x42017589]\n[bt]: (9) ./test(__register_frame_info+0x3d) [0x8048981]\n</code></pre>\n\n<p><strong>Demangled Output</strong> (<code>./test 2>&1 | c++filt</code>):</p>\n\n<pre><code>signal 11 (Segmentation fault), address is (nil) from 0x8048e07\n[bt]: (1) ./test(foo::crash(void)+0x13) [0x8048e07]\n[bt]: (2) ./test(foo::foo4(void)+0x12) [0x8048dee]\n[bt]: (3) ./test(foo::foo3(void)+0x12) [0x8048dd6]\n[bt]: (4) ./test(foo::foo2(void)+0x12) [0x8048dbe]\n[bt]: (5) ./test(foo::foo1(void)+0x12) [0x8048da6]\n[bt]: (6) ./test(foo::foo(void)+0x12) [0x8048d8e]\n[bt]: (7) ./test(main+0xe0) [0x8048d18]\n[bt]: (8) ./test(__libc_start_main+0x95) [0x42017589]\n[bt]: (9) ./test(__register_frame_info+0x3d) [0x8048981]\n</code></pre>\n\n<hr>\n\n<p>The following builds on the signal handler from my <a href="https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes/1925461#1925461">original answer</a> and can replace the signal handler in the above example to demonstrate how <a href="http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html" rel="noreferrer"><code>abi::__cxa_demangle</code></a> can be used to demangle the symbols. This signal handler produces the same demangled output as the above example.</p>\n\n<p><strong>Code</strong>:</p>\n\n<pre><code>void crit_err_hdlr(int sig_num, siginfo_t * info, void * ucontext)\n{\n sig_ucontext_t * uc = (sig_ucontext_t *)ucontext;\n\n void * caller_address = (void *) uc->uc_mcontext.eip; // x86 specific\n\n std::cerr << "signal " << sig_num \n << " (" << strsignal(sig_num) << "), address is " \n << info->si_addr << " from " << caller_address \n << std::endl << std::endl;\n\n void * array[50];\n int size = backtrace(array, 50);\n\n array[1] = caller_address;\n\n char ** messages = backtrace_symbols(array, size); \n\n // skip first stack frame (points here)\n for (int i = 1; i < size && messages != NULL; ++i)\n {\n char *mangled_name = 0, *offset_begin = 0, *offset_end = 0;\n\n // find parantheses and +address offset surrounding mangled name\n for (char *p = messages[i]; *p; ++p)\n {\n if (*p == \'(\') \n {\n mangled_name = p; \n }\n else if (*p == \'+\') \n {\n offset_begin = p;\n }\n else if (*p == \')\')\n {\n offset_end = p;\n break;\n }\n }\n\n // if the line could be processed, attempt to demangle the symbol\n if (mangled_name && offset_begin && offset_end && \n mangled_name < offset_begin)\n {\n *mangled_name++ = \'\\0\';\n *offset_begin++ = \'\\0\';\n *offset_end++ = \'\\0\';\n\n int status;\n char * real_name = abi::__cxa_demangle(mangled_name, 0, 0, &status);\n\n // if demangling is successful, output the demangled function name\n if (status == 0)\n { \n std::cerr << "[bt]: (" << i << ") " << messages[i] << " : " \n << real_name << "+" << offset_begin << offset_end \n << std::endl;\n\n }\n // otherwise, output the mangled function name\n else\n {\n std::cerr << "[bt]: (" << i << ") " << messages[i] << " : " \n << mangled_name << "+" << offset_begin << offset_end \n << std::endl;\n }\n free(real_name);\n }\n // otherwise, print the whole line\n else\n {\n std::cerr << "[bt]: (" << i << ") " << messages[i] << std::endl;\n }\n }\n std::cerr << std::endl;\n\n free(messages);\n\n exit(EXIT_FAILURE);\n}\n</code></pre>\n'}, {'answer_id': 6599348, 'author': 'jhclark', 'author_id': 758067, 'author_profile': 'https://Stackoverflow.com/users/758067', 'pm_score': 7, 'selected': False, 'text': '<p>It\'s even easier than "man backtrace", there\'s a little-documented library (GNU specific) distributed with glibc as libSegFault.so, which was I believe was written by Ulrich Drepper to support the program catchsegv (see "man catchsegv").</p>\n\n<p>This gives us 3 possibilities. Instead of running "program -o hai":</p>\n\n<ol>\n<li><p>Run within catchsegv:</p>\n\n<pre><code>$ catchsegv program -o hai\n</code></pre></li>\n<li><p>Link with libSegFault at runtime:</p>\n\n<pre><code>$ LD_PRELOAD=/lib/libSegFault.so program -o hai\n</code></pre></li>\n<li><p>Link with libSegFault at compile time:</p>\n\n<pre><code>$ gcc -g1 -lSegFault -o program program.cc\n$ program -o hai\n</code></pre></li>\n</ol>\n\n<p>In all 3 cases, you will get clearer backtraces with less optimization (gcc -O0 or -O1) and debugging symbols (gcc -g). Otherwise, you may just end up with a pile of memory addresses.</p>\n\n<p>You can also catch more signals for stack traces with something like:</p>\n\n<pre><code>$ export SEGFAULT_SIGNALS="all" # "all" signals\n$ export SEGFAULT_SIGNALS="bus abrt" # SIGBUS and SIGABRT\n</code></pre>\n\n<p>The output will look something like this (notice the backtrace at the bottom):</p>\n\n<pre><code>*** Segmentation fault Register dump:\n\n EAX: 0000000c EBX: 00000080 ECX:\n00000000 EDX: 0000000c ESI:\nbfdbf080 EDI: 080497e0 EBP:\nbfdbee38 ESP: bfdbee20\n\n EIP: 0805640f EFLAGS: 00010282\n\n CS: 0073 DS: 007b ES: 007b FS:\n0000 GS: 0033 SS: 007b\n\n Trap: 0000000e Error: 00000004 \nOldMask: 00000000 ESP/signal:\nbfdbee20 CR2: 00000024\n\n FPUCW: ffff037f FPUSW: ffff0000 \nTAG: ffffffff IPOFF: 00000000 \nCSSEL: 0000 DATAOFF: 00000000 \nDATASEL: 0000\n\n ST(0) 0000 0000000000000000 ST(1)\n0000 0000000000000000 ST(2) 0000\n0000000000000000 ST(3) 0000\n0000000000000000 ST(4) 0000\n0000000000000000 ST(5) 0000\n0000000000000000 ST(6) 0000\n0000000000000000 ST(7) 0000\n0000000000000000\n\nBacktrace:\n/lib/libSegFault.so[0xb7f9e100]\n??:0(??)[0xb7fa3400]\n/usr/include/c++/4.3/bits/stl_queue.h:226(_ZNSt5queueISsSt5dequeISsSaISsEEE4pushERKSs)[0x805647a]\n/home/dbingham/src/middle-earth-mud/alpha6/src/engine/player.cpp:73(_ZN6Player5inputESs)[0x805377c]\n/home/dbingham/src/middle-earth-mud/alpha6/src/engine/socket.cpp:159(_ZN6Socket4ReadEv)[0x8050698]\n/home/dbingham/src/middle-earth-mud/alpha6/src/engine/socket.cpp:413(_ZN12ServerSocket4ReadEv)[0x80507ad]\n/home/dbingham/src/middle-earth-mud/alpha6/src/engine/socket.cpp:300(_ZN12ServerSocket4pollEv)[0x8050b44]\n/home/dbingham/src/middle-earth-mud/alpha6/src/engine/main.cpp:34(main)[0x8049a72]\n/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5)[0xb7d1b775]\n/build/buildd/glibc-2.9/csu/../sysdeps/i386/elf/start.S:122(_start)[0x8049801]\n</code></pre>\n\n<p>If you want to know the gory details, the best source is unfortunately the source: See <a href="http://sourceware.org/git/?p=glibc.git;a=blob;f=debug/segfault.c" rel="noreferrer">http://sourceware.org/git/?p=glibc.git;a=blob;f=debug/segfault.c</a> and its parent directory <a href="http://sourceware.org/git/?p=glibc.git;a=tree;f=debug" rel="noreferrer">http://sourceware.org/git/?p=glibc.git;a=tree;f=debug</a> </p>\n'}, {'answer_id': 15152011, 'author': 'markhor', 'author_id': 69708, 'author_profile': 'https://Stackoverflow.com/users/69708', 'pm_score': 3, 'selected': False, 'text': '<p>You can use <a href="https://github.com/vmarkovtsev/DeathHandler" rel="noreferrer" title="DeathHandler">DeathHandler</a> - small C++ class which does everything for you, reliable.</p>\n'}, {'answer_id': 15801966, 'author': 'arr_sea', 'author_id': 1797414, 'author_profile': 'https://Stackoverflow.com/users/1797414', 'pm_score': 4, 'selected': False, 'text': '<p>Thank you to enthusiasticgeek for drawing my attention to the addr2line utility.</p>\n\n<p>I\'ve written a quick and dirty script to process the output of the answer provided <a href="https://stackoverflow.com/a/1925461/1797414">here</a>:\n(much thanks to jschmier!) using the addr2line utility.</p>\n\n<p>The script accepts a single argument: The name of the file containing the output from jschmier\'s utility.</p>\n\n<p>The output should print something like the following for each level of the trace:</p>\n\n<pre><code>BACKTRACE: testExe 0x8A5db6b\nFILE: pathToFile/testExe.C:110\nFUNCTION: testFunction(int) \n 107 \n 108 \n 109 int* i = 0x0;\n *110 *i = 5;\n 111 \n 112 }\n 113 return i;\n</code></pre>\n\n<p>Code:</p>\n\n<pre><code>#!/bin/bash\n\nLOGFILE=$1\n\nNUM_SRC_CONTEXT_LINES=3\n\nold_IFS=$IFS # save the field separator \nIFS=$\'\\n\' # new field separator, the end of line \n\nfor bt in `cat $LOGFILE | grep \'\\[bt\\]\'`; do\n IFS=$old_IFS # restore default field separator \n printf \'\\n\'\n EXEC=`echo $bt | cut -d\' \' -f3 | cut -d\'(\' -f1` \n ADDR=`echo $bt | cut -d\'[\' -f3 | cut -d\']\' -f1`\n echo "BACKTRACE: $EXEC $ADDR"\n A2L=`addr2line -a $ADDR -e $EXEC -pfC`\n #echo "A2L: $A2L"\n\n FUNCTION=`echo $A2L | sed \'s/\\<at\\>.*//\' | cut -d\' \' -f2-99`\n FILE_AND_LINE=`echo $A2L | sed \'s/.* at //\'`\n echo "FILE: $FILE_AND_LINE"\n echo "FUNCTION: $FUNCTION"\n\n # print offending source code\n SRCFILE=`echo $FILE_AND_LINE | cut -d\':\' -f1`\n LINENUM=`echo $FILE_AND_LINE | cut -d\':\' -f2`\n if ([ -f $SRCFILE ]); then\n cat -n $SRCFILE | grep -C $NUM_SRC_CONTEXT_LINES "^ *$LINENUM\\>" | sed "s/ $LINENUM/*$LINENUM/"\n else\n echo "File not found: $SRCFILE"\n fi\n IFS=$\'\\n\' # new field separator, the end of line \ndone\n\nIFS=$old_IFS # restore default field separator \n</code></pre>\n'}, {'answer_id': 16448454, 'author': 'enthusiasticgeek', 'author_id': 264683, 'author_profile': 'https://Stackoverflow.com/users/264683', 'pm_score': 2, 'selected': False, 'text': "<p>In addition to above answers, here how you make Debian Linux OS generate core dump </p>\n\n<ol>\n<li>Create a “coredumps” folder in the user's home folder</li>\n<li>Go to /etc/security/limits.conf. Below the ' ' line, type “ soft core unlimited”, and “root soft core unlimited” if enabling core dumps for root, to allow unlimited space for core dumps. </li>\n<li>NOTE: “* soft core unlimited” does not cover root, which is why root has to be specified in its own line.</li>\n<li>To check these values, log out, log back in, and type “ulimit -a”. “Core file size” should be set to unlimited.</li>\n<li>Check the .bashrc files (user, and root if applicable) to make sure that ulimit is not set there. Otherwise, the value above will be overwritten on startup.</li>\n<li>Open /etc/sysctl.conf. \nEnter the following at the bottom: “kernel.core_pattern = /home//coredumps/%e_%t.dump”. (%e will be the process name, and %t will be the system time)</li>\n<li>Exit and type “sysctl -p” to load the new configuration\nCheck /proc/sys/kernel/core_pattern and verify that this matches what you just typed in.</li>\n<li>Core dumping can be tested by running a process on the command line (“ &”), and then killing it with “kill -11 ”. If core dumping is successful, you will see “(core dumped)” after the segmentation fault indication.</li>\n</ol>\n"}, {'answer_id': 20556298, 'author': 'jard18', 'author_id': 2980910, 'author_profile': 'https://Stackoverflow.com/users/2980910', 'pm_score': 2, 'selected': False, 'text': "<p>I have seen a lot of answers here performing a signal handler and then exiting.\nThat's the way to go, but remember a very important fact: If you want to get the core dump for the generated error, you can't call <code>exit(status)</code>. Call <code>abort()</code> instead!</p>\n"}, {'answer_id': 22532288, 'author': 'Daniil Iaitskov', 'author_id': 342882, 'author_profile': 'https://Stackoverflow.com/users/342882', 'pm_score': 2, 'selected': False, 'text': '<p>I found that @tgamblin solution is not complete.\nIt cannot handle with stackoverflow.\nI think because by default signal handler is called with the same stack and\nSIGSEGV is thrown twice. To protect you need register an independent stack for the signal handler.</p>\n\n<p>You can check this with code below. By default the handler fails. With defined macro STACK_OVERFLOW it\'s all right.</p>\n\n<pre><code>#include <iostream>\n#include <execinfo.h>\n#include <signal.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <string>\n#include <cassert>\n\nusing namespace std;\n\n//#define STACK_OVERFLOW\n\n#ifdef STACK_OVERFLOW\nstatic char stack_body[64*1024];\nstatic stack_t sigseg_stack;\n#endif\n\nstatic struct sigaction sigseg_handler;\n\nvoid handler(int sig) {\n cerr << "sig seg fault handler" << endl;\n const int asize = 10;\n void *array[asize];\n size_t size;\n\n // get void*\'s for all entries on the stack\n size = backtrace(array, asize);\n\n // print out all the frames to stderr\n cerr << "stack trace: " << endl;\n backtrace_symbols_fd(array, size, STDERR_FILENO);\n cerr << "resend SIGSEGV to get core dump" << endl;\n signal(sig, SIG_DFL);\n kill(getpid(), sig);\n}\n\nvoid foo() {\n foo();\n}\n\nint main(int argc, char **argv) {\n#ifdef STACK_OVERFLOW\n sigseg_stack.ss_sp = stack_body;\n sigseg_stack.ss_flags = SS_ONSTACK;\n sigseg_stack.ss_size = sizeof(stack_body);\n assert(!sigaltstack(&sigseg_stack, nullptr));\n sigseg_handler.sa_flags = SA_ONSTACK;\n#else\n sigseg_handler.sa_flags = SA_RESTART; \n#endif\n sigseg_handler.sa_handler = &handler;\n assert(!sigaction(SIGSEGV, &sigseg_handler, nullptr));\n cout << "sig action set" << endl;\n foo();\n return 0;\n} \n</code></pre>\n'}, {'answer_id': 38224204, 'author': 'loopzilla', 'author_id': 4182817, 'author_profile': 'https://Stackoverflow.com/users/4182817', 'pm_score': 3, 'selected': False, 'text': '<p>Forget about changing your sources and do some hacks with backtrace() function or macroses - these are just poor solutions.</p>\n\n<p>As a properly working solution, I would advice:</p>\n\n<ol>\n<li>Compile your program with "-g" flag for embedding debug symbols to binary (don\'t worry this will not impact your performance). </li>\n<li>On linux run next command: "ulimit -c unlimited" - to allow system make big crash dumps.</li>\n<li>When your program crashed, in the working directory you will see file "core".</li>\n<li>Run next command to print backtrace to stdout: gdb -batch -ex "backtrace" ./your_program_exe ./core</li>\n</ol>\n\n<p>This will print proper readable backtrace of your program in human readable way (with source file names and line numbers).\nMoreover this approach will give you freedom to automatize your system:\nhave a short script that checks if process created a core dump, and then send backtraces by email to developers, or log this into some logging system.</p>\n'}, {'answer_id': 41404312, 'author': 'Roy', 'author_id': 1040618, 'author_profile': 'https://Stackoverflow.com/users/1040618', 'pm_score': 4, 'selected': False, 'text': '<p>The new king in town has arrived\n<a href="https://github.com/bombela/backward-cpp" rel="noreferrer">https://github.com/bombela/backward-cpp</a></p>\n\n<p>1 header to place in your code and 1 library to install.</p>\n\n<p>Personally I call it using this function</p>\n\n<pre><code>#include "backward.hpp"\nvoid stacker() {\n\nusing namespace backward;\nStackTrace st;\n\n\nst.load_here(99); //Limit the number of trace depth to 99\nst.skip_n_firsts(3);//This will skip some backward internal function from the trace\n\nPrinter p;\np.snippet = true;\np.object = true;\np.color = true;\np.address = true;\np.print(st, stderr);\n}\n</code></pre>\n'}, {'answer_id': 49050274, 'author': 'IInspectable', 'author_id': 1889329, 'author_profile': 'https://Stackoverflow.com/users/1889329', 'pm_score': 3, 'selected': False, 'text': '<p>As a Windows-only solution, you can get the equivalent of a stack trace (with much, much more information) using <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb513641.aspx" rel="nofollow noreferrer">Windows Error Reporting</a>. With just a few registry entries, it can be set up to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb787181.aspx" rel="nofollow noreferrer">collect user-mode dumps</a>:</p>\n<blockquote>\n<p>Starting with Windows Server 2008 and Windows Vista with Service Pack 1 (SP1), Windows Error Reporting (WER) can be configured so that full user-mode dumps are collected and stored locally after a user-mode application crashes. [...]</p>\n<p>This feature is not enabled by default. Enabling the feature requires administrator privileges. To enable and configure the feature, use the following registry values under the <strong>HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\LocalDumps</strong> key.</p>\n</blockquote>\n<p>You can set the registry entries from your installer, which has the required privileges.</p>\n<p>Creating a user-mode dump has the following advantages over generating a stack trace on the client:</p>\n<ul>\n<li>It\'s already implemented in the system. You can either use WER as outlined above, or call <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms680360.aspx" rel="nofollow noreferrer">MiniDumpWriteDump</a> yourself, if you need more fine-grained control over the amount of information to dump. (Make sure to call it from a different process.)</li>\n<li><strong>Way</strong> more complete than a stack trace. Among others it can contain local variables, function arguments, stacks for other threads, loaded modules, and so on. The amount of data (and consequently size) is highly customizable.</li>\n<li>No need to ship debug symbols. This both drastically decreases the size of your deployment, as well as makes it harder to reverse-engineer your application.</li>\n<li>Largely independent of the compiler you use. Using WER does not even require any code. Either way, having a way to get a symbol database (PDB) is <em>very</em> useful for offline analysis. I believe GCC can either generate PDB\'s, or there are tools to convert the symbol database to the PDB format.</li>\n</ul>\n<p>Take note, that WER can only be triggered by an application crash (i.e. the system terminating a process due to an unhandled exception). <code>MiniDumpWriteDump</code> can be called at any time. This may be helpful if you need to dump the current state to diagnose issues other than a crash.</p>\n<p>Mandatory reading, if you want to evaluate the applicability of mini dumps:</p>\n<ul>\n<li><a href="http://www.debuginfo.com/articles/effminidumps.html" rel="nofollow noreferrer">Effective minidumps</a></li>\n<li><a href="http://www.debuginfo.com/articles/effminidumps2.html" rel="nofollow noreferrer">Effective minidumps (Part 2)</a></li>\n</ul>\n'}, {'answer_id': 54427899, 'author': 'baziorek', 'author_id': 1350091, 'author_profile': 'https://Stackoverflow.com/users/1350091', 'pm_score': 4, 'selected': False, 'text': '<p>It looks like in one of last c++ boost version appeared library to provide exactly what You want, probably the code would be multiplatform.\nIt is <a href="https://www.boost.org/doc/libs/1_69_0/doc/html/stacktrace.html" rel="noreferrer">boost::stacktrace</a>, which You can use like <a href="https://www.boost.org/doc/libs/1_69_0/doc/html/stacktrace/getting_started.html" rel="noreferrer">as in boost sample</a>:</p>\n\n<pre><code>#include <filesystem>\n#include <sstream>\n#include <fstream>\n#include <signal.h> // ::signal, ::raise\n#include <boost/stacktrace.hpp>\n\nconst char* backtraceFileName = "./backtraceFile.dump";\n\nvoid signalHandler(int)\n{\n ::signal(SIGSEGV, SIG_DFL);\n ::signal(SIGABRT, SIG_DFL);\n boost::stacktrace::safe_dump_to(backtraceFileName);\n ::raise(SIGABRT);\n}\n\nvoid sendReport()\n{\n if (std::filesystem::exists(backtraceFileName))\n {\n std::ifstream file(backtraceFileName);\n\n auto st = boost::stacktrace::stacktrace::from_dump(file);\n std::ostringstream backtraceStream;\n backtraceStream << st << std::endl;\n\n // sending the code from st\n\n file.close();\n std::filesystem::remove(backtraceFileName);\n }\n}\n\nint main()\n{\n ::signal(SIGSEGV, signalHandler);\n ::signal(SIGABRT, signalHandler);\n\n sendReport();\n // ... rest of code\n}\n</code></pre>\n\n<p>In Linux You compile the code above:</p>\n\n<pre><code>g++ --std=c++17 file.cpp -lstdc++fs -lboost_stacktrace_backtrace -ldl -lbacktrace\n</code></pre>\n\n<p>Example backtrace copied from <a href="https://www.boost.org/doc/libs/1_69_0/doc/html/stacktrace/getting_started.html" rel="noreferrer">boost documentation</a>:</p>\n\n<pre><code>0# bar(int) at /path/to/source/file.cpp:70\n1# bar(int) at /path/to/source/file.cpp:70\n2# bar(int) at /path/to/source/file.cpp:70\n3# bar(int) at /path/to/source/file.cpp:70\n4# main at /path/to/main.cpp:93\n5# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6\n6# _start\n</code></pre>\n'}, {'answer_id': 55626241, 'author': 'Geoffrey', 'author_id': 637874, 'author_profile': 'https://Stackoverflow.com/users/637874', 'pm_score': 2, 'selected': False, 'text': '<p>If you still want to go it alone as I did you can link against <code>bfd</code> and avoid using <code>addr2line</code> as I have done here:</p>\n<p><a href="https://github.com/gnif/LookingGlass/blob/master/common/src/platform/linux/crash.c" rel="nofollow noreferrer">https://github.com/gnif/LookingGlass/blob/master/common/src/platform/linux/crash.c</a></p>\n<p>This produces the output:</p>\n<pre><code>[E] crash.linux.c:170 | crit_err_hdlr | ==== FATAL CRASH (a12-151-g28b12c85f4+1) ====\n[E] crash.linux.c:171 | crit_err_hdlr | signal 11 (Segmentation fault), address is (nil)\n[E] crash.linux.c:194 | crit_err_hdlr | [trace]: (0) /home/geoff/Projects/LookingGlass/client/src/main.c:936 (register_key_binds)\n[E] crash.linux.c:194 | crit_err_hdlr | [trace]: (1) /home/geoff/Projects/LookingGlass/client/src/main.c:1069 (run)\n[E] crash.linux.c:194 | crit_err_hdlr | [trace]: (2) /home/geoff/Projects/LookingGlass/client/src/main.c:1314 (main)\n[E] crash.linux.c:199 | crit_err_hdlr | [trace]: (3) /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xeb) [0x7f8aa65f809b]\n[E] crash.linux.c:199 | crit_err_hdlr | [trace]: (4) ./looking-glass-client(_start+0x2a) [0x55c70fc4aeca]\n</code></pre>\n'}, {'answer_id': 71143028, 'author': 'Oleksandr Kozlov', 'author_id': 2091463, 'author_profile': 'https://Stackoverflow.com/users/2091463', 'pm_score': 1, 'selected': False, 'text': "<pre><code>gdb -ex 'set confirm off' -ex r -ex bt -ex q <my-program>\n</code></pre>\n"}, {'answer_id': 72486459, 'author': 'Graham Toal', 'author_id': 210830, 'author_profile': 'https://Stackoverflow.com/users/210830', 'pm_score': 0, 'selected': False, 'text': '<p>You are probably not going to like this - all I can say in its favour is that it works for me, and I have similar but not identical requirements: I am writing a compiler/transpiler for a 1970\'s Algol-like language which uses C as it\'s output and then compiles the C so that as far as the user is concerned, they\'re generally not aware of C being involved, so although you might call it a transpiler, it\'s effectively a compiler that uses C as it\'s intermediate code. The language being compiled has a history of providing good diagnostics and a full backtrace in the original native compilers. I\'ve been able to find gcc compiler flags and libraries etc that allow me to trap most of the runtime errors that the original compilers did (although with one glaring exception - unassigned variable trapping). When a runtime error occurs (eg arithmetic overflow, divide by zero, array index out of bounds, etc) the original compilers output a backtrace to the console listing all variables in the stack frames of every active procedure call. I struggled to get this effect in C, but eventually did so with what can only be described as a hack... When the program is invoked, the wrapper that supplies the C "main" looks at its argv, and if a special option is not present, it restarts itself under gdb with an altered argv containing both gdb options and the \'magic\' option string for the program itself. This restarted version then hides those strings from the user\'s code by restoring the original arguments before calling the main block of the code written in our language. When an error occurs (as long as it is not one explicitly trapped within the program by user code), it exits to gdb which prints the required backtrace.</p>\n<p>Keys lines of code in the startup sequence include:</p>\n<pre><code> if ((argc >= 1) && (strcmp(origargv[argc-1], "--restarting-under-gdb")) != 0) {\n // initial invocation\n // the "--restarting-under-gdb" option is how the copy running under gdb knows\n // not to start another gdb process.\n</code></pre>\n<p>and</p>\n<pre><code> char *gdb [] = {\n "/usr/bin/gdb", "-q", "-batch", "-nx", "-nh", "-return-child-result",\n "-ex", "run",\n "-ex", "bt full",\n "--args"\n };\n</code></pre>\n<p>The original arguments are appended to the gdb options above. That should be enough of a hint for you to do something similar for your own system.\nI did look at other library-supported backtrace options (eg libbacktrace,\n<a href="https://codingrelic.geekhold.com/2010/09/gcc-function-instrumentation.html" rel="nofollow noreferrer">https://codingrelic.geekhold.com/2010/09/gcc-function-instrumentation.html</a>, etc) but they only output the procedure call stack, not the local variables. However if anyone knows of any cleaner mechanism to get a similar effect, do please let us know. The main downside to this is that the variables are printed in C syntax, not the syntax of the language the user writes in. And (until I add suitable #line directives <em>on every generated line of C :-(</em>) the backtrace lists the C source file and line numbers.</p>\n<p>G\nPS The gcc compile options I use are:</p>\n<pre><code> GCCOPTS=" -Wall -Wno-return-type -Wno-comment -g -fsanitize=undefined\n -fsanitize-undefined-trap-on-error -fno-sanitize-recover=all -frecord-gcc-switches\n -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -ftrapv\n -grecord-gcc-switches -O0 -ggdb3 "\n</code></pre>\n'}, {'answer_id': 74549444, 'author': 'Ciro Santilli OurBigBook.com', 'author_id': 895245, 'author_profile': 'https://Stackoverflow.com/users/895245', 'pm_score': 0, 'selected': False, 'text': '<p><strong>My best async signal safe attempt so far</strong></p>\n<p>Let me know if it is not actually safe. I could not yet find a way to show line numbers.</p>\n<pre><code>#include <execinfo.h>\n#include <signal.h>\n#include <stdlib.h>\n#include <unistd.h>\n\n#define TRACE_MAX 1024\n\nvoid handler(int sig) {\n (void)sig;\n void *array[TRACE_MAX];\n size_t size;\n const char msg[] = "failed with a signal\\n";\n\n size = backtrace(array, TRACE_MAX);\n write(STDERR_FILENO, msg, sizeof(msg));\n backtrace_symbols_fd(array, size, STDERR_FILENO);\n _Exit(1);\n}\n\nvoid my_func_2(void) {\n *((int*)0) = 1;\n}\n\nvoid my_func_1(double f) {\n (void)f;\n my_func_2();\n}\n\nvoid my_func_1(int i) {\n (void)i;\n my_func_2();\n}\n\nint main() {\n /* Make a dummy call to `backtrace` to load libgcc because man backrace says:\n * * backtrace() and backtrace_symbols_fd() don\'t call malloc() explicitly, but they are part of libgcc, which gets loaded dynamically when first used. Dynamic loading usually triggers a call to mal‐\n * loc(3). If you need certain calls to these two functions to not allocate memory (in signal handlers, for example), you need to make sure libgcc is loaded beforehand.\n */\n void *dummy[1];\n backtrace(dummy, 1);\n signal(SIGSEGV, handler);\n\n my_func_1(1);\n}\n</code></pre>\n<p>Compile and run:</p>\n<pre><code>g++ -ggdb3 -O2 -std=c++11 -Wall -Wextra -pedantic -rdynamic -o stacktrace_on_signal_safe.out stacktrace_on_signal_safe.cpp\n./stacktrace_on_signal_safe.out\n</code></pre>\n<p><code>-rdynamic</code> is needed to get the function names:</p>\n<pre><code>failed with a signal\n./stacktrace_on_signal_safe.out(_Z7handleri+0x6e)[0x56239398928e]\n/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f04b1459520]\n./stacktrace_on_signal_safe.out(main+0x38)[0x562393989118]\n/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f04b1440d90]\n/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f04b1440e40]\n./stacktrace_on_signal_safe.out(_start+0x25)[0x562393989155]\n</code></pre>\n<p>We can then pipe it to <code>c++filt</code> to demangle:</p>\n<pre><code>./stacktrace_on_signal_safe.out |& c++filt\n</code></pre>\n<p>giving:</p>\n<pre><code>failed with a signal\n/stacktrace_on_signal_safe.out(handler(int)+0x6e)[0x55b6df43f28e]\n/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f40d4167520]\n./stacktrace_on_signal_safe.out(main+0x38)[0x55b6df43f118]\n/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f40d414ed90]\n/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f40d414ee40]\n./stacktrace_on_signal_safe.out(_start+0x25)[0x55b6df43f155]\n</code></pre>\n<p>Several levels are missing due to optimizations, with <code>-O0</code> we get a fuller:</p>\n<pre><code>/stacktrace_on_signal_safe.out(handler(int)+0x76)[0x55d39b68325f]\n/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f4d8ffdd520]\n./stacktrace_on_signal_safe.out(my_func_2()+0xd)[0x55d39b6832bb]\n./stacktrace_on_signal_safe.out(my_func_1(int)+0x14)[0x55d39b6832f1]\n./stacktrace_on_signal_safe.out(main+0x4a)[0x55d39b68333e]\n/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f4d8ffc4d90]\n/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f4d8ffc4e40]\n./stacktrace_on_signal_safe.out(_start+0x25)[0x55d39b683125]\n</code></pre>\n<p>Line numbers are not present, but we can get them with <code>addr2line</code>. This requires building without <code>-rdynamic</code>:</p>\n<pre><code>g++ -ggdb3 -O0 -std=c++23 -Wall -Wextra -pedantic -o stacktrace_on_signal_safe.out stacktrace_on_signal_safe.cpp\n./stacktrace_on_signal_safe.out |& sed -r \'s/.*\\(//;s/\\).*//\' | addr2line -C -e stacktrace_on_signal_safe.out -f\n</code></pre>\n<p>producing:</p>\n<pre><code>??\n??:0\nhandler(int)\n/home/ciro/stacktrace_on_signal_safe.cpp:14\n??\n??:0\nmy_func_2()\n/home/ciro/stacktrace_on_signal_safe.cpp:22\nmy_func_1(i\n/home/ciro/stacktrace_on_signal_safe.cpp:33\nmain\n/home/ciro/stacktrace_on_signal_safe.cpp:45\n??\n??:0\n??\n??:0\n_start\n??:?\n</code></pre>\n<p><code>awk</code> parses the <code>+<addr></code> numbers out o the non <code>-rdynamic</code> output:</p>\n<pre><code>./stacktrace_on_signal_safe.out(+0x125f)[0x55984828825f]\n/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f8644a1e520]\n./stacktrace_on_signal_safe.out(+0x12bb)[0x5598482882bb]\n./stacktrace_on_signal_safe.out(+0x12f1)[0x5598482882f1]\n./stacktrace_on_signal_safe.out(+0x133e)[0x55984828833e]\n/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f8644a05d90]\n/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f8644a05e40]\n./stacktrace_on_signal_safe.out(+0x1125)[0x559848288125]\n</code></pre>\n<p>If you also want to print the actual signal number to stdout, here\'s an async signal safe implementation int to string: <a href="https://stackoverflow.com/questions/14573000/print-int-from-signal-handler-using-write-or-async-safe-functions/52111436#52111436">Print int from signal handler using write or async-safe functions</a> since <code>printf</code> is not.</p>\n<p>Tested on Ubuntu 22.04.</p>\n<p><strong>C++23 <code><stacktrace></code></strong></p>\n<p>Like many other answers, this section ignores async signal safe aspects of the problem, which could lead your code to deadlock on crash, which could be serious. We can only hope one day the C++ standard will add a <code>boost::stacktrace::safe_dump_to</code>-like function to solve this once and for all.</p>\n<p>This will be the generally superior C++ stacktrace option moving forward as mentioned at: <a href="https://stackoverflow.com/questions/3899870/print-call-stack-in-c-or-c/54365144#54365144">print call stack in C or C++</a> as it shows line numbers and does demangling for us automatically.</p>\n<p>stacktrace_on_signal.cpp</p>\n<pre><code>#include <stacktrace>\n#include <iostream>\n\n#include <signal.h>\n#include <stdlib.h>\n#include <unistd.h>\n\nvoid handler(int sig) {\n (void)sig;\n /* De-register this signal in the hope of avoiding infinite loops\n * if asyns signal unsafe things fail later on. But can likely still deadlock. */\n signal(sig, SIG_DFL);\n // std::stacktrace::current\n std::cout << std::stacktrace::current();\n // C99 async signal safe version of exit().\n _Exit(1);\n}\n\nvoid my_func_2(void) {\n *((int*)0) = 1;\n}\n\nvoid my_func_1(double f) {\n (void)f;\n my_func_2();\n}\n\nvoid my_func_1(int i) {\n (void)i;\n my_func_2();\n}\n\nint main() {\n signal(SIGSEGV, handler);\n my_func_1(1);\n}\n</code></pre>\n<p>Compile and run:</p>\n<pre><code>g++ -ggdb3 -O2 -std=c++23 -Wall -Wextra -pedantic -o stacktrace_on_signal.out stacktrace_on_signal.cpp -lstdc++_libbacktrace\n./stacktrace_on_signal.out\n</code></pre>\n<p>Output on GCC 12.1 compiled from source, Ubuntu 22.04:</p>\n<pre><code> 0# handler(int) at /home/ciro/stacktrace_on_signal.cpp:11\n 1# at :0\n 2# my_func_2() at /home/ciro/stacktrace_on_signal.cpp:16\n 3# at :0\n 4# at :0\n 5# at :0\n 6#\n</code></pre>\n<p>I think it missed <code>my_func_1</code> due to optimization being turned on, and there is in general nothing we can do about that AFAIK. With <code>-O0</code> instead it is better:</p>\n<pre><code> 0# handler(int) at /home/ciro/stacktrace_on_signal.cpp:11\n 1# at :0\n 2# my_func_2() at /home/ciro/stacktrace_on_signal.cpp:16\n 3# my_func_1(int) at /home/ciro/stacktrace_on_signal.cpp:26\n 4# at /home/ciro/stacktrace_on_signal.cpp:31\n 5# at :0\n 6# at :0\n 7# at :0\n 8#\n</code></pre>\n<p>but not sure why <code>main</code> didn\'t show up there.</p>\n<p><strong><code>backtrace_simple</code></strong></p>\n<p><a href="https://github.com/gcc-mirror/gcc/blob/releases/gcc-12.1.0/libstdc%2B%2B-v3/src/libbacktrace/backtrace-supported.h.in#L45" rel="nofollow noreferrer">https://github.com/gcc-mirror/gcc/blob/releases/gcc-12.1.0/libstdc%2B%2B-v3/src/libbacktrace/backtrace-supported.h.in#L45</a> mentions that <code>backtrace_simple</code> is safe:</p>\n<pre><code>/* BACKTRACE_USES_MALLOC will be #define\'d as 1 if the backtrace\n library will call malloc as it works, 0 if it will call mmap\n instead. This may be used to determine whether it is safe to call\n the backtrace functions from a signal handler. In general this\n only applies to calls like backtrace and backtrace_pcinfo. It does\n not apply to backtrace_simple, which never calls malloc. It does\n not apply to backtrace_print, which always calls fprintf and\n therefore malloc. */\n</code></pre>\n<p>but it does not appear very convenient for usage, mostly an internal tool.</p>\n<p><strong><code>std::basic_stacktrace</code></strong></p>\n<p>This is what <code>std::stacktrace</code> is based on according to: <a href="https://en.cppreference.com/w/cpp/utility/basic_stacktrace" rel="nofollow noreferrer">https://en.cppreference.com/w/cpp/utility/basic_stacktrace</a></p>\n<p>It has an allocator parameter which cppreference describes as:</p>\n<blockquote>\n<p>Support for custom allocators is provided for using basic_stacktrace on a hot path or in embedded environments. Users can allocate stacktrace_entry objects on the stack or in some other place, where appropriate.</p>\n</blockquote>\n<p>so I wonder if <code>basic_stacktrace</code> is itself async signal safe, and if it wouldn\'t be possible to make a version of <code>std::stacktrace</code> that is also with a custom allocator, e.g. either something that:</p>\n<ul>\n<li>writes to a file on disk like <code>boost::stacktrace::safe_dump_to</code></li>\n<li>or writes to some pre-alocated stack buffer with some maximum size</li>\n</ul>\n<p><a href="https://apolukhin.github.io/papers/stacktrace_r1.html" rel="nofollow noreferrer">https://apolukhin.github.io/papers/stacktrace_r1.html</a> might be the proposal that got in, mentions:</p>\n<blockquote>\n<p>Note about signal safety: this proposal does not attempt to provide a signal-safe solution for capturing and decoding stacktraces. Such functionality currently is not implementable on some of the popular platforms. However, the paper attempts to provide extensible solution, that may be made signal safe some day by providing a signal safe allocator and changing the stacktrace implementation details.</p>\n</blockquote>\n<p><strong>Just getting the core dump instead?</strong></p>\n<p>The core dump allows you to inspect memory with GDB: <a href="https://stackoverflow.com/questions/8305866/how-do-i-analyze-a-programs-core-dump-file-with-gdb-when-it-has-command-line-pa/54943610#54943610">How do I analyze a program's core dump file with GDB when it has command-line parameters?</a> so it is more powerful than just having the trace.</p>\n<p>Just make sure you enable it properly, notably on Ubuntu 22.04 you need:</p>\n<pre><code>echo \'core\' | sudo tee /proc/sys/kernel/core_pattern\n</code></pre>\n<p>or to learn to use apport, see also: <a href="https://askubuntu.com/questions/1349047/where-do-i-find-core-dump-files-and-how-do-i-view-and-analyze-the-backtrace-st/1442665#1442665">https://askubuntu.com/questions/1349047/where-do-i-find-core-dump-files-and-how-do-i-view-and-analyze-the-backtrace-st/1442665#1442665</a></p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77005', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13676/']
|
77,013 |
<p>I am looking for an open-source project involving c++ GUI(s) working with a database. I have not done it before, and am looking for a way to get my feet wet. Which can I work on?</p>
|
[{'answer_id': 77032, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 1, 'selected': False, 'text': '<p>Anything that you like and feel that you can contribute to.</p>\n'}, {'answer_id': 77049, 'author': 'benefactual', 'author_id': 6445, 'author_profile': 'https://Stackoverflow.com/users/6445', 'pm_score': 3, 'selected': True, 'text': '<p>How about this one <a href="http://sourceforge.net/projects/sqlitebrowser/" rel="nofollow noreferrer">http://sourceforge.net/projects/sqlitebrowser/</a>:</p>\n\n<blockquote>\n <p>SQLite Database browser is a light GUI editor for SQLite databases, built on top of QT. The main goal of the project is to allow non-technical users to create, modify and edit SQLite databases using a set of wizards and a spreadsheet-like interface.</p>\n</blockquote>\n'}, {'answer_id': 77051, 'author': 'Jonathan Arkell', 'author_id': 11052, 'author_profile': 'https://Stackoverflow.com/users/11052', 'pm_score': 2, 'selected': False, 'text': '<p>Do a project you can get <strong>involved</strong> in and passionate about. Hopefully a product you use every day. </p>\n'}, {'answer_id': 77069, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 0, 'selected': False, 'text': '<p>Sourceforge has a help wanted page: <a href="http://sourceforge.net/people/" rel="nofollow noreferrer">http://sourceforge.net/people/</a></p>\n\n<p>browse the postings to see if a project is in your expertise or find one that sound interesting...</p>\n\n<p>And let me be the first to say thank you for being willing to contribute your time and knowlede to the open source movement.</p>\n'}, {'answer_id': 77073, 'author': 'Jon Homan', 'author_id': 7589, 'author_profile': 'https://Stackoverflow.com/users/7589', 'pm_score': 1, 'selected': False, 'text': "<p>In my brief experience contributing to an open-source project, I found two points keep me contributing:</p>\n\n<ul>\n<li>Great people - the other people contributing were fun to collaborate with and hang out with (virtually).</li>\n<li>Project you care about - doesn't really matter which project as long as the its goals are something you want to spend your free time working on.</li>\n</ul>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77013', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13790/']
|
77,025 |
<p>I want to set a breakpoint on the <code>__DoPostBack</code> method, but it's a pain to find the correct file to set the breakpoint in.</p>
<p>The method <code>__DoPostBack</code> is contained in an auto-generated js file called something like: </p>
<pre><code>ScriptResource.axd?d=P_lo2...
</code></pre>
<p>After a few post-backs visual studio gets littered with many of these files, and it's a bit of a bear to check which one the current page is referencing. Any thoughts?</p>
|
[{'answer_id': 77032, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 1, 'selected': False, 'text': '<p>Anything that you like and feel that you can contribute to.</p>\n'}, {'answer_id': 77049, 'author': 'benefactual', 'author_id': 6445, 'author_profile': 'https://Stackoverflow.com/users/6445', 'pm_score': 3, 'selected': True, 'text': '<p>How about this one <a href="http://sourceforge.net/projects/sqlitebrowser/" rel="nofollow noreferrer">http://sourceforge.net/projects/sqlitebrowser/</a>:</p>\n\n<blockquote>\n <p>SQLite Database browser is a light GUI editor for SQLite databases, built on top of QT. The main goal of the project is to allow non-technical users to create, modify and edit SQLite databases using a set of wizards and a spreadsheet-like interface.</p>\n</blockquote>\n'}, {'answer_id': 77051, 'author': 'Jonathan Arkell', 'author_id': 11052, 'author_profile': 'https://Stackoverflow.com/users/11052', 'pm_score': 2, 'selected': False, 'text': '<p>Do a project you can get <strong>involved</strong> in and passionate about. Hopefully a product you use every day. </p>\n'}, {'answer_id': 77069, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 0, 'selected': False, 'text': '<p>Sourceforge has a help wanted page: <a href="http://sourceforge.net/people/" rel="nofollow noreferrer">http://sourceforge.net/people/</a></p>\n\n<p>browse the postings to see if a project is in your expertise or find one that sound interesting...</p>\n\n<p>And let me be the first to say thank you for being willing to contribute your time and knowlede to the open source movement.</p>\n'}, {'answer_id': 77073, 'author': 'Jon Homan', 'author_id': 7589, 'author_profile': 'https://Stackoverflow.com/users/7589', 'pm_score': 1, 'selected': False, 'text': "<p>In my brief experience contributing to an open-source project, I found two points keep me contributing:</p>\n\n<ul>\n<li>Great people - the other people contributing were fun to collaborate with and hang out with (virtually).</li>\n<li>Project you care about - doesn't really matter which project as long as the its goals are something you want to spend your free time working on.</li>\n</ul>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77025', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7936/']
|
77,034 |
<p>I would like to display multiple colors (and potentially shapes and sizes) of data points in a Google Chart scatter chart. Does anyone have an example of how to do so?</p>
|
[{'answer_id': 77065, 'author': 'davethegr8', 'author_id': 12930, 'author_profile': 'https://Stackoverflow.com/users/12930', 'pm_score': 2, 'selected': False, 'text': '<p>You can only use one dataset in a scatter plot, thus only one color.</p>\n\n<p><a href="http://code.google.com/apis/chart/#scatter_plot" rel="nofollow noreferrer">http://code.google.com/apis/chart/#scatter_plot</a></p>\n\n<p><em>From the API description:</em></p>\n\n<blockquote>\n <p>Scatter plots use multiple data sets differently than other chart types. You can only show one data set in a scatter plot. </p>\n</blockquote>\n'}, {'answer_id': 77155, 'author': 'Tyler', 'author_id': 3561, 'author_profile': 'https://Stackoverflow.com/users/3561', 'pm_score': 1, 'selected': False, 'text': '<p>You could effectively fake a multi-color scatter plot by using a line plot with white lines and colored <a href="http://code.google.com/apis/chart/#shape_markers2" rel="nofollow noreferrer">shape markers</a> at the points you want to display.</p>\n'}, {'answer_id': 77448, 'author': 'Kent Beck', 'author_id': 13842, 'author_profile': 'https://Stackoverflow.com/users/13842', 'pm_score': 3, 'selected': True, 'text': '<p>I answered my own question after waiting SECONDS for an answer here :-)</p>\n\n<p>You can indeed have different colors for different data elements. For example:</p>\n\n<p><a href="http://chart.apis.google.com/chart?chs=300x200&cht=s&chd=t:1,2,3|6,5,4&chds=1,3,0,10&chxt=x,y&chxl=0:|0|1|2|1:|0|10&chm=d,ff0000,0,0,8,0|a,ff8080,0,1,42,0|c,ffff00,0,2,16,0" rel="nofollow noreferrer">http://chart.apis.google.com/chart?chs=300x200&cht=s&chd=t:1,2,3|6,5,4&chds=1,3,0,10&chxt=x,y&chxl=0:|0|1|2|1:|0|10&chm=d,ff0000,0,0,8,0|a,ff8080,0,1,42,0|c,ffff00,0,2,16,0</a></p>\n\n<p>It\'s the chm= that does the magic. I was trying to have multiple chm= statements. You need to have just one, but with multiple descriptions separated by vertical bars.</p>\n'}, {'answer_id': 3086991, 'author': 'craig', 'author_id': 134367, 'author_profile': 'https://Stackoverflow.com/users/134367', 'pm_score': 0, 'selected': False, 'text': '<p>Here\'s another example: <a href="http://www.xefer.com/twitter/gruber" rel="nofollow noreferrer">twitter charts</a>. I\'m hoping to do the same thing. Need to find out how to do the concentric circles.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77034', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13842/']
|
77,082 |
<p>Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of a very large system, so it really wouldn't be wise for me to revise the table structure (the app is filled with similar tables).</p>
<p>This is a webapp in C# .NET - data comes in from a webservice and is displayed onscreen in a table. The table's rows are generated with asp:Repeaters, so that the rows alternate colers nicely. The table previously held one item of data per row. Now, essentially, the table has sub-headers... The first row is the date, the second row shows a line of data, and all the next rows are data rows until data of a new date comes in, in which case there will be another sub-header row.</p>
<p>At first I thought I could cheat a little and do this pretty easily to keep the current repeater structure- I just need to feed some cells the empty string so that no data appears in them. Now, however, we're considering one of those +/- collapsers next to each date, so that they can collapse all the data. My mind immediately went to hiding rows when a button is pressed... but I don't know how to hide rows from the code behind unless the row has a unique id, and I'm not sure if you can do that with repeaters.</p>
<p>I hope I've expressed the problem well. I'm sure I'll find a way TBH but I just saw this site on slashdot and thought I'd give it a whirl :)</p>
|
[{'answer_id': 77104, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 2, 'selected': True, 'text': '<p>When you build the row in the databinding event, you can add in a unique identifier using say the id of the data field or something else that you use to make it unique.</p>\n\n<p>Then you could use a client side method to expand collapse if you want to fill it with data in the beginning, toggling the style.display setting in Javascript for the table row element.</p>\n'}, {'answer_id': 77105, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 0, 'selected': False, 'text': '<p><strike>just wrap the contents of the item template in an asp:Panel, then you have you have a unique id.</strike> Then throw in <a href="http://www.learningjquery.com/2007/03/accordion-madness" rel="nofollow noreferrer">some jquery</a> for some spice ;)</p>\n\n<p><strong>edit</strong>: just noticed that you are using a table. put the id on the row. then toggle it.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77082', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13732/']
|
77,086 |
<p>Which is faster, python webpages or php webpages?</p>
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? </p>
<p>I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p>
<p>I enjoy using pylons and I would still use it if it was slower than php. But if pylons was faster than php, I could maybe, hopefully, eventually convince my employer to allow me to convert the site over to pylons.</p>
|
[{'answer_id': 77093, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 2, 'selected': False, 'text': "<p>If it ain't broke don't fix it.</p>\n\n<p>Just write a quick test, but bear in mind that each language will be faster with certain functions then the other.</p>\n"}, {'answer_id': 77112, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 0, 'selected': False, 'text': '<p>The only right answer is "It depends". There\'s a lot of variables that can affect the performance, and you can optimize many things in either situation.</p>\n'}, {'answer_id': 77166, 'author': 'Peter Bailey', 'author_id': 8815, 'author_profile': 'https://Stackoverflow.com/users/8815', 'pm_score': 2, 'selected': False, 'text': '<p>You need to be able to make a business case for switching, not just that "it\'s faster". If a site built on technology B costs 20% more in developer time for maintenance over a set period (say, 3 years), it would likely be cheaper to add another webserver to the system running technology A to bridge the performance gap.</p>\n\n<p>Just saying "we should switch to technology B because technology B is <em>faster!</em>" doesn\'t really work.</p>\n\n<p>Since Python is far less ubiquitous than PHP, I wouldn\'t be surprised if hosting, developer, and other maintenance costs for it (long term) would have it fit this scenario.</p>\n'}, {'answer_id': 77174, 'author': 'indentation', 'author_id': 7706, 'author_profile': 'https://Stackoverflow.com/users/7706', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s about the same. The difference shouldn\'t be large enough to be the reason to pick one or the other. Don\'t try to compare them by writing your own tiny benchmarks (<code>"hello world"</code>) because you will probably not have results that are representative of a real web site generating a more complex page.</p>\n'}, {'answer_id': 77220, 'author': 'SCdF', 'author_id': 1666, 'author_profile': 'https://Stackoverflow.com/users/1666', 'pm_score': 2, 'selected': False, 'text': "<p>PHP and Python are similiar enough to not warrent any kind of switching.</p>\n\n<p>Any performance improvement you might get from switching from one language to another would be vastly outgunned by simply not spending the money on converting the code (you don't code for free right?) and just buy more hardware.</p>\n"}, {'answer_id': 77297, 'author': 'Rob', 'author_id': 3542, 'author_profile': 'https://Stackoverflow.com/users/3542', 'pm_score': 5, 'selected': False, 'text': "<p>There's no point in attempting to convince your employer to port from PHP to Python, especially not for an existing system, which is what I think you implied in your question.</p>\n\n<p>The reason for this is that you already have a (presumably) working system, with an existing investment of time and effort (and experience). To discard this in favour of a trivial performance gain (not that I'm claiming there would be one) would be foolish, and no manager worth his salt ought to endorse it.</p>\n\n<p>It may also create a problem with maintainability, depending on who else has to work with the system, and their experience with Python.</p>\n"}, {'answer_id': 79744, 'author': 'Ross', 'author_id': 14794, 'author_profile': 'https://Stackoverflow.com/users/14794', 'pm_score': 8, 'selected': True, 'text': '<p>It sounds like you don\'t want to compare the two <strong>languages</strong>, but that you want to compare two <strong>web systems</strong>.</p>\n\n<p>This is tricky, because there are many variables involved.</p>\n\n<p>For example, Python web applications can take advantage of <a href="http://code.google.com/p/modwsgi/" rel="noreferrer">mod_wsgi</a> to talk to web servers, which is faster than any of the typical ways that PHP talks to web servers (even mod_php ends up being slower if you\'re using Apache, because Apache can only use the Prefork MPM with mod_php rather than multi-threaded MPM like Worker).</p>\n\n<p>There is also the issue of code compilation. As you know, Python is compiled just-in-time to byte code (.pyc files) when a file is run each time the file changes. Therefore, after the first run of a Python file, the compilation step is skipped and the Python interpreter simply fetches the precompiled .pyc file. Because of this, one could argue that Python has a native advantage over PHP. However, optimizers and caching systems can be installed for PHP websites (my favorite is <a href="http://eaccelerator.net/" rel="noreferrer">eAccelerator</a>) to much the same effect.</p>\n\n<p>In general, enough tools exist such that one can pretty much do everything that the other can do. Of course, as others have mentioned, there\'s more than just speed involved in the business case to switch languages. We have an app written in oCaml at my current employer, which turned out to be a mistake because the original author left the company and nobody else wants to touch it. Similarly, the PHP-web community is much larger than the Python-web community; Website hosting services are more likely to offer PHP support than Python support; etc.</p>\n\n<p>But back to speed. You must recognize that the question of speed here involves many moving parts. Fortunately, many of these parts can be independently optimized, affording you various avenues to seek performance gains.</p>\n'}, {'answer_id': 510276, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>an IS organization would not ponder this unless availability was becoming an issue.</p>\n\n<p>if so the case, look into replication, load balancing and lots of ram.</p>\n'}, {'answer_id': 2412215, 'author': 'notageek', 'author_id': 289967, 'author_profile': 'https://Stackoverflow.com/users/289967', 'pm_score': -1, 'selected': False, 'text': '<p>I had to come back to web development at my new job, and, if not Pylons/Python, maybe I would have chosen to live in jungle instead :) In my subjective opinion, PHP is for kindergarten, I did it in my 3rd year of uni and, I believe, many self-respecting (or over-estimating) software engineers will not want to be bothered with PHP code. </p>\n\n<p>Why my employers agreed? We (the team) just switched to Python, and they did not have much to say. The website still is and will be PHP, but we are developing other applications, including web, in Python. Advantages of Pylons? You can integrate your python libraries into the web app, and that is, imho, a huge advantage.</p>\n\n<p>As for performance, we are still having troubles.</p>\n'}, {'answer_id': 33627050, 'author': 'RubbelDeCatc', 'author_id': 2504554, 'author_profile': 'https://Stackoverflow.com/users/2504554', 'pm_score': 3, 'selected': False, 'text': '<p>I would assume that PHP (>5.5) is faster and more reliable for complex web applications because it is optimized for website scripting.</p>\n\n<p>Many of the benchmarks you will find at the net are only made to prove that the favoured language is better. But you can not compare 2 languages with a mathematical task running X-times. For a real benchmark you need two comparable frameworks with hundreds of classes/files an a web application running 100 clients at once.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77086', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13778/']
|
77,090 |
<p>I've used the <a href="http://groups.csail.mit.edu/pag/continuoustesting/" rel="noreferrer">MIT Continuous testing</a> plugin in the past, but it has long since passed out of date and is no longer compatible with anything approaching a modern release of Eclipse. </p>
<p>Does anyone have a good replacement? Free, naturally, is preferred. </p>
|
[{'answer_id': 77260, 'author': 'Bradley Harris', 'author_id': 10503, 'author_profile': 'https://Stackoverflow.com/users/10503', 'pm_score': 2, 'selected': False, 'text': '<p>There is a list in this Ben Rady article at Object Mentor: <a href="http://blog.objectmentor.com/articles/2007/09/20/continuous-testing-explained" rel="nofollow noreferrer">Continuous Testing Explained</a>. Unfortunately the only Eclipse tool appears to be <a href="http://ct-eclipse.tigris.org/" rel="nofollow noreferrer">CT-Eclipse</a> which is not currently maintained either.</p>\n\n<p>There is also <a href="http://swing1979.googlepages.com/fireworks" rel="nofollow noreferrer">Fireworks</a> for IntelliJ and <a href="http://www.infinitest.org/" rel="nofollow noreferrer">Infinitest</a> which is not IDE specific but also has some IntelliJ integration.</p>\n'}, {'answer_id': 88380, 'author': 'Oisin Hurley', 'author_id': 16912, 'author_profile': 'https://Stackoverflow.com/users/16912', 'pm_score': 2, 'selected': False, 'text': '<p>My experience is that continuous testing within the IDE can become unwieldy and distracting, so I prefer to use something like <a href="http://cruisecontrol.sourceforge.net/" rel="nofollow noreferrer">CruiseControl</a> to do this kind of testing. One tool I have found very useful is <a href="http://www.eclemma.org/" rel="nofollow noreferrer">EclEmma</a>, which gives you a very fast coverage turnaround for your units, helping you to decide when you have finished testing a particular area of the code.</p>\n'}, {'answer_id': 161228, 'author': 's3v1', 'author_id': 17554, 'author_profile': 'https://Stackoverflow.com/users/17554', 'pm_score': 1, 'selected': False, 'text': "<p>I've had good experience with infinitest on a small and simple project. I've not run into any issues with it and find it fast and helpful.</p>\n"}, {'answer_id': 1479467, 'author': 'awied', 'author_id': 13812, 'author_profile': 'https://Stackoverflow.com/users/13812', 'pm_score': 4, 'selected': True, 'text': '<p>I found that <a href="http://infinitest.github.com/" rel="noreferrer">Infinitest</a> now has an Eclipse plugin that seems to work pretty well. </p>\n'}, {'answer_id': 2986441, 'author': 'Mo Mo', 'author_id': 359953, 'author_profile': 'https://Stackoverflow.com/users/359953', 'pm_score': 2, 'selected': False, 'text': '<p>Infinitest decides what tests it wants to run. Often it runs the wrong ones. Green bar sometimes good, sometimes meaningless.</p>\n'}, {'answer_id': 6425104, 'author': 'Bananeweizen', 'author_id': 44089, 'author_profile': 'https://Stackoverflow.com/users/44089', 'pm_score': 1, 'selected': False, 'text': '<p>I also use Infinitest (and voted for one of its answers), but I wanted to add another approach, which <strong>relies on the build server</strong>. Whenever you want to implement something, create a branch in your VCS, do your changes, commit to your branch. If you have a build server configured, which runs unit tests on every checkin, your unit tests are then run on the build server without actually having polluted the trunk (or HEAD, whatever you call it) and without you waiting for the test run to finish.</p>\n\n<p>I admit that this is not really continuous unit testing in the sense you asked the question, but for large projects or large test suites even a "normal" continuous test runner may slow you down way to much.</p>\n\n<p>For small projects I also recommend Infinitest or CT Eclipse.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77090', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13812/']
|
77,102 |
<p>I am programmatically creating PDFs, and a recent change to my generator is creating documents that crash both Mac Preview and Adobe Reader on my Mac. Before Adobe Reader crashes, it reports:</p>
<blockquote>
<p>There was an error processing a page.
There was a problem reading this document (18).</p>
</blockquote>
<p>I suspect that that "18" might give me some information on what is wrong with the PDF I've created. Is there a document explaining the meaning of these status codes?</p>
|
[{'answer_id': 78506, 'author': 'flxkid', 'author_id': 13036, 'author_profile': 'https://Stackoverflow.com/users/13036', 'pm_score': 3, 'selected': False, 'text': '<p>Hold down the Ctrl key while pressing OK and you should be able to load past this point in the document and possibly get more details.</p>\n\n<p>What tool are you using to create the PDF (Aspose)?</p>\n'}, {'answer_id': 83996, 'author': 'Ryan Olson', 'author_id': 166, 'author_profile': 'https://Stackoverflow.com/users/166', 'pm_score': 2, 'selected': False, 'text': '<p>I wasn\'t able to locate any info on the Adobe error code, so I ended up installing <a href="http://xpdf.darwinports.com/" rel="nofollow noreferrer">xpdf via Darwinports</a>. Loading my PDF with xpdf spit out much more useful error information and I was able to track down the problem. (I was creating a circular reference in a form when I copied content from one document to another.) </p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77102', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/166/']
|
77,126 |
<p>What are some suggestions for easy to use C++ compilers for a beginner? Free or open-source ones would be preferred.</p>
|
[{'answer_id': 77146, 'author': 'Keith Nicholas', 'author_id': 10431, 'author_profile': 'https://Stackoverflow.com/users/10431', 'pm_score': 1, 'selected': False, 'text': '<p>Microsoft Visual Studio Express Edition of their C++ compiler is good</p>\n'}, {'answer_id': 77147, 'author': 'Matt Price', 'author_id': 852, 'author_profile': 'https://Stackoverflow.com/users/852', 'pm_score': 5, 'selected': True, 'text': "<p>GCC is a good choice for simple things.</p>\n\n<p>Visual Studio Express edition is the free version of the major windows C++ compiler.</p>\n\n<p>If you are on Windows I would use VS. If you are on linux you should use GCC.</p>\n\n<p>*I say GCC for simple things because for a more complicated project the build process isn't so easy</p>\n"}, {'answer_id': 77154, 'author': 'toluju', 'author_id': 12457, 'author_profile': 'https://Stackoverflow.com/users/12457', 'pm_score': 2, 'selected': False, 'text': '<p>I\'d recommend using <a href="http://www.bloodshed.net/devcpp.html" rel="nofollow noreferrer">Dev C++</a>. It\'s a small and lightweight IDE that uses the mingw ports as the backend, meaning you\'ll be compiling the the defacto C/C++ compiler, <a href="http://gcc.gnu.org/" rel="nofollow noreferrer">gcc</a> </p>\n'}, {'answer_id': 77159, 'author': 'Jonathan Mueller', 'author_id': 13832, 'author_profile': 'https://Stackoverflow.com/users/13832', 'pm_score': 2, 'selected': False, 'text': '<p>G++ is the GNU C++ compiler. Most *nix distros should have the package available.</p>\n'}, {'answer_id': 77162, 'author': 'MP24', 'author_id': 6206, 'author_profile': 'https://Stackoverflow.com/users/6206', 'pm_score': 2, 'selected': False, 'text': '<p>You can always use the C++ compiler from the Gnu Compiler Collection (GCC). It is available for almost any Unix system on earth, BSDs, Mac OS, Linux, and Windows (via Cygwin or mingw).</p>\n\n<p>A number of IDEs are supporting the GCC C++ compiler, e.g. KDevelop under Linux/KDE, or Dev-CPP as mentioned in other posts.</p>\n'}, {'answer_id': 77170, 'author': 'Tom Ritter', 'author_id': 8435, 'author_profile': 'https://Stackoverflow.com/users/8435', 'pm_score': 2, 'selected': False, 'text': "<p>For a beginner: g++ --pedantic-errors -Wall</p>\n\n<p>It'll help enforce good programming from the start.</p>\n"}, {'answer_id': 77201, 'author': 'INS', 'author_id': 13136, 'author_profile': 'https://Stackoverflow.com/users/13136', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.codeblocks.org/" rel="nofollow noreferrer">CodeBlocks</a> is a very good IDE that can use besides many other compilers CL.EXE (from visual studio) and gcc. It comes also in a version with gcc included.</p>\n\n<p>Visual Studio Express edition is avery good choice also (with Platform SDK if you will develop application that call winapi functions). </p>\n'}, {'answer_id': 77215, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>gcc with -Wall (enable all warnings) -Werror (change warnings into errors), -pedantic (get warnings for non-standard code) and -ansi (make the standard c++98).</p>\n\n<p>If a warning is something you're aware of and need to turn off, you can always turn them back into warnings.</p>\n"}, {'answer_id': 77245, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>Eclipse is a good one for mac, or Apple's own free Xcode which can be d/l'd off their development site.</p>\n"}, {'answer_id': 77307, 'author': 'magpulse', 'author_id': 13581, 'author_profile': 'https://Stackoverflow.com/users/13581', 'pm_score': 2, 'selected': False, 'text': "<p>I recommend gcc because it's designed to be used on the command line, and you can compile simple programs and see exactly what's happening:</p>\n\n<pre><code>g++ -o myprogram myprogram.cc\nls -l myprogram\n</code></pre>\n\n<p>One file in, two files out. With Visual C++, most people use it with the GUI, where you have to set up a project and the IDE generates a bunch of files which can get in the way if you're just starting out.</p>\n\n<p>If you're using Windows, you'll choose between MingW or Cygwin. Cygwin is a little work to set up because you have to choose which packages to install, but I don't have experience with MingW.</p>\n"}, {'answer_id': 77519, 'author': 'Cyber Oliveira', 'author_id': 9793, 'author_profile': 'https://Stackoverflow.com/users/9793', 'pm_score': 0, 'selected': False, 'text': '<p>Visual Studio in command line behaves just like GCC. Just open the Visual Studio command line window and:</p>\n\n<p><code><pre>\nc:\\temp> cl /nologo /EHsc /W4 foo.cpp\nc:\\temp> dir /b foo.*\nfoo.cpp <-- your source file\nfoo.obj <-- result of compiling the cpp file\nfoo.pdb <-- debugging symbols (friendly names for debugging)\nfoo.exe <-- result of linking the obj with libraries\n</pre></code></p>\n'}, {'answer_id': 77556, 'author': 'user14055', 'author_id': 14055, 'author_profile': 'https://Stackoverflow.com/users/14055', 'pm_score': 1, 'selected': False, 'text': "<p>One reason to use g++ or MingW/Cygwin that hasn't been mentioned yet is that starting and IDE will hide some of what is going on. It will be incredibly useful down the road to understand the differences between compiling and linking for instance. Learn it and understand it from the start, and you won't even know you should be thanking yourself later.</p>\n\n<p>-Max</p>\n"}, {'answer_id': 77724, 'author': 'paercebal', 'author_id': 14089, 'author_profile': 'https://Stackoverflow.com/users/14089', 'pm_score': 0, 'selected': False, 'text': "<p>I agree with Iulian Șerbănoiu: <strong>Code::Blocks is a very good solution</strong>, usable both from Linux (it will use g++/gcc) and from Windows (it will use either the MS compiler or gcc)</p>\n\n<p>Note that you should at least once or twice try to compile using a good old makefile, if only to understand the logic behind headers, sources, inclusion, etc. etc..</p>\n\n<p>As a beginner, don't forget to read books about C++ (Scott Meyers and Herb Sutter books come to the mind, when trying to learns the quirks of the language), and to study open source high profile projects to learn from their code style (they already encountered the problems you will encounter, and probably found viable solutions...).</p>\n"}, {'answer_id': 77862, 'author': 'KeyserSoze', 'author_id': 14116, 'author_profile': 'https://Stackoverflow.com/users/14116', 'pm_score': 1, 'selected': False, 'text': "<p><code>I say GCC for simple things because for a more complicated project the build process isn't so easy</code></p>\n\n<p>True, but I don't think understanding the build process of a large project is orthogonal to understanding the project itself. My last job I worked at, they had a huge project that needed to build for the target platform (LynxOS) as well as an emulation environment (WinXP). They chose to throw everything into one .VCP file for on windows, and build it as one big executable. On target it was about 50 individual processes, so they wrote a makefile that listed all 3000 source files, compiled them all into one big library, and then linked the individual main.cpp's for each executable with the all-in-one library, to make 50 executables (which shared maybe 10% of their code with the other executables). As a result, no developer had a clue about what code depended on any other code. As a result, they never bothered trying to define clean interfaces between anything, because everything was easily accessible from <em>everywhere</em>. A hierarchical build system could have helped enforce some sort of order in an otherwise disorganized source code repository.</p>\n\n<p>If you don't learn how .cpp files produce object code, what a static library is, what a shared library is, etc., when you are learning C/C++, you do still need to learn it at some point to be a competent C/C++ developer.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77126', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13846/']
|
77,127 |
<p>I have exceptions created for every condition that my application does not expect. <code>UserNameNotValidException</code>, <code>PasswordNotCorrectException</code> etc.</p>
<p>However I was told I should not create exceptions for those conditions. In my UML those ARE exceptions to the main flow, so why should it not be an exception?</p>
<p>Any guidance or best practices for creating exceptions?</p>
|
[{'answer_id': 77161, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 4, 'selected': False, 'text': '<p>Exceptions are a somewhat costly effect, if for example you have a user that provides an invalid password, it is typically a better idea to pass back a failure flag, or some other indicator that it is invalid.</p>\n\n<p>This is due to the way that exceptions are handled, true bad input, and unique critical stop items should be exceptions, but not failed login info.</p>\n'}, {'answer_id': 77164, 'author': 'blowdart', 'author_id': 2525, 'author_profile': 'https://Stackoverflow.com/users/2525', 'pm_score': 8, 'selected': False, 'text': "<p>Because they're things that will happen normally. Exceptions are not control flow mechanisms. Users often get passwords wrong, it's not an exceptional case. Exceptions should be a truly rare thing, <code>UserHasDiedAtKeyboard</code> type situations.</p>\n"}, {'answer_id': 77175, 'author': 'EricSchaefer', 'author_id': 8976, 'author_profile': 'https://Stackoverflow.com/users/8976', 'pm_score': 5, 'selected': False, 'text': "<p>It is NOT an exception if the username is not valid or the password is not correct. Those are things you should expect in the normal flow of operation. Exceptions are things that are not part of the normal program operation and are rather rare.</p>\n<p>I do not like using exceptions because you can not tell if a method throws an exception just by looking at the call. Thats why exceptions should only be used if you can't handle the situation in a decent manner (think "out of memory" or "computer is on fire").</p>\n"}, {'answer_id': 77179, 'author': 'Jon', 'author_id': 12261, 'author_profile': 'https://Stackoverflow.com/users/12261', 'pm_score': 4, 'selected': False, 'text': '<p>I think you should only throw an exception when there\'s nothing you can do to get out of your current state. For example if you are allocating memory and there isn\'t any to allocate. In the cases you mention you can clearly recover from those states and can return an error code back to your caller accordingly.</p>\n\n<hr>\n\n<p>You will see plenty of advice, including in answers to this question, that you should throw exceptions only in "exceptional" circumstances. That seems superficially reasonable, but is flawed advice, because it replaces one question ("when should I throw an exception") with another subjective question ("what is exceptional"). Instead, follow the advice of Herb Sutter (for C++, available in the <a href="http://www.drdobbs.com/when-and-how-to-use-exceptions/184401836" rel="noreferrer">Dr Dobbs article <em>When and How to Use Exceptions</em></a>, and also in his book with Andrei Alexandrescu, <em>C++ Coding Standards</em>): throw an exception if, and only if</p>\n\n<ul>\n<li>a precondition is not met (which typically makes one of the following\nimpossible) or</li>\n<li>the alternative would fail to meet a post-condition or</li>\n<li>the alternative would fail to maintain an invariant.</li>\n</ul>\n\n<p>Why is this better? Doesn\'t it replace the question with <em>several</em> questions about preconditions, postconditions and invariants? This is better for several connected reasons.</p>\n\n<ul>\n<li>Preconditions, postconditions and invariants are <em>design</em> characteristics of our program (its internal API), whereas the decision to <code>throw</code> is an implementation detail. It forces us to bear in mind that we must consider the design and its implementation separately, and our job while implementing a method is to produce something that satisfies the design constraints.</li>\n<li>It forces us to think in terms of preconditions, postconditions and invariants, which are the <em>only</em> assumptions that callers of our method should make, and are expressed precisely, enabling loose coupling between the components of our program.</li>\n<li>That loose coupling then allows us to refactor the implementation, if necessary.</li>\n<li>The post-conditions and invariants are testable; it results in code that can be easily unit tested, because the post-conditions are predicates our unit-test code can check (assert).</li>\n<li>Thinking in terms of post-conditions naturally produces a design that has <em>success as a post-condition</em>, which is the natural style for using exceptions. The normal ("happy") execution path of your program is laid out linearly, with all the error handling code moved to the <code>catch</code> clauses.</li>\n</ul>\n'}, {'answer_id': 77180, 'author': 'japollock', 'author_id': 1210318, 'author_profile': 'https://Stackoverflow.com/users/1210318', 'pm_score': 5, 'selected': False, 'text': "<p>One rule of thumb is to use exceptions in the case of something you couldn't normally predict. Examples are database connectivity, missing file on disk, etc. For scenarios that you can predict, ie users attempting to log in with a bad password you should be using functions that return booleans and know how to handle the situation gracefully. You don't want to abruptly end execution by throwing an exception just because someone mistyped their password.</p>\n"}, {'answer_id': 77189, 'author': 'Shachar', 'author_id': 13897, 'author_profile': 'https://Stackoverflow.com/users/13897', 'pm_score': 3, 'selected': False, 'text': '<p>Exception classes are like "normal" classes. You create a new class when it "is" a different type of object, with different fields and different operations.</p>\n\n<p>As a rule of thumb, you should try balance between the number of exceptions and the granularity of the exceptions. If your method throws more than 4-5 different exceptions, you can probably merge some of them into more "general" exceptions, (e.g. in your case "AuthenticationFailedException"), and using the exception message to detail what went wrong. Unless your code handles each of them differently, you needn\'t creates many exception classes. And if it does, may you should just return an enum with the error that occured. It\'s a bit cleaner this way.</p>\n'}, {'answer_id': 77197, 'author': 'Sam', 'author_id': 9406, 'author_profile': 'https://Stackoverflow.com/users/9406', 'pm_score': 1, 'selected': False, 'text': '<p>the main reason for avoiding throwing an exception is that there is a lot of overhead involved with throwing an exception.</p>\n\n<p>One thing the article below states is that an exception is for an exceptional conditions and errors.</p>\n\n<p>A wrong user name is not necessarily a program error but a user error...</p>\n\n<p>Here is a decent starting point for exceptions within .NET:\n<a href="http://msdn.microsoft.com/en-us/library/ms229030(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms229030(VS.80).aspx</a></p>\n'}, {'answer_id': 77227, 'author': 'Gord', 'author_id': 12560, 'author_profile': 'https://Stackoverflow.com/users/12560', 'pm_score': 2, 'selected': False, 'text': '<p>In general you want to throw an exception for anything that can happen in your application that is "Exceptional"</p>\n\n<p>In your example, both of those exceptions look like you are calling them via a password / username validation. In that case it can be argued that it isn\'t really exceptional that someone would mistype a username / password.</p>\n\n<p>They are "exceptions" to the main flow of your UML but are more "branches" in the processing.</p>\n\n<p>If you attempted to access your passwd file or database and couldn\'t, that would be an exceptional case and would warrant throwing an exception.</p>\n'}, {'answer_id': 77235, 'author': 'Jason Etheridge', 'author_id': 2193, 'author_profile': 'https://Stackoverflow.com/users/2193', 'pm_score': 2, 'selected': False, 'text': "<p>Firstly, if the users of your API aren't interested in specific, fine-grained failures, then having specific exceptions for them isn't of any value.</p>\n\n<p>Since it's often not possible to know what may be useful to your users, a better approach is to have the specific exceptions, but ensure they inherit from a common class (e.g., std::exception or its derivatives in C++). That allows your client to catch specific exceptions if they choose, or the more general exception if they don't care.</p>\n"}, {'answer_id': 77248, 'author': 'Charles Graham', 'author_id': 7705, 'author_profile': 'https://Stackoverflow.com/users/7705', 'pm_score': 3, 'selected': False, 'text': "<p>If it's code running inside a loop that will likely cause an exception over and over again, then throwing exceptions is not a good thing, because they are pretty slow for large N. But there is nothing wrong with throwing custom exceptions if the performance is not an issue. Just make sure that you have a base exception that they all inherite, called BaseException or something like that. BaseException inherits System.Exception, but all of your exceptions inherit BaseException. You can even have a tree of Exception types to group similar types, but this may or may not be overkill.</p>\n\n<p>So, the short answer is that if it doesn't cause a significant performance penalty (which it should not unless you are throwing a lot of exceptions), then go ahead.</p>\n"}, {'answer_id': 77250, 'author': 'Serhat Ozgel', 'author_id': 31505, 'author_profile': 'https://Stackoverflow.com/users/31505', 'pm_score': 0, 'selected': False, 'text': "<p>You may use a little bit generic exceptions for that conditions. For e.g. ArgumentException is meant to be used when anything goes wrong with the parameters to a method (with the exception of ArgumentNullException). Generally you would not need exceptions like LessThanZeroException, NotPrimeNumberException etc. Think of the user of your method. The number of the conditions that she will want to handle specifically is equal to the number of the type of the exceptions that your method needs to throw. This way, you can determine how detailed exceptions you will have.</p>\n\n<p>By the way, always try to provide some ways for users of your libraries to avoid exceptions. TryParse is a good example, it exists so that you don't have to use int.Parse and catch an exception. In your case, you may want to provide some methods to check if user name is valid or password is correct so your users (or you) will not have to do lots of exception handling. This will hopefully result in more readble code and better performance.</p>\n"}, {'answer_id': 77256, 'author': 'Arno', 'author_id': 13685, 'author_profile': 'https://Stackoverflow.com/users/13685', 'pm_score': 1, 'selected': False, 'text': "<p>Throwing exceptions causes the stack to unwind, which has some performance impacts (admitted, modern managed environments have improved on that). Still repeatedly throwing and catching exceptions in a nested situation would be a bad idea.</p>\n\n<p>Probably more important than that, exceptions are meant for exceptional conditions. They should not be used for ordinary control flow, because this will hurt your code's readability.</p>\n"}, {'answer_id': 77308, 'author': 'eli', 'author_id': 5105, 'author_profile': 'https://Stackoverflow.com/users/5105', 'pm_score': 0, 'selected': False, 'text': "<p>Ultimately the decision comes down to whether it is more helpful to deal with application-level errors like this using exception handling, or via your own home-rolled mechanism like returning status codes. I don't think there's a hard-and-fast rule about which is better, but I would consider:</p>\n\n<ul>\n<li>Who's calling your code? Is this a public API of some sort or an internal library?</li>\n<li>What language are you using? If it's Java, for example, then throwing a (checked) exception puts an explicit burden on your caller to handle this error condition in some way, as opposed to a return status which could be ignored. That could be good or bad.</li>\n<li>How are other error conditions in the same application handled? Callers won't want to deal with a module that handles errors in an idiosyncratic way unlike anything else in the system.</li>\n<li>How many things can go wrong with the routine in question, and how would they be handled differently? Consider the difference between a series of catch blocks that handle different errors and a switch on an error code.</li>\n<li>Do you have structured information about the error you need to return? Throwing an exception gives you a better place to put this information than just returning a status.</li>\n</ul>\n"}, {'answer_id': 77361, 'author': 'The Digital Gabeg', 'author_id': 12782, 'author_profile': 'https://Stackoverflow.com/users/12782', 'pm_score': 10, 'selected': True, 'text': '<p>My personal guideline is: an exception is thrown when a fundamental assumption of the current code block is found to be false.</p>\n\n<p>Example 1: say I have a function which is supposed to examine an arbitrary class and return true if that class inherits from List<>. This function asks the question, "Is this object a descendant of List?" This function should never throw an exception, because there are no gray areas in its operation - every single class either does or does not inherit from List<>, so the answer is always "yes" or "no".</p>\n\n<p>Example 2: say I have another function which examines a List<> and returns true if its length is more than 50, and false if the length is less. This function asks the question, "Does this list have more than 50 items?" But this question makes an assumption - it assumes that the object it is given is a list. If I hand it a NULL, then that assumption is false. In that case, if the function returns <i>either</i> true <i>or</i> false, then it is breaking its own rules. The function cannot return <i>anything</i> and claim that it answered the question correctly. So it doesn\'t return - it throws an exception.</p>\n\n<p>This is comparable to the <a href="http://en.wikipedia.org/wiki/Fallacy_of_many_questions" rel="noreferrer">"loaded question"</a> logical fallacy. Every function asks a question. If the input it is given makes that question a fallacy, then throw an exception. This line is harder to draw with functions that return void, but the bottom line is: if the function\'s assumptions about its inputs are violated, it should throw an exception instead of returning normally.</p>\n\n<p>The other side of this equation is: if you find your functions throwing exceptions frequently, then you probably need to refine their assumptions.</p>\n'}, {'answer_id': 77419, 'author': 'Bjorn Reppen', 'author_id': 1324220, 'author_profile': 'https://Stackoverflow.com/users/1324220', 'pm_score': 5, 'selected': False, 'text': "<p>Others propose that exceptions should not be used because the bad login is to be expected in a normal flow if the user mistypes. I disagree and I don't get the reasoning. Compare it with opening a file.. if the file doesn't exist or is not available for some reason then an exception will be thrown by the framework. Using the logic above this was a mistake by Microsoft. They should have returned an error code. Same for parsing, webrequests, etc., etc.. </p>\n\n<p>I don't consider a bad login part of a normal flow, it's exceptional. Normally the user types the correct password, and the file does exist. The exceptional cases are exceptional and it's perfectly fine to use exceptions for those. Complicating your code by propagating return values through n levels up the stack is a waste of energy and will result in messy code. Do the simplest thing that could possibly work. Don't prematurely optimize by using error codes, exceptional stuff by definition rarely happens, and exceptions don't cost anything unless you throw them.</p>\n"}, {'answer_id': 77595, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>I have three type of conditions that I catch. </p>\n\n<ol>\n<li><p>Bad or missing input should not be an exception. Use both client side js and server side regex to detect, set attributes and forward back to the same page with messages.</p></li>\n<li><p>The AppException. This is usually an exception that you detect and throw with in your code. In other words these are ones you expect (the file does not exist). Log it, set the message, and forward back to the general error page. This page usually has a bit of info about what happened.</p></li>\n<li><p>The unexpected Exception. These are the ones you don't know about. Log it with details and forward them to a general error page.</p></li>\n</ol>\n\n<p>Hope this helps</p>\n"}, {'answer_id': 77692, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': 2, 'selected': False, 'text': '<p>Exceptions are intended for events that are abnormal behaviors, errors, failures, and such. Functional behavior, user error, etc., should be handled by program logic instead. Since a bad account or password is an expected part of the logic flow in a login routine, it should be able to handle those situations without exceptions.</p>\n'}, {'answer_id': 78087, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': '<p>The exceptions versus returning error code argument should be about flow control not philosophy (how "exceptional" an error is):</p>\n\n<pre><code>void f1() throws ExceptionType1, ExceptionType2 {}\n\nvoid catchFunction() {\n try{\n while(someCondition){\n try{\n f1(); \n }catch(ExceptionType2 e2){\n //do something, don\'t break the loop\n }\n }\n }catch(ExceptionType1 e1){\n //break the loop, do something else\n }\n</code></pre>\n\n<p>}</p>\n'}, {'answer_id': 78232, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Security is conflated with your example: You shouldn\'t tell an attacker that a username exists, but the password is wrong. That\'s extra information you don\'t need to share. Just say "the username or password is incorrect."</p>\n'}, {'answer_id': 78337, 'author': 'Robert', 'author_id': 14364, 'author_profile': 'https://Stackoverflow.com/users/14364', 'pm_score': 3, 'selected': False, 'text': '<p>I would say there are no hard and fast rules on when to use exceptions. However there are good reasons for using or not using them:</p>\n\n<p>Reasons to use exceptions:</p>\n\n<ul>\n<li>The code flow for the common case is clearer</li>\n<li>Can return complex error information as an object (although this can also be achieved using error "out" parameter passed by reference)</li>\n<li>Languages generally provide some facility for managing tidy cleanup in the event of the exception (try/finally in Java, using in C#, RAII in C++)</li>\n<li>In the event no exception is thrown, execution can <em>sometimes</em> be faster than checking return codes</li>\n<li>In Java, checked exceptions must be declared or caught (although this can be a reason against)</li>\n</ul>\n\n<p>Reasons not to use exceptions:</p>\n\n<ul>\n<li>Sometimes it\'s overkill if the error handling is simple</li>\n<li>If exceptions are not documented or declared, they may be uncaught by calling code, which may be worse than if the the calling code just ignored a return code (application exit vs silent failure - which is worse may depend on the scenario)</li>\n<li>In C++, code that uses exceptions must be exception safe (even if you don\'t throw or catch them, but call a throwing function indirectly)</li>\n<li>In C++, it is hard to tell when a function might throw, therefore you must be paranoid about exception safety if you use them</li>\n<li>Throwing and catching exceptions is generally significantly more expensive compared to checking a return flag</li>\n</ul>\n\n<p>In general, I would be more inclined to use exceptions in Java than in C++ or C#, because I am of the opinion that an exception, declared or not, is fundamentally part of the formal interface of a function, since changing your exception guarantee may break calling code. The biggest advantage of using them in Java IMO, is that you know that your caller MUST handle the exception, and this improves the chance of correct behaviour.</p>\n\n<p>Because of this, in any language, I would always derive all exceptions in a layer of code or API from a common class, so that calling code can always guarantee to catch all exceptions. Also I would consider it bad to throw exception classes that are implementation-specific, when writing an API or library (i.e. wrap exceptions from lower layers so that the exception that your caller receives is understandable in the context of your interface).</p>\n\n<p>Note that Java makes the distinction between general and Runtime exceptions in that the latter need not be declared. I would only use Runtime exception classes when you know that the error is a result of a bug in the program.</p>\n'}, {'answer_id': 78500, 'author': 'dclaysmith', 'author_id': 14378, 'author_profile': 'https://Stackoverflow.com/users/14378', 'pm_score': 2, 'selected': False, 'text': '<p>I agree with japollock way up there--throw an acception when you are uncertain about the outcome of an operation. Calls to APIs, accessing filesystems, database calls, etc. Anytime you are moving past the "boundaries" of your programming languages.</p>\n\n<p>I\'d like to add, feel free to throw a standard exception. Unless you are going to do something "different" (ignore, email, log, show that twitter whale picture thingy, etc), then don\'t bother with custom exceptions.</p>\n'}, {'answer_id': 78935, 'author': 'Crusty', 'author_id': 9810, 'author_profile': 'https://Stackoverflow.com/users/9810', 'pm_score': -1, 'selected': False, 'text': '<p>There are two main classes of exception: </p>\n\n<p>1) System exception (eg Database connection lost) or \n2) User exception. (eg User input validation, \'password is incorrect\')</p>\n\n<p>I found it helpful to create my own User Exception Class and when I want to throw a user error I want to be handled differently (ie resourced error displayed to the user) then all I need do in my main error handler is check the object type:</p>\n\n<pre><code> If TypeName(ex) = "UserException" Then\n Display(ex.message)\n Else\n DisplayError("An unexpected error has occured, contact your help desk") \n LogError(ex)\n End If\n</code></pre>\n'}, {'answer_id': 79187, 'author': 'Mike Kantor', 'author_id': 14607, 'author_profile': 'https://Stackoverflow.com/users/14607', 'pm_score': 0, 'selected': False, 'text': "<p>Some useful things to think about when deciding whether an exception is appropriate:</p>\n\n<ol>\n<li><p>what level of code you want to have run after the exception candidate occurs - that is, how many layers of the call stack should unwind. You generally want to handle an exception as close as possible to where it occurs. For username/password validation, you would normally handle failures in the same block of code, rather than letting an exception bubble up. So an exception is probably not appropriate. (OTOH, after three failed login attempts, control flow may shift elsewhere, and an exception may be appropriate here.)</p></li>\n<li><p>Is this event something you would want to see in an error log? Not every exception is written to an error log, but it's useful to ask whether this entry in an error log would be useful - i.e., you would try to do something about it, or would be the garbage you ignore.</p></li>\n</ol>\n"}, {'answer_id': 79931, 'author': 'core', 'author_id': 11574, 'author_profile': 'https://Stackoverflow.com/users/11574', 'pm_score': 2, 'selected': False, 'text': '<p>The simple answer is, whenever an operation is impossible (because of either application OR because it would violate business logic). If a method is invoked and it impossible to do what the method was written to do, throw an Exception. A good example is that constructors always throw ArgumentExceptions if an instance cannot be created using the supplied parameters. Another example is InvalidOperationException, which is thrown when an operation cannot be performed because of the state of another member or members of the class.</p>\n\n<p>In your case, if a method like Login(username, password) is invoked, if the username is not valid, it is indeed correct to throw a UserNameNotValidException, or PasswordNotCorrectException if password is incorrect. The user cannot be logged in using the supplied parameter(s) (i.e. it\'s impossible because it would violate authentication), so throw an Exception. Although I might have your two Exceptions inherit from ArgumentException.</p>\n\n<p>Having said that, if you wish NOT to throw an Exception because a login failure may be very common, one strategy is to instead create a method that returns types that represent different failures. Here\'s an example:</p>\n\n<pre><code>{ // class\n ...\n\n public LoginResult Login(string user, string password)\n {\n if (IsInvalidUser(user))\n {\n return new UserInvalidLoginResult(user);\n }\n else if (IsInvalidPassword(user, password))\n {\n return new PasswordInvalidLoginResult(user, password);\n }\n else\n {\n return new SuccessfulLoginResult();\n }\n }\n\n ...\n}\n\npublic abstract class LoginResult\n{\n public readonly string Message;\n\n protected LoginResult(string message)\n {\n this.Message = message;\n }\n}\n\npublic class SuccessfulLoginResult : LoginResult\n{\n public SucccessfulLogin(string user)\n : base(string.Format("Login for user \'{0}\' was successful.", user))\n { }\n}\n\npublic class UserInvalidLoginResult : LoginResult\n{\n public UserInvalidLoginResult(string user)\n : base(string.Format("The username \'{0}\' is invalid.", user))\n { }\n}\n\npublic class PasswordInvalidLoginResult : LoginResult\n{\n public PasswordInvalidLoginResult(string password, string user)\n : base(string.Format("The password \'{0}\' for username \'{0}\' is invalid.", password, user))\n { }\n}\n</code></pre>\n\n<p>Most developers are taught to avoid Exceptions because of the overhead caused by throwing them. It\'s great to be resource-conscious, but usually not at the expense of your application design. That is probably the reason you were told not to throw your two Exceptions. Whether to use Exceptions or not usually boils down to how frequently the Exception will occur. If it\'s a fairly common or an fairly expectable result, this is when most developers will avoid Exceptions and instead create another method to indicate failure, because of the supposed consumption of resources.</p>\n\n<p>Here\'s an example of avoiding using Exceptions in a scenario like just described, using the Try() pattern:</p>\n\n<pre><code>public class ValidatedLogin\n{\n public readonly string User;\n public readonly string Password;\n\n public ValidatedLogin(string user, string password)\n {\n if (IsInvalidUser(user))\n {\n throw new UserInvalidException(user);\n }\n else if (IsInvalidPassword(user, password))\n {\n throw new PasswordInvalidException(password);\n }\n\n this.User = user;\n this.Password = password;\n }\n\n public static bool TryCreate(string user, string password, out ValidatedLogin validatedLogin)\n {\n if (IsInvalidUser(user) || \n IsInvalidPassword(user, password))\n {\n return false;\n }\n\n validatedLogin = new ValidatedLogin(user, password);\n\n return true;\n }\n}\n</code></pre>\n'}, {'answer_id': 80458, 'author': 'Petr Macek', 'author_id': 15045, 'author_profile': 'https://Stackoverflow.com/users/15045', 'pm_score': 2, 'selected': False, 'text': "<p>I'd say that generally every fundamentalism leads to hell. </p>\n\n<p>You certainly wouldn't want to end up with exception driven flow, but avoiding exceptions altogether is also a bad idea. You have to find a balance between both approaches. What I would not do is to create an exception type for every exceptional situation. That is not productive.</p>\n\n<p>What I generally prefer is to create two basic types of exceptions which are used throughout the system: <em>LogicalException</em> and <em>TechnicalException</em>. These can be further distinguished by subtypes if needed, but it is not generally not necessary. </p>\n\n<p>The technical exception denotes the really unexpected exception like database server being down, the connection to the web service threw the IOException and so on. </p>\n\n<p>On the other hand the logical exceptions are used to propagate the less severe erroneous situation to the upper layers (generally some validation result). </p>\n\n<p>Please note that even the logical exception is not intended to be used on regular basis to control the program flow, but rather to highlight the situation when the flow should really end. When used in Java, both exception types are <em>RuntimeException</em> subclasses and error handling is highly aspect oriented. </p>\n\n<p>So in the login example it might be wise to create something like AuthenticationException and distinguish the concrete situations by enum values like <em>UsernameNotExisting</em>, <em>PasswordMismatch</em> etc. Then you won't end up in having a huge exception hierarchy and can keep the catch blocks on maintainable level. You can also easily employ some generic exception handling mechanism since you have the exceptions categorized and know pretty well what to propagate up to the user and how.</p>\n\n<p>Our typical usage is to throw the LogicalException during the Web Service call when the user's input was invalid. The Exception gets marshalled to the SOAPFault detail and then gets unmarshalled to the exception again on the client which is resulting in showing the validation error on one certain web page input field since the exception has proper mapping to that field.</p>\n\n<p>This is certainly not the only situation: you don't need to hit web service to throw up the exception. You are free to do so in any exceptional situation (like in the case you need to fail-fast) - it is all at your discretion.</p>\n"}, {'answer_id': 81151, 'author': 'Commander Keen', 'author_id': 13194, 'author_profile': 'https://Stackoverflow.com/users/13194', 'pm_score': 6, 'selected': False, 'text': '<p>My little guidelines are heavily influenced by the great book "Code complete":</p>\n\n<ul>\n<li>Use exceptions to notify about things that should not be ignored. </li>\n<li>Don\'t use exceptions if the error can be handled locally</li>\n<li>Make sure the exceptions are at the same level of abstraction as the rest of your routine.</li>\n<li>Exceptions should be reserved for what\'s <strong>truly exceptional</strong>. </li>\n</ul>\n'}, {'answer_id': 86263, 'author': 'Dan', 'author_id': 8040, 'author_profile': 'https://Stackoverflow.com/users/8040', 'pm_score': 1, 'selected': False, 'text': '<p>I have philosophical problems with the use of exceptions. Basically, you are expecting a specific scenario to occur, but rather than handling it explicitly you are pushing the problem off to be handled "elsewhere." And where that "elsewhere" is can be anyone\'s guess.</p>\n'}, {'answer_id': 3112033, 'author': 'supercat', 'author_id': 363751, 'author_profile': 'https://Stackoverflow.com/users/363751', 'pm_score': 1, 'selected': False, 'text': '<p>To my mind, the fundamental question should be whether one would expect that the caller would want to continue normal program flow if a condition occurs. If you don\'t know, either have separate doSomething and trySomething methods, where the former returns an error and the latter does not, or have a routine that accepts a parameter to indicate whether an exception should be thrown if it fails). Consider a class to send commands to a remote system and report responses. Certain commands (e.g. restart) will cause the remote system to send a response but then be non-responsive for a certain length of time. It is thus useful to be able to send a "ping" command and find out whether the remote system responds in a reasonable length of time without having to throw an exception if it doesn\'t (the caller would probably expect that the first few "ping" attempts would fail, but one would eventually work). On the other hand, if one has a sequence of commands like:</p>\n\n<pre>\n exchange_command("open tempfile");\n exchange_command("write tempfile data {whatever}");\n exchange_command("write tempfile data {whatever}");\n exchange_command("write tempfile data {whatever}");\n exchange_command("write tempfile data {whatever}");\n exchange_command("close tempfile");\n exchange_command("copy tempfile to realfile");\n</pre>\n\n<p>one would want failure of any operation to abort the whole sequence. While one could check each operation to ensure it succeeded, it\'s more helpful to have the exchange_command() routine throw an exception if a command fails.</p>\n\n<p>Actually, in the above scenario it may be helpful to have a parameter to select a number of failure-handling modes: never throw exceptions, throw exceptions for communication errors only, or throw exceptions in any cases where a command does not return a "success" indication.</p>\n'}, {'answer_id': 5392233, 'author': 'DanMan', 'author_id': 428241, 'author_profile': 'https://Stackoverflow.com/users/428241', 'pm_score': 0, 'selected': False, 'text': '<p>"PasswordNotCorrectException" isn\'t a good example for using exceptions. Users getting their passwords wrong is to be expected, so it\'s hardly an exception IMHO. You probably even recover from it, showing a nice error message, so it\'s just a validity check.</p>\n\n<p>Unhandled exceptions will stop the execution eventually - which is good. If you\'re returning false, null or error codes, you will have to deal with the program\'s state all by yourself. If you forget to check conditions somewhere, your program may keep running with wrong data, and you may have a hard time figuring out <em>what</em> happened and <em>where</em>.</p>\n\n<p>Of course, you could cause the same problem with empty catch statements, but at least spotting those is easier and doesn\'t require you to understand the logic.</p>\n\n<p>So as a rule of thumb:</p>\n\n<p>Use them wherever you don\'t want or simply can\'t recover from an error.</p>\n'}, {'answer_id': 7676705, 'author': 'Genjuro', 'author_id': 978769, 'author_profile': 'https://Stackoverflow.com/users/978769', 'pm_score': 2, 'selected': False, 'text': '<p>for me Exception should be thrown when a required technical or business rule fails.\nfor instance if a car entity is associated with array of 4 tires ... if one tire or more are null ... an exception should be Fired "NotEnoughTiresException" , cuz it can be caught at different level of the system and have a significant meaning through logging.\nbesides if we just try to flow control the null and prevent the instanciation of the car .\nwe might never never find the source of the problem , cuz the tire isn\'t supposed to be null in the first place . </p>\n'}, {'answer_id': 8560585, 'author': 'goran', 'author_id': 1105768, 'author_profile': 'https://Stackoverflow.com/users/1105768', 'pm_score': 2, 'selected': False, 'text': '<p>the rule of thumb for throwing exceptions is pretty simple. you do so when your code has entered into an UNRECOVERABLE INVALID state. if data is compromised or you cannot wind back the processing that occurred up to the point then you must terminate it. indeed what else can you do? your processing logic will eventually fail elsewhere. if you can recover somehow then do that and do not throw exception.</p>\n\n<p>in your particular case if you were forced to do something silly like accept money withdrawal and only then check user/pasword you should terminate the process by throwing an exception to notify that something bad has happened and prevent further damage.</p>\n'}, {'answer_id': 23236815, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': '<p>Here are my suggestions:</p>\n\n<p>I don\'t think it\'s ALWAYS a good way to throw an exception because it will take more time, memory to process with such exceptions. </p>\n\n<p>In my mind, <strong>if something can be processed with a "kind,polite" way (this means if we can "predicate such errors by using if…… or something like this), we should AVOID using "exceptions" but just return a flag like "false" , with an outer parameter value telling him/her the detailled reason.</strong></p>\n\n<p>An example is, we can make a class like this following:</p>\n\n<pre><code>public class ValueReturnWithInfo<T>\n{\n public T Value{get;private set;}\n public string errorMsg{get;private set;}\n public ValueReturnWithInfo(T value,string errmsg)\n {\n Value = value;\n errMsg = errmsg;\n }\n}\n</code></pre>\n\n<p>We can use such "multiple-value-returned" classes instead of errors, which seems to be a better,polite way to process with exception problems.</p>\n\n<p>However, notice that <strong>if some errors cannot be described so easily (this depends on your programming experience) with "if"……(such as FileIO exceptions), you have to throw exceptions</strong>.</p>\n'}, {'answer_id': 74203785, 'author': 'garcipat', 'author_id': 2372525, 'author_profile': 'https://Stackoverflow.com/users/2372525', 'pm_score': 0, 'selected': False, 'text': '<p>I would say that exceptions should be thrown if an unexpected behaviour is occuring that wasnt meant to be.</p>\n<p>Like trying to update or delete a non existing entity. And it should be catched where the Exception can be handled and has meaning. For working in an alternative way to continue, add logging or returning a specific result on Api level.</p>\n<p>If you expect something to be the case, you should build code to check and ensure it.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77127', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/279750/']
|
77,128 |
<p>We have various php projects developed on windows (xampp) that need to be deployed to a mix of linux/windows servers. </p>
<p>We've used <a href="http://www.capify.org/" rel="nofollow noreferrer">capistrano</a> in the past to deploy from windows to the linux servers, but recent changes in architecture and windows servers left the old config not working. The recipe works fine for the linux deployment, but setting up the windows servers has required more time than we have right now. Ideas for the Capistrano recipe are valid answers. obviously the windows/linux servers don't share users, so this complicates it a tad (for the capistrano assumption of same username/password everywhere).</p>
<p>Currently we're using svn-update for the windows servers, which i dislike, since it leaves all the svn files hanging on the production servers. (and we still have to manually svn-update them on windows) And manual updating of files using winscp and syncing the directories with their linux counterparts.</p>
<p>My question is, what tools/setup do you suggest to automatize this deployment scenario:
<strong>"Various php windows/linux developers deploying to 2+ mixed windows/linux machines"</strong></p>
<p>(ps: we have no problems using linux tools or anything working through cygwin, we simply need to make deployment a simple one-step operation)</p>
<p><em>edit: Currently we can't work on a all-linux enviroment, we have to deploy to both linux and windows server. We can start the deploy from anywhere, but we'd prefer to be able to do it from either enviroment.</em></p>
|
[{'answer_id': 77185, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 0, 'selected': False, 'text': "<p>Capistrano is the nicest deployment tool I've seen. Do the architecture changes make it impossible to fix the configs so it works again? </p>\n"}, {'answer_id': 77211, 'author': 'reefnet_alex', 'author_id': 2745, 'author_profile': 'https://Stackoverflow.com/users/2745', 'pm_score': 1, 'selected': False, 'text': '<p>This will probably sound silly but... I used to have this kind of problem all the time until I decided in the end that if I\'m always <em>deploying</em> on Linux, I ought really to at least try <em>developing</em> on Linux also. I did. It was pain free. I never went back. </p>\n\n<p>Now. I am not suggesting this is for everyone. But, if you install <a href="http://www.virtualbox.org/" rel="nofollow noreferrer">VirtualBox</a> you could run a Linux install as a local server on your windows box. Share a folder in the virtual machine and you can use all your known and trusted Windows software and techniques <em>and</em> have the piece of mind of knowing that everything is working well on its target platform. </p>\n\n<p>Plus you\'ll be able to go back to Capistrano (a fine choice) for deployment. </p>\n\n<p>Best of all, if you thought you knew Linux / Unix wait until you use it everyday on your desktop! Who knows you may even like it :)</p>\n'}, {'answer_id': 77440, 'author': 'Bruce', 'author_id': 9698, 'author_profile': 'https://Stackoverflow.com/users/9698', 'pm_score': 3, 'selected': True, 'text': '<p>I use 4 different approaches depending on the client environment:</p>\n\n<ol>\n<li>Capistrano and similar tools (effective, but complex)</li>\n<li><code>rsync</code> from + to Windows, Linux, Mac (simple, doesn\'t enforce discipline)</li>\n<li><code>svn</code> from + to Windows, Linux, Mac (simple, doesn\'t enforce discipline)</li>\n<li>On-server scripts (run through the browser, complex)</li>\n</ol>\n\n<p>There are some requirements that drive what you need:</p>\n\n<ul>\n<li>How much discipline you want to enforce</li>\n<li>If you need database (or configuration) migrations (up and/or down)</li>\n<li>If you want a static "we\'re down" page</li>\n<li>Who can do the update</li>\n<li>Configuration differences between servers</li>\n</ul>\n\n<p>I strongly suggest enforcing enough discipline to save you from yourself: deploy to a development server, allow for upward migrations and simple database restore, and limit who can update the live server to a small number of responsible admins (where the dev server is open to more developers). Also consider pushing via a cron job (to the development server), so there\'s a daily snapshot of your incremental changes.</p>\n\n<p>Most of the time, I find that either <code>svn</code> or <code>rsync</code> setups are enough, with a few server-side scripts, especially when the admin set is limited to a few developers.</p>\n'}, {'answer_id': 77819, 'author': 'kmilo', 'author_id': 14015, 'author_profile': 'https://Stackoverflow.com/users/14015', 'pm_score': 0, 'selected': False, 'text': "<p>Why you can't use capistrano anymore?</p>\n\n<p>Why you dislike svn-update?</p>\n\n<p>What things in your app requires an special deployment ?</p>\n"}, {'answer_id': 82311, 'author': 'rami', 'author_id': 9629, 'author_profile': 'https://Stackoverflow.com/users/9629', 'pm_score': 0, 'selected': False, 'text': "<p>You can setup <code>svn:ignore</code> property on configuration files, so that <code>svn update</code> doesn't erase them, and then use <code>svn export /target/path/</code> to get rid of <code>.svn</code> files in your Subversion repository.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77128', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9114/']
|
77,133 |
<p>I want to debug a windows C++ application I've written to see why it isn't responding to WM_QUERYENDSESSION how I expect it to. Clearly it's a little tricky to do this by just shutting the system down. Is there any utility or code which I can use to send a fake WM_QUERYENDSESSION to my application windows myself?</p>
|
[{'answer_id': 77208, 'author': 'Ferruccio', 'author_id': 4086, 'author_profile': 'https://Stackoverflow.com/users/4086', 'pm_score': 0, 'selected': False, 'text': "<p>Yes. If you can get the window handle (maybe using FindWindow()), you can send/post any message to it as long as the WPARAM & LPARAM aren't pointers.</p>\n"}, {'answer_id': 77210, 'author': 'ChrisN', 'author_id': 3853, 'author_profile': 'https://Stackoverflow.com/users/3853', 'pm_score': 2, 'selected': True, 'text': '<p>I\'ve used the <a href="http://winguitest.sourceforge.net" rel="nofollow noreferrer">Win32::GuiTest</a> Perl module to do this kind of thing in the past.</p>\n'}, {'answer_id': 77218, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>The Windows API SendMessage can be used to do this.\n<a href="http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx</a></p>\n\n<p>IS ti possible it\'s not responding because some other running process has responded with a zero (making the system wait on it.)</p>\n'}, {'answer_id': 77496, 'author': 'Bob Moore', 'author_id': 9368, 'author_profile': 'https://Stackoverflow.com/users/9368', 'pm_score': 1, 'selected': False, 'text': '<p>Yes of course, it possible. I faced a similar issue some months ago where some (unknown, but probably mine) app was preventing shutdown, so I wrote some quick code that used EnumWindows to enumerate all the top level windows, sent each one a WM_QUERYENDSESSION message, noted what the return value from SendMessage was and stopped the enumeration if anyone returned FALSE. Took about ten minutes in C++/MFC. This was the guts of it:</p>\n\n<pre><code>void CQes_testDlg::OnBtnTest() \n{ \n // enumerate all the top-level windows. \n m_ctrl_ListMsgs.ResetContent(); \n EnumWindows (EnumProc, 0); \n} \n\n\nBOOL CALLBACK EnumProc (HWND hTarget, LPARAM lParam) \n{ \n CString csTitle; \n CString csMsg; \n CWnd * pWnd = CWnd::FromHandle (hTarget); \n BOOL bRetVal = TRUE; \n DWORD dwPID; \n\n if (pWnd) \n { \n pWnd->GetWindowText (csTitle); \n if (csTitle.GetLength() == 0) \n { \n GetWindowThreadProcessId (hTarget, &dwPID); \n csTitle.Format ("<PID=%d>", dwPID); \n } \n\n if (pWnd->SendMessage (WM_QUERYENDSESSION, 0, ENDSESSION_LOGOFF)) \n { \n csMsg.Format ("window 0x%X (%s) returned TRUE", hTarget, csTitle); \n } \n else \n { \n csMsg.Format ("window 0x%X (%s) returned FALSE", hTarget, csTitle); \n bRetVal = FALSE; \n } \n\n mg_pThis->m_ctrl_ListMsgs.AddString (csMsg);\n }\n else \n { \n csMsg.Format ("Unable to resolve HWND 0x%X to a CWnd", hTarget); \n mg_pThis->m_ctrl_ListMsgs.AddString (csMsg); \n } \n return bRetVal; \n}\n</code></pre>\n\n<p>mg_pThis was just a local copy of the dialog\'s this pointer, so the helper callback could access it. I told you it was quick and dirty :-)</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77133', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1849/']
|
77,171 |
<p>After reading Evan's and Nilsson's books I am still not sure how to manage Data access in a domain driven project. Should the CRUD methods be part of the repositories, i.e. OrderRepository.GetOrdersByCustomer(customer) or should they be part of the entities: Customer.GetOrders(). The latter approach seems more OO, but it will distribute Data Access for a single entity type among multiple objects, i.e. Customer.GetOrders(), Invoice.GetOrders(), ShipmentBatch.GetOrders() ,etc. What about Inserting and updating?</p>
|
[{'answer_id': 77244, 'author': 'Vin', 'author_id': 1747, 'author_profile': 'https://Stackoverflow.com/users/1747', 'pm_score': 2, 'selected': False, 'text': '<p>Even in a DDD, I would keep Data Access classes and routines separate from Entities.</p>\n\n<p>Reasons are,</p>\n\n<ol>\n<li>Testability improves</li>\n<li>Separation of concerns and Modular design</li>\n<li>More maintainable in the long run, as you add entities, routines</li>\n</ol>\n\n<p>I am no expert, just my opinion.</p>\n'}, {'answer_id': 77275, 'author': 'Chris Bilson', 'author_id': 12934, 'author_profile': 'https://Stackoverflow.com/users/12934', 'pm_score': 5, 'selected': True, 'text': '<p>CRUD-ish methods should be part of the Repository...ish. But I think you should ask why you have a bunch of CRUD methods. What do they <em>really</em> do? What are they <em>really</em> for? If you actually call out the data access patterns your application uses I think it makes the repository a lot more useful and keeps you from having to do shotgun surgery when certain types of changes happen to your domain.</p>\n\n<pre><code>CustomerRepo.GetThoseWhoHaventPaidTheirBill()\n\n// or\n\nGetCustomer(new HaventPaidBillSpecification())\n\n// is better than\n\nforeach (var customer in GetCustomer()) {\n /* logic leaking all over the floor */\n}\n</code></pre>\n\n<p>"Save" type methods should also be part of the repository.</p>\n\n<p>If you have aggregate roots, this keeps you from having a Repository explosion, or having logic spread out all over: You don\'t have 4 x # of entities data access patterns, just the ones you actually use on the aggregate roots.</p>\n\n<p>That\'s my $.02.</p>\n'}, {'answer_id': 77323, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>The annoying thing with Nilsson\'s Applying DDD&P is that he always starts with "I wouldn\'t do that in a real-world-application but..." and then his example follows. Back to the topic: I think OrderRepository.GetOrdersByCustomer(customer) is the way to go, but there is also a discussion on the ALT.Net Mailing list (<a href="http://tech.groups.yahoo.com/group/altdotnet/" rel="nofollow noreferrer">http://tech.groups.yahoo.com/group/altdotnet/</a>) about DDD. </p>\n'}, {'answer_id': 77444, 'author': 'Shane Courtrille', 'author_id': 12503, 'author_profile': 'https://Stackoverflow.com/users/12503', 'pm_score': 2, 'selected': False, 'text': "<p>I've done it both ways you are talking about, My preferred approach now is the persistent ignorant (or PONO -- Plain Ole' .Net Object) method where your domain classes are only worried about being domain classes. They do not know anything about how they are persisted or even if they are persisted. Of course you have to be pragmatic about this at times and allow for things such as an Id (but even then I just use a layer super type which has the Id so I can have a single point where things like default value live)</p>\n\n<p>The main reason for this is that I strive to follow the principle of Single Responsibility. By following this principle I've found my code much more testable and maintainable. It's also much easier to make changes when they are needed since I only have one thing to think about.</p>\n\n<p>One thing to be watchful of is the method bloat that repositories can suffer from. GetOrderbyCustomer.. GetAllOrders.. GetOrders30DaysOld.. etc etc. One good solution to this problem is to look at the Query Object pattern. And then your repositories can just take in a query object to execute.</p>\n\n<p>I'd also strongly recommend looking into something like NHibernate. It includes a lot of the concepts that make Repositories so useful (Identity Map, Cache, Query objects..)</p>\n"}, {'answer_id': 77847, 'author': 'JasonTrue', 'author_id': 13433, 'author_profile': 'https://Stackoverflow.com/users/13433', 'pm_score': 3, 'selected': False, 'text': "<p>DDD usually prefers the repository pattern over the active record pattern you hint at with Customer.Save.</p>\n\n<p>One downside in the Active Record model is that it pretty much presumes a single persistence model, barring some particularly intrusive code (in most languages).</p>\n\n<p>The repository interface is defined in the domain layer, but doesn't know whether your data is stored in a database or not. With the repository pattern, I can create an InMemoryRepository so that I can test domain logic in isolation, and use dependency injection in the application to have the service layer instantiate a SqlRepository, for example.</p>\n\n<p>To many people, having a special repository just for testing sounds goofy, but if you use the repository model, you may find that you don't really need a database for your particular application; sometimes a simple FileRepository will do the trick. Wedding to yourself to a database before you know you need it is potentially limiting. Even if a database is necessary, it's a lot faster to run tests against an InMemoryRepository.</p>\n\n<p>If you don't have much in the way of domain logic, you probably don't need DDD. ActiveRecord is quite suitable for a lot of problems, especially if you have mostly data and just a little bit of logic.</p>\n"}, {'answer_id': 108610, 'author': 'Stefan Moser', 'author_id': 8739, 'author_profile': 'https://Stackoverflow.com/users/8739', 'pm_score': 2, 'selected': False, 'text': "<p>Let's step back for a second. Evans recommends that repositories return aggregate roots and not just entities. So assuming that your Customer is an aggregate root that includes Orders, then when you fetched the customer from its repository, the orders came along with it. You would access the orders by navigating the relationship from Customer to Orders.</p>\n\n<pre><code>customer.Orders;\n</code></pre>\n\n<p>So to answer your question, CRUD operations are present on aggregate root repositories.</p>\n\n<pre><code>CustomerRepository.Add(customer);\nCustomerRepository.Get(customerID);\nCustomerRepository.Save(customer);\nCustomerRepository.Delete(customer);\n</code></pre>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77171', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2133/']
|
77,172 |
<p>Do you guys keep track of stored procedures and database schema in your source control system of choice?</p>
<p>When you make a change (add a table, update an stored proc, how do you get the changes into source control? </p>
<p>We use SQL Server at work, and I've begun using darcs for versioning, but I'd be curious about general strategies as well as any handy tools.</p>
<p><em>Edit:</em> Wow, thanks for all the great suggestions, guys! I wish I could select more than one "Accepted Answer"!</p>
|
[{'answer_id': 77187, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 0, 'selected': False, 'text': '<p>We keep stored procedures in source control. </p>\n'}, {'answer_id': 77196, 'author': 'ahockley', 'author_id': 8209, 'author_profile': 'https://Stackoverflow.com/users/8209', 'pm_score': 0, 'selected': False, 'text': "<p>Script everything (object creation, etc) and store those scripts in source control. How do the changes get there? It's part of the standard practice of how things are done. Need to add a table? Write a CREATE TABLE script. Update a sproc? Edit the stored procedure script.</p>\n\n<p>I prefer one script per object.</p>\n"}, {'answer_id': 77203, 'author': 'Manu', 'author_id': 2133, 'author_profile': 'https://Stackoverflow.com/users/2133', 'pm_score': 3, 'selected': False, 'text': '<p>create a "Database project" in Visual Studio to write and manage your sQL code and keep the project under version control together with the rest of your solution.</p>\n'}, {'answer_id': 77212, 'author': 'John Flinchbaugh', 'author_id': 12591, 'author_profile': 'https://Stackoverflow.com/users/12591', 'pm_score': 0, 'selected': False, 'text': "<p>For procs, write the procs with script wrappers into plain files, and apply the changes from those files. If it applied correctly, then you can check in that file, and you'll be able to reproduce it from that file as well.</p>\n\n<p>For schema changes, you may need to check in scripts to incrementally make the changes you've made. Write the script, apply it, and then check it in. You can build a process then, to automatically apply each schema script in series.</p>\n"}, {'answer_id': 77216, 'author': 'Adrian Mouat', 'author_id': 4332, 'author_profile': 'https://Stackoverflow.com/users/4332', 'pm_score': 2, 'selected': False, 'text': '<p>I think you should write a script which automatically sets up your database, including any stored procedures. This script should then be placed in source control.</p>\n'}, {'answer_id': 77223, 'author': 'Rik', 'author_id': 5409, 'author_profile': 'https://Stackoverflow.com/users/5409', 'pm_score': 0, 'selected': False, 'text': "<p>We do keep stored procedures in source control. The way we (or at least I) do it is add a folder to my project, add a file for each SP and manually copy, paste the code into it. So when I change the SP, I manually need to change the file the source control.</p>\n\n<p>I'd be interested to hear if people can do this automatically.</p>\n"}, {'answer_id': 77238, 'author': 'japollock', 'author_id': 1210318, 'author_profile': 'https://Stackoverflow.com/users/1210318', 'pm_score': 3, 'selected': False, 'text': '<p>The solution we used at my last job was to number the scripts as they were added to source control:</p>\n\n<p>01.CreateUserTable.sql<br>\n02.PopulateUserTable<br>\n03.AlterUserTable.sql<br>\n04.CreateOrderTable.sql</p>\n\n<p>The idea was that we always knew which order to run the scripts, and we could avoid having to manage data integrity issues that might arise if you tried modifying script #1 (which would presumable cause the INSERTs in #2 to fail).</p>\n'}, {'answer_id': 77270, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I highly recommend maintaining schema and stored procedures in source control. </p>\n\n<p>Keeping stored procedures versioned allows them to be rolled back when determined to be problematic. </p>\n\n<p>Schema is a less obvious answer depending on what you mean. It is very useful to maintain the SQL that defines your tables in source control, for duplicating environments (prod/dev/user etc.). </p>\n'}, {'answer_id': 77379, 'author': 'Rikalous', 'author_id': 4271, 'author_profile': 'https://Stackoverflow.com/users/4271', 'pm_score': 0, 'selected': False, 'text': "<p>We have been using an alternative approach in my current project - we haven't got the db under source control but instead have been using a database diff tool to script out the changes when we get to each release.<br>\nIt has been working very well so far.</p>\n"}, {'answer_id': 77443, 'author': 'Chris Hall', 'author_id': 5933, 'author_profile': 'https://Stackoverflow.com/users/5933', 'pm_score': 0, 'selected': False, 'text': '<p>We store everything related to an application in our SCM. The DB scripts are generally stored in their own project, but are treated just like any other code... design, implement, test, commit.</p>\n'}, {'answer_id': 77500, 'author': 'Robert Paulson', 'author_id': 14033, 'author_profile': 'https://Stackoverflow.com/users/14033', 'pm_score': 6, 'selected': True, 'text': "<p>We choose to script everything, and that includes all stored procedures and schema changes. No wysiwyg tools, and no fancy 'sync' programs are necessary.</p>\n\n<p>Schema changes are easy, all you need to do is create and maintain a single file for that version, including all schema and data changes. This becomes your conversion script from version x to x+1. You can then run it against a production backup and integrate that into your 'daily build' to verify that it works without errors. Note it's important not to change or delete already written schema / data loading sql as you can end up breaking any sql written later.</p>\n\n<pre><code>-- change #1234\nALTER TABLE asdf ADD COLUMN MyNewID INT\nGO\n\n-- change #5678\nALTER TABLE asdf DROP COLUMN SomeOtherID\nGO\n</code></pre>\n\n<p>For stored procedures, we elect for a single file per sproc, and it uses the drop/create form. All stored procedures are recreated at deployment. The downside is that if a change was done outside source control, the change is lost. At the same time, that's true for any code, but your DBA'a need to be aware of this. This really stops people outside the team mucking with your stored procedures, as their changes are lost in an upgrade. </p>\n\n<p>Using Sql Server, the syntax looks like this:</p>\n\n<pre><code>if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_MyProc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)\ndrop procedure [usp_MyProc]\nGO\n\nCREATE PROCEDURE [usp_MyProc]\n(\n @UserID INT\n)\nAS\n\nSET NOCOUNT ON\n\n-- stored procedure logic.\n\nSET NOCOUNT OFF\n\nGO \n</code></pre>\n\n<p>The only thing left to do is write a utility program that collates all the individual files and creates a new file with the entire set of updates (as a single script). Do this by first adding the schema changes then recursing the directory structure and including all the stored procedure files.</p>\n\n<p>As an upside to scripting everything, you'll become much better at reading and writing SQL. You can also make this entire process more elaborate, but this is the basic format of how to source-control all sql without any special software.</p>\n\n<p>addendum: Rick is correct that you will lose permissions on stored procedures with DROP/CREATE, so you may need to write another script will re-enable specific permissions. This permission script would be the last to run. Our experience found more issues with ALTER verses DROP/CREATE semantics. YMMV</p>\n"}, {'answer_id': 77594, 'author': 'Ed Lucas', 'author_id': 12551, 'author_profile': 'https://Stackoverflow.com/users/12551', 'pm_score': 2, 'selected': False, 'text': '<p>Couple different perspectives from my experience. In the Oracle world, everything was managed by "create" DDL scripts. As ahockley mentioned, one script for each object. If the object needs to change, its DDL script is modified. There\'s one wrapper script that invokes all the object scripts so that you can deploy the current DB build to whatever environment you want. This is for the main core create. </p>\n\n<p>Obviously in a live application, whenever you push a new build that requires, say, a new column, you\'re not going to drop the table and create it new. You\'re going to do an ALTER script and add the column. So each time this kind of change needs to happen, there are always two things to do: 1) write the alter DDL and 2) update the core create DDL to reflect the change. Both go into source control, but the single alter script is more of a momentary point in time change since it will only be used to apply a delta.</p>\n\n<p>You could also use a tool like ERWin to update the model and forward generate the DDL, but most DBAs I know don\'t trust a modeling tool to gen the script exactly the way they want. You could also use ERWin to reverse engineer your core DDL script into a model periodically, but that\'s a lot of fuss to get it to look right (every blasted time you do it).</p>\n\n<p>In the Microsoft world, we employed a similar tactic, but we used the Red Gate product to help manage the scripts and deltas. Still put the scripts in source control. Still one script per object (table, sproc, whatever). In the beginning, some of the DBAs really preferred using the SQL Server GUI to manage the objects rather than use scripts. But that made it very difficult to manage the enterprise consistently as it grew.</p>\n\n<p>If the DDL is in source control, it\'s trivial to use any build tool (usually ant) to write a deployment script.</p>\n'}, {'answer_id': 77665, 'author': 'Dean Poulin', 'author_id': 5462, 'author_profile': 'https://Stackoverflow.com/users/5462', 'pm_score': 2, 'selected': False, 'text': '<p>In past experiences, I\'ve kept database changes source controlled in such a way that for each release of the product any database changes were always scripted out and stored in the release that we\'re working on. The build process in place would automatically bring the database up to the current version based on a table in the database that stored the current version for each "application". A custom .net utility application we wrote would then run and determine the current version of the database, and run any new scripts against it in order of the prefix numbers of the scripts. Then we\'d run unit tests to make sure everything was all good.</p>\n\n<p>We\'d store the scripts in source control as follows (folder structure below):</p>\n\n<p>I\'m a little rusty on current naming conventions on tables and stored procedures so bare with my example...</p>\n\n<p>[root]<br>\n [application]<br>\n [version]<br>\n [script] </p>\n\n<p>\\scripts<br>\n MyApplication\\<br>\n 1.2.1\\<br>\n 001.MyTable.Create.sql<br>\n 002.MyOtherTable.Create.sql<br>\n 100.dbo.usp.MyTable.GetAllNewStuff.sql </p>\n\n<p>With the use of a Versions table that would take into account the Application and Version the application would restore the weekly production backup, and run all the scripts needed against the database since the current version. By using .net we were easily able to package this into a transaction and if anything failed we would rollback, and send emails out, so we knew that release had bad scripts.</p>\n\n<p>So, all developers would make sure to maintain this in source control so the coordinated release would make sure that all the scripts we plan to run against the database would run successfully.</p>\n\n<p>This is probably more information than you were looking for, but it worked very well for us and given the structure it was easy to get all developers on board.</p>\n\n<p>When release day came around the operations team would follow the release notes and pick up the scripts from source control and run the package against the database with the .net application we used during the nightly build process which would automatically package the scripts in transactions so if something failed it would automatically roll back and no impact to the database was made.</p>\n'}, {'answer_id': 77672, 'author': 'John Rudy', 'author_id': 14048, 'author_profile': 'https://Stackoverflow.com/users/14048', 'pm_score': 2, 'selected': False, 'text': "<p>Similar to Robert Paulson, above, our organization keeps the database under source control. However, our difference is that we try to limit the number of scripts we have. </p>\n\n<p>For any new project, there's a set procedure. We have a schema creation script at version 1, a stored proc creation script and possibly an initial data load creation script. All procs are kept in a single, admittedly massive file. If we're using Enterprise Library, we include a copy of the creation script for logging; if it's an ASP.NET project using the ASP.NET application framework (authentication, personalization, etc.), we include that script as well. (We generated it from Microsoft's tools, then tweaked it until it worked in a replicable fashion across different sites. Not fun, but a valuable time investment.)</p>\n\n<p>We use the magic CTRL+F to find the proc we like. :) (We'd love it if SQL Management Studio had code navigation like VS does. Sigh!)</p>\n\n<p>For subsequent versions, we usually have upgradeSchema, upgradeProc and/or updateDate scripts. For schema updates, we ALTER tables as much as possible, creating new ones as needed. For proc updates, we DROP and CREATE.</p>\n\n<p>One wrinkle does pop up with this approach. It's easy to generate a database, and it's easy to get a new one up to speed on the current DB version. However, care has to be taken with DAL generation (which we currently -- usually -- do with SubSonic), to ensure that DB/schema/proc changes are synchronized cleanly with the code used to access them. However, in our build paths is a batch file which generates the SubSonic DAL, so it's our SOP to checkout the DAL code, re-run that batch file, then check it all back in anytime the schema and/or procs change. (This, of course, triggers a source build, updating shared dependencies to the appropriate DLLs ... )</p>\n"}, {'answer_id': 77782, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I run a job to script it out to a formal directory structure.</p>\n\n<p>The following is VS2005 code, command line project, called from a batch file, that does the work. app.config keys at end of code.</p>\n\n<p>It is based on other code I found online. Slightly a pain to set up, but works well once you get it working.</p>\n\n<pre><code>Imports Microsoft.VisualStudio.SourceSafe.Interop\nImports System\nImports System.Configuration\n\nModule Module1\n\n Dim sourcesafeDataBase As String, sourcesafeUserName As String, sourcesafePassword As String, sourcesafeProjectName As String, fileFolderName As String\n\n\n Sub Main()\n If My.Application.CommandLineArgs.Count > 0 Then\n GetSetup()\n For Each thisOption As String In My.Application.CommandLineArgs\n Select Case thisOption.ToUpper\n Case "CHECKIN"\n DoCheckIn()\n Case "CHECKOUT"\n DoCheckOut()\n Case Else\n DisplayUsage()\n End Select\n Next\n Else\n DisplayUsage()\n End If\n End Sub\n\n Sub DisplayUsage()\n Console.Write(System.Environment.NewLine + "Usage: SourceSafeUpdater option" + System.Environment.NewLine + _\n "CheckIn - Check in ( and adds any new ) files in the directory specified in .config" + System.Environment.NewLine + _\n "CheckOut - Check out all files in the directory specified in .config" + System.Environment.NewLine + System.Environment.NewLine)\n End Sub\n\n Sub AddNewItems()\n Dim db As New VSSDatabase\n db.Open(sourcesafeDataBase, sourcesafeUserName, sourcesafePassword)\n Dim Proj As VSSItem\n Dim Flags As Integer = VSSFlags.VSSFLAG_DELTAYES + VSSFlags.VSSFLAG_RECURSYES + VSSFlags.VSSFLAG_DELNO\n Try\n Proj = db.VSSItem(sourcesafeProjectName, False)\n Proj.Add(fileFolderName, "", Flags)\n Catch ex As Exception\n If Not ex.Message.ToString.ToLower.IndexOf("already exists") > 0 Then\n Console.Write(ex.Message)\n End If\n End Try\n Proj = Nothing\n db = Nothing\n End Sub\n\n Sub DoCheckIn()\n AddNewItems()\n Dim db As New VSSDatabase\n db.Open(sourcesafeDataBase, sourcesafeUserName, sourcesafePassword)\n Dim Proj As VSSItem\n Dim Flags As Integer = VSSFlags.VSSFLAG_DELTAYES + VSSFlags.VSSFLAG_UPDUPDATE + VSSFlags.VSSFLAG_FORCEDIRYES + VSSFlags.VSSFLAG_RECURSYES\n Proj = db.VSSItem(sourcesafeProjectName, False)\n Proj.Checkin("", fileFolderName, Flags)\n Dim File As String\n For Each File In My.Computer.FileSystem.GetFiles(fileFolderName)\n Try\n Proj.Add(fileFolderName + File)\n Catch ex As Exception\n If Not ex.Message.ToString.ToLower.IndexOf("access code") > 0 Then\n Console.Write(ex.Message)\n End If\n End Try\n Next\n Proj = Nothing\n db = Nothing\n End Sub\n\n Sub DoCheckOut()\n Dim db As New VSSDatabase\n db.Open(sourcesafeDataBase, sourcesafeUserName, sourcesafePassword)\n Dim Proj As VSSItem\n Dim Flags As Integer = VSSFlags.VSSFLAG_REPREPLACE + VSSFlags.VSSFLAG_RECURSYES\n Proj = db.VSSItem(sourcesafeProjectName, False)\n Proj.Checkout("", fileFolderName, Flags)\n Proj = Nothing\n db = Nothing\n End Sub\n\n Sub GetSetup()\n sourcesafeDataBase = ConfigurationManager.AppSettings("sourcesafeDataBase")\n sourcesafeUserName = ConfigurationManager.AppSettings("sourcesafeUserName")\n sourcesafePassword = ConfigurationManager.AppSettings("sourcesafePassword")\n sourcesafeProjectName = ConfigurationManager.AppSettings("sourcesafeProjectName")\n fileFolderName = ConfigurationManager.AppSettings("fileFolderName")\n\n End Sub\n\nEnd Module\n\n\n\n<add key="sourcesafeDataBase" value="C:\\wherever\\srcsafe.ini"/>\n<add key="sourcesafeUserName" value="vssautomateuserid"/>\n<add key="sourcesafePassword" value="pw"/>\n<add key="sourcesafeProjectName" value="$/where/you/want/it"/>\n<add key="fileFolderName" value="d:\\yourdirstructure"/>\n</code></pre>\n'}, {'answer_id': 78261, 'author': 'Rick', 'author_id': 14138, 'author_profile': 'https://Stackoverflow.com/users/14138', 'pm_score': 3, 'selected': False, 'text': '<p>One thing to keep in mind with your drop/create scripts in SQL Server is that object-level permissions will be lost. We changed our standard to use ALTER scripts instead, which maintains those permissions.</p>\n\n<p>There are a few other caveats, like the fact that dropping an object drops the dependency records used by sp_depends, and creating the object only creates the dependencies for that object. So if you drop/create a view, sp_depends will no longer know of any objects referencing that view.</p>\n\n<p>Moral of the story, use ALTER scripts.</p>\n'}, {'answer_id': 78328, 'author': 'knight0323', 'author_id': 14281, 'author_profile': 'https://Stackoverflow.com/users/14281', 'pm_score': 1, 'selected': False, 'text': "<p>Stored procedures get 1 file per sp with the standard if exist drop/create statements at the top. Views and functions also get their own files so they are easier to version and reuse.</p>\n\n<p>Schema is all 1 script to begin with then we'll do version changes.</p>\n\n<p>All of this is stored in a visual studio database project connected to TFS (@ work or VisualSVN Server @ home for personal stuff) with a folder structure as follows:<br />\n- project<br />\n-- functions<br />\n-- schema<br />\n-- stored procedures<br />\n-- views<br /></p>\n"}, {'answer_id': 78415, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>At my company, we tend to store all database items in source control as individual scripts just as you would for individual code files. Any updates are first made in the database and then migrated into the source code repository so a history of changes is maintained.<br>\nAs a second step, all database changes are migrated to an integration database. This integration database represents exactly what the production database should look like post deployment. We also have a QA database which represents the current state of production (or the last deployment). Once all changes are made in the Integration database, we use a schema diff tool (Red Gate's SQL Diff for SQL Server) to generate a script that will migrate all changes from one database to the other.<br>\nWe have found this to be fairly effective as it generates a single script that we can integrate with our installers easily. The biggest issue we often have is developers forgetting to migrate their changes into integration.</p>\n"}, {'answer_id': 81694, 'author': 'icelava', 'author_id': 2663, 'author_profile': 'https://Stackoverflow.com/users/2663', 'pm_score': 3, 'selected': False, 'text': '<p>I agree with (and upvote) Robert Paulson\'s practice. That is assuming you are in control of a development team with the responsibility and discipline to adhere to such a practice.</p>\n\n<p>To "force" that onto my teams, our solutions maintain at least one database project from <strong><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7DE00386-893D-4142-A778-992B69D482AD&displaylang=en" rel="noreferrer">Visual Studio Team Edition for Database Professionals</a></strong>. As with other projects in the solution, the database project gets versioned control. It makes it a natural development process to break the everything in the database into maintainable chunks, "disciplining" my team along the way.</p>\n\n<p>Of course, being a Visual Studio project, it is no where near perfect. There are many quirks you will run into that may frustrate or confuse you. It takes a fair bit of understanding how the project works before getting it to accomplish your tasks. Examples include</p>\n\n<ul>\n<li><a href="http://icelava.net/forums/post/2620.aspx" rel="noreferrer">deploying data from CSV files</a>.</li>\n<li><a href="http://icelava.net/forums/post/2756.aspx" rel="noreferrer">selective deployment of test data based on build type</a>.</li>\n<li><a href="http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1750819&SiteID=1" rel="noreferrer">Visual Studio crashing on comparing with databases with certain type of CLR assembly embedded within</a>.</li>\n<li>no means of differntiation between test/production databases that implement different authentication schemes - SQL users vs Active Directory users.</li>\n</ul>\n\n<p>But for teams who don\'t have a practice of versioning their database objects, this is a good start. The other famous alternative is of course, <a href="http://www.red-gate.com/products/index.htm" rel="noreferrer">Red Gate\'s suite of SQL Server products</a>, which most people who use them consider superior to Microsoft\'s offering.</p>\n'}, {'answer_id': 7841276, 'author': 'anopres', 'author_id': 1537, 'author_profile': 'https://Stackoverflow.com/users/1537', 'pm_score': 2, 'selected': False, 'text': "<p>I've found that by far, the easiest, fastest and safest way to do this is to just bite the bullet and use SQL Source Control from RedGate. Scripted and stored in the repository in a matter of minutes. I just wish that RedGate would look at the product as a loss leader so that it could get more widespread use.</p>\n"}, {'answer_id': 28448690, 'author': 'jlee-tessik', 'author_id': 4281149, 'author_profile': 'https://Stackoverflow.com/users/4281149', 'pm_score': -1, 'selected': False, 'text': '<p>If you\'re looking for an easy, ready-made solution, our <a href="http://tessik.com/sqlhistorian" rel="nofollow">Sql Historian</a> system uses a background process to automatically synchronizes DDL changes to TFS or SVN, transparent to anyone making changes on the database. In my experience, the big problem is maintaining the code in source control with what was changed on your server--and that\'s because usually you have to rely on people (developers, even!) to change their workflow and remember to check in their changes after they\'ve already made it on the server. Putting that burden on a machine makes everyone\'s life easier. </p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77172', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7856/']
|
77,193 |
<p>You've just written a pile of code to deliver some important feature under pressure. You've cut a few corners, you've mashed some code into some over-bloated classes with names like SerialIndirectionShutoffManager..</p>
<p>You tell your boss you're going to need a week to clean this stuff up.</p>
<p>"Clean what up?"</p>
<p>"My code - its a pigsty!"</p>
<p>"You mean there's some more bug fixing?"</p>
<p>"Not really, its more like.."</p>
<p>"You're gonna make it run faster?"</p>
<p>"Perhaps, buts thats not.."</p>
<p>"Then you should have written it properly when you had the chance. Now I'm glad you're here, yeah, I'm gonna have to go ahead and ask you to come in this weekend.. "</p>
<p>I've read Matin Fowler's book, but I'm not sure I agree with his advice on this matter:</p>
<ul>
<li>Encourage regular code reviews, so refactoring work is encouraged as a natural part of the development process. </li>
<li>Just don't tell, you're the developer and its part of your duty. </li>
</ul>
<p>Both these methods squirm out of the need to communicate with your manager.</p>
<p>What do you tell your boss?</p>
|
[{'answer_id': 77206, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 3, 'selected': False, 'text': "<p>Lie. Tell him it's research into a new technology. Then tell him you decided the cost didn't justify the benefits. He'll think you did a great job.</p>\n\n<p>lol @ people down modding / marking offensive.</p>\n\n<p>Really, if it's a penny pinching boss, who doesn't understand good software from cheap software, what he doesn't know will ultimately make him happier. if it was me, i would leave the company and go someplace where they respect their developers ability to write good code. But then again, this is why I'm in a senior position.</p>\n"}, {'answer_id': 77230, 'author': 'Keith Nicholas', 'author_id': 10431, 'author_profile': 'https://Stackoverflow.com/users/10431', 'pm_score': 2, 'selected': False, 'text': '<p>Refactoring you should do all the time.... so you shouldn\'t have to justify it.</p>\n\n<p>Cleaning up big messes / Redesign may include refactoring in order to get it under control, however its not "Refactoring"</p>\n\n<p>Refactoring should be a matter of moments...or if you have no tool support, minutes.</p>\n'}, {'answer_id': 77236, 'author': 'Alex B', 'author_id': 6180, 'author_profile': 'https://Stackoverflow.com/users/6180', 'pm_score': 2, 'selected': False, 'text': '<p>I like the answer given in "Refactoring" by Martin Fowler. Tell your boss that you are going to develop software the fastest way that you know how. It happens that in most cases the fastest way to develop software is to refactor as you go.</p>\n\n<p>The other thing to tell your boss is you are reducing the cost to make future improvements.</p>\n'}, {'answer_id': 77240, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Tell him 80% of the costs associated with a software project comes in the maintenance phase of the lifecycle. Any refactoring done now to alleviate future problems, and have some examples, will net substantial cost benefits later on when the need arises to maintaining that code.</p>\n\n<p>This is assuming you are refactoring for a reason and not for programmer vanity.</p>\n'}, {'answer_id': 77241, 'author': 'John Flinchbaugh', 'author_id': 12591, 'author_profile': 'https://Stackoverflow.com/users/12591', 'pm_score': 3, 'selected': False, 'text': "<p>Just do it and schedule it into your normal process. Estimate refactoring time into starting a new change or into finishing a change (ideal).\nI always refactor while I'm initially exploring new code (extracting methods, etc).</p>\n"}, {'answer_id': 77242, 'author': 'Brian Leahy', 'author_id': 580, 'author_profile': 'https://Stackoverflow.com/users/580', 'pm_score': 5, 'selected': False, 'text': '<p>Speak in a language he can understand.</p>\n\n<p>Refactoring is paying design debt. </p>\n\n<p>Ask your boss why he pays the company credit card bill every month vs not paying it until there is a collections notice. Tell him refactoring is like making your monthly payment.</p>\n'}, {'answer_id': 77247, 'author': 'japollock', 'author_id': 1210318, 'author_profile': 'https://Stackoverflow.com/users/1210318', 'pm_score': 0, 'selected': False, 'text': '<p>Less money now for me to refactor...</p>\n\n<p>or more money later to fix whatever goes wrong and for me to refactor.</p>\n'}, {'answer_id': 77261, 'author': 'Torlack', 'author_id': 5243, 'author_profile': 'https://Stackoverflow.com/users/5243', 'pm_score': 2, 'selected': False, 'text': "<p>In one of Robert Glass's recent books (I'll have to look up the reference) he mentioned a study on the cost of well maintained code. What they found is that well maintained code was edited more often than poorly maintained code. That sounds counter intuitive but when they dug deeper the discovered the reason:</p>\n\n<p>Well maintained code has more features added to it in the same time frame than poorly maintained code.</p>\n\n<p>Does your Boss like features? Sure, they all do. If more you improve the maintainability of the code, the more features you will be able to deliver with that limited budget.</p>\n"}, {'answer_id': 77363, 'author': 'Charles Graham', 'author_id': 7705, 'author_profile': 'https://Stackoverflow.com/users/7705', 'pm_score': 0, 'selected': False, 'text': '<p>Sometimes, it\'s just time to get a new job. There are certian poeple who just want you to "get it done". If you are ever in one of those situations, and I\'ve been there, then just leave.</p>\n\n<p>But yeah, all that other stuff about future costs and such is good idea. I just think that most bosses lie to themselves because they want what they want when they want it, and they are just not able to see what\'s going to happen in the future.</p>\n\n<p>So, good luck with your boss. Hpefully he or she is reasonable.</p>\n'}, {'answer_id': 77425, 'author': 'Thomas Wagner', 'author_id': 13997, 'author_profile': 'https://Stackoverflow.com/users/13997', 'pm_score': 0, 'selected': False, 'text': '<p>Dont.... just go get a new job in a place thats more in synch with you. </p>\n'}, {'answer_id': 77459, 'author': 'Seibar', 'author_id': 357, 'author_profile': 'https://Stackoverflow.com/users/357', 'pm_score': 0, 'selected': False, 'text': "<p>I think you should just start working on it without telling your boss. This is truly how I've done my best work. I just don't tell my boss what I'm doing and slowly replace bad/legacy code when I have time. </p>\n\n<p>It has acutally saved my ass on more than one occasion.</p>\n"}, {'answer_id': 77526, 'author': 'nsayer', 'author_id': 13757, 'author_profile': 'https://Stackoverflow.com/users/13757', 'pm_score': 0, 'selected': False, 'text': "<p>If your boss doesn't understand the need to refactor or clean up code, then you have to wonder if he has enough engineering knowledge to be an engineering manager.</p>\n"}, {'answer_id': 77641, 'author': 'Orion Adrian', 'author_id': 7756, 'author_profile': 'https://Stackoverflow.com/users/7756', 'pm_score': 6, 'selected': True, 'text': "<p>It's important to include refactoring time in your original estimates. Going to your boss after you've delivered the product and then telling him that you're not actually done is lying about being done. You didn't actually make the deliverable deadline. It's like a surgeon doing surgery and then not making sure he put everything back the way it was supposed to be.</p>\n\n<p>It is important to include all the parts of development (e.g. refactoring, usability research, testing, QA, revisions) in your original schedules. Ultimately this isn't so much a management problem as a programmer problem.</p>\n\n<p>If, however, you've inherited a mess then you will have to explain to the boss that the last set of programmers in a rush to get the project out the door cut corners and that it's been limping along. You can band-aid the problem for awhile (as they likely did), but each band-aid just delays the problem and ultimately makes the problem that much more expensive to fix.</p>\n\n<p>Be honest with your boss and understand that a project isn't done until it's done.</p>\n"}, {'answer_id': 77668, 'author': 'EvilEddie', 'author_id': 12986, 'author_profile': 'https://Stackoverflow.com/users/12986', 'pm_score': 0, 'selected': False, 'text': "<p>It's rare to find a boss who will give you time to refactor...just do it as you go along.</p>\n"}, {'answer_id': 77737, 'author': 'torial', 'author_id': 13990, 'author_profile': 'https://Stackoverflow.com/users/13990', 'pm_score': 0, 'selected': False, 'text': "<p>In my opinion, the simplest case to make for refactoring is fixing overly complex code. Measure the McCabe cyclomatic complexity of the source code in question (Source Monitor is an excellent tool for such a problem). Source code with high cyclomatic complexity has a strong correlation defects and bad fixes. What this means in simple terms is that complex code is harder to fix and more likely to have bad fixes. What this means to a manager is that the quality of the product will likely be worse, and the bugs harder to fix, and the schedule for the project ultimately worse. However, in refactoring out the complexity, you are improving the transparency of the code, reducing the likelihood of obscure / difficult bugs, and making it easier to maintain (e.g. a maintenance programmer can have a larger maintenance scope because of this).</p>\n\n<p>Additionally, you can make the case (if it isn't a dead product in maintenance cycle) that decreasing complexity makes the application easier to extend when new requirements are added to the project.</p>\n"}, {'answer_id': 77814, 'author': 'Amy B', 'author_id': 8155, 'author_profile': 'https://Stackoverflow.com/users/8155', 'pm_score': 0, 'selected': False, 'text': '<p>The boss has to trust the dev to make correct technical decisions (including when to refactor).</p>\n\n<p>Establish that trust or replace the boss or replace the dev.</p>\n'}, {'answer_id': 6917850, 'author': 'Tom W', 'author_id': 313414, 'author_profile': 'https://Stackoverflow.com/users/313414', 'pm_score': 0, 'selected': False, 'text': '<p>Another good analogy is the maintenance of a tidy building site. The only catch here is that a programmer does not represent a construction worker, and a manager does not represent a foreman. If that were the case, his counter of "do it right first time" would still apply, since a competent and conscientious construction worker is responsible for maintaining good order on their workspace as they go. </p>\n\n<p>Really the <strong>code itself</strong> represents the labourers, and the development process is the foreman. The mess is generated by various trades going about their business around one another (i.e. by different code features interacting, where each feature does its job well, but the seams between them are disorganised) and is cleaned up by the foreman taking a firm hand and keeping an eye on where disorder is setting in, and acting to get it cleaned up (i.e. the software process demanding refactoring). </p>\n'}, {'answer_id': 11564382, 'author': 'clopez', 'author_id': 845225, 'author_profile': 'https://Stackoverflow.com/users/845225', 'pm_score': 0, 'selected': False, 'text': "<p>What I just did recently is to explain to my business counterpart that the re-factory process helps to develop new features faster and decrease the probability of new bugs because the code has a better order and structure, and is even posible to make some speeds improvements because you can inspect the code easier than before.</p>\n\n<p>When the business guys get that, if they are smart, they will encourage you to do a constant re-factory process.</p>\n\n<p>You can explain that with a building metaphor. If you don't do refactory you will end with a crappy building with a bad core so you will have problems with the pipes, windows, doors.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77193', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13899/']
|
77,198 |
<p>I'm doing a tech review and looking at AMF integration with various backends (Rails, Python, Grails etc).</p>
<p>Lots of options are out there, question is, what do the Adobe products do (BlazeDS etc) that something like RubyAMF / pyAMF don't?</p>
|
[{'answer_id': 77458, 'author': 'James Law', 'author_id': 11855, 'author_profile': 'https://Stackoverflow.com/users/11855', 'pm_score': 1, 'selected': False, 'text': '<p>Good question. I\'m not a ruby guy (i use java with flex), but what I believe differentiates blazeds vs commercial livecycle ds is</p>\n\n<ol>\n<li>Streaming protocol support (rtmp) - competition for comet and such, delivering video</li>\n<li>Some advanced stuff for hibernate detached objects and large resultset caching that I don\'t fully understand or need\n\n<ol start="3">\n<li>support?\nMight be others but those are the ones I know off the top of my head.</li>\n</ol></li>\n</ol>\n'}, {'answer_id': 83014, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Adobe has two products: Livecycle Data Services ES (LCDS) and BlazeDS. BlazeDS contains a subset of LCDS features and was made open source. Unfortunately NIO channels (RTMP NIO/HTTP) and the DataManagement features are implemented only in LCDS, not BlazeDS.</p>\n\n<p>BlazeDS can be used only to integrate Flex with Java backend. It offers not only remoting services using AMF serialization (as RubyAMF) but also messaging and collaboration features - take a look at this link (<a href="http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=lcoverview_3.html" rel="nofollow noreferrer">http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=lcoverview_3.html</a>). Also I suppose that the support is better compared with RubyAMF/pyAMF.</p>\n\n<p>If your backend is JAVA and you want to use only a free product you can also use GraniteDS or WebORB (BlazeDS competitors)</p>\n'}, {'answer_id': 98180, 'author': 'Cosma Colanicchia', 'author_id': 11867, 'author_profile': 'https://Stackoverflow.com/users/11867', 'pm_score': 3, 'selected': True, 'text': '<p>Other than NIO (RTMP) channels, LCDS include also the "data management" features. </p>\n\n<p>Using this feature, you basically implement, in an ActionScript class, a CRUD-like interface defined by LCDS, and you get:</p>\n\n<ul>\n<li>automatic progressive list loading (large lists/datagrids loads while scrolling)</li>\n<li>automatic crud management (you get object locally in flash, modify it, send it back and DB will get updated automatically)</li>\n<li>feature for conflict resolution (if multiple user try to updated the same record at the same time)</li>\n<li>if I remember well, also some improved integration with the LiveCycle ES workflow engine</li>\n</ul>\n\n<p>IMO, it can be very fast to develop this way, but only if you have only basic requirements and a simple architecture (forget SOA, that otherwise works so well with Flex). I\'m fine with BlazeDS.</p>\n'}, {'answer_id': 99603, 'author': 'user10440', 'author_id': 10440, 'author_profile': 'https://Stackoverflow.com/users/10440', 'pm_score': 2, 'selected': False, 'text': '<p>The data management features for LCDS described here are certainly valid, however I believe they do not let you actually develop a solution faster. A developer still has to write ALL the data access code, query execution, extracting data from datareaders into value objects. ALL of this has been solved a dozen of times with code generators. For instance the data management approach in WebORB for Java (much like in WebORB for .NET and PHP) is based on code generation which creates code for both client side AND server-side. You get all the ActionScript APIs out of the code generator to do full CRUD. </p>\n\n<p>Additionally, WebORB provides video streaming and real-time messaging features and goes WAY beyond what both BlazeDS and LCDS offer combined, especially considering that the product is free. Just google it.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77198', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4787/']
|
77,213 |
<p>I have a large number of Enums that implement this interface:</p>
<pre><code>/**
* Interface for an enumeration, each element of which can be uniquely identified by its code
*/
public interface CodableEnum {
/**
* Get the element with a particular code
* @param code
* @return
*/
public CodableEnum getByCode(String code);
/**
* Get the code that identifies an element of the enum
* @return
*/
public String getCode();
}
</code></pre>
<p>A typical example is:</p>
<pre><code>public enum IMType implements CodableEnum {
MSN_MESSENGER("msn_messenger"),
GOOGLE_TALK("google_talk"),
SKYPE("skype"),
YAHOO_MESSENGER("yahoo_messenger");
private final String code;
IMType (String code) {
this.code = code;
}
public String getCode() {
return code;
}
public IMType getByCode(String code) {
for (IMType e : IMType.values()) {
if (e.getCode().equalsIgnoreCase(code)) {
return e;
}
}
}
}
</code></pre>
<p>As you can imagine these methods are virtually identical in all implementations of CodableEnum. I would like to eliminate this duplication, but frankly don't know how. I tried using a class such as the following:</p>
<pre><code>public abstract class DefaultCodableEnum implements CodableEnum {
private final String code;
DefaultCodableEnum(String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
public abstract CodableEnum getByCode(String code);
}
</code></pre>
<p>But this turns out to be fairly useless because:</p>
<ol>
<li>An enum cannot extend a class</li>
<li>Elements of an enum (SKYPE, GOOGLE_TALK, etc.) cannot extend a class</li>
<li>I cannot provide a default implementation of getByCode(), because DefaultCodableEnum is not itself an Enum. I tried changing DefaultCodableEnum to extend java.lang.Enum, but this doesn't appear to be allowed.</li>
</ol>
<p>Any suggestions that do not rely on reflection?
Thanks,
Don</p>
|
[{'answer_id': 77298, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': 1, 'selected': False, 'text': "<p>Unfortunately, I don't think that there is a way to do this. Your best bet would pro ably be to give up in emums altogether and use conventional class extension and static members. Otherwise, get used to duplicating that code. Sorry.</p>\n"}, {'answer_id': 77321, 'author': 'Dave Hillier', 'author_id': 1575281, 'author_profile': 'https://Stackoverflow.com/users/1575281', 'pm_score': 0, 'selected': False, 'text': '<p>It seems like you are actually implementing run time type information. Java provides this as a language feature. </p>\n\n<p>I suggest you look up RTTI or reflection.</p>\n'}, {'answer_id': 77355, 'author': 'Jorn', 'author_id': 8681, 'author_profile': 'https://Stackoverflow.com/users/8681', 'pm_score': 0, 'selected': False, 'text': "<p>I don't think this is possible. However, you could use the enum's valueOf(String name) method if you were going to use the enum value's name as your code.</p>\n"}, {'answer_id': 77393, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>How about a static generic method? You could reuse it from within your enum's getByCode() methods or simply use it directly. I always user integer ids for my enums, so my getById() method only has do do this: return values()[id]. It's a lot faster and simpler.</p>\n"}, {'answer_id': 77465, 'author': 'Alex Miller', 'author_id': 7671, 'author_profile': 'https://Stackoverflow.com/users/7671', 'pm_score': 3, 'selected': False, 'text': '<p>Abstract enums are potentially very useful (and currently not allowed). But a proposal and prototype exists if you\'d like to lobby someone in Sun to add it:</p>\n\n<p><a href="http://freddy33.blogspot.com/2007/11/abstract-enum-ricky-carlson-way.html" rel="noreferrer">http://freddy33.blogspot.com/2007/11/abstract-enum-ricky-carlson-way.html</a></p>\n\n<p>Sun RFE:</p>\n\n<p><a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6570766" rel="noreferrer">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6570766</a></p>\n'}, {'answer_id': 77486, 'author': 'Greg Mattes', 'author_id': 13940, 'author_profile': 'https://Stackoverflow.com/users/13940', 'pm_score': 2, 'selected': False, 'text': '<p>I had a similar issue with a localization component that I wrote. My component is designed to access localized messages with enum constants that index into a resource bundle, not a hard problem.</p>\n\n<p>I found that I was copying and pasting the same "template" enum code all over the place. My solution to avoid the duplication is a code generator that accepts an XML configuration file with the enum constant names and constructor args. The output is the Java source code with the "duplicated" behaviors.</p>\n\n<p>Now, I maintain the configuration files and the generator, not all of the duplicated code. Everywhere I would have had enum source code, there is now an XML config file. My build scripts detect out-of-date generated files and invoke the code generator to create the enum code.</p>\n\n<p><p>You can see this component <a href="http://virtualteamtls.svn.sourceforge.net/viewvc/virtualteamtls/trunk/jill" rel="nofollow noreferrer">here</a>. The template that I was copying and pasting is factored out into <a href="http://virtualteamtls.svn.sourceforge.net/viewvc/virtualteamtls/trunk/jill/resources/com/iparelan/jill/jill.xsl?view=markup" rel="nofollow noreferrer">an XSLT stylesheet</a>. The <a href="http://virtualteamtls.svn.sourceforge.net/viewvc/virtualteamtls/trunk/jill/src/com/iparelan/jill/Jill.java?view=markup" rel="nofollow noreferrer">code generator</a> runs the stylesheet transformation. An <a href="http://virtualteamtls.svn.sourceforge.net/viewvc/virtualteamtls/trunk/jill/src/com/iparelan/jill/jill.xml?view=markup" rel="nofollow noreferrer">input file</a> is quite concise compared to the generated enum source code.</p>\n\n<p>HTH,<br/>\nGreg</p>\n'}, {'answer_id': 77578, 'author': 'Mwanji Ezana', 'author_id': 7288, 'author_profile': 'https://Stackoverflow.com/users/7288', 'pm_score': 0, 'selected': False, 'text': '<p>If you really want inheritance, don\'t forget that you can <a href="http://snipplr.com/view/1655/typesafe-enum-pattern" rel="nofollow noreferrer">implement the enum pattern yourself</a>, like in the bad old Java 1.4 days.</p>\n'}, {'answer_id': 78029, 'author': 'Javamann', 'author_id': 10166, 'author_profile': 'https://Stackoverflow.com/users/10166', 'pm_score': 0, 'selected': False, 'text': "<p>About as close as I got to what you want was to create a template in IntelliJ that would 'implement' the generic code (using enum's valueOf(String name)). Not perfect but works quite well.</p>\n"}, {'answer_id': 78306, 'author': 'dave', 'author_id': 14355, 'author_profile': 'https://Stackoverflow.com/users/14355', 'pm_score': 5, 'selected': True, 'text': '<p>You could factor the duplicated code into a <code>CodeableEnumHelper</code> class:</p>\n\n<pre><code>public class CodeableEnumHelper {\n public static CodeableEnum getByCode(String code, CodeableEnum[] values) {\n for (CodeableEnum e : values) {\n if (e.getCode().equalsIgnoreCase(code)) {\n return e;\n }\n }\n return null;\n }\n}\n</code></pre>\n\n<p>Each <code>CodeableEnum</code> class would still have to implement a <code>getByCode</code> method, but the actual implementation of the method has at least been centralized to a single place.</p>\n\n<pre><code>public enum IMType implements CodeableEnum {\n ...\n public IMType getByCode(String code) {\n return (IMType)CodeableEnumHelper.getByCode(code, this.values());\n } \n}\n</code></pre>\n'}, {'answer_id': 78511, 'author': 'triggerNZ', 'author_id': 13822, 'author_profile': 'https://Stackoverflow.com/users/13822', 'pm_score': 1, 'selected': False, 'text': '<p>Create a type-safe utility class which will load enums by code:</p>\n\n<p>The interface comes down to:</p>\n\n<pre><code>public interface CodeableEnum {\n String getCode();\n}\n</code></pre>\n\n<p>The utility class is:</p>\n\n<pre><code>import java.lang.reflect.InvocationTargetException;\n\n\npublic class CodeableEnumUtils {\n @SuppressWarnings("unchecked")\n public static <T extends CodeableEnum> T getByCode(String code, Class<T> enumClass) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {\n T[] allValues = (T[]) enumClass.getMethod("values", new Class[0]).invoke(null, new Object[0]);\n for (T value : allValues) {\n if (value.getCode().equals(code)) {\n return value;\n }\n }\n return null;\n}\n</code></pre>\n\n<p>}</p>\n\n<p>A test case demonstrating usage:</p>\n\n<pre><code>import junit.framework.TestCase;\n\n\npublic class CodeableEnumUtilsTest extends TestCase {\n public void testWorks() throws Exception {\n assertEquals(A.ONE, CodeableEnumUtils.getByCode("one", A.class));\n assertEquals(null, CodeableEnumUtils.getByCode("blah", A.class));\n }\n\nenum A implements CodeableEnum {\n ONE("one"), TWO("two"), THREE("three");\n\n private String code;\n\n private A(String code) {\n this.code = code;\n }\n\n public String getCode() {\n return code;\n } \n}\n}\n</code></pre>\n\n<p>Now you are only duplicating the getCode() method and the getByCode() method is in one place. It might be nice to wrap all the exceptions in a single RuntimeException too :)</p>\n'}, {'answer_id': 81912, 'author': 'Tom Hawtin - tackline', 'author_id': 4725, 'author_profile': 'https://Stackoverflow.com/users/4725', 'pm_score': 3, 'selected': False, 'text': "<p>To tidy up dave's code:</p>\n\n<pre><code>public class CodeableEnumHelper {\n public static <E extends CodeableEnum> E getByCode(\n String code, E[] values\n ) {\n for (E e : values) {\n if (e.getCode().equalsIgnoreCase(code)) {\n return e;\n }\n }\n return null;\n }\n}\n\npublic enum IMType implements CodableEnum {\n ...\n public IMType getByCode(String code) {\n return CodeableEnumHelper.getByCode(code, values());\n } \n}\n</code></pre>\n\n<p>Or more efficiently:</p>\n\n<pre><code>public class CodeableEnumHelper {\n public static <E extends CodeableEnum> Map<String,E> mapByCode(\n E[] values\n ) {\n Map<String,E> map = new HashMap<String,E>();\n for (E e : values) {\n map.put(e.getCode().toLowerCase(Locale.ROOT), value) {\n }\n return map;\n }\n}\n\npublic enum IMType implements CodableEnum {\n ...\n private static final Map<String,IMType> byCode =\n CodeableEnumHelper.mapByCode(values());\n public IMType getByCode(String code) {\n return byCode.get(code.toLowerCase(Locale.ROOT));\n } \n}\n</code></pre>\n"}, {'answer_id': 82005, 'author': 'Nicolas', 'author_id': 1730, 'author_profile': 'https://Stackoverflow.com/users/1730', 'pm_score': 0, 'selected': False, 'text': "<p>In your specific case, the getCode() / getByCode(String code) methods seems very closed (euphemistically speaking) to the behaviour of the toString() / valueOf(String value) methods provided by all enumeration. Why don't you want to use them?</p>\n"}, {'answer_id': 2471851, 'author': 'sleske', 'author_id': 43681, 'author_profile': 'https://Stackoverflow.com/users/43681', 'pm_score': 0, 'selected': False, 'text': '<p>Another solution would be not to put anything into the enum itself, and just provide a bi-directional map Enum <-> Code for each enum. You could e.g. use <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/ImmutableBiMap.html" rel="nofollow noreferrer">ImmutableBiMap</a> from Google Collections for this.</p>\n\n<p>That way there no duplicate code at all.</p>\n\n<p>Example:</p>\n\n<pre><code>public enum MYENUM{\n VAL1,VAL2,VAL3;\n}\n\n/** Map MYENUM to its ID */\npublic static final ImmutableBiMap<MYENUM, Integer> MYENUM_TO_ID = \nnew ImmutableBiMap.Builder<MYENUM, Integer>().\nput(MYENUM.VAL1, 1).\nput(MYENUM.VAL2, 2).\nput(MYENUM.VAL3, 3).\nbuild();\n</code></pre>\n'}, {'answer_id': 2867061, 'author': 'Marius Burz', 'author_id': 110750, 'author_profile': 'https://Stackoverflow.com/users/110750', 'pm_score': 0, 'selected': False, 'text': '<p>In my opinion, this would be the easiest way, without reflection and without adding any extra wrapper to your enum.</p>\n\n<p>You create an interface that your enum implements:</p>\n\n<pre><code>public interface EnumWithId {\n\n public int getId();\n\n}\n</code></pre>\n\n<p>Then in a helper class you just create a method like this one:</p>\n\n<pre><code>public <T extends EnumWithId> T getById(Class<T> enumClass, int id) {\n T[] values = enumClass.getEnumConstants();\n if (values != null) {\n for (T enumConst : values) {\n if (enumConst.getId() == id) {\n return enumConst;\n }\n }\n }\n\n return null;\n}\n</code></pre>\n\n<p>This method could be then used like this:</p>\n\n<pre><code>MyUtil.getInstance().getById(MyEnum.class, myEnumId);\n</code></pre>\n'}, {'answer_id': 5368044, 'author': 'bueyuekt', 'author_id': 668132, 'author_profile': 'https://Stackoverflow.com/users/668132', 'pm_score': 1, 'selected': False, 'text': '<p>Here I have another solution:</p>\n\n<pre><code>interface EnumTypeIF {\nString getValue();\n\nEnumTypeIF fromValue(final String theValue);\n\nEnumTypeIF[] getValues();\n\nclass FromValue {\n private FromValue() {\n }\n\n public static EnumTypeIF valueOf(final String theValue, EnumTypeIF theEnumClass) {\n\n for (EnumTypeIF c : theEnumClass.getValues()) {\n if (c.getValue().equals(theValue)) {\n return c;\n }\n }\n throw new IllegalArgumentException(theValue);\n }\n}\n</code></pre>\n\n<p>The trick is that the inner class can be used to hold "global methods".</p>\n\n<p>Worked pretty fine for me. OK, you have to implement 3 Methods, but those methods,\nare just delegators.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77213', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2648/']
|
77,217 |
<p>I will be moving our production SQL2005 application to SQL2008 soon. Any things to lookout for before/after the move? Any warnings, advices?</p>
<p>Thank you!</p>
|
[{'answer_id': 77408, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>The upgrade adviser can also help. </p>\n\n<p>Look at the execution plans with production data in the database.</p>\n\n<p>Though my best advice is to test, test, test. </p>\n\n<p>When people started moving from 2000 to 2005 it wasn't the breaking features that were show stoppers it was the change in how queries performed with the new optimizer. </p>\n\n<p>Queries that were heavily optimized for 2000 now performed poorly or even worse erratically leading people to chase down non-problems and generally lowering the confidence of the end users. </p>\n"}, {'answer_id': 215821, 'author': 'Brent Ozar', 'author_id': 26837, 'author_profile': 'https://Stackoverflow.com/users/26837', 'pm_score': 2, 'selected': False, 'text': "<p>Change your compatibility level on the database after moving it to the 2008 server. By default, it will still stay at the old compatibility level. This will let you use the new goodies in SQL 2008 for that database.</p>\n\n<p>If you're using the Enterprise Edition of SQL 2008 and you're not running at 80-90% CPU on the box, turn on data compression and compress all of your objects. There's a big performance gain on that. Unfortunately, you have to do it manually for every single object - there's not a single switch to throw.</p>\n\n<p>If you're not using Enterprise, after upping the compatibility level, rebuild all of your indexes. (This holds pretty much true for any version upgrade.)</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77217', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4808/']
|
77,226 |
<p>What is the easiest way to capitalize the first letter in each word of a string?</p>
|
[{'answer_id': 77237, 'author': 'zigdon', 'author_id': 4913, 'author_profile': 'https://Stackoverflow.com/users/4913', 'pm_score': 4, 'selected': False, 'text': '<p>Take a look at the <a href="http://perldoc.perl.org/functions/ucfirst.html" rel="noreferrer">ucfirst</a> function.</p>\n\n<pre><code>$line = join " ", map {ucfirst} split " ", $line;\n</code></pre>\n'}, {'answer_id': 77249, 'author': 'piCookie', 'author_id': 8763, 'author_profile': 'https://Stackoverflow.com/users/8763', 'pm_score': 5, 'selected': True, 'text': '<p>See <a href="http://learn.perl.org/faq/perlfaq4.html#How-do-I-capitalize-all-the-words-on-one-line" rel="nofollow noreferrer">the faq</a>.</p>\n\n<p>I don\'t believe <code>ucfirst()</code> satisfies the OP\'s question to capitalize the first letter of each word in a string without splitting the string and joining it later.</p>\n'}, {'answer_id': 77828, 'author': 'moritz', 'author_id': 14132, 'author_profile': 'https://Stackoverflow.com/users/14132', 'pm_score': 3, 'selected': False, 'text': '<pre><code>$string =~ s/(\\w+)/\\u$1/g;\n</code></pre>\n\n<p>should work just fine</p>\n'}, {'answer_id': 78165, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>Note that the FAQ solution doesn't work if you have words that are in all-caps and you want them to be (only) capitalized instead. You can either make a more complicated regex, or just do a lc on the string before applying the FAQ solution.</p>\n"}, {'answer_id': 79379, 'author': 'RET', 'author_id': 14750, 'author_profile': 'https://Stackoverflow.com/users/14750', 'pm_score': -1, 'selected': False, 'text': '<p>The <a href="http://perldoc.perl.org/functions/ucfirst.html" rel="nofollow noreferrer">ucfirst</a> function in a map certainly does this, but only in a very rudimentary way. If you want something a bit more sophisticated, have a look at <a href="http://daringfireball.net/2008/08/title_case_update" rel="nofollow noreferrer">John Gruber\'s TitleCase script</a>.</p>\n'}, {'answer_id': 163826, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 6, 'selected': False, 'text': '<p>As @brian is mentioning in the comments the currently accepted answer by @piCookie is wrong!</p>\n\n<pre><code>$_="what\'s the wrong answer?";\ns/\\b(\\w)/\\U$1/g\nprint; \n</code></pre>\n\n<p>This will print "What\'S The Wrong Answer?" notice the wrongly capitalized S </p>\n\n<p>As the <a href="http://faq.perl.org/perlfaq4.html#How_do_I_capitalize_" rel="noreferrer">FAQ</a> says you are probably better off using </p>\n\n<pre><code>s/([\\w\']+)/\\u\\L$1/g\n</code></pre>\n\n<p>or <a href="https://metacpan.org/module/Text::Autoformat" rel="noreferrer">Text::Autoformat</a></p>\n'}, {'answer_id': 182104, 'author': 'kixx', 'author_id': 11260, 'author_profile': 'https://Stackoverflow.com/users/11260', 'pm_score': 4, 'selected': False, 'text': '<pre><code>$capitalized = join \'\', map { ucfirst lc $_ } split /(\\s+)/, $line;\n</code></pre>\n\n<p>By capturing the whitespace, it is inserted in the list and used to rebuild the original spacing. "ucfirst lc" capitalizes "teXT" to "Text".</p>\n'}, {'answer_id': 2334645, 'author': 'vsync', 'author_id': 104380, 'author_profile': 'https://Stackoverflow.com/users/104380', 'pm_score': 1, 'selected': False, 'text': '<p>You can use \'<a href="http://daringfireball.net/2008/05/title_case" rel="nofollow noreferrer">Title Case</a>\', its a very cool piece of code written in Perl.</p>\n'}, {'answer_id': 9508413, 'author': 'alemol', 'author_id': 1241476, 'author_profile': 'https://Stackoverflow.com/users/1241476', 'pm_score': 2, 'selected': False, 'text': '<p>This capitalizes only the first word of each line:</p>\n\n<pre><code>perl -ne "print (ucfirst($1)$2) if s/^(\\w)(.*)/\\1\\2/" file\n</code></pre>\n'}, {'answer_id': 47477440, 'author': 'bill god', 'author_id': 8557675, 'author_profile': 'https://Stackoverflow.com/users/8557675', 'pm_score': 1, 'selected': False, 'text': '<p>try this : </p>\n\n<pre><code>echo "what\'s the wrong answer?" |perl -pe \'s/^/ /; s/\\s(\\w+)/ \\u$1/g; s/^ //\'\n</code></pre>\n\n<p>Output will be:</p>\n\n<pre><code>What\'s The Wrong Answer?\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77226', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13912/']
|
77,258 |
<p>I am trying to solve the current problem using GPU capabilities: "given a point cloud P and an oriented plane described by a point and a normal (Pp, Np) return the points in the cloud which lye at a distance equal or less than EPSILON from the plane".</p>
<p>Talking with a colleague of mine I converged toward the following solution:</p>
<p>1) prepare a vertex buffer of the points with an attached texture coordinate such that every point has a different vertex coordinate
2) set projection status to orthogonal
3) rotate the mesh such that the normal of the plane is aligned with the -z axis and offset it such that x,y,z=0 corresponds to Pp
4) set the z-clipping plane such that z:[-EPSILON;+EPSILON]
5) render to a texture
6) retrieve the texture from the graphic card
7) read the texture from the graphic card and see what points were rendered (in terms of their indexes), which are the points within the desired distance range.</p>
<p>Now the problems are the following:
q1) Do I need to open a window-frame to be able to do such operation? I am working within MATLAB and calling MEX-C++. By experience I know that as soon as you open a new frame the whole suit crashes miserably!
q2) what's the primitive to give a GLPoint a texture coordinate?
q3) I am not too clear how the render to a texture would be implemented? any reference, tutorial would be awesome...
q4) How would you retrieve this texture from the card? again, any reference, tutorial would be awesome...</p>
<p>I am on a tight schedule, thus, it would be nice if you could point me out the names of the techniques I should learn about, rather to the GLSL specification document and the OpenGL API as somebody has done. Those are a tiny bit too vague answers to my question.</p>
<p>Thanks a lot for any comment.</p>
<p>p.s.
Also notice that I would rather not use any resource like CUDA if possible, thus, getting something which uses
as much OpenGL elements as possible without requiring me to write a new shader. </p>
<p>Note: cross posted at
<a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=245911#Post245911" rel="nofollow noreferrer">http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=245911#Post245911</a></p>
|
[{'answer_id': 77543, 'author': 'Sarien', 'author_id': 1994377, 'author_profile': 'https://Stackoverflow.com/users/1994377', 'pm_score': 0, 'selected': False, 'text': '<p>Ok first as a little disclaimer: I know nothing about 3D programming.</p>\n\n<p>Now my purely mathematical idea:</p>\n\n<p>Given a plane by a normal N (of unit length) and a distance L of the plane to the center (the point [0/0/0]). The distance of a point X to the plane is given by the scalar product of N and X minus L the distance to the center. Hence you only have to check wether</p>\n\n<p>|n . x - L| <= epsilon</p>\n\n<p>. being the scalar product and | | the absolute value</p>\n\n<p>Of course you have to intersect the plane with the normal first to get the distance L.</p>\n\n<p>Maybe this helps.</p>\n'}, {'answer_id': 81165, 'author': 'Sarien', 'author_id': 1994377, 'author_profile': 'https://Stackoverflow.com/users/1994377', 'pm_score': 1, 'selected': False, 'text': '<p>It\'s simple:\nLet n be the normal of the plane and x be the point.</p>\n\n<pre><code>n_u = n/norm(n) //this is a normal vector of unit length\nd = scalarprod(n,x) //this is the distance of the plane to the origin\n\nfor each point p_i\n d_i = abs(scalarprod(p_i,n) - d) //this is the distance of the point to the plane\n</code></pre>\n\n<p>Obviously "scalarprod" means "scalar product" and "abs" means "absolute value".\nIf you wonder why just read the article on scalar products at wikipedia.</p>\n'}, {'answer_id': 93928, 'author': 'thing2k', 'author_id': 3180, 'author_profile': 'https://Stackoverflow.com/users/3180', 'pm_score': 0, 'selected': False, 'text': "<p>I have one question for Andrea Tagliasacchi, Why?</p>\n\n<p>Only if you are looking at 1000s of points and possible 100s of planes, would there would be any benefit from using the method outlined. As apposed to dot producting the point and plane, as outlined my Corporal Touchy.</p>\n\n<p>Also due to the finite nature of pixels you'll often find two or more points will project to the same pixel in the texture. </p>\n\n<p>If you still want to do this, I could work up a sample glut program in C++, but how this would help with MATLAB I don't know, as I'm unfamiliar with it.</p>\n"}, {'answer_id': 116939, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>IT seems to me you should be able to implement something similar to Corporal Touchy\'s method a a vertex program rather than in a for loop, right? Maybe use a C API to GPU programming, such as <a href="http://www.nvidia.com/object/cuda_what_is.html" rel="nofollow noreferrer">CUDA</a>?</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77258', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
77,266 |
<p>Can I persuade <code>operator>></code> in C++ to read both a <code>hex</code> value AND and a <code>decimal</code> value? The following program demonstrates how reading hex goes wrong. I'd like the same <code>istringstream</code> to be able to read both <code>hex</code> and <code>decimal</code>.</p>
<pre><code>#include <iostream>
#include <sstream>
int main(int argc, char** argv)
{
int result = 0;
// std::istringstream is("5"); // this works
std::istringstream is("0x5"); // this fails
while ( is.good() ) {
if ( is.peek() != EOF )
is >> result;
else
break;
}
if ( is.fail() )
std::cout << "failed to read string" << std::endl;
else
std::cout << "successfully read string" << std::endl;
std::cout << "result: " << result << std::endl;
}
</code></pre>
|
[{'answer_id': 77359, 'author': 'nsanders', 'author_id': 1244, 'author_profile': 'https://Stackoverflow.com/users/1244', 'pm_score': 4, 'selected': False, 'text': '<p>You need to tell C++ what your base is going to be.</p>\n\n<p>Want to parse a hex number? Change your "is >> result" line to:</p>\n\n<pre><code>is >> std::hex >> result;\n</code></pre>\n\n<p>Putting a std::dec indicates decimal numbers, std::oct indicates octal.</p>\n'}, {'answer_id': 77360, 'author': 'user10392', 'author_id': 10392, 'author_profile': 'https://Stackoverflow.com/users/10392', 'pm_score': 5, 'selected': True, 'text': '<p>Use <a href="http://en.cppreference.com/w/cpp/io/manip/setbase" rel="nofollow noreferrer"><code>std::setbase(0)</code></a> which enables prefix dependent parsing. It will be able to parse <code>10</code> (dec) as 10 decimal, <code>0x10</code> (hex) as 16 decimal and <code>010</code> (octal) as 8 decimal.</p>\n\n<pre><code>#include <iomanip>\nis >> std::setbase(0) >> result;\n</code></pre>\n'}, {'answer_id': 77437, 'author': 'Dave Hillier', 'author_id': 1575281, 'author_profile': 'https://Stackoverflow.com/users/1575281', 'pm_score': -1, 'selected': False, 'text': "<p>0x is C/C++ specific prefix. A hex number is just digits like a decimal one.\nYou'll need to check for presence of those characters then parse appropriately.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77266', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1359466/']
|
77,278 |
<p>People also often ask "How can I compile Perl?" while what they really want is to create an executable that can run on machines even if they don't have Perl installed.</p>
<p>There are several solutions, I know of:</p>
<ol>
<li><a href="http://www.indigostar.com/perl2exe.htm" rel="noreferrer">perl2exe</a> of IndigoStar
It is commercial. I never tried. Its web site says it can cross compile Win32, Linux, and Solaris.</li>
<li><a href="http://www.activestate.com/Products/perl_dev_kit/" rel="noreferrer">Perl Dev Kit</a> from ActiveState.
It is commercial. I used it several years ago on Windows and it worked well for my needs. According to its web site it works on Windows, Mac OS X, Linux, Solaris, AIX and HP-UX.</li>
<li><a href="http://search.cpan.org/dist/PAR/" rel="noreferrer">PAR</a> or rather <a href="http://search.cpan.org/dist/PAR-Packer/" rel="noreferrer">PAR::Packer</a> that is free and open source. Based on the test reports it works on the Windows, Mac OS X, Linux, NetBSD and Solaris but theoretically it should work on other UNIX systems as well.
Recently I have started to use PAR for packaging on Linux and will use it on Windows as well.</li>
</ol>
<p>Other recommended solutions?</p>
|
[{'answer_id': 77325, 'author': 'Bruce', 'author_id': 9698, 'author_profile': 'https://Stackoverflow.com/users/9698', 'pm_score': -1, 'selected': False, 'text': "<p>You could use the <code>perlcc</code> tool that's shipped with most distributions of Perl. I've also found both <code>perl2exe</code> and Active State's Perl Dev kit useful for shipping Perl applications.</p>\n"}, {'answer_id': 80777, 'author': 'tsee', 'author_id': 13164, 'author_profile': 'https://Stackoverflow.com/users/13164', 'pm_score': 5, 'selected': True, 'text': '<p>In addition to the three tools listed in the question, there\'s another one called <a href="http://www.cavapackager.com/" rel="nofollow noreferrer">Cava Packager</a> written by Mark Dootson, who has also contributed to <a href="http://par.perl.org" rel="nofollow noreferrer">PAR</a> in the past. It only runs under Windows, has a nice Wx GUI and works differently from the typical three contenders in that it assembles all Perl dependencies in a source / lib directory instead of creating a single archive containing everything. There\'s a free version, but it\'s not Open Source. I haven\'t used this except for testing.</p>\n\n<p>As for PAR, it\'s really a toolkit. It comes with a packaging tool which does the dependency scanning and assembly of stand-alone executables, but it can also be used to generate and use so-called .par files, in analogy to Java\'s JARs. It also comes with <a href="http://search.cpan.org/dist/PAR-Repository-Client" rel="nofollow noreferrer">client</a> and <a href="http://search.cpan.org/dist/PAR-Repository" rel="nofollow noreferrer">server</a> for automatically loading missing packages over the network, etc. The <a href="http://steffen-mueller.net/talks/appdeployment/" rel="nofollow noreferrer">slides of my PAR talk</a> at <a href="http://yapceurope.org/" rel="nofollow noreferrer">YAPC::EU</a> 2008 go into more details on this.\nThere\'s also an active mailing list: par at perl dot org.</p>\n'}, {'answer_id': 992376, 'author': 'mcwong', 'author_id': 79547, 'author_profile': 'https://Stackoverflow.com/users/79547', 'pm_score': 1, 'selected': False, 'text': "<p>I'm a Perl newbie and I just downloaded Cava Packager and that's the only one I found working. I've tried ActiveState 5.10.1005 and Strawberry Perl with PAR-Packager on Windows XP. \npp just hangs in mid-stream and no executables created.</p>\n\n<p>Cava provides the only solution to creating exe on Windows so far. Thks.</p>\n"}, {'answer_id': 6082885, 'author': 'cavapack', 'author_id': 764127, 'author_profile': 'https://Stackoverflow.com/users/764127', 'pm_score': 3, 'selected': False, 'text': '<p>It is some time since this question was first asked, but <a href="http://www.cavapackager.com/" rel="noreferrer">Cava Packager</a> can currently produce executable packages for Windows, Linux and Mac OS X. It is no longer Windows only.</p>\n\n<p>Note: As indicated by my name, I am affiliated with Cava Packager.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77278', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11827/']
|
77,280 |
<p>Let say that I have a website with some information that could be access externally. Those information need to be only change by the respected client. Example: Google Analytic or WordPress API key. How can I create a system that work like that (no matter the programming language)?</p>
|
[{'answer_id': 77300, 'author': 'Nikolai Prokoschenko', 'author_id': 6460, 'author_profile': 'https://Stackoverflow.com/users/6460', 'pm_score': 2, 'selected': False, 'text': '<p>Simple:</p>\n\n<ol>\n<li>Generate a key for each user</li>\n<li>Deny access for each request without this key</li>\n</ol>\n'}, {'answer_id': 77313, 'author': 'digiguru', 'author_id': 5055, 'author_profile': 'https://Stackoverflow.com/users/5055', 'pm_score': 0, 'selected': False, 'text': '<p>A good way of generating a key would be to store a GUID (Globally Unique Identifier) on each user record n the database. GUID is going to be unique and almost impossible to guess.</p>\n'}, {'answer_id': 77324, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 5, 'selected': True, 'text': '<p>A number of smart people are working on a standard, and it\'s called <a href="http://oauth.net/" rel="noreferrer">OAuth</a>. It already has a number of <a href="http://oauth.net/code" rel="noreferrer">sample implementations</a>, so it\'s pretty easy to get started.</p>\n'}, {'answer_id': 77335, 'author': 'Ian P', 'author_id': 10853, 'author_profile': 'https://Stackoverflow.com/users/10853', 'pm_score': 1, 'selected': False, 'text': '<p>Currently, I use a concatenation of multiple MD5s with a salt. The MD5s are generated off of various concatenations of user data.</p>\n'}, {'answer_id': 25814785, 'author': 'steve', 'author_id': 70088, 'author_profile': 'https://Stackoverflow.com/users/70088', 'pm_score': 0, 'selected': False, 'text': '<p>There are also infrastructure services that manage all this for you like <a href="http://www.3scale.net" rel="nofollow">http://www.3scale.net</a> (disclosure I work there), <a href="http://www.mashery.com" rel="nofollow">http://www.mashery.com</a> and <a href="http://www.apigee.com/" rel="nofollow">http://www.apigee.com/</a>.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77280', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13913/']
|
77,287 |
<p>I have a <code>modal dialog</code> form which has some "help links" within it which should open other non-modal panels or dialogs on top of it (while keeping the main dialog otherwise modal). </p>
<p>However, these always end up behind the mask. <code>YUI</code> seems to be recognizing the highest <code>z-index</code> out there and setting the mask and modal dialog to be higher than that.</p>
<p>If i wait to panel-ize the help content, then i can set those to have a higher z-index. So far, so good. The problem then is that fields within the secondary, non-modal dialogs are unfocusable. The modal dialog beneath them seems to somehow be preventing the focus from going to anything not in the initial, modal dialog.</p>
<p>It would also be acceptable if i could do this "dialog group modality" with jQuery, if YUI simply won't allow this.</p>
<p>Help!</p>
|
[{'answer_id': 81688, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 0, 'selected': False, 'text': "<p>The original dialog can't be modal if the user is supposed to interact with other elements—that's the definition of modal. Does the original dialog <em>really</em> need to be modal at all? If so, have you tried toggling the modal property of the original dialog before you open the other elements?</p>\n"}, {'answer_id': 162315, 'author': 'Bialecki', 'author_id': 2484, 'author_profile': 'https://Stackoverflow.com/users/2484', 'pm_score': 3, 'selected': True, 'text': '<p>By default, YUI manages the z-index of anything that extends YAHOO.widget.Overlay and uses an overlay panel. It does this through the YAHOO.widget.Overlay\'s "bringToTop" method. You can turn this off by simply changing the "bringToTop" method to be an empty function:</p>\n\n<pre><code>YAHOO.widget.Overlay.prototype.bringToTop = function() { };\n</code></pre>\n\n<p>That code would turn it off for good and you could just put this at the bottom of the container.js file. I find that approach to be a little bit too much of a sledge hammer approach, so we extend the YUI classes and after calling "super.constuctor" write:</p>\n\n<pre><code>this.bringToTop = function() { };\n</code></pre>\n\n<p>If you do this, you are essentially telling YUI that you will manage the z-indices of your elements yourself. That\'s probably fine, but something to consider before doing it.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77287', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8131/']
|
77,293 |
<p>I would like to keep the overhead at a minimum. Right now I have:</p>
<pre><code>// Launch a Message Box with advice to the user
DialogResult result = MessageBox::Show("This may take awhile, do you wish to continue?", "Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Exclamation);
// The test will only be launched if the user has selected Yes on the Message Box
if(result == DialogResult::Yes)
{
// Execute code
}
</code></pre>
<p>Unfortunately my client would prefer "Continue" and "Cancel" in place of the default "Yes" and "No" button text. It seems like there should be an easy way to do this.</p>
|
[{'answer_id': 77457, 'author': 'Corin Blaikie', 'author_id': 1736, 'author_profile': 'https://Stackoverflow.com/users/1736', 'pm_score': 3, 'selected': True, 'text': '<p>You can use "OK" and "Cancel"</p>\n\n<p>By substituting <code>MessageBoxButtons::YesNo</code> with <code>MessageBoxButtons::OKCancel</code></p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxbuttons.aspx" rel="nofollow noreferrer">MessageBoxButtons Enum</a></p>\n\n<p>Short of that you would have to create a new form, as I don\'t believe the Enum can be extended.</p>\n'}, {'answer_id': 86358, 'author': 'Andrew Dunaway', 'author_id': 9058, 'author_profile': 'https://Stackoverflow.com/users/9058', 'pm_score': 0, 'selected': False, 'text': '<p>From everything I can find it looks like <a href="https://stackoverflow.com/users/1736/corin">Corin</a> is right. Here is the code that I used to accomplish the original goal. I am not usually a Managed C++ programmer, so any editing would be appreciated.</p>\n\n<p>CustomMessageBox.h:</p>\n\n<pre><code>using namespace System::Windows::Forms;\n\n/// <summary>\n/// A message box for the test. Used to ensure user wishes to continue before starting the test.\n/// </summary>\npublic ref class CustomMessageBox : Form\n{\nprivate:\n /// Used to determine which button is pressed, default action is Cancel\n static String^ Button_ID_ = "Cancel";\n\n // GUI Elements\n Label^ warningLabel_;\n Button^ continueButton_;\n Button^ cancelButton_;\n\n // Button Events\n void CustomMessageBox::btnContinue_Click(System::Object^ sender, EventArgs^ e);\n void CustomMessageBox::btnCancel_Click(System::Object^ sender, EventArgs^ e);\n\n // Constructor is private. CustomMessageBox should be accessed through the public ShowBox() method\n CustomMessageBox();\n\npublic:\n /// <summary>\n /// Displays the CustomMessageBox and returns a string value of "Continue" or "Cancel"\n /// </summary>\n static String^ ShowBox();\n};\n</code></pre>\n\n<p>CustomMessageBox.cpp:</p>\n\n<pre><code>#include "StdAfx.h"\n#include "CustomMessageBox.h"\n\nusing namespace System::Windows::Forms;\nusing namespace System::Drawing;\n\nCustomMessageBox::CustomMessageBox()\n{\n this->Size = System::Drawing::Size(420, 150);\n this->Text="Warning";\n this->AcceptButton=continueButton_;\n this->CancelButton=cancelButton_;\n this->FormBorderStyle= ::FormBorderStyle::FixedDialog;\n this->StartPosition= FormStartPosition::CenterScreen;\n this->MaximizeBox=false;\n this->MinimizeBox=false;\n this->ShowInTaskbar=false;\n\n // Warning Label\n warningLabel_ = gcnew Label();\n warningLabel_->Text="This may take awhile, do you wish to continue?";\n warningLabel_->Location=Point(5,5);\n warningLabel_->Size=System::Drawing::Size(400, 78);\n Controls->Add(warningLabel_);\n\n // Continue Button\n continueButton_ = gcnew Button();\n continueButton_->Text="Continue";\n continueButton_->Location=Point(105,87);\n continueButton_->Size=System::Drawing::Size(70,22);\n continueButton_->Click += gcnew System::EventHandler(this, &CustomMessageBox::btnContinue_Click);\n Controls->Add(continueButton_);\n\n // Cancel Button\n cancelButton_ = gcnew Button();\n cancelButton_->Text="Cancel";\n cancelButton_->Location=Point(237,87);\n cancelButton_->Size=System::Drawing::Size(70,22);\n cancelButton_->Click += gcnew System::EventHandler(this, &CustomMessageBox::btnCancel_Click);\n Controls->Add(cancelButton_);\n}\n\n/// <summary>\n/// Displays the CustomMessageBox and returns a string value of "Continue" or "Cancel", depending on the button\n/// clicked.\n/// </summary>\nString^ CustomMessageBox::ShowBox()\n{\n CustomMessageBox^ box = gcnew CustomMessageBox();\n box->ShowDialog();\n\n return Button_ID_;\n}\n\n/// <summary>\n/// Event handler: When the Continue button is clicked, set the Button_ID_ value and close the CustomMessageBox.\n/// </summary>\n/// <param name="sender">The source of the event.</param>\n/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>\nvoid CustomMessageBox::btnContinue_Click(System::Object^ sender, EventArgs^ e)\n{\n Button_ID_ = "Continue";\n this->Close();\n}\n\n/// <summary>\n/// Event handler: When the Cancel button is clicked, set the Button_ID_ value and close the CustomMessageBox.\n/// </summary>\n/// <param name="sender">The source of the event.</param>\n/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>\nvoid CustomMessageBox::btnCancel_Click(System::Object^ sender, EventArgs^ e)\n{\n Button_ID_ = "Cancel";\n this->Close();\n}\n</code></pre>\n\n<p>And then finally the modification to the original code:</p>\n\n<pre><code>// Launch a Message Box with advice to the user\nString^ result = CustomMessageBox::ShowBox();\n\n// The test will only be launched if the user has selected Continue on the Message Box\nif(result == "Continue")\n{\n // Execute Code\n}\n</code></pre>\n'}, {'answer_id': 13408763, 'author': 'Namhwan Sung', 'author_id': 1828322, 'author_profile': 'https://Stackoverflow.com/users/1828322', 'pm_score': 0, 'selected': False, 'text': '<p>Change the message as below. This may be the simplest way I think.</p>\n\n<pre><code>DialogResult result = MessageBox::Show(\n "This may take awhile, do you wish to continue?**\\nClick Yes to continue.\\nClick No to cancel.**",\n "Warning",\n MessageBoxButtons::YesNo,\n MessageBoxIcon::Exclamation\n);\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77293', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9058/']
|
77,342 |
<p>The use of XSLT (XML Stylesheet Language Transform) has never seen the same popularity of many of the other languages that came out during the internet boom. While it is in use, and in some cases by large successful companies (i.e. Blizzard Entertainment), it has never seemed to reach mainstream. Why do you think this is?</p>
|
[{'answer_id': 77362, 'author': 'Bryant', 'author_id': 10893, 'author_profile': 'https://Stackoverflow.com/users/10893', 'pm_score': 2, 'selected': False, 'text': "<p>XSL is mainstream and widely adopted. What other languages are you referring to? XSL isn't a programming language, <strong>just a transformation language</strong>, so it is pretty limited in scope.</p>\n"}, {'answer_id': 77378, 'author': 'Mo.', 'author_id': 1870, 'author_profile': 'https://Stackoverflow.com/users/1870', 'pm_score': 2, 'selected': False, 'text': '<p>Well... Maybe because it is a pain to write xslts... I had to write a few xslts a few months ago and I was dreaming of pointy brackets...</p>\n\n<pre><code><Really> \n <No>\n <fun/>\n </No>\n</Really> \n</code></pre>\n\n<p>(I do know, that this is no xslt)</p>\n'}, {'answer_id': 77388, 'author': 'Arno', 'author_id': 13685, 'author_profile': 'https://Stackoverflow.com/users/13685', 'pm_score': 3, 'selected': False, 'text': "<p>Because most XSLT implementations have a high memory footprint (I suppose that's caused by the design of the language), because people tended to abuse XSLT for all kinds of things that it was not particularly well-suited for and the purely-declarative nature of XSL which makes certain types of transformations quite difficult.</p>\n"}, {'answer_id': 77394, 'author': 'Orclev', 'author_id': 13739, 'author_profile': 'https://Stackoverflow.com/users/13739', 'pm_score': 2, 'selected': False, 'text': "<p>Generally, the times when you will be required to transform XML data into a different form of XML data, but not do any other processing to it are going to be very limited. Usually XML is used as an intermediary between two separate systems, one of which is usually custom made to process the output of the other. As such it's simpler to just write one of the systems to process the XML output of the other without the extra step of having to perform some kind of transform.</p>\n"}, {'answer_id': 77427, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': "<p>It's great for xml, but not great for typical coding. It lacks typical basic concepts (ie mutable variables) and makes what should be simple quite complex (or impossible). Most of its problems stem from the fact that xml is a great data representation language but not a great programming language. That being said, I use it daily and would recommend it where it makes sense. In conjunction with external namespaces, it can be made more useful (calls to java, etc). In the end, it's another language to learn, and many coders would prefer to stick with something they're used to or resembles something they're used to.</p>\n"}, {'answer_id': 77450, 'author': 'user13998', 'author_id': 13998, 'author_profile': 'https://Stackoverflow.com/users/13998', 'pm_score': 3, 'selected': False, 'text': '<p>XSLTs uses functional programming - something most programmers are not used to (hence why some people consider it non-intuitive I guess).</p>\n'}, {'answer_id': 77478, 'author': 'artificialidiot', 'author_id': 7988, 'author_profile': 'https://Stackoverflow.com/users/7988', 'pm_score': 2, 'selected': False, 'text': '<p>I think it tried to cover way too many use cases thus becoming a Turing-complete (or so I heard) language. If you try to do any nontrivial transformation, you end up writing complex loops, conditions... in an ugly and verbose language, which is best done with a GPL.</p>\n\n<p>In my view, this complexity makes writing a correct implementation of XSLT difficult and limited the available choices, thus, widespread use among the vocal hackers who often likes to tinker with small and efficient code, not enterprisey code.</p>\n'}, {'answer_id': 77505, 'author': 'Ray Hayes', 'author_id': 7093, 'author_profile': 'https://Stackoverflow.com/users/7093', 'pm_score': 2, 'selected': False, 'text': '<p>XSLT is very powerful, but requires a different way of thinking about the problem. It also made life hard for itself by not providing useful data functionality in the early versions. Take for example a ToUpper() style method, you typically implement it with something like:</p>\n\n<pre><code><xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>\n<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable> \n\n<xsl:value-of select="translate($toconvert,$lcletters,$ucletters)"/>\n</code></pre>\n\n<p>Not the easiest way of coding!</p>\n'}, {'answer_id': 77514, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Because it is easier to write and maintain code that uses Java, C#, JavaScript, etc. to deserialize an XML stream, transform it, and export the desired output, and XSLT offers no substantial performance advantage.</p>\n\n<p>XSLT makes somethings easy, but it makes other things very, very hard.</p>\n'}, {'answer_id': 77525, 'author': 'Michael Burr', 'author_id': 12711, 'author_profile': 'https://Stackoverflow.com/users/12711', 'pm_score': 2, 'selected': False, 'text': "<p>I think it boils down to XML syntax is arguably good for describing data, but it's not a great syntax for what's essentially a programming language (XSLT).</p>\n"}, {'answer_id': 77593, 'author': 'Chuck', 'author_id': 9714, 'author_profile': 'https://Stackoverflow.com/users/9714', 'pm_score': 6, 'selected': True, 'text': "<p>One problem is that XSLT <em>looks</em> complicated. Any developer should be able to pick up the language constructs as there are analogs in most other languages. The problem is that the constructs and data all look exactly the same which makes it difficult to distinguish between the two which makes XSLT more difficult to read than other languges.</p>\n\n<p>A second issue is that the uses for it are more limited than other languages. XSLT is great at what it does; making complicated or radical transformations on XML. But it doesn't apply to as wide a range of problems as other languages, so it is not used as much.</p>\n\n<p>Third, many programming languages have their own libraries for transforming XML. Much of the time when working with XML, only small changes or lookups are needed. The XML is also probably being generated or consumed by a program the developer is already writing in another language. These factors mean that using a language's built in utilities is just more convenient.</p>\n\n<p>Another problem that all of these issues contribute to is inertia. That is, people don't know it, they don't see that they have much need for it, so they avoid it as a solution if there is another option.</p>\n\n<p>What you end up with is a language that is the last choice of many developers when creating solutions. It is likely that XSLT is even avoided when it would be the best tool for the job as a result.</p>\n"}, {'answer_id': 77644, 'author': 'Adam', 'author_id': 13320, 'author_profile': 'https://Stackoverflow.com/users/13320', 'pm_score': 1, 'selected': False, 'text': '<p>xslt is great for xml to xml, when you have data that is already escaped and a clear definition of inputs and outputs. using it for things like xml2html to me just seems like such a headache, and with nearly any dynamic language and css the output is a lot easier to implement with style.</p>\n'}, {'answer_id': 211115, 'author': 'rasx', 'author_id': 22944, 'author_profile': 'https://Stackoverflow.com/users/22944', 'pm_score': 2, 'selected': False, 'text': '<p>As previously stated XSLT (like “the good parts” of JavaScript) is a functional programming language. Most traditional programmers hate this statelessness. Also too many traditional programmers hate angle brackets.</p>\n\n<p>But, most importantly, correct use of XSLT solves both the declarative-GUI-generation and the data-binding problem for the Web server in a platform agnostic way. Vendors like Microsoft are not motivated to celebrate this “inconvenient” power.</p>\n\n<p>However, I will argue that Microsoft has the finest XSLT support for the IDE (Visual Studio) <em>in the world.</em></p>\n'}, {'answer_id': 220164, 'author': 'Diego Tercero', 'author_id': 2046272, 'author_profile': 'https://Stackoverflow.com/users/2046272', 'pm_score': 3, 'selected': False, 'text': '<p>In my opinion, one of the most annoying things in standard XSLT (I\'m talking about XSLT 1.0 because that\'s the only version I have used) is that it lacked support of string transformations and some basic date-time functions manipulations.</p>\n\n<p>One thing I could never understand is why a function such as translate() was designed and implemented into xpath wheras other more useful functions such as <em>replace</em>, <em>to_lower</em>, <em>to_upper,</em> or - let\'s be crazy - regular expressions were not.</p>\n\n<p>Some of these issues were adressed I guess with <a href="http://www.exslt.org/" rel="noreferrer">eXSLT</a> (extended xslt ?) for parsers other than Microsoft\'s MSXML. I say I guess because I actually never used it as it was declared incompatible with MSXML.</p>\n\n<p>I don\'t understand why XSLT 1.0 was designed with this principle that \'text\' manipulation was not be in the scope of the language when it\'s obvious that whenever you are converting files you can\'t avoid those string conversion issues (e.g. : transform an unregularly padded date given in french format to american format, 31/1/2008 to 2008-01-31) huh...</p>\n\n<p>These text manipulation issues were generally very basic and easily adressed in MSXML by allowing XSL to be extended with JScript functions : you could call a JScript function to perform some processing just as you would call any XSL template, but I always found that solution inelegant and ended up creating my own XSL template libraries. First because the JScript way broke your XSL portability, and then because it forced you to mix your programming logic : some bits in pure XPath/XSLT expression and other bits in DOM/object notation with JScript.</p>\n\n<p>Not having updatable variables is another limitation that is very confusing for newcomers, some people just don\'t overcome this and keep struggling with that.\nIn some simple cases you can have workarounds with a mix of paremetrized templates and recursive calls (for example to implement an increasing or decrasing counter) but let\'s face it, recursion is not that natural.</p>\n\n<p>I think I heard all those limitations were adressed in the XSLT 2.0 specification, sadly MS decided not to implement it and promote XQuery instead. That\'s sad, why not implement both of them? I think that XSLT would still have a good chance of becoming as popular as CSS became for HTML. When you think about it, the most difficult part in learning XSLT is XPath, the rest is not as difficult as understanding the cascading behaviour in CSS, and CSS has become so popular...</p>\n\n<p>So, in my opinon, it\'s the lack of all those little things mentioned here and the time it took to adress them in XSLT 2.0 (with not even MS supporting it anyway) that has lead to this situation of impopularity. How I wish MS decided to implement it after all...</p>\n'}, {'answer_id': 3761000, 'author': 'Kazi T Ahsan', 'author_id': 406655, 'author_profile': 'https://Stackoverflow.com/users/406655', 'pm_score': 1, 'selected': False, 'text': "<p>I found it great for 'composite web service architecture'.Sometimes number of webservices work together to have the final output.When those webservices need to communicate among them via XML then XSLT can transform the xml message from one form to another.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77342', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13930/']
|
77,382 |
<p>I have a class with a public array of bytes. Lets say its</p>
<pre><code>Public myBuff as byte()
</code></pre>
<p>Events within the class get chunks of data in byte array. How do i tell the event code to stick the get chunk on the end? Lets say</p>
<pre><code>Private Sub GetChunk
Dim chunk as byte
'... get stuff in chunk
Me.myBuff += chunk '(stick chunk on end of public array)
End sub
</code></pre>
<p>Or am I totally missing the point?</p>
|
[{'answer_id': 77390, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 1, 'selected': False, 'text': '<p>if i remember right, in vb you want to redim with preserve to grow an array.</p>\n'}, {'answer_id': 77402, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>You'll be constantly using the ReDim keyword, which is <em>extremely</em> inefficient.</p>\n\n<p>Are you using .Net? If so, consider using a System.Collections.Generic.List(Of Byte) instead. You can use it's .AddRange() method to append your bytes, and it's .ToArray() method to get an array back out if you really need one.</p>\n"}, {'answer_id': 77405, 'author': 'Sam', 'author_id': 9406, 'author_profile': 'https://Stackoverflow.com/users/9406', 'pm_score': 0, 'selected': False, 'text': "<p>Your question doesn't seem to be very clear. You should probably not have the array of bytes as public. It should probably be private and you should provide a set of public functions that allow users of the class to perform operations against the array.</p>\n"}, {'answer_id': 77449, 'author': 'David J. Sokol', 'author_id': 1390, 'author_profile': 'https://Stackoverflow.com/users/1390', 'pm_score': 0, 'selected': False, 'text': '<p>I think you might be looking for something other then an array. If you are trying to gradually extend the amount of data frequently, you should use a dynamic data structure such as<code>ArrayList</code>. This has an <code>Add</code> method which adds the specific object or value to the array without concerns for space. It also has a nifty <code>ToArray()</code> method that you can use.</p>\n\n<p>If you are trying to use an array for specific reasons (performance, I guess), use <code>ReDim Preserve array(newSize)</code>.</p>\n'}, {'answer_id': 78059, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>If the array is small, and new data is infrequently added, an easy way would be to:</p>\n\n<pre><code>public BufferSize as long 'or you can just use Ubound(mybuff), I prefer a tracker var tho\npublic MyBuff\n\nprivate sub GetChunk()\ndim chunk as byte\n'get stuff\nBufferSize=BufferSize+1\n\nredim preserve MyBuff(buffersize)\nmybuff(buffersize) = chunk\nend sub\n</code></pre>\n\n<p>if chunk is an array of bytes, it would look more like:</p>\n\n<pre><code>buffersize=buffersize+ubound(chunk) 'or if it's a fixed-size chunk, just use that number\nredim preserve mybuff(buffersize)\nfor k%=0 to ubound(chunk) 'copy new information to buffersize\n mybuff(k%+buffersize-ubound(chunk))=chunk(k%)\nnext\n</code></pre>\n\n<p>if you will be doing this frequently (say, many times per second) you'd want to do something like how the StringBuilder class works:</p>\n\n<pre><code>public BufSize&,BufAlloc& 'initialize bufalloc to 1 or a number >= bufsize\npublic MyBuff() as byte\n\nsub getdata()\nbufsize=bufsize+ubound(chunk)\nif bufsize>bufalloc then\n bufalloc=bufalloc*2\n redim preserve mybuff(bufalloc)\nend if\nfor k%=0 to ubound(chunk) 'copy new information to buffersize\n mybuff(k%+bufsize-ubound(chunk))=chunk(k%)\nnext\nend sub\n</code></pre>\n\n<p>that basically doubles the memory allocated to mybuf each time the pointer passes the end of the buffer. this means much less shuffling around of memory.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77382', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
|
77,387 |
<p>In the Java collections framework, the Collection interface declares the following method:</p>
<blockquote>
<p><a href="http://java.sun.com/javase/6/docs/api/java/util/Collection.html#toArray(T%5B%5D)" rel="noreferrer"><code><T> T[] toArray(T[] a)</code></a></p>
<p>Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.</p>
</blockquote>
<p>If you wanted to implement this method, how would you create an array of the type of <strong>a</strong>, known only at runtime?</p>
|
[{'answer_id': 77426, 'author': 'Arno', 'author_id': 13685, 'author_profile': 'https://Stackoverflow.com/users/13685', 'pm_score': 2, 'selected': False, 'text': '<pre><code>Array.newInstance(Class componentType, int length)\n</code></pre>\n'}, {'answer_id': 77429, 'author': 'SCdF', 'author_id': 1666, 'author_profile': 'https://Stackoverflow.com/users/1666', 'pm_score': 4, 'selected': False, 'text': '<p>By looking at how ArrayList does it:</p>\n\n<pre><code>public <T> T[] toArray(T[] a) {\n if (a.length < size)\n a = (T[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size);\n System.arraycopy(elementData, 0, a, 0, size);\n if (a.length > size)\n a[size] = null;\n return a;\n}\n</code></pre>\n'}, {'answer_id': 77474, 'author': 'user9116', 'author_id': 9116, 'author_profile': 'https://Stackoverflow.com/users/9116', 'pm_score': 6, 'selected': True, 'text': '<p>Use the static method</p>\n\n<pre><code>java.lang.reflect.Array.newInstance(Class<?> componentType, int length)\n</code></pre>\n\n<p>A tutorial on its use can be found here:\n<a href="http://java.sun.com/docs/books/tutorial/reflect/special/arrayInstance.html" rel="noreferrer">http://java.sun.com/docs/books/tutorial/reflect/special/arrayInstance.html</a></p>\n'}, {'answer_id': 77481, 'author': 'Christian P.', 'author_id': 9479, 'author_profile': 'https://Stackoverflow.com/users/9479', 'pm_score': -1, 'selected': False, 'text': "<p>To create a new array of a generic type (which is only known at runtime), you have to create an array of Objects and simply cast it to the generic type and then use it as such. This is a limitation of the generics implementation of Java (erasure).</p>\n\n<pre><code>T[] newArray = (T[]) new Object[X]; // where X is the number of elements you want.\n</code></pre>\n\n<p>The function then takes the array given (a) and uses it (checking it's size beforehand) or creates a new one.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77387', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13979/']
|
77,407 |
<p>There are a number of commercial offerings that I've come across but nothing open-source.</p>
<p>I realise that you could do something simiilar with JUnit / JMeter but I'm looking for something a bit more specific.</p>
|
[{'answer_id': 77489, 'author': 'Arno', 'author_id': 13685, 'author_profile': 'https://Stackoverflow.com/users/13685', 'pm_score': 1, 'selected': False, 'text': '<p>You might want to have a look at <a href="http://jakarta.apache.org/cactus/" rel="nofollow noreferrer">Apache Jakarta Cactus</a></p>\n'}, {'answer_id': 87687, 'author': 'Ragoler', 'author_id': 9855, 'author_profile': 'https://Stackoverflow.com/users/9855', 'pm_score': -1, 'selected': False, 'text': "<p>Load testing is a very complex activity. You'll need to be able to simulate many contexts (e.g., IP, port) and divide the load generators on many machines. While doing that you'll need to monitor the server (Application under test).</p>\n\n<p>As of today, there are several very good commercial tools that needs certain level of expertise to work with.\nI don't think there is any serious open source load testing tool. </p>\n"}, {'answer_id': 1526376, 'author': 'Conor', 'author_id': 73305, 'author_profile': 'https://Stackoverflow.com/users/73305', 'pm_score': 0, 'selected': False, 'text': '<p>Jmeter + server logging + your brain.</p>\n'}, {'answer_id': 13572369, 'author': 'benten', 'author_id': 1854534, 'author_profile': 'https://Stackoverflow.com/users/1854534', 'pm_score': 2, 'selected': False, 'text': '<p>What about clif\n<a href="http://clif.ow2.org/" rel="nofollow">http://clif.ow2.org/</a></p>\n\n<p>or jmeter\n<a href="http://jmeter.apache.org/" rel="nofollow">http://jmeter.apache.org/</a></p>\n\n<p>I think there are others, but these two spring to mind.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77407', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9922/']
|
77,428 |
<p>So if you have a RIA version (Silverlight or Flash) and a standard HTML version (or AJAX even), should you have the same URL for both, or is it ok to have a different one for the RIA app and just redirect accordingly?</p>
<p>So, for instance, if you have a site (<a href="http://example.com" rel="nofollow noreferrer">http://example.com</a>), is it ok to have the about page URL for the RIA app be <a href="http://example.com/#/about" rel="nofollow noreferrer">http://example.com/#/about</a> and the html be <a href="http://example.com/about" rel="nofollow noreferrer">http://example.com/about</a>? Does it matter? </p>
<p>Of course if you take the route with different URLs you will need to map between them. </p>
|
[{'answer_id': 77441, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 2, 'selected': False, 'text': "<p>It's perfectly acceptable to use 2 different link formats. If 2 users are not seeing the same content why should they be at the same URL.</p>\n"}, {'answer_id': 78245, 'author': 'Bryant', 'author_id': 10893, 'author_profile': 'https://Stackoverflow.com/users/10893', 'pm_score': 1, 'selected': False, 'text': "<p>I guess what I really need here is not a Question/Answer format but some kind of poll. While I agree (and accepted) that because they are getting two different views of the same content, that different urls are ok, but I'm thinking more of sharing these urls out. </p>\n\n<p>Thanks for the reply though!</p>\n"}, {'answer_id': 78378, 'author': 'Ian Dickinson', 'author_id': 6716, 'author_profile': 'https://Stackoverflow.com/users/6716', 'pm_score': 3, 'selected': True, 'text': '<p>The URLs of your pages denote the identity of the content. In my view, if the content is the same but the presentation varies (i.e RIA vs. HTML), then the URL should be the same and you should use some other mechanism to select between the different presentation forms. Choices of other mechanisms include cookies, content negotiation, session identifiers or, if your users are identified, a persistent user preferences model. Even using a URL argument would at least keep the root of the URL consistent (e.g. <code>http://your.si.te/foobar</code> vs. <code>http://your.si.te/foobar?view=plain</code>)</p>\n\n<p>If the content of the two presentations differs in some meaningful way, then you should make that difference meaningful in the URL. Exploiting the presence or absence of #, and other such hacks, would be a mistake in my view.</p>\n\n<p>Try to pick URL\'s that do not change over time: so-called <a href="http://www.w3.org/Provider/Style/URI" rel="nofollow noreferrer" title="cool URL's">cool URL\'s</a>. This will aide the long-term usefulness of your site to your users: consider what happens if they come back to a bookmarked page in a year\'s time. Consistency will also help you to get a better critical mass of links or reviews of your site in <a href="http://del.icio.us" rel="nofollow noreferrer">del.icio.us</a> and similar bookmarking/review sites.</p>\n\n<p>Ian</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77428', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10893/']
|
77,431 |
<p>I make a lot of web applications and from time to time I need a color picker. What's one that I can use like an API and doesn't require a lot of code to plug in? I also need it to work in all browsers.</p>
|
[{'answer_id': 77463, 'author': 'Jacob', 'author_id': 8119, 'author_profile': 'https://Stackoverflow.com/users/8119', 'pm_score': 5, 'selected': True, 'text': '<p><a href="http://acko.net/dev/farbtastic" rel="noreferrer">Farbtastic</a> is a nice jQuery color picker </p>\n\n<p>But apparently doesn\'t work in IE6</p>\n\n<p><a href="http://www.eyecon.ro/colorpicker/#about" rel="noreferrer">Here</a> is another jQuery color picker that looks nice, not sure about it compatibility though.</p>\n'}, {'answer_id': 77477, 'author': 'Lincoln Johnson', 'author_id': 13419, 'author_profile': 'https://Stackoverflow.com/users/13419', 'pm_score': 2, 'selected': False, 'text': '<p>I haven\'t personally implemented this, but I have heard good things about it, and it appears to be a great script:\n<a href="http://johndyer.name/post/2007/09/PhotoShop-like-JavaScript-Color-Picker.aspx" rel="nofollow noreferrer">http://johndyer.name/post/2007/09/PhotoShop-like-JavaScript-Color-Picker.aspx</a></p>\n'}, {'answer_id': 744082, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>If your using prototype and script.aculo.us this one is great:</p>\n\n<p><a href="http://code.google.com/p/colorpickerjs/" rel="nofollow noreferrer">http://code.google.com/p/colorpickerjs/</a></p>\n'}, {'answer_id': 3695762, 'author': 'serg', 'author_id': 20128, 'author_profile': 'https://Stackoverflow.com/users/20128', 'pm_score': 4, 'selected': False, 'text': '<p>I like <a href="http://jscolor.com/try.php" rel="noreferrer">jscolor</a> the most, lightweight and lots of options.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77431', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13978/']
|
77,434 |
<p>Suppose I have a vector that is nested in a dataframe one or two levels. Is there a quick and dirty way to access the last value, without using the <code>length()</code> function? Something ala PERL's <code>$#</code> special var?</p>
<p>So I would like something like:</p>
<pre><code>dat$vec1$vec2[$#]
</code></pre>
<p>instead of</p>
<pre><code>dat$vec1$vec2[length(dat$vec1$vec2)]
</code></pre>
|
[{'answer_id': 83162, 'author': 'Gregg Lind', 'author_id': 15842, 'author_profile': 'https://Stackoverflow.com/users/15842', 'pm_score': 7, 'selected': False, 'text': "<p>If you're looking for something as nice as Python's x[-1] notation, I think you're out of luck. The standard idiom is</p>\n\n<pre><code>x[length(x)] \n</code></pre>\n\n<p>but it's easy enough to write a function to do this:</p>\n\n<pre><code>last <- function(x) { return( x[length(x)] ) }\n</code></pre>\n\n<p>This missing feature in R annoys me too!</p>\n"}, {'answer_id': 83222, 'author': 'lindelof', 'author_id': 1428, 'author_profile': 'https://Stackoverflow.com/users/1428', 'pm_score': 9, 'selected': False, 'text': '<p>I use the <code>tail</code> function:</p>\n\n<pre><code>tail(vector, n=1)\n</code></pre>\n\n<p>The nice thing with <code>tail</code> is that it works on dataframes too, unlike the <code>x[length(x)]</code> idiom.</p>\n'}, {'answer_id': 153852, 'author': 'Florian Jenn', 'author_id': 23813, 'author_profile': 'https://Stackoverflow.com/users/23813', 'pm_score': 6, 'selected': False, 'text': '<p>Combining <a href="https://stackoverflow.com/a/83222/10221765">lindelof\'s</a> and <a href="https://stackoverflow.com/a/83162/10221765">Gregg Lind\'s</a> ideas:</p>\n\n<pre><code>last <- function(x) { tail(x, n = 1) }\n</code></pre>\n\n<p>Working at the prompt, I usually omit the <code>n=</code>, i.e. <code>tail(x, 1)</code>.</p>\n\n<p>Unlike <code>last</code> from the <code>pastecs</code> package, <code>head</code> and <code>tail</code> (from <code>utils</code>) work not only on vectors but also on data frames etc., and also can return data "<em>without first/last n elements</em>", e.g. </p>\n\n<pre><code>but.last <- function(x) { head(x, n = -1) }\n</code></pre>\n\n<p>(Note that you have to use <code>head</code> for this, instead of <code>tail</code>.)</p>\n'}, {'answer_id': 21706190, 'author': 'James', 'author_id': 269476, 'author_profile': 'https://Stackoverflow.com/users/269476', 'pm_score': 4, 'selected': False, 'text': '<p>Another way is to take the first element of the reversed vector:</p>\n\n<pre><code>rev(dat$vect1$vec2)[1]\n</code></pre>\n'}, {'answer_id': 23638765, 'author': 'scuerda', 'author_id': 1748028, 'author_profile': 'https://Stackoverflow.com/users/1748028', 'pm_score': 4, 'selected': False, 'text': '<p>I just benchmarked these two approaches on data frame with 663,552 rows using the following code:</p>\n\n<pre><code>system.time(\n resultsByLevel$subject <- sapply(resultsByLevel$variable, function(x) {\n s <- strsplit(x, ".", fixed=TRUE)[[1]]\n s[length(s)]\n })\n )\n\n user system elapsed \n 3.722 0.000 3.594 \n</code></pre>\n\n<p>and</p>\n\n<pre><code>system.time(\n resultsByLevel$subject <- sapply(resultsByLevel$variable, function(x) {\n s <- strsplit(x, ".", fixed=TRUE)[[1]]\n tail(s, n=1)\n })\n )\n\n user system elapsed \n 28.174 0.000 27.662 \n</code></pre>\n\n<p>So, assuming you\'re working with vectors, accessing the length position is significantly faster.</p>\n'}, {'answer_id': 27992356, 'author': 'Akash ', 'author_id': 2682018, 'author_profile': 'https://Stackoverflow.com/users/2682018', 'pm_score': 4, 'selected': False, 'text': '<p>I have another method for finding the last element in a vector.\nSay the vector is <code>a</code>.</p>\n\n<pre><code>> a<-c(1:100,555)\n> end(a) #Gives indices of last and first positions\n[1] 101 1\n> a[end(a)[1]] #Gives last element in a vector\n[1] 555\n</code></pre>\n\n<p>There you go!</p>\n'}, {'answer_id': 32510333, 'author': 'Kurt Ludikovsky', 'author_id': 4934536, 'author_profile': 'https://Stackoverflow.com/users/4934536', 'pm_score': 3, 'selected': False, 'text': '<p>Whats about</p>\n\n<pre><code>> a <- c(1:100,555)\n> a[NROW(a)]\n[1] 555\n</code></pre>\n'}, {'answer_id': 37238415, 'author': 'anonymous', 'author_id': 179927, 'author_profile': 'https://Stackoverflow.com/users/179927', 'pm_score': 8, 'selected': False, 'text': "<p>To answer this not from an aesthetical but performance-oriented point of view, I've put all of the above suggestions through a <strong>benchmark</strong>. To be precise, I've considered the suggestions</p>\n\n<ul>\n<li><code>x[length(x)]</code></li>\n<li><code>mylast(x)</code>, where <code>mylast</code> is a C++ function implemented through Rcpp,</li>\n<li><code>tail(x, n=1)</code></li>\n<li><code>dplyr::last(x)</code></li>\n<li><code>x[end(x)[1]]]</code></li>\n<li><code>rev(x)[1]</code></li>\n</ul>\n\n<p>and applied them to random vectors of various sizes (10^3, 10^4, 10^5, 10^6, and 10^7). Before we look at the numbers, I think it should be clear that anything that becomes noticeably slower with greater input size (i.e., anything that is not O(1)) is not an option. Here's the code that I used:</p>\n\n<pre><code>Rcpp::cppFunction('double mylast(NumericVector x) { int n = x.size(); return x[n-1]; }')\noptions(width=100)\nfor (n in c(1e3,1e4,1e5,1e6,1e7)) {\n x <- runif(n);\n print(microbenchmark::microbenchmark(x[length(x)],\n mylast(x),\n tail(x, n=1),\n dplyr::last(x),\n x[end(x)[1]],\n rev(x)[1]))}\n</code></pre>\n\n<p>It gives me</p>\n\n<pre><code>Unit: nanoseconds\n expr min lq mean median uq max neval\n x[length(x)] 171 291.5 388.91 337.5 390.0 3233 100\n mylast(x) 1291 1832.0 2329.11 2063.0 2276.0 19053 100\n tail(x, n = 1) 7718 9589.5 11236.27 10683.0 12149.0 32711 100\n dplyr::last(x) 16341 19049.5 22080.23 21673.0 23485.5 70047 100\n x[end(x)[1]] 7688 10434.0 13288.05 11889.5 13166.5 78536 100\n rev(x)[1] 7829 8951.5 10995.59 9883.0 10890.0 45763 100\nUnit: nanoseconds\n expr min lq mean median uq max neval\n x[length(x)] 204 323.0 475.76 386.5 459.5 6029 100\n mylast(x) 1469 2102.5 2708.50 2462.0 2995.0 9723 100\n tail(x, n = 1) 7671 9504.5 12470.82 10986.5 12748.0 62320 100\n dplyr::last(x) 15703 19933.5 26352.66 22469.5 25356.5 126314 100\n x[end(x)[1]] 13766 18800.5 27137.17 21677.5 26207.5 95982 100\n rev(x)[1] 52785 58624.0 78640.93 60213.0 72778.0 851113 100\nUnit: nanoseconds\n expr min lq mean median uq max neval\n x[length(x)] 214 346.0 583.40 529.5 720.0 1512 100\n mylast(x) 1393 2126.0 4872.60 4905.5 7338.0 9806 100\n tail(x, n = 1) 8343 10384.0 19558.05 18121.0 25417.0 69608 100\n dplyr::last(x) 16065 22960.0 36671.13 37212.0 48071.5 75946 100\n x[end(x)[1]] 360176 404965.5 432528.84 424798.0 450996.0 710501 100\n rev(x)[1] 1060547 1140149.0 1189297.38 1180997.5 1225849.0 1383479 100\nUnit: nanoseconds\n expr min lq mean median uq max neval\n x[length(x)] 327 584.0 1150.75 996.5 1652.5 3974 100\n mylast(x) 2060 3128.5 7541.51 8899.0 9958.0 16175 100\n tail(x, n = 1) 10484 16936.0 30250.11 34030.0 39355.0 52689 100\n dplyr::last(x) 19133 47444.5 55280.09 61205.5 66312.5 105851 100\n x[end(x)[1]] 1110956 2298408.0 3670360.45 2334753.0 4475915.0 19235341 100\n rev(x)[1] 6536063 7969103.0 11004418.46 9973664.5 12340089.5 28447454 100\nUnit: nanoseconds\n expr min lq mean median uq max neval\n x[length(x)] 327 722.0 1644.16 1133.5 2055.5 13724 100\n mylast(x) 1962 3727.5 9578.21 9951.5 12887.5 41773 100\n tail(x, n = 1) 9829 21038.0 36623.67 43710.0 48883.0 66289 100\n dplyr::last(x) 21832 35269.0 60523.40 63726.0 75539.5 200064 100\n x[end(x)[1]] 21008128 23004594.5 37356132.43 30006737.0 47839917.0 105430564 100\n rev(x)[1] 74317382 92985054.0 108618154.55 102328667.5 112443834.0 187925942 100\n</code></pre>\n\n<p>This immediately rules out anything involving <code>rev</code> or <code>end</code> since they're clearly not <code>O(1)</code> (and the resulting expressions are evaluated in a non-lazy fashion). <code>tail</code> and <code>dplyr::last</code> are not far from being <code>O(1)</code> but they're also considerably slower than <code>mylast(x)</code> and <code>x[length(x)]</code>. Since <code>mylast(x)</code> is slower than <code>x[length(x)]</code> and provides no benefits (rather, it's custom and does not handle an empty vector gracefully), I think the answer is clear: <strong>Please use <code>x[length(x)]</code></strong>.</p>\n"}, {'answer_id': 37686960, 'author': 'Enrique Pérez Herrero', 'author_id': 4678112, 'author_profile': 'https://Stackoverflow.com/users/4678112', 'pm_score': 4, 'selected': False, 'text': '<p>Package <code>data.table</code> includes <code>last</code> function</p>\n\n<pre><code>library(data.table)\nlast(c(1:10))\n# [1] 10\n</code></pre>\n'}, {'answer_id': 37687126, 'author': 'Sam Firke', 'author_id': 4470365, 'author_profile': 'https://Stackoverflow.com/users/4470365', 'pm_score': 5, 'selected': False, 'text': '<p>The <a href="https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html" rel="noreferrer">dplyr</a> package includes a function <code>last()</code>:</p>\n\n<pre><code>last(mtcars$mpg)\n# [1] 21.4\n</code></pre>\n'}, {'answer_id': 43760585, 'author': 'smoff', 'author_id': 6029286, 'author_profile': 'https://Stackoverflow.com/users/6029286', 'pm_score': 2, 'selected': False, 'text': '<p>The xts package provides a <code>last</code> function:</p>\n\n<pre><code>library(xts)\na <- 1:100\nlast(a)\n[1] 100\n</code></pre>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77434', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14008/']
|
77,436 |
<p>I have an ant build that makes directories, calls javac and all the regular stuff. The issue I am having is that when I try to do a clean (delete all the stuff that was generated) the delete task reports that is was unable to delete some files. When I try to delete them manually it works just fine. The files are apparently not open by any other process but ant still does not manage to delete them. What can I do?</p>
|
[{'answer_id': 77491, 'author': 'BQ.', 'author_id': 4632, 'author_profile': 'https://Stackoverflow.com/users/4632', 'pm_score': 2, 'selected': False, 'text': '<p>You don\'t say if your build is run as the currently logged on user. If not, the fact that explorer.exe or other process has the directory shown can cause it to be locked as well. But deleting it in that same explorer.exe process would succeed. Try Unlocker from <a href="http://ccollomb.free.fr/unlocker/" rel="nofollow noreferrer">http://ccollomb.free.fr/unlocker/</a> to see what processes have the files/directories locked.</p>\n'}, {'answer_id': 77510, 'author': 'John Meagher', 'author_id': 3535, 'author_profile': 'https://Stackoverflow.com/users/3535', 'pm_score': 2, 'selected': False, 'text': '<p>Is there something from the Ant process that is holding the files (or directory) open? This would cause the situation where you could delete them after running ant, but not during. </p>\n'}, {'answer_id': 77548, 'author': 'Craig Trader', 'author_id': 12895, 'author_profile': 'https://Stackoverflow.com/users/12895', 'pm_score': 3, 'selected': False, 'text': '<p>It depends ...</p>\n\n<ul>\n<li>The Ant process doesn\'t have enough permissions to delete the files (typically because they were created by a different user, perhaps a system user). Try running your Ant script as an administrative user, using Run As.</li>\n<li>Windows is really bad at cleaning up file locks when processes die or are killed; consequently, Windows thinks the file is locked by a process that died (or was killed). There\'s nothing you can do in this situation other than reboot.</li>\n<li>Get better tools to inspect your system state. I recommend downloading the <a href="http://technet.microsoft.com/en-us/sysinternals/default.aspx" rel="noreferrer">SysInternals</a> tools and using them instead of the default Windows equivalents.</li>\n</ul>\n'}, {'answer_id': 81222, 'author': 'Shimi Bandiel', 'author_id': 15100, 'author_profile': 'https://Stackoverflow.com/users/15100', 'pm_score': 5, 'selected': True, 'text': '<p>I encountered this problem once.\nIt was because the file i tried to delete was a part of a <strong>classpath</strong> for another task.</p>\n'}, {'answer_id': 9566907, 'author': 'Sergey', 'author_id': 141408, 'author_profile': 'https://Stackoverflow.com/users/141408', 'pm_score': 2, 'selected': False, 'text': '<p>Ant versions before 1.8.0 have a bug which leads to random errors during delete operation. Try using Ant 1.8.0 or newer.</p>\n\n<p>You can see the bug details here <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=45960" rel="nofollow">https://issues.apache.org/bugzilla/show_bug.cgi?id=45960</a></p>\n'}, {'answer_id': 12032987, 'author': 'Artem Nakonechny', 'author_id': 298552, 'author_profile': 'https://Stackoverflow.com/users/298552', 'pm_score': 3, 'selected': False, 'text': "<p>Using Ant Retry task has helped me.\nI've just wrapped it around the Delete Task.</p>\n"}, {'answer_id': 17351723, 'author': 'Sarel Botha', 'author_id': 35264, 'author_profile': 'https://Stackoverflow.com/users/35264', 'pm_score': 0, 'selected': False, 'text': "<p>I've been having this problem a lot lately and it's random. One time it works, the next time it doesn't work. I'm using NetBeans (in case that matters) and I've added a lot of extra tasks to build.xml. I was having this problem in the -post-jar task. It would happen when I call unjar on the file, then delete. I suspect that NB is trying to scan the jar and this causes the lock on it.</p>\n\n<p>What worked for me is to immediately rename the jar at the start of -post-jar and add a .tmp extension to it. Then I call unjar on the temp file. When I'm done I rename back to the desired jar name.</p>\n"}, {'answer_id': 17675788, 'author': 'Sudheer Palyam', 'author_id': 534832, 'author_profile': 'https://Stackoverflow.com/users/534832', 'pm_score': 0, 'selected': False, 'text': '<p>I too had the same problem and was tried of manually deleting the build directories. Finally I solved it by renaming the .jar artifact of my project to a different name from project name itself. For ex: my project was portal and my ant built script use to generate portal.jar, where eclipse ant was not able to delete this portal.jar. When i changed my build.xml to generate my .jar as portalnew.jar, eclipse was able to delete this portalnew.jar next time. Hope this helps.</p>\n'}, {'answer_id': 23909598, 'author': 'Vinila', 'author_id': 3683279, 'author_profile': 'https://Stackoverflow.com/users/3683279', 'pm_score': 2, 'selected': False, 'text': "<p>I faced the same problem.<br>\nI didn't have any classpath set to or antivirus running on my machine.<br>\nHowever, the ANT version I was using was 32 bit and the JDK I installed was 64 bit.<br>\nI installed a 32 bit JDK and the issue was resolved.</p>\n"}, {'answer_id': 25642430, 'author': 'MikeRoger', 'author_id': 459655, 'author_profile': 'https://Stackoverflow.com/users/459655', 'pm_score': 1, 'selected': False, 'text': '<p>In my case my ant clean was failing from Eclipse, unable to remove build files. I see this from time to time. Usually succeeds on a repeat attempt. This time no. \nTried running ant clean from command line, failed Unable to delete"unable to delete". \nIt must have been Eclipse holding on to the problem file, when I exited Eclipse, cmd line was able to delete OK.</p>\n'}, {'answer_id': 27246020, 'author': 'maQbex', 'author_id': 3416893, 'author_profile': 'https://Stackoverflow.com/users/3416893', 'pm_score': 0, 'selected': False, 'text': '<p>You need to delete it manually in Windows. It worked for me. (Usually the files to be deleted are older versions of jar.. For example: if there exists httpcore.4.2.5.ja5r and httpcore.4.3.jar, it will try to delete 4.2.5.jar)</p>\n'}, {'answer_id': 45319304, 'author': 'priya', 'author_id': 3876624, 'author_profile': 'https://Stackoverflow.com/users/3876624', 'pm_score': 0, 'selected': False, 'text': '<p>i faced this issue as the file the ant was trying to delete was being used by some other service/process.\nI stopped the service, and then the ant build script did run through.</p>\n'}, {'answer_id': 49192466, 'author': 'ShivaKumar', 'author_id': 6203724, 'author_profile': 'https://Stackoverflow.com/users/6203724', 'pm_score': 0, 'selected': False, 'text': '<p>In my case, I stopped running Java process from Task Manager and re-run the Ant build file. The file was able to delete and build was successful.</p>\n'}, {'answer_id': 53188224, 'author': 'momo', 'author_id': 5118529, 'author_profile': 'https://Stackoverflow.com/users/5118529', 'pm_score': 0, 'selected': False, 'text': '<p>I am seeing problems like this way too often since I switched to Microsoft Windows 10. Renaming the file immediately before removing it solved it for me:</p>\n\n<pre><code><rename src="file.name" dest="file.name.old"/>\n<delete file="file.name.old" />\n</code></pre>\n'}, {'answer_id': 69431386, 'author': 'Milan Patel', 'author_id': 14627788, 'author_profile': 'https://Stackoverflow.com/users/14627788', 'pm_score': 0, 'selected': False, 'text': "<p>For me, I am using mac so I tried sudo before ant cmd, <code>sudo ant clean all</code> and it did work perfectly fine.</p>\n<p>As i've read javac will not have access to delete JAR files so you can either sudo it or find alternative.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77436', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8621/']
|
77,473 |
<p>The backup and restore process of a large database or collection of databases on sql server is very important for disaster & recovery purposes. However, I have not found a robust solution that will guarantee the whole process is as efficient as possible, 100% reliable and easily maintainable and configurable accross multiple servers. </p>
<p>Microsft's Maintenance Plans doesn't seem to be sufficient. The best solution I have used is one that I created manually using many jobs with many steps per database running on the source server (backup) and destination server (restore). The jobs use stored procedures to do the backup, copying & restoring. This runs once a day (full backup/restore) and intraday every 5 mins (transaction log shipping). </p>
<p>Although my current process works and reports any job failures via email, I know the whole process isn't very reliable and cannot be easily maintained/configured on all our servers by a non-DBA without having in-depth knowledge of the process.</p>
<p>I would like to know if others have this same backup/restore process and how others overcome this issue.</p>
|
[{'answer_id': 77611, 'author': 'YonahW', 'author_id': 3821, 'author_profile': 'https://Stackoverflow.com/users/3821', 'pm_score': 0, 'selected': False, 'text': '<p>I am doing precisely the same thing and have various issues semi regularly even with this process.</p>\n\n<p>How do you handle the spacing between copying the file from Server A to Server B and restoring the transactional backup on Server B.</p>\n\n<p>Every once in a while the transaction backup is larger than normal and takes a longer time to copy. The restore job then gets an operating system error that the file is in use.</p>\n\n<p>This is not such a big deal since the file is automatically applied the next time around however it would be nicer to have a more elegant solution in general and one that specifically fixes this issue.</p>\n'}, {'answer_id': 77924, 'author': 'Michael K. Campbell', 'author_id': 11191, 'author_profile': 'https://Stackoverflow.com/users/11191', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve used a similar step to keep dev/test/QA databases \'zero-stepped\' on a nightly basis for developers and QA folks to use. </p>\n\n<p>Documentation is the key - if you want to remove what Scott Hanselman calls \'bus factor\' (i.e. the danger that the creator of the system will get hit by a bus and everything starts to suck). </p>\n\n<p>That said, for normal database backups and disaster recovery plans, I\'ve found that SQL Server Maintenance Plans work out pretty well. As long as you include:\n1) Decent documentation\n2) Routine testing. </p>\n\n<p>I\'ve outlined some of the ways to go about doing that (for anyone drawn to this question looking for an example of how to go about creating a disaster recovery plan):<br>\n<a href="http://www.sqlservervideos.com/sqlserver-backups/sqlbackup-best-practices" rel="nofollow noreferrer">SQL Server Backup Best Practices (Free Tutorial/Video)</a></p>\n'}, {'answer_id': 215801, 'author': 'Brent Ozar', 'author_id': 26837, 'author_profile': 'https://Stackoverflow.com/users/26837', 'pm_score': 2, 'selected': False, 'text': "<p>The key part of your question is the ability for the backup solution to be managed by a non-DBA. Any native SQL Server answer like backup scripts isn't going to meet that need, because backup scripts require T-SQL knowledge.</p>\n\n<p>Because of that, you want to look toward third-party solutions like the ones Mitch Wheat mentioned. I work for Quest (the makers of LiteSpeed) so of course I'm partial to that one - it's easy to show to non-DBAs. Before I left my last company, I had a ten minute session to show the sysadmins and developers how the LiteSpeed console worked, and that was that. They haven't called since.</p>\n\n<p>Another approach is using the same backup software that the rest of your shop uses. TSM, Veritas, Backup Exec and Microsoft DPM all have SQL Server agents that let your Windows admins manage the backup process with varying degrees of ease-of-use. If you really want a non-DBA to manage it, this is probably the most dead-easy way to do it, although you sacrifice a lot of performance that the SQL-specific backup tools give you.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77473', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11989/']
|
77,485 |
<p>What do folks here see as the relative strengths and weaknesses of Git, Mercurial, and Bazaar?</p>
<p>In considering each of them with one another and against version control systems like SVN and Perforce, what issues should be considered?</p>
<p>In planning a migration from SVN to one of these distributed version control systems, what factors would you consider?</p>
|
[{'answer_id': 77631, 'author': 'jfm3', 'author_id': 11138, 'author_profile': 'https://Stackoverflow.com/users/11138', 'pm_score': 1, 'selected': False, 'text': '<p>This is a big question that depends a lot on context that would take you a lot of time to type into one of these little text boxes. Also, all three of these appear substantially similar when used for the usual stuff most programmers do, so even understanding the differences requires some fairly esoteric knowledge.</p>\n\n<p>You will probably get much better answers if you can break your analysis of these tools down to the point at which you have more specific questions.</p>\n'}, {'answer_id': 77727, 'author': 'Charles Duffy', 'author_id': 14122, 'author_profile': 'https://Stackoverflow.com/users/14122', 'pm_score': 8, 'selected': True, 'text': '<p>Git is very fast, scales very well, and is very transparent about its concepts. The down side of this is that it has a relatively steep learning curve. A Win32 port is available, but not quite a first-class citizen. Git exposes hashes as version numbers to users; this provides guarantees (in that a single hash always refers to the exact same content; an attacker cannot modify history without being detected), but can be cumbersome to the user. Git has a unique concept of tracking file contents, even as those contents move between files, and views files as first-level objects, but does not track directories. Another issue with git is that has many operations (such as <I>rebase</I>) which make it easy to modify history (in a sense -- the content referred to by a hash will never change, but references to that hash may be lost); some purists (myself included) don\'t like that very much.</p>\n\n<p>Bazaar is reasonably fast (very fast for trees with shallow history, but presently scales poorly with history length), and is easy-to-learn to those familiar with the command-line interfaces of traditional SCMs (CVS, SVN, etc). Win32 is considered a first-class target by its development team. It has a pluggable architecture for different components, and replaces its storage format frequently; this allows them to introduce new features (such as better support for integration with revision control systems based on different concepts) and improve performance. The Bazaar team considers directory tracking and rename support first-class functionality. While globally unique revision-id identifiers are available for all revisions, tree-local revnos (standard revision numbers, more akin to those used by svn or other more conventional SCMs) are used in place of content hashes for identifying revisions. Bazaar has support for "lightweight checkouts", in which history is kept on a remote server instead of copied down to the local system and is automatically referred to over the network when needed; at present, this is unique among DSCMs.</p>\n\n<p>Both have some form of SVN integration available; however, bzr-svn is considerably more capable than git-svn, largely due to backend format revisions introduced for that purpose. <I>[Update, as of 2014: The third-party commercial product SubGit provides a bidirectional interface between SVN and Git which is comparable in fidelity to bzr-svn, and considerably more polished; I <B>strongly</B> recommend its use over that of git-svn when budget and licensing constraints permit].</I></p>\n\n<p>I have not used Mercurial extensively, and so cannot comment on it in detail -- except to note that it, like Git, has content-hash addressing for revisions; also like Git, it does not treat directories as first-class objects (and cannot store an empty directory). It is, however, faster than any other DSCM except for Git, and has far better IDE integration (especially for Eclipse) than any of its competitors. Given its performance characteristics (which lag only slightly behind those of Git) and its superior cross-platform and IDE support, Mercurial may be compelling for teams with significant number of win32-centric or IDE-bound members.</p>\n\n<p>One concern in migrating from SVN is that SVN\'s GUI frontends and IDE integration are more mature than those of any of the distributed SCMs. Also, if you currently make heavy use of precommit script automation with SVN (ie. requiring unit tests to pass before a commit can proceed), you\'ll probably want to use a tool similar to <A HREF="https://launchpad.net/pqm" rel="noreferrer">PQM</A> for automating merge requests to your shared branches.</p>\n\n<p>SVK is a DSCM which uses Subversion as its backing store, and has quite good integration with SVN-centric tools. However, it has dramatically worse performance and scalability characteristics than any other major DSCM (even Darcs), and should be avoided for projects which are liable to grow large in terms of either length of history or number of files.</p>\n\n<p>[About the author: I use Git and Perforce for work, and Bazaar for my personal projects and as an embedded library; other parts of my employer\'s organization use Mercurial heavily. In a previous life I built a great deal of automation around SVN; before that I have experience with GNU Arch, BitKeeper, CVS and others. Git was quite off-putting at first -- it felt like GNU Arch inasmuch as being a concept-heavy environment, as opposed to toolkits built to conform to the user\'s choice of workflows -- but I\'ve since come to be quite comfortable with it].</p>\n'}, {'answer_id': 77794, 'author': 'Herge', 'author_id': 14102, 'author_profile': 'https://Stackoverflow.com/users/14102', 'pm_score': 3, 'selected': False, 'text': "<p>Mercurial and Bazaar resemble themselves very much on the surface. They both provide basic distributed version control, as in offline commit and merging multiple branches, are both written in python and are both slower than git. There are many differences once you delve into the code, but, for your routine day-to-day tasks, they are effectively the same, although Mercurial seems to have a bit more momentum.</p>\n\n<p>Git, well, is not for the uninitiated. It is much faster than both Mercurial and Bazaar, and was written to manage the Linux kernel. It is the fastest of the three and it is also the most powerful of the three, by quite a margin. Git's log and commit manipulation tools are unmatched. However, it is also the most complicated and the most dangerous to use. It is very easy to lose a commit or ruin a repository, especially if you do not understand the inner workings of git.</p>\n"}, {'answer_id': 77834, 'author': 'Craig Trader', 'author_id': 12895, 'author_profile': 'https://Stackoverflow.com/users/12895', 'pm_score': 0, 'selected': False, 'text': '<p>Distributed version control systems (DVCSs) solve different problems than Centralized VCSs. Comparing them is like comparing hammers and screwdrivers.</p>\n\n<p><a href="http://en.wikipedia.org/wiki/Revision_control" rel="nofollow noreferrer">Centralized VCS</a> systems are designed with the intent that there is One True Source that is Blessed, and therefore Good. All developers work (checkout) from that source, and then add (commit) their changes, which then become similarly Blessed. The only real difference between CVS, Subversion, ClearCase, Perforce, VisualSourceSafe and all the other CVCSes is in the workflow, performance, and integration that each product offers.</p>\n\n<p><a href="http://en.wikipedia.org/wiki/Distributed_revision_control" rel="nofollow noreferrer">Distributed VCS</a> systems are designed with the intent that one repository is as good as any other, and that merges from one repository to another are just another form of communication. Any semantic value as to which repository should be trusted is imposed from the outside by process, not by the software itself.</p>\n\n<p>The real choice between using one type or the other is organizational -- if your project or organization wants centralized control, then a DVCS is a non-starter. If your developers are expected to work all over the country/world, without secure broadband connections to a central repository, then DVCS is probably your salvation. If you need both, you\'re fsck\'d.</p>\n'}, {'answer_id': 77883, 'author': 'Rafał Rawicki', 'author_id': 13767, 'author_profile': 'https://Stackoverflow.com/users/13767', 'pm_score': 1, 'selected': False, 'text': '<p>Bazaar is IMHO easier to learn than git.\nGit has a nice support in github.com.</p>\n\n<p>I think you should try to use both and decide which suits you most.</p>\n'}, {'answer_id': 77943, 'author': 'ddaa', 'author_id': 11549, 'author_profile': 'https://Stackoverflow.com/users/11549', 'pm_score': 1, 'selected': False, 'text': '<blockquote>\n <p>What do folks here see as the relative strengths and weaknesses of Git, Mercurial, and Bazaar?</p>\n</blockquote>\n\n<p>This is a very open question, bordering on flamebait.</p>\n\n<p>Git is fastest, but all three are fast enough. Bazaar is the most flexible (it has transparent read-write support for SVN repositories) and cares a lot about the user experience. Mercurial is somewhere in the middle.</p>\n\n<p>All three systems have lots of fanboys. I am personally a Bazaar fanboy.</p>\n\n<blockquote>\n <p>In considering each of them with one another and against version control systems like SVN and Perforce, what issues should be considered?</p>\n</blockquote>\n\n<p>The former are distributed systems. The latter are centralized systems. In addition, Perforce is proprietary while all the others are free <a href="http://www.gnu.org/philosophy/free-sw.html" rel="nofollow noreferrer">as in speech</a>.</p>\n\n<p>Centralized versus decentralized is a much more momentous choice than any of the systems you mentioned within its category.</p>\n\n<blockquote>\n <p>In planning a migration from SVN to one of these distributed version control systems, what factors would you consider?</p>\n</blockquote>\n\n<p>First, lack of a good substitute for TortoiseSVN. Although Bazaar is working on their own <a href="http://bazaar-vcs.org/TortoiseBzr" rel="nofollow noreferrer">Tortoise variant</a>, but it\'s not there yet, as of September 2008.</p>\n\n<p>Then, training the key people about how using a decentralized system is going to affect their work.</p>\n\n<p>Finally, integration with the rest of the system, such as issue trackers, the nightly build system, the automated test system, etc.</p>\n'}, {'answer_id': 79577, 'author': 'DGentry', 'author_id': 4761, 'author_profile': 'https://Stackoverflow.com/users/4761', 'pm_score': 3, 'selected': False, 'text': '<p>Sun did an evaluation of <A HREF="http://opensolaris.org/os/community/tools/scm/git-eval.txt" rel="noreferrer">git</A>, <A HREF="http://opensolaris.org/os/community/tools/scm/mercurial-eval.html" rel="noreferrer">Mercurial</A>, and <A HREF="http://opensolaris.org/os/community/tools/scm/bzr-eval/" rel="noreferrer">Bazaar</A> as candidates to replace the Sun Teamware VCS for the Solaris code base. I found it very interesting.</p>\n'}, {'answer_id': 81563, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 1, 'selected': False, 'text': "<p>ddaa.myopenid.com mentioned it in passing, but I think it's worth mentioning again: Bazaar can read and write to remote SVN repositories. That means you could use Bazaar locally as a proof-of-concept while the rest of the team is still using Subversion.</p>\n\n<p>EDIT: Pretty much all the tool now have <em>some</em> way of interacting with SVN, but I now have personal experience that <code>git svn</code> works <strong>extremely</strong> well. I've been using it for months, with minimal hiccups.</p>\n"}, {'answer_id': 91429, 'author': 'David Plumpton', 'author_id': 16709, 'author_profile': 'https://Stackoverflow.com/users/16709', 'pm_score': 1, 'selected': False, 'text': "<p>Your major issue is going to be that these are <strong>Distributed</strong> SCMs, and as such require a bit of a change to the user's mindset. Once people get used to the idea the technical details and usage patterns will fall into place, but don't underestimate that initial hurdle, especially in a corporate setting. Remember, all problems are people problems.</p>\n"}, {'answer_id': 437296, 'author': 'Jakub Narębski', 'author_id': 46058, 'author_profile': 'https://Stackoverflow.com/users/46058', 'pm_score': 4, 'selected': False, 'text': '<hr>\n\n<blockquote><em>What do folks here see as the relative strengths and weaknesses of Git, Mercurial, and Bazaar?</em></blockquote>\n\n<p>In my opinion <strong>Git</strong> strength is its clean underlying design and very rich set of features. It also has I think the best support for multi-branch repositories and managing branch-heavy workflows. It is very fast and has small repository size.</p>\n\n<p>It has some features which are useful but take some effort to be used to them. Those include <em>visible</em> intermediate staging ara (index) between working area and repository database, which allows for better merge resolution in more complicated cases, incremental comitting, and comitting with dirty tree; <em>detecting</em> renames and copies using similarity heuristic rather than tracking them using some kind of file-ids, which works well and which allow for blame (annotate) which can follow code movement across files and not only wholesale renames.</p>\n\n<p>One of its disadvantages is that MS Windows support lags behind and is not full. Another perceived disadvantage is that it is not as well documented as for example Mercurial, and is less user friendly than competition, but it changes.</p>\n\n<p>In my opinion <strong>Mercurial</strong> strength lies in its good performance and small repository size, in its good MS Windows support.</p>\n\n<p>The main disadvanatge is in my opinion the fact that local branches (multiple branches in single repository) is still second-class citizen, and in strange and complicated way it implements tags. Also the way it deals with file renames was suboptimal (but this migth have changed). Mercurial doesn\'t support octopus merges (with more than two parents).</p>\n\n<p>From what I have heard and read main <strong>Bazaar</strong> advantages are it easy support for centralized workflow (which is also disadvantage, with centralized concepts visible where it shouldn\'t), tracking renames of both files and directories.</p>\n\n<p>Its main disadvantage are performance and repository size for large repositories with long nonlinear history (the performance improved at least for not too large repositories), the fact that default paradigm is one ranch per repository (you can set it up to share data, though), and centralized concepts (but that also from what I have heard changes).</p>\n\n<p>Git is written in C, shell scripts and Perl, and is scriptable; Mercurial is written in C (core, for performance) and Python, and provides API for extensions; Bazaar is written in Python, and provides API for extensions.</p>\n\n<hr>\n\n<blockquote><em>In considering each of them with one another and against version control systems like SVN and Perforce, what issues should be considered?</em></blockquote>\n\n<p>Version control systems like Subversion (SVN), Perforce, or ClearCase are <em>centralized</em> version control systems. Git, Mercurial, Bazaar (and also Darcs, Monotone and BitKeeper) are <em>distributed</em> version control systems. Distributed version control systems allow for much wider range of workflows. They allow to use "publish when ready". They have better support for branching and merging, and for branch-heavy workflows. You don\'t need to trust people with commit access to be able to get contributions from them in an easy way.</p>\n\n<hr>\n\n<blockquote><em>In planning a migration from SVN to one of these distributed version control systems, what factors would you consider?</em></blockquote>\n\n<p>One of factors you might want to consider is the support for inetracting with SVN; Git has git-svn, Bazaar has bzr-svn, and Mercurial has hgsubversion extension.</p>\n\n<p><strong>Disclaimer:</strong> I am Git user and small time contributor, and watch (and participate on) git mailing list. I know Mercurial and Bazaar only from their documentation, various discussion on IRC and mailing lists, and blog posts and articles comparing various version control systems (some of which are listed on <a href="http://git.or.cz/gitwiki/GitComparison" rel="noreferrer">GitComparison</a> page on Git Wiki).</p>\n'}, {'answer_id': 493199, 'author': 'Davide', 'author_id': 25891, 'author_profile': 'https://Stackoverflow.com/users/25891', 'pm_score': 2, 'selected': False, 'text': '<p>A very important <strong>missing</strong> thing in bazaar is cp. You cannot have multiple files sharing the same history, as you have in SVN, see for example <a href="https://lists.ubuntu.com/archives/bazaar/2007q3/029792.html" rel="nofollow noreferrer">here</a> and <a href="https://bugs.launchpad.net/bzr/+bug/269095" rel="nofollow noreferrer">here</a>. If you don\'t plan to use cp, bzr is a great (and very easy to use) replacement for svn.</p>\n'}, {'answer_id': 493241, 'author': 'sh1mmer', 'author_id': 53569, 'author_profile': 'https://Stackoverflow.com/users/53569', 'pm_score': 2, 'selected': False, 'text': '<p>I was using Bazaar for a while which I liked a lot but it was only smaller projects and even then it was pretty slow. So easy to learn, but not super fast. It is very x-platform though.</p>\n\n<p>I currently use Git which I like a lot since version 1.6 made it much more similar to other VCS in terms of the commands to use.</p>\n\n<p>I think the main differences for my experience in using DVCS is this:</p>\n\n<ol>\n<li>Git has the most vibrant community and it\'s common to see articles about Git</li>\n<li><a href="http://github.com" rel="nofollow noreferrer">GitHub</a> really rocks. Launchpad.net is ok, but nothing like the pleasure of Github</li>\n<li>The number of workflow tools for Git has been great. It\'s integrated all over the place. There are some for Bzr but not nearly as many or as well maintained.</li>\n</ol>\n\n<p>In summary Bzr was great when I was cutting my teeth on DVCS but I\'m now very happy with Git and Github.</p>\n'}, {'answer_id': 783778, 'author': 'k1udge', 'author_id': 74220, 'author_profile': 'https://Stackoverflow.com/users/74220', 'pm_score': 1, 'selected': False, 'text': '<p>There is good video by Linus Torvalds on git. He is creator of Git so this is what he promotes but in the video he explain what distributed SCMs are and why they are better then centralized ones. There is a good deal of comparing git (mercurial is considered to be OK) and cvs/svn/perforce. There are also questions from the audience regarding migration to distributed SCM.</p>\n\n<p>I found this material enlightening and I am sold to distributed SCM. But despite Linus\' efforts my choice is mercurial. The reason is bitbucket.org, I found it better (more generous) then github.</p>\n\n<p>I need to say here a word of warning: Linus has quite aggressive style, I think he wants to be funny but I didn\'t laugh. Apart from that the video is great if you are new to distributed SCMs and think about move from SVN.</p>\n\n<p><a href="http://www.youtube.com/watch?v=4XpnKHJAok8" rel="nofollow noreferrer">http://www.youtube.com/watch?v=4XpnKHJAok8</a></p>\n'}, {'answer_id': 897862, 'author': 'Martin Geisler', 'author_id': 110204, 'author_profile': 'https://Stackoverflow.com/users/110204', 'pm_score': 3, 'selected': False, 'text': '<p>Take a look at the comparison made recently by the Python developers: <a href="http://wiki.python.org/moin/DvcsComparison" rel="noreferrer">http://wiki.python.org/moin/DvcsComparison</a>. They chose Mercurial based on three important reasons:</p>\n\n<blockquote>\n <p>The choice to go with Mercurial was made for three important reasons:</p>\n \n <ul>\n <li>According to a small survey, Python developers are more interested in using Mercurial\n than in Bazaar or Git.</li>\n <li>Mercurial is written in Python, which is congruent with the python-dev tendency to \'eat their own dogfood\'.</li>\n <li>Mercurial is significantly faster than bzr (it\'s slower than git, though by a much smaller difference).</li>\n <li>Mercurial is easier to learn for SVN users than Bazaar.</li>\n </ul>\n \n <p>(from <a href="http://www.python.org/dev/peps/pep-0374/" rel="noreferrer">http://www.python.org/dev/peps/pep-0374/</a>)</p>\n</blockquote>\n'}, {'answer_id': 1489019, 'author': 'Michael La Voie', 'author_id': 65843, 'author_profile': 'https://Stackoverflow.com/users/65843', 'pm_score': 4, 'selected': False, 'text': '<p>Steve Streeting of the Ogre 3D project just (9/28/2009) published a blog entry on this topic where he does a great and even handed <a href="http://www.stevestreeting.com/2009/09/28/early-stage-gitmercurialbazaar-evaluation-thoughts/" rel="nofollow noreferrer">comparison of Git, Mercurial and Bazaar</a>.</p>\n\n<p>In the end he finds strengths and weaknesses with all three and no clear winner. On the plus side, he gives a great table to help you decide which to go with.</p>\n\n<p><img src="https://i.stack.imgur.com/hlrmT.png" alt="alt text"></p>\n\n<p>Its a short read and I highly recommend it.</p>\n'}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77485', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13750/']
|
77,503 |
<p>I am trying to compare two large datasets from a SQL query. Right now the SQL query is done externally and the results from each dataset is saved into its own csv file. My little C# console application loads up the two text/csv files and compares them for differences and saves the differences to a text file.</p>
<p>Its a very simple application that just loads all the data from the first file into an arraylist and does a .compare() on the arraylist as each line is read from the second csv file. Then saves the records that don't match.</p>
<p>The application works but I would like to improve the performance. I figure I can greatly improve performance if I can take advantage of the fact that both files are sorted, but I don't know a datatype in C# that keeps order and would allow me to select a specific position. Theres a basic array, but I don't know how many items are going to be in each list. I could have over a million records. Is there a data type available that I should be looking at? </p>
|
[{'answer_id': 77546, 'author': 'MagicKat', 'author_id': 8505, 'author_profile': 'https://Stackoverflow.com/users/8505', 'pm_score': 0, 'selected': False, 'text': '<p>Well, there are several approaches that would work. You could write your own data structure that did this. Or you can try and use SortedList. You can also return the DataSets in code, and then use .Select() on the table. Granted, you would have to do this on both tables.</p>\n'}, {'answer_id': 77551, 'author': 'Sam', 'author_id': 9406, 'author_profile': 'https://Stackoverflow.com/users/9406', 'pm_score': 0, 'selected': False, 'text': '<p>You can easily use a SortedList to do fast lookups. If the data you are loading is already sorted, insertions into the SortedList should not be slow.</p>\n'}, {'answer_id': 77567, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 0, 'selected': False, 'text': '<p>If you are looking simply to see if all lines in FileA are included in FileB you could read it in and just compare streams inside a loop.</p>\n\n<p>File 1\nEntry1\nEntry2\nEntry3</p>\n\n<p>File 2\nEntry1\nEntry3</p>\n\n<p>You could loop through with two counters and find omissions, going line by line through each file and see if you get what you need.</p>\n'}, {'answer_id': 77570, 'author': 'Arno', 'author_id': 13685, 'author_profile': 'https://Stackoverflow.com/users/13685', 'pm_score': 0, 'selected': False, 'text': '<p>Maybe I misunderstand, but the ArrayList will maintain its elements in the same order by which you added them. This means you can compare the two ArrayLists within one pass only - just increment the two scanning indices according to the comparison results.</p>\n'}, {'answer_id': 77574, 'author': 'Shane Courtrille', 'author_id': 12503, 'author_profile': 'https://Stackoverflow.com/users/12503', 'pm_score': 0, 'selected': False, 'text': '<p>One question I have is have you considered "out-sourcing" your comparison. There are plenty of good diff tools that you could just call out to. I\'d be surprised if there wasn\'t one that let you specify two files and get only the differences. Just a thought.</p>\n'}, {'answer_id': 77588, 'author': 'cranley', 'author_id': 10308, 'author_profile': 'https://Stackoverflow.com/users/10308', 'pm_score': 1, 'selected': False, 'text': "<p>System.Collections.Specialized.StringCollection allows you to add a range of values and, using the .IndexOf(string) method, allows you to retrieve the index of that item.</p>\n\n<p>That being said, you could likely just load up a couple of byte[] from a filestream and do byte comparison... don't even worry about loading that stuff into a formal datastructure like StringCollection or string[]; if all you're doing is checking for differences, and you want speed, I would wreckon byte differences are where it's at.</p>\n"}, {'answer_id': 77617, 'author': 'David J. Sokol', 'author_id': 1390, 'author_profile': 'https://Stackoverflow.com/users/1390', 'pm_score': 2, 'selected': False, 'text': '<p>If data in both of your CSV files is already sorted and have the same number of records, you could skip the data structure entirely and do in-place analysis.</p>\n\n<pre><code>StreamReader one = new StreamReader("C:\\file1.csv");\nStreamReader two = new StreamReader("C:\\file2.csv");\nString lineOne;\nString lineTwo;\n\nStreamWriter differences = new StreamWriter("Output.csv");\nwhile (!one.EndOfStream)\n{\n lineOne = one.ReadLine();\n lineTwo = two.ReadLine();\n // do your comparison.\n bool areDifferent = true;\n\n if (areDifferent)\n differences.WriteLine(lineOne + lineTwo);\n}\n\none.Close();\ntwo.Close();\ndifferences.Close();\n</code></pre>\n'}, {'answer_id': 77823, 'author': 'skb', 'author_id': 14101, 'author_profile': 'https://Stackoverflow.com/users/14101', 'pm_score': 0, 'selected': False, 'text': '<p>I think the reason everyone has so many different answers is that you haven\'t quite got your problem specified well enough to be answered. First off, it depends what kind of differences you want to track. Are you wanting the differences to be output like in a WinDiff where the first file is the "original" and second file is the "modified" so you can list changes as INSERT, UPDATE or DELETE? Do you have a primary key that will allow you to match up two lines as different versions of the same record (when fields other than the primary key are different)? Or is is this some sort of reconciliation where you just want your difference output to say something like "RECORD IN FILE 1 AND NOT FILE 2"?</p>\n\n<p>I think the asnwers to these questions will help everyone to give you a suitable answer to your problem.</p>\n'}, {'answer_id': 77901, 'author': 'Jason Jackson', 'author_id': 13103, 'author_profile': 'https://Stackoverflow.com/users/13103', 'pm_score': 0, 'selected': False, 'text': '<p>If you have two files that are each a million lines as mentioned in your post, you might be using up <em>a lot</em> of memory. Some of the performance problem might be that you are swapping from disk. If you are simply comparing line 1 of file A to line one of file B, line2 file A -> line 2 file B, etc, I would recommend a technique that does not store so much in memory. You could either read write off of two file streams as a previous commenter posted and write out your results "in real time" as you find them. This would not explicitly store anything in memory. You could also dump chunks of each file into memory, say one thousand lines at a time, into something like a List. This could be fine tuned to meet your needs.</p>\n'}, {'answer_id': 77932, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 1, 'selected': False, 'text': '<p>This is an adaptation of David Sokol\'s code to work with varying number of lines, outputing the lines that are in one file but not the other:</p>\n\n<pre><code>StreamReader one = new StreamReader("C:\\file1.csv");\nStreamReader two = new StreamReader("C:\\file2.csv");\nString lineOne;\nString lineTwo;\nStreamWriter differences = new StreamWriter("Output.csv");\nlineOne = one.ReadLine();\nlineTwo = two.ReadLine();\nwhile (!one.EndOfStream || !two.EndOfStream)\n{\n if(lineOne == lineTwo)\n {\n // lines match, read next line from each and continue\n lineOne = one.ReadLine();\n lineTwo = two.ReadLine();\n continue;\n }\n if(two.EndOfStream || lineOne < lineTwo)\n {\n differences.WriteLine(lineOne);\n lineOne = one.ReadLine();\n }\n if(one.EndOfStream || lineTwo < lineOne)\n {\n differences.WriteLine(lineTwo);\n lineTwo = two.ReadLine();\n }\n}\n</code></pre>\n\n<p>Standard caveat about code written off the top of my head applies -- you may need to special-case running out of lines in one while the other still has lines, but I think this basic approach should do what you\'re looking for.</p>\n'}, {'answer_id': 92833, 'author': 'Shane Courtrille', 'author_id': 12503, 'author_profile': 'https://Stackoverflow.com/users/12503', 'pm_score': 0, 'selected': False, 'text': "<p>To resolve question #1 I'd recommend looking into creating a hash of each line. That way you can compare hashes quick and easy using a dictionary. </p>\n\n<p>To resolve question #2 one quick and dirty solution would be to use an IDictionary. Using itemId as your first string type and the rest of the line as your second string type. You can then quickly find if an itemId exists and compare the lines. This of course assumes .Net 2.0+</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77503', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8664/']
|
77,507 |
<p>What are your favourite assemblers, compilers, environments, interpreters for the
good old <a href="http://en.wikipedia.org/wiki/ZX_Spectrum" rel="noreferrer">ZX Spectrum</a>?</p>
|
[{'answer_id': 77864, 'author': 'tovare', 'author_id': 12677, 'author_profile': 'https://Stackoverflow.com/users/12677', 'pm_score': 2, 'selected': False, 'text': "<p>Just programming in BASIC, the commands are right there on those rubbery keys. Now if only PC's could have key-legends with while, case, switch etc. on them :-)</p>\n"}, {'answer_id': 85290, 'author': 'Ray Hayes', 'author_id': 7093, 'author_profile': 'https://Stackoverflow.com/users/7093', 'pm_score': 2, 'selected': False, 'text': '<p>I used to type in hex-tables from a magazine and then a a short basic application to unpack the data into assembly code. I couldn\'t make heads nor tails of it for ages until I discovered I wasn\'t actually coding at all!</p>\n\n<p>I then moved onto <a href="http://en.wikipedia.org/wiki/Zilog_Z80#The_Z80_assembly_language" rel="nofollow noreferrer">Z80 assembly</a> on a College owned <a href="http://en.wikipedia.org/wiki/CP/M" rel="nofollow noreferrer">CP/M</a> mini computer system. Programming the Speccy was never the same after that and I never went back!</p>\n'}, {'answer_id': 85417, 'author': 'djpowell', 'author_id': 7274, 'author_profile': 'https://Stackoverflow.com/users/7274', 'pm_score': 4, 'selected': True, 'text': '<p>I always used to use <a href="http://www.worldofspectrum.org/infoseek.cgi?regexp=%5EComplete+Machine+Code+Package$&pub=%5ERoybot$&loadpics=1" rel="noreferrer">Roybot Assembler</a> - which had you enter your program using the BASIC editor and REM statements. It comes with a decent debugger/disassembler that lets you single-step machine code too.</p>\n\n<p>The Hisoft Gens and Mons assembler and disassembler (aka Devpak) are probably fairly popular.</p>\n\n<p>For high-level compiling, the <a href="http://www.worldofspectrum.org/infoseekid.cgi?id=0012459" rel="noreferrer">Mira Modula-2</a> compiler is very good.</p>\n'}, {'answer_id': 85560, 'author': 'akauppi', 'author_id': 14455, 'author_profile': 'https://Stackoverflow.com/users/14455', 'pm_score': 2, 'selected': False, 'text': '<p>Devpac (a blue cassette) comes to my mind, even after all these years.</p>\n\n<p>Sure, it was #1. I don\'t miss the cassette loadings, though. Nice question!!! :D</p>\n\n<p><a href="http://www.clive.nl/detail/22916/" rel="nofollow noreferrer">http://www.clive.nl/detail/22916/</a></p>\n\n<p>I think I had v.3. It sure looked much more home-made than the this pic. But it <em>worked</em> and didn\'t have a single bug. Beat that, current software!!!</p>\n'}, {'answer_id': 86273, 'author': 'Linulin', 'author_id': 12481, 'author_profile': 'https://Stackoverflow.com/users/12481', 'pm_score': 2, 'selected': False, 'text': '<p><strong>ZX ASM 3.0</strong></p>\n\n<p>It had the best user interface and good feature set compared to other assemblers at the end of the twentieth century.</p>\n'}, {'answer_id': 143678, 'author': 'SmacL', 'author_id': 22564, 'author_profile': 'https://Stackoverflow.com/users/22564', 'pm_score': 0, 'selected': False, 'text': '<p>Well outside of GEN80, <a href="http://en.wikipedia.org/wiki/HiSoft_Systems" rel="nofollow noreferrer">HiSoft Pascal</a> and <a href="http://en.wikipedia.org/wiki/HiSoft_Systems" rel="nofollow noreferrer">Hisoft C</a> were pretty impressive. <em>Proper</em> high level languages, way cool. Before I learnt Z80, and was frustrated by the speed of BASIC, I also loved <a href="http://en.wikipedia.org/wiki/ZX_Spectrum_software" rel="nofollow noreferrer">MCODER</a>, though more on the ZX81 than ZX Spectrum.</p>\n'}, {'answer_id': 294698, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>ZX-Asm v3.1 + patched HiSoft-C v1.1 / figFORTH / BetaBasic 3.0</p>\n'}, {'answer_id': 388423, 'author': 'DamienG', 'author_id': 5720, 'author_profile': 'https://Stackoverflow.com/users/5720', 'pm_score': 1, 'selected': False, 'text': "<p>There are some good PC-based packages too. For Sinclair BASIC based development the excellent BASin package for Windows gives you a good syntax highlighter, runtime virtual machine, built-in editors for fonts and UDG's etc.</p>\n"}, {'answer_id': 388435, 'author': 'Martin', 'author_id': 8157, 'author_profile': 'https://Stackoverflow.com/users/8157', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/Zeus_Assembler" rel="nofollow noreferrer">Zeus assembler</a>, was the best.</p>\n\n<p>I\'d add a couple of the Spectrum books in there if I could remember the names, still have them at home. One was The Complete Spectrum ROM Disassembly by Ian Logan and Frank O\'Hara (ISBN 0 86161 116 0), which was commented and described as if it was the source, a fantastic piece of reverse engineering, including a suggested bug fix for the known ROM bugs. If only flash memory had been around in those days. I also memorised a tiny book called the Z80 Workshop Manual which was a great summary of the processor.</p>\n'}, {'answer_id': 793378, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Assembler Prometheus from Proxima Software.</p>\n'}, {'answer_id': 1238482, 'author': 'Flavius Suciu', 'author_id': 128722, 'author_profile': 'https://Stackoverflow.com/users/128722', 'pm_score': 3, 'selected': False, 'text': '<p>Hisoft Gens and Mons assembler and disassembler for programming/debugging.</p>\n\n<p>The Artist / The Art Studio for graphics:<br>\n<a href="http://www.worldofspectrum.org/infoseekid.cgi?id=0007918" rel="noreferrer">http://www.worldofspectrum.org/infoseekid.cgi?id=0007918</a></p>\n\n<p>The Music Box for sound:<br>\n<a href="http://www.worldofspectrum.org/infoseekid.cgi?id=0008481" rel="noreferrer">http://www.worldofspectrum.org/infoseekid.cgi?id=0008481</a></p>\n'}, {'answer_id': 1847649, 'author': 'Andrew Rollings', 'author_id': 40410, 'author_profile': 'https://Stackoverflow.com/users/40410', 'pm_score': 2, 'selected': False, 'text': '<p>For contemporary development, <a href="http://sourceforge.net/projects/tommygun/" rel="nofollow noreferrer">TommyGun</a> is an excellent choice.</p>\n\n<p>It has a built in assembler, map editor, graphics editor and other goodies. It also supports multiple 8-bit platforms.</p>\n\n<p>It works well in conjunction with the excellent <a href="http://worldofspectrum.org/forums/showthread.php?t=27547" rel="nofollow noreferrer">ZX Spin</a> emulator for debugging.</p>\n'}, {'answer_id': 2799321, 'author': 'polomint', 'author_id': 308711, 'author_profile': 'https://Stackoverflow.com/users/308711', 'pm_score': 2, 'selected': False, 'text': '<p>BASin, TommyGun, ConTEXT and the Pasmo cross-compiler. Works great with the ZXSpin emulator too,,</p>\n'}, {'answer_id': 17589710, 'author': 'liftarn', 'author_id': 1771388, 'author_profile': 'https://Stackoverflow.com/users/1771388', 'pm_score': 0, 'selected': False, 'text': "<p>I'm using Z88DK, but I think also SDCC may be of interest.</p>\n"}]
|
2008/09/16
|
['https://Stackoverflow.com/questions/77507', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13967/']
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.