@Malachi Your edit removed too many things. I almost edited your edit but Jamal did it first while I was actually reviewing the code and just beat him to it :D
@Jamal Ow, you beat my edit concerning the return 0; stuff.
I'm in a class for Java, and I'm reading over some of the powerpoints and from the book, but I don't really understand why the x array is printing out an integer of 50 at x[0]. This is a very specific case, but it's more of an example as anything could be placed at the initial point of all of the...
I'm in a beginner javascript class and I feel like I have a pretty good grasp on all the intro material. All of my homework assignments work but they seem longer than they have to be, especially my most recent one. I'm not asking for answers to my homework as it is already complete (you can see t...
I just got into Object Oriented Programming, and it made me think about certain code how I can make them as efficient as possible.
Right now am I just including my header and footer like the following:
PHP
require_once 'core/init.php';
require_once 'includes/header.php';
//Big block of conte...
The purpose of the below code is to update a column based on the name of the field name sent from the .NET code. This allows one piece of code to handle multiple rows when a user is only adding/updating one at a time.
I have been using Stored Procedures for a while but normally just Add/Update b...
While Stack Overflow questions often contain segments of pseudocode or purposely abbreviated code in order to make the question more palatable to other readers, for something like a Code Review, the asker is generally going to have to post their actual code that composes a given system (otherwise...
Obviously related to this, but I want to know the opposite. How short is too short? For example this doesn't seem long enough to be appropriate for a code review:
Highlight input if empty
The entire code sample:
/* highlight input, if it is empty */
$(function() {
var highlight_if_no_val=f...
I wouldn't call that spam myself, but it does very well fit the definition of spam on SE...
But there still is some relevancy, if I were to consider something spam perosnally, I'd expect no relevance (like an ad about socks as an answer on SE)
@skiwi That's one of the problems with working in Scala. The language has some complexities that still confound the syntax checking of even the best IDEs.
@konijn What makes this spam vs. being a link-only answer? (spam and Non-an-answer have very different rsponses in SE land...).
Spam flags are a sledge-hammer... and in this case, (personally, not as a mod), I am not sure it warrants that flag, I am interested in what motivated your distinction.
When flagging, there are two special case options: spam and offensive.
What is spam, and when should I flag content as such?
What is considered offensive content?
How does the spam flag differ from the offensive flag?
What is the effect of these special flags?
Is there any way to remove these f...
@rolfl The OP did not ask for a link to an alternative approach ( unsolicited message ),I will agree the spam is on topic and not for Viagra, but it's still unsolicited
@konijn "Furthermore, the user has 1 Rep, so not loosing anything" is a weak argument, are you suggesting a user with more rep could post spam and it's OK? As for the unsolicited ... just by asking, I think the OP did ask for alternatives....
Those of you that weren't following what's going on in the chat room might have been taken by surprise by a recent avalanche of Rock Paper Scissors Lizard Spock posts.
This is how it started:
OK, weekend challenge.... we all solve the Rock Paper Scissors Lizzard Spock problem with our 'favou...
I have the following C++ wrapper class (that wraps a C library) that will be called from C#:
extern "C" {
__declspec(dllexport) BSTR GroupInit(const char* szIniFile, bool bDiagErr, bool bProcErr);
__declspec(dllexport) void Terminate();
/* ... */.
} // end extern "C"
BSTR GroupInit(con...
@konijn - this is just a general to @all that spam and offensive have a different 'priority' in the mod world, and should be used when appropriate. This one was fuzzy, no problem, but, when in doubt ....
Seems like a bad example,
I find that some of the shortest code samples contain large amounts of wrong.
There is no point in creating an anonymous function here, do function highlight_if_no_val()
In fact, use lowerCamelCase; highlight_if_no_val -> highlightIfNoVal
In fact, would highlightEmpty...
Every once in a blue moon, a question gets posted (often as a new user's first post) where the OP is asking a quite specific question about very minimalistic code, for example:
if (strstr($url, "?")) {
$url = strstr($url, "?", true);
}
There is something to say about this code, of course....
This is a form generator I created so users can input a URL, description and link. The output will eventually be a javascript news slider. The HTML the form generated is irrelevant for now but I'd like to see how I can improve the javascript code handing the processing.
This is my first version...
This is a form generator I created so users can input a URL, description and link. The output will eventually be a JavaScript news slider. The HTML the form generated is irrelevant for now but I'd like to see how I can improve the JavaScript code handing the processing.
This is my first version...
ListOfString = null; is useless, fields get initialized to default(T) which is null for reference types. So you can drop the constructor.
For simple initializations you can use inline initializers. e.g.
private string ListOfString = "";
You're hiding ToString() instead of overriding it.
You'r...
@200_success no problem - there's a nice answer on StackOverflow about this. ToString is a member of System.Object, by overriding the method you provide an alternate implementation to that method; by hiding it, calling ToString on a downcasted instance of the type will not produce the expected results.
like, var a = ((object)myClass).ToString(); will call the implementation of ToString that's in myClass if it's overridden, but will call the base System.Object.ToString() implementation if myClass.ToString is only hiding the method.
If the hiding is intentional, it's good practice to use the new keyword so as to make it clear (that will remove a compiler warning about the method being hidden) - so the signature becomes public new string ToString().
I've borrowed and written the following code to output the disconnect time. All works well but I'm curious as to how I could tighten/ shorten the code. If anyone feels like having some fun then I'd love to see what can be done. Be a learning lesson for me.
Output:
ftp> !:--- FTP commands below ...
I have a string variable that holds text loaded from database.
When program loads, I should find the node in treeview control with matching label text and select it.
I have found several solutions on StackOveflow, and one elsewhere, thus I am interested in the most efficient one.
If anyone c...
I'm trying to pass a basic cookie over. The code is below and the data stored in it is not private and useless to anyone who accesses it but can anyone take a peek over the code and let me know if it is subject to any security exploit? Still new to JavaScript but I don't think the below can be ex...
Task-based Asynchronous Pattern (MSDN)
public async Task<IProblemSolution> Search(CancellationTokenSource cts)
As I explain in this answer, one would rightfully expect the signature of that method to read like this:
public async Task<IProblemSolution> SearchAsync(CancellationTokenSource cts...
@rolfl The fun thing about your CLListIterator is that it can access items on an index in constant time, with a linked list that's not possible :( I need to always have a next and previous element (if present) present.
I'm running Windows 7 French and I'm trying to compile this really basic program, but Visual Studio is being stubborn and refuses to comply. I also tried compiling it with both GCC 4.7 and Clang trunk on Coliru and I get more or less the same errors (output is below the code), though I think Coli...
So baisically, this is my code which recieves file to read and converts binary values to ASCII text.
The code works fine, my question is though, is there a way to do this same thing without string buffer?
Help would be very appreciated.
import java.io.File;
import java.util.Scanner;
/**
*
* @...
@200_success that's painful. I only use a fr-CA computer if I'm forced to - re-learning all keyboard shortcuts is a PITA, especially in Visual Studio (not to mention everything that breaks if you have Excel macros that write formulae in cells)
I'll never get used to see "Générer" in place of "Build"
First you specify the type `<E>`, then the return type `void` (here), because it is logical to first define the type before you can return it, as in: `private <E> E takeList(List<E> list);` - Doing it the other way around would make no sense!
It can get interesting if you're extending a bunch of different classes. Only one of them can be an actual class, of course, but you can extend as many traits as you want.
So baisically, this is my code which recieves file to read and converts binary values to ASCII text.
The code works fine, my question is though, is there a way to do this same thing without string buffer?
Help would be very appreciated.
import java.io.File;
import java.util.Scanner;
/**
*
* @...
Is her program correct? It looks like she's grabbing eight BYTES and then converting it into an integer and then into a character. In her description, it says she wants to get ASCII characters from a binary files. Doesn't Java have a getchar() or read() or something like that?
Aside from turning StringBuffer into StringBuilder, there are a few more things I'd like to note about your code.
Compound assignment operator
This line:
lastString = lastString + line;
Can be rewritten as this one:
lastString += line;
It's short and it complies with what many people wo...
Consider the following code which uses the ability to intersect types, which was added in Java 8:
private <E, T extends List<E> & RandomAccess> void takeList(T list) {
}
private void fakingRandomAccess() {
List<Integer> linkedList = new LinkedList<>();
takeList((List<Integer> & RandomA...
@200_success I know that should be an answer but I don't want to make one since you were already saying what I would have said (except for the suggestion I made)
@skiwi it takes 5 downvotes to counter a single upvote, modz will probably tell you do not worry about it; if it's really abusive serial downvoting, it will get reversed in about 5 hours and 20 minutes ;)
whitespace is something that is typically fixed by any good IDE, its not something to base an answer on... it isn't relavant to the code, the code is identical... that being said, if you don't want me to fix op whitespace, I will make it an answer
@BenVlodgi Whitespace is absolutely reviewable, even in languages where it is not syntactically significant. You just earned 20 points for that answer. That said, please avoid starting any flame wars about brace styles and indentation widths.
In addition to indentation, spaces between words is important too.
I was asked to create a test APK file by a company HR when I applied for a an Android developers job,
Specification: "The goal is to develop a simple application which finds the local restaurants. The application will contain 2 screens:
A list of nearby restaurants within 1 mile radius
A map th...
The following is some code I just wrote. I keep wondering as always what I can do to make this more efficient. Please help me make this code object oriented and if anyone could help me write automated or even non automated tests for my widget...
Also is this considered a closure? I don't think...
I'm on chapter 7 of Chris Pine's book, trying to work on the last exercise in that chapter. This code works fine, but I'm wondering if there is a better way to do this...
toc_array = ['Table of Contents', 'Chapter 1: Numbers', 'page 1', 'Chapter 2: Letters', 'page 72', 'Chapter 3: Variables...
I would like to test reliability of system flock in a multi-threaded and concurrent environment as some suggest that they are not reliable (in comments).
Thus I wrote this code which requests non-blocking exclusive lock, with multiple threads at the same time (well, almost same time).
Is there...
I've currently got a MSSQL stored procedure that uses multiple SQL functions to achieve a number of returns. Now I've been told about using sets rather than functions as it creates " bad code smell of a DBA who is not yet thinking in sets" Original Link
I'd like to better my code and love to kno...