Side note: it seems that a template<typename Container> sort(Container& container); should exist in the standard library. I suppose those much much wiser than I though think differently.
Yeah... And a few things that would be nice to have are missing.
http://crystalcleanhomes.com/slide/
There are countless scripts that perform this simple slide-out navigation menu but they are all so bloated and the styles are so convoluted that I decided to make my own and it seems almost too simple and too basic so I've come here for criticism. From my test...
http://crystalcleanhomes.com/slide/
There are countless scripts that perform this simple slide-out navigation menu but they are all so bloated and the styles are so convoluted that I decided to make my own and it seems almost too simple and too basic so I've come here for criticism. From my test...
Rather than having the user pass in name and quantity, have the user pass in a Grocery. You complete throw away any sense of encapsulation by having the user provide the components rather than the object.
Rather than displayGroceries, I would overload operator>> for ostreams.
Give Grocery a...
Hah. Especially in C++. There's a particular interesting talk (if you're into cache-y type things) by Stroustrup where he compares a vector to a list and basically concludes that lists suck even when logically/algorithmically a list is what you think you need.
yeah, I haven't seen it, but I can guess some of what he talks about
removes any opportunity for SIMD, has to jump around the heap so loses any kind of locality of reference...probably a lot of extra stuff I don't know about as well :)
@Corbin Do keep in mind that this is still a toy program. :-) I'm going with the "Not Another Linked List" for April Fool's that Jerry Coffin already started.
@Jamal Yeah, I thought about prefixing my post with a note about how I knew you probably knew a lot of what I was going to say. I tend to review all programs as if they were real programs though. Otherwise, everything really comes down to "tl;dr: it doesn't matter in a one off, toy program." :D
I might post my list, but it's a bit less toy-ish and more... massive. It's only about 75% finished and I'm afraid it's already probably too long for CR. github.com/nibroc/containerpp/tree/dev. I will likely post it at some point after I go through and refactor it heavily. I've never posted anything before, and I'm a bit curious what bad habits/design pitfalls/etc I have.
@Yuushi Hrmm, perhaps when I get a chance in a few days, I'll clean it up and post it.
@Jamal well, ideally an container should have no idea (nor care) what it's storing, so it would be completely separate from the container. In this case though, since the list is special purpose, that doesn't really apply. I would have the list keep using Grocery (rather than going the templated route), and just pull Grocery out into its own header (e.g. Grocery.h) and maybe implementation file if you give it methods.
It just feels icky to use a string/number pair since it's both vague and prone to break when changes are made (Like what if you wanted to add a cost field to Grocery? Then you would have to update all of your methods).
I'm looking for a more cleaner and simpler solution to auto-format a text-box field intended only for the user to enter their college Grade Point Average (GPA). Here is my code:
<label for="collegeGPA">GPA:</label>
<input type="text" name="collegeGPA" id="collegeGPA" maxlength="4" style="width:4...
Here is another example of a moving ball I would like to see how to make a more efficient and better Javascript program. I think that moving the variables to the top of the function would be better but then I tried this and it would not work as good as it did.
Question: How to make the Javascrip...
I think the day the average upper management no longer sees code quality, peer reviews, refactorings, readability, extensibility and all of SOLID as something that costs more and delays delivery, but rather as something that reduces total costs and only adds positiveness in every single possible aspect of a project, that day, ...pigs will fly.
I don't see how maintaining code could be diminishing overall.
But I'm slightly biased. I work with legacy VB6 crap code
well of course if you're talking about overall maintenance in specific languages or technologies, ...thing is, maintenance doesn't diminish overall - the only thing that changes is the language of the code being maintained..
if anything that demand will (hopefully) increase over time; more time, more programmers; more programmers, more code; the more code there is, the more there's code to maintain - the more jobs we have ;)
Inspired by all of the lovely linked lists lately, I decided to implement one in assembly language. This code maintains two linked lists - one is a free store and the other is the active linked list. Rather than allocating memory whenever a new node is needed, the Node is pulled from the free l...
@Sham I think that's specific to how each company runs their stuff.. you can find a job where you land in a team of 3 devs that each work in their own "silos", or you can land in a team of 3 devs that work as a team, and have a team lead that reports to some IT director. The maintenance team is often the dev team and the test team.
I wrote a stack implementation using a singly linked list in x86_64 assembly. This stack supports the usual push/pop operations as well as first/next for iterating over each element.
I'm looking for general feedback.
Here are the stack subroutines.
; Stack Structure
; Pointer Head
; Pointe...
@Corbin: I have made some massive changes to the code, including removing some member functions. I've probably rushed my implementation a bit, and you have pointed out some of the biggest things, so I may accept your answer soon.
...unless @JerryCoffin has something else to add. ;-)
@Jamal I apparently forgot it too. What do you mean about removing them in C++11? If there's some kind of resource management going on, they're still very much required (and it becomes the rule of 4 or 5 in some circumstances if moving is involved).
You need to consider the Rule of Three.
That is: the default copy and assignment implementations will not handle the head as you'd like. You need to define them correctly, or hide them (or remove them in C++ 11).
For example:
class LinkedGroceryList
{
private:
LinkedGroceryList(const Linke...
Given ( and ) and length of 4, generate the following combinations -
()() and (()).
Looking for code review, optimizations and best practices. Also verifying complexity to be O(2(n+1) - 1), where n is half the 'input length'.
public final class BraceCombinations {
private BraceCombin...
@Jamal I don't think he meant remove them as in "or you can just not have them." I think he meant it in the sense of "if you want to disable copying and assigning, you can T(const T& t) = delete; them." You do either need to implement them or delete them though.
I just wrote this pool to avoid calling malloc and free when I have some code that frequently allocates and deallocates chunks of same-sized memory. I would like to know if there are any bugs I didn't notice and what would be the best solution to achieve this goal.
I'm using some small functions...
I need to delete a file when an error occurs during loading it.
In other words:
Happy path:
Load a file
Move on
Unhappy path:
Load a file, exception is thrown
Delete the file
Move on
Exceptional path:
Load a file, exception is thrown
Delete the file, exception is thrown
Handle exc...
just realized the "Body" part/section of my answer contradicted the approach I researched just after writing that part. wow. removed, and TTGTB! 'night @all!
It looks like I'm able to assign unique pointers with std::move, but I'm not sure how to successfully assign tail->next to a unique pointer (tail being of the same type).
@Jamal That creates a circular list--but with a unique_ptr, you really don't want to do that. You probably want to set the tail to nullptr to indicate the end of the list.
I want to develope a module from scratch for activation and licensing of my product.The architecture needs to be generic so that it can be used for any product to activate and license.Also the module will require to communicate with my server to get license information for a product periodically,...
I want to develope a module from scratch for activation and licensing of my product.The architecture needs to be generic so that it can be used for any product to activate and license.Also the module will require to communicate with my server to get license information for a product periodically,...
@Jamal If you're inserting before some existing item in the list, you'll move the pointer to that existing item into your new items' next pointer. If you're adding to the end of the list, its next pointer will be a nullptr.
Keep in mind that unique_ptr's are unique. They own the underlying object. tail is (apparently) intended to refer to the last item in your list. If so, it can't be a unique_ptr (that would imply its owning the last item in the list, which is already owned by the unique_ptr in the previous node). As such, tail should be a normal pointer, and should just point to the last item in the list. When you insert into an empty list, both head and tail will refer to the one node in the list.
When you add more nodes, head will still refer to the first, and tail to the last.
No--a unique_ptr is specifically intended to own the item...uniquely. Something like tail is just supposed to see the item rather than owning it, so unique_ptr doesn't fit.
Now I'm in the remove function. For the first case in which the single node is to be removed, would I just release the pointer and set head to nullprt? I know I no longer use delete here.
If memory serves, I'd done deleting by swapping to a local variable (that goes out of scope and deletes the item). So, to delete the first item in the list, you point your local variable to the second node in the list, then swap it with the head of the list. That gives the head of the list ownership of the remainder, and it ownership of the first element. Then when the function exits, it automatically deletes that first element.
For something other than the head of the list, you're swapping with the pointer in the previous node that points to the node you want to delete.
I wonder if there are some possible ways to simplify my code.
startDate = '04/02/2014'
endDate = '04/06/2014'
mondayTag = 0
tuesdayTag = 0
wednesdayTag = 1
thursdayTag = 0
fridayTag = 1
saturdayTag = 0
sundayTag = 0
public int GetRemainingDays(DateTime startDate, DateTime endDate, bool monday...
It was suggested to me that I should post this Stack Overflow post over here.
Here is the code as it stands right now:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
from random import randint
arraySize = 50
Z = np.array([[randint(0, 1) for x in range(...
somebody had asked same type of question on stakeoverflow.com and than he was suggested by some expert that he needs to ask such question on codereview.stackexchange.com. So I asked this question here . May I know what is wrong in it ? — KRC47 mins ago
Whomever said that this kind of question belongs here is absolutely wrong. If the question contains no code, it's automatically off-topic. We cannot review code that doesn't exist. — Jamal ♦1 min ago
Writing a MMORPG server in nodejs, I have to handle packets. These packets have a structure of
<length> <id> <data>
So what I did was use a node package called packet
And first get the packet id:
client.on('data', function(data) {
parser.extract("l16 => length, l16 => id", function (packe...
I use to compute primes using linear code which took a long time. As I've an 8 cores processor I thought about multi-threading.
At first I use to put a huge number of int in a vector then share the vector between the threads which takeout each number which is not a prime. The first thread proce...
I use to compute primes using linear code which took a long time. As I've an 8 cores processor I thought about multi-threading.
At first I use to put a huge number of int in a vector then share the vector between the threads which takeout each number which is not a prime. The first thread proce...
I was asked to answer the following question before setting up a phone interview, but they said my code wasn't detailed enough.
Question :
Without using any of the .NET Collection or Linq libraries (i.e. without using List), implement a ListOfStrings object that contains a set of strings. This o...
I am using X2JS for converting XML file into JSON Object. Some XML Tags contains HTML Tags inside it.
<xmltag>I am the data <strong>available</strong> for sale now</xmltag>
Now I dont want the html tag "strong" to get converted into a JSON Object. When I use the variable "JsonObj.xmltag" it s...
xkcd, sometimes stylized as XKCD, is a webcomic created by Randall Munroe. The comic's tagline describes it as "a webcomic of romance, sarcasm, math, and language." Munroe mentions on the comic's website that the name of the comic is not an acronym but "just a word with no phonetic pronunciation".
The subject matter of the comic varies from statements on life and love to mathematical and scientific in-jokes. Some strips feature simple humor or pop-culture references. Although it has a cast of stick figures,
the comic occasionally features landscapes, intricate mathematical patterns su...
I implemented K-Nearest Neighbours algorithm, but my experience using matlab is very few. I need you to check the small portion of code and tell me what can be improved or modified ? and hope it is a correct implementation of the algorithm ?
function test_data = knn(test_data, tr_data,k)
numof...
import java.util.ArrayList;
public class LargestPalindrome {
//Write a java program to find the biggest palindrome of the string entered by the user.
//Ex:: User input is ABABABAAAB
//This string has following palindromes, ABA, BAB, BAAAB
//Our program should return the biggest string of these ...
How can I elegantly serialize a lambda?
For example, the code below (expectedly) throws a NotSerializableException. How can I fix it without creating a SerializableRunnable "dummy" interface?
public static void main(String[] args) throws Exception {
File file = Files.createTempFile("lambda"...
But haven't had time at the moment, working on android app for university project
It is an app that has something to do with walking form one point ot another and being on time, got the current speed, etc. distance covered and eta working :D
@Vogel612 I actually agree that it's not very clear, it should be a line between them. Right now it's a bit hard to know if the folks in the bottom-right are visitors or room owners.
I wanted to see who the owners were of a certain chat room today, and here's what I saw:
My first thought was, did I somehow become a room owner without knowing it? Upon more careful consideration, I realized that there are actually 2 columns of users, the left two are room owners, the right t...
I just read the Lib/argparse.py code (class FileType) on http://hg.python.org/cpython/file/default/Lib/argparse.py. File objects are opened without the with statement. For safe file opening/closing, should I instead encapsulate my argparse.ArgumentParser() in a contextlib stack like below? I feel...
I'm coding a little class hierarchy printing tool for easy show hierarchies of java classes.
This is my current code:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
i...
Type safety: Unchecked cast from Serializable & Indexer<Fight<TTAI,TTController>> to Serializable & Indexer<Fight<TTAI,TTController>> - How on earth can that be unchecked?
I'm a beginner and I only know limited amounts such as IF, While, Do While. So I'm here to check if I'm coding with best practise and the most effective methods to my current knowledge. Any feedback really is greatly appreciated! :)
import java.util.Scanner;
public class SixtyTwo {
public...
You have waaaay too many sums you are checking. KISS --> Keep it Simple Stupid:
private boolean checkSudokuStatus(int[][] grid) {
for (int columnIterator = 0; columnIterator < 9; columnIterator++) {
int[] row = new int[9];
int[] square = new int[9];
int[] column = gr...
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...
You can greatly reduce the complexity of your code, by using the ternary operator:
while (n != 1){
counter++;
stepsTaken++;
n = (n % 2 == 0) ? n / 2 : n * 3 + n;
System.out.print(n);
//Your largest number and the linebreaks go here;
}
Just to see how it worked, looked at the g++ implementation of the structure std::common_type in the header type_traits and I must admit that I can't get how it really works. Here it is:
/// common_type
template<typename... _Tp>
struct common_type;
template<typename _Tp>
struct common_...
@Vogel612 That's because GURUs only know about good practices.
When you avoid bad practices, you don't know how they work :o
Sometimes, people ask me "why doesn't my C++ code work", and I can only answer "I've no fucking idea, but if you rewrite it like that, it'll surely work".
There are actually two errors in this statement.
isTrue ? System.out.println("true"): System.out.println("false");
As @Slaks points out, the ternary '?' operator requires that the second and third operand expressions have a non-void type. That explains the message
"Type mismatch: cannot ...
Here is another example of a moving ball. I would like to see how to make it more efficient and better. I think that moving the variables to the top of the function would be better but then I tried this and it would not work as good as it did.
<!doctype html>
<html lang="en">
<head>
<meta chars...
2-player card fighting game
This is not about playing cards as in "Hearts, Diamonds, Clubs and Spades".
This is a game where 2-players (or more if you are really enthusiastic) can play/use cards or spells to do some effect against themselves or their opponent(s).
Minimum requirement:
Two pla...
@Edward - people are not the same without bobbleheads
I needed a script for working out billing dates over a period of time, the date should be the same day every month however if the billing date starts on a date that doesn't exist in another monhth, then it should be on the last day of that month. This rules out the DateTimeInterval Object, becaus...