Following the discussions here on SO I already read several times the remark that mutable structs are evil (like in the answer to this question).
What's the actual problem with mutability and structs?
I know this isn't directly related to a specific coding problem. It's a more general programming question. I'm a n00b... Been coding for 1 year, and it's where I belong. I want to get hardcore and put everything I have into it. I started with C++ and now I'm into C#. I love it all. What can I do to up my game and up my respect in the programming world?
I'm trying to decide on the best similarity metric for a product recommendation system using item-based collaborative filtering. This is a shopping basket scenario where ratings are binary valued - the user has either purchased an item or not - there is no explicit rating system (eg, 5-stars).
Step 1 is to compute item-to-item similarity, though I want to look at incorporating more features later on.
Is the Tanimoto coefficient the best way to go for binary values? Or are there other metrics that are appropriate here? Thanks.
I am running remote audio-file-fetching and audio file playback operations in a background thread using AsnycTask. A Cancellable progress bar is shown for the time the fetch operation runs.
I want to cancel/abort the AsnycTask run when the user cancels(decides against) the operation. What is the ideal way to handle such a case?
Thanks.
I've been searching on how to do Unit testing and find thats is quite easy, but, what I want to know is, In a asp.net mvc application, what should be REALLY important to test and which methods you guys use?
I just can't find a clear answer on about WHAT TO REALLY TEST when programming unit tests.
I just don't want to make unecessary tests and loose developement time doing overkill tests.
I've got a view in my app that does pretty much everything, and I like it that way. The problem however is that it's implementing 5 or 6 different delegates, which seems a little bit messy.
My question is, does the view controller have to implement all of the delegates? or is there some way I can separate the code out into different files (without having to do a major restructure or rewrite)?
Here's all the delegates I'm implementing:
@interface MyView : UIViewController <UIScrollViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate, MFMailComposeViewControllerDelegate>
I am working in an environment with a very small team (3 developers only) and each of us have been assigned a different project, without counting support tasks. I know this is a bad business practice and that we should all work on a single project at a time, and then move on to the next one (Already explained to the management on how much it sucks).
So don't answer me that we should work all together on one project at a time.
Energizing the work when in a team is mostly pair programming we did that when less project were thrown at us and that was great.
What I would like to know is how you energize your work when working alone on a project.
Do you follow any particular practice?
Java example method:
//Stores the user input into an integer variable called 'choice'
int choice = keyboard.nextInt();
Do I need to write javadoc for a simple method like this or should I only document the main method of any program, if so then what sort of things should I write for the main method?
Thanks,
Chris.
I need to prompt the user to enter his/her zip code at certain times in my iPhone application. I cannot store it or get it from the user's current location.
What is the optimal input method?
I started with a 5 wheel picker. This seemed like a bad direction, so I opted for a PIN-like entry screen. My implepentation is about the same as the 'enter passcode' screen you see when unlocking the iphone - including automatically ending input on the 5th digit instead of providing a return/enter button.
Does this seem optimal? Or is there a better way?
Note: I only need to accept a 5 digit US zip code.
I have a PDO mysql that updates 3 fields.
$update = $mypdo->prepare("UPDATE tablename SET field1=:field1,
field2=:field2,
field3=:field3
WHERE key=:key");
But I want field3 to be updated only when $update3 = true;
Is this possible to accomplish with a single query?
I could do it with 2 queries where I update field1 and field2 then check the boolean and update field3 if needed in a separate query. But hopefully there is a way to accomplish this in 1 query?
Now that I got my head wrapped around the 'C' language to a point where I feel proficient enough to write clean code, I'd like to focus my attention on project architecture guidelines. I'm looking for a good resource that coves the following topics:
How to create an interface that promotes code maintainability and is extensible for future upgrades.
Library creation guidelines. Example, when should I consider using static vs dynamic libraries. How to properly design an ABI to cope with either one.
Header files: what to partition out and when. Examples on when to use 1:1 vs 1:many .h to .c
Anything you feel I missed but is important when attempting to architect a new C project.
Ideally, I'd like to see some example projects ranging from small to large and see how the architecture changes depending on project size, function or customer.
What resource(s) would you recommend for such topics?
Hi. We have a non-profit web site that got about 5 million hits in May. Of those, about 5,700 were from IE 5.x or lower; about 4,000 were from folks with Netscape 4.x or lower. We know that the current site's layout works for newer browsers and we're testing it on IE6 as well (along with Chrome, Opera, Safari, and Firefox). How do you handle the folks with the older browsers? Because of jQuery libraries and such, the pages might not function correctly on those old browsers.
Is there an easy way to show a text-only version on browsers that can't handle the CSS and jQuery goodies? How do large sites handle this sort of thing? I've used the @embed to hide the stylesheet from Netscape 4.x, but not sure beyond that.
What is the best (as in cross-browser) technique to do image replacement in CSS? I am using sprites to do my navigation, but I want the markup to remain SEO friendly. Given the following HTML structure...
<div id="menu">
<ul>
<li><a href="#">Test</a></li>
<li><a href="#">Tester</a></li>
<li><a href="#">Testing Testing</a></li>
</ul>
</div>
What is the best way to replace the text with a background image using CSS only?
I am currently using this...
text-indent: -9999px;
But, it fails with CSS on, and images off.
I've been in some discussion recently about where email (notifications, etc...) should be sent in an ASP.NET MVC application. My nemesis grin argues that it only makes sense that the email should be sent from the controller.
I argue that an email is simply an alternate or augmented view through a different channel. Much like I would download a file as the payload of an ActionResult, the email is simply delivered through a different protocol.
I've worked an extension method that allows me to do the following:
<% Html.RenderEmail(model.FromAddress, model.ToAddress, model.Subject); %>
which I actually include within my the view that is displayed on the screen. The beauty is that, based on convention, if I call RenderEmail from a parent view named MyView.ascx, I attempt to render the contents of a view named MyViewEmail.ascx, unless it is not found, in which case I simply email a copy of parent view.
It certainly does make it testable (I still have an ISMTPService injected for testing), I wondered if anyone had any thoughts on whether or not this breaks from good practice. In use it has been extremely handy when we needed to easily send an email or modify the contents of the emailed results vs the browser rendered results.
Thanks,
Hal
The java.lang.Iterator interface has 3 methods: hasNext, next and remove. In order to implement a read-only iterator, you have to provide an implementation for 2 of those: hasNext and next.
My problem is that these methods does not declare any exceptions. So if my code inside the iteration process declares exceptions, I must enclose my iteration code inside a try/catch block.
My current policy has been to rethrow the exception enclosed in a RuntimeException. But this has issues because the checked exceptions are lost and the client code no longer can catch those exceptions explicitly.
How can I work around this limitation in the Iterator class?
Here is a sample code for clarity:
class MyIterator implements Iterator
{
@Override
public boolean hasNext()
{
try
{
return implementation.testForNext();
}
catch ( SomethingBadException e )
{
throw new RuntimeException(e);
}
}
@Override
public boolean next()
{
try
{
return implementation.getNext();
}
catch ( SomethingBadException e )
{
throw new RuntimeException(e);
}
}
...
}
Hi,
I'm a PHP programmer and I really want to increase the quality of my code and most importantly I want to be better at programming.
What book, tutorial or article would you guys suggest that I read that teaches how to make programs that are less coupled and easy to maintain? Are there any specific tips for PHP especially for the CakePHP framework?
Thanks in advance!
This does not really apply to any language specifically, but if it matters I am using VB.NET in Visual Studio 2008.
I can't seem to find anything really that useful using Google about this topic, but I was wondering what is common practice when an exception is thrown and caught but since it has been thrown the application cannot continue operating.
For example I have exceptions that are thrown by my FileLoader class when a file cannot be found or when a file is deemed corrupt. The exception is only thrown within the class and is not handled really. If the error is detected, then the exception is thrown and whatever function is was thrown is basically quits.
So in the code trying to create that object or call one of its members I use a Try...Catch statement. However, I was wondering, what should even do when this exception is caught? My application needs these files to be intact, and if they are not, the application is almost useless. So far I just pop up a message box telling the user their is an error and to reinstall. What else can I do, or better, what's common practice in these situations?
I have a vector X that contains positive numbers that I want to bin/discretize. For this vector, I want the numbers [0, 10) to show up just as they exist in the vector, but numbers [10,∞) to be 10+.
I'm using:
x <- c(0,1,3,4,2,4,2,5,43,432,34,2,34,2,342,3,4,2)
binned.x <- as.factor(ifelse(x > 10,"10+",x))
but this feels klugey to me. Does anyone know a better solution or a different approach?
mcpeterson
Java lets you create an entirely new subtype of Throwable, e.g:
public class FlyingPig extends Throwable { ... }
Now, very rarely, I may do something like this:
throw new FlyingPig("Oink!");
and of course elsewhere:
try { ... } catch (FlyingPig porky) { ... }
My questions are:
Is this a bad idea? And if so, why?
What could've been done to prevent this subtyping if it is a bad idea?
Since it's not preventable (as far as I know), what catastrophies could result?
If this isn't such a bad idea, why not?
How can you make something useful out of the fact that you can extends Throwable?
I understand the concept and reasons behind using the using statement, and I use it with things like file resources and remote connections, I was wondering if it is good practice to
use the using statement with WinForm forms and dialogs?
using (MyDialog dlg = new MyDialog())
{
if (dlg.ShowDialog() == EDialogResult.OK)
{
// Do Something
}
}
Thanks!
I'm trying to learn Perforce and want to delete a file from the depot(easy to do with p4 delete, p4 submit), but that deletes it from the client machine dir structure as well. I want to keep my local file in my directory intact.
The only way I can see to do this would be to move it out of the hierarchy that is under Perforce control before deleting. I was able to get my file back by syncing an earlier version.
Maybe I set up my client workspace wrong? Or am I misunderstanding a fundamental concept of source control? The client workspace is /home/user and I did it this way so I could add any file under my home directory without getting an error about the file not being under client's root.
FYI - Linux client and server running P4D/LINUX26X86/2009.1/222893 (2009/11/12)
Any advice appreciated.
Thanks.
Is there a better way to output data to html page with PHP ?
if i like to make a div with some var in php i will write something like that
print ('<div>'.$var.'</div>);
or
echo "'<div>'.$var.'</div>'";
what is the PROPER way to do that ?
or a better way, fill a $tempvar and print it once? like that:
$tempvar = '<div>'.$var.'</div>'
print ($tempvar);
in fact, in real life, the var will be fill with much more !
I recently heard about the use of several different languages in a (big) project, I also read about famous services such as Twitter using Rails as frontend, mixed with some other languages, and Scala I think it was as backend.
Is this common practice? Who does that?
I'm sure there are disadvantages to this. I think that you will have problems with the different interpreters/compilers and seamlessly connecting the different languages. Is this true?
Why is this actually done? For performance?