if (x >= 0) {
return true;
}
return false;
if (x <= 0) {
return true;
}
return false;
if (matcher.find()) {
return true;
}
return false;
Are constructs I'd express as
return x >= 0;
and
return x <= 0;
and
return matcher.find...
and the remaining java 0 answers not closed questions are...
design, unknown library, something I should answer, design, design, design, design, asked 2 days ago and asked 2 days ago
A while ago I designed an IO library that tries to bridge the gap between sync & async I/O. The initial impetus was that I wanted to design some utilities that could work both with async and sync I/O and any type of content (bytes, chars,...).
However the nio design of Buffer/Channel falls a bit...
I needed to add a logger into my flow based on FluentIterable from the Guava library. I have a lot of functions and in some cases I would like to add logging when in other cases (for the same function) I would not.
Of course the natural solution for this problem is to use the decorator pattern,...
I'm implementing classes for simulating and generating different kind of automata. I'd prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc.
For a PDA a transition from one state to another work require some sort of an extension, because the transition req...
I have the following API code (unchangeable):
interface IMessage {};
interface IMessageHandler<REQ extends IMessage, ANS extends IMessage> {
public ANS onMessage(REQ message, MessageContext ctx);
};
public class Registry {
public static <REQ extends IMessage, ANS extends IMessage> regi...
In one of my recent projects I faced the problem of transforming an abstract class into another abstract class. The classes were structured like this and are part of an api for questionnaires:
abstract class AnswerConstraint { /* shared implementation for all entities */ }
class LengthConstrain...
@JeroenVannevel Each rule has to be figured out inside this same method, and they do it in order, so for each rule there is accessing a different part of an XML file to see if certain information exists, so when one of these goes to set a rule to true, I just return instead. eventually I will turn each one into a method that is called from this method. like I said it's ugly spaghetti
/**
* Retrieves the XML schema definition using an XSD.
*
* @param node The document (or child node) to traverse seeking processing
* instruction nodes.
* @return null if no XSD is present in the XML document.
* @throws IOException Never thrown (uses StringReader).
*/
pri...
I am using json parsing for my login page but i get full String same as printed in Json file and not able to get the exact value when user enter valid Username and Password.
Java 7 comes with multi-catch: You can catch multiple exceptions with the same code block.
By using it, you can change
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
/* (non-Javadoc)
...
This question appears to be off-topic because it is about seeking opinions on the design and concept, not the code doing the implementation: In conclusion the question is: is this library a good idea? — rolfl ♦13 secs ago
It has been said in various comments that on Code Review we review code and not design.
I find this statement not very clear though. Obviously, if someone has an UML and not any written code, that's off-topic on Code Review.
However, if there is a question with a finished implementation, such a...
I was wondering if, as part of asking for a review here, can I ask about how useful my code is? That is, getting feedback about what possible use-cases the code I have written has and if people would use it if it were a library.
I would not intend on asking only about the usefulness but of cours...
Wells, for the nth time... Good IO library design
Copying my comment in verbatim, with extra emphasis:
Wells this is the really really grey area hmms? I took a quick glance at the GitHub project, quite interesting... Obviously the whole project will be too big to be reviewed here (and beside...
The first thing you can do is to store the intermediate objects in variables,
in order to get rid of the repeated and deeply nested objectForKey: chains
like
NSArray *keys4 = [[[[plistDictionary objectForKey:key] objectForKey:key2] objectForKey:key3] allKeys];
Then it would look like this:
NS...
The concept seems fine to me. The problem is that you will still need to decide whether to decorate, or not decorate the function, and that is done outside the function. That makes it a once-per-create decision, which is OK, but you may still end up with a lot of conditions in your code:
Functio...
@Pimgd I found an HTML question once where someone said there was nothing wrong, I VTD'd his answer and answered the question, I don't remember what question it was though
Not having seen a given pattern usually means that you didn't use exactly the right search string, or you've modified a pattern that already exists enough so it looks different, so I wouldn't worry about finding solutions that you haven't seen before.
Having a class handling input is the way tha...
Does that come under the heading of review my code or review my design?
I am working on my first HTML5/CSS web site and, like all of my first-time projects, they end up cumbersome, crude, and hard to work with when changes need to be made later in the life cycle. I am attaching some code with a small amount of HTML and CSS. I have read up on CSS and HTML and, after q...
I've answered the question, but I realised after that It wasn't so much the code that I was reviewing, and I can't tell if that's me doing a bad review or OP asking an off topic question.
Not having seen a given pattern usually means that you didn't use exactly the right search string, or you've modified a pattern that already exists enough so it looks different, so I wouldn't worry about finding solutions that you haven't seen before.
Having a class handling input is the way tha...
Also, what's the general consensus on semi-answering zombies? So where you don't know enough to write a full answer, but enough to suggest some improvements.
In your hash function, you're doing x.size() in a loop, which will slow the function down quite a lot for a long string. Instead, store the size in a variable and compare to that
int hash(const string &x)
{
int y=0;
int xLength = x.size();
for (int i = 0; i < xLength; ++i){
y...
I can't find anything wrong with this.
Just ... nitpicks.
You name your variables in for each loops t.
for (T t : supplier.tasks()) {
taskQueue.add(t);
}
I think if you gave them a better name like task it would improve readability.
Your test code seems to be on ...
So, can anyone explain to me why in Microsoft WebApi they bothered tinkering with ModelBinding? In what way is a MediaTypeFormatter better than a ModelBinder?
Good afternoon, I started to code on Android, but I think my code is very heavy and may slow down the performance of my app.
For example, when I run my app and I try to drag the page in one of my webviews, it's pretty laggy.
Here is the code (without the imports ^^) :
package com...
I have the following API code (unchangeable):
interface IMessage {};
interface IMessageHandler<REQ extends IMessage, ANS extends IMessage> {
public ANS onMessage(REQ message, MessageContext ctx);
};
public class Registry {
public static <REQ extends IMessage, ANS extends IMessage> regi...
@Vogel612 Mostly how to use the new features, with some real examples. I learned that I will not work with Java 8 since we are still developing in Java 6.
I still used mostly Java 7 doc, since for most part it does not change from Java 6 -> Java 7 except for new stuff (since they're new) and some changes in the implementation (but normally I'm good at spotting them)
I have two classes, Node2D and Node3D:
class Node3D(object):
@property
def coords(self):
return self.__dict__
@coords.setter
def coords(self,Coords):
self.set_coords(**Coords)
@Validator(ValidateKeys, 'x','y','z')
def set_coords(self,**Coords):
pa...
I code Haskell as a hobbyist. I'm interested in feedback on my naive implementation of Conway's Game of Life. Specifically, as stated in the Quick Tour of the website, I am interested in:
Best practices and design pattern usage
Correctness in unanticipated cases
Admitting the naivete of the i...
We have a lot of weird questions come up in chat and fun comments about how we destroy worlds over a lunch break. Here is one that though I might share. You are a power that can affect cosmic bodies and phenomena. You have been offended mightily by some questions on SE and wish to blow up their s...
I'm reading up about ASP.NET but I have a problem because VisualStudio is not available on Mac OS X and I don't have easy access to a Windows computer... Has anyone used MonoDevelop as an IDE?
I don't know how Mono is for Web Development, I never got into it that deep, I still have Xamarin on my machine at home but I am impatient so I downloaded VS2013 Express
I'm trying to run a python script I've downloaded from the internet. It's meant to be a demo visualizing some properties of an image dataset and get this error:
Traceback (most recent call last):
File "pycocotools_demo.py", line 8, in ?
from pycocotools.coco import COCO
File "coco.py", l...
I use a little IDE-like program designed for web dev called Brackets which can do PHP, JS, CSS and all that in one place, I don't think it does ASP.NET though
I need to start developing a website for a personal project and I'm just trying to see what options are out there. It needs to connect to a RDBMS so PHP was my first thought (lol?)
I posted a question on code review (about a syntax error in a python for loop) and it got closed and then deleted in the time span of a minute without me having any sort of feedback on what was wrong with the question.
I believe there should be a better way of handling questions that are believe...
@Matteo quick question... did you even read the link provided in the close-reason banner that's hanging direcly above the deletion notice? Did you read the tour, did you read the help center? Your question is (pardon my french) **** for the purposes of codereview. — Vogel6121 min ago
I'm wondering if my design is flawed or if I'm thinking this incorrectly:
I have a class Lexer that has a number of methods. All methods are regex processing methods that take a string as an argument (sometimes the same string), and all return a list of matches (list could be empty)
I need the ...
@Marc-Andre He mentioned using threads for front-end and back-end. A lot of the general stuff wasn't new to me since it was covered in my parallel programming class.
@JeroenVannevel Well, I am just having a hard time understanding how / when to use ModelBinding vs a MediaTypeFilter. I am trying to accomplish something that was very useful in MVC, but seems to be difficult to set up in WebApi.
The others are different ways to accomplish similar things between the two technologies.
I am trying to check a bunch of files that should have a leading | delimiter but sometimes don't. If the first line doesn't have the |, the rest of the file won't, if it does have it, then the rest of the file will.
So I'm checking the first line which works and enters the update logic, which ad...
I'm doing two jobs, In one of them I'm suppose to maintain 4000+ line Java classes while in the another one I'm suppose to convert 1000 line Perl code to multiple modules to make it follow conventions. Should I leave one job ? It's started to get to me.
I have a long list of SORTED strings in a Workbook, and I have to find a lot of values in it, I was hoping to build a binary search Class Module that will find them for me faster than Excel's builtin search formulas/methods. The code bellow is what I have so far can anyone think of a faster way, ...
I'm sure I will get some help, we have another guy (not sure if you've met him, GreyFox he gets on sometimes) that is learning JavaScript & CSS for the front end stuff, and I will be doing the backend mostly
Yeah Simon has a PostgreSQL installed on his server (we have not used the DB for the game yet, but I designed the schema)
Eventually the Java guys will setup JDBC so the game server can pass game data to the DB, and also retrieve things like player score and decks from the DB
This is a simple Trie data structure for strings, except it puts the strings into the structure backwards.
The insert method simply iterates over chars from the string-to-be-inserted backwards, and starting at the root of the graph, looks for an edge that is labeled with the current char. If ...
There are so many options for doing server-side stuff though, I was going to go for PHP since it is so common and there are tons and tons of resources. It's just a bit ... ugly.
@Phrancis The abundance of resources does not mean it's good! There are other options that could be fun to do for back end. But back end for you is like REST Api or deliver static page or something with a templating engine ?
My thought was basically this: - User supplies values via HTML form; - POST values get passed to a DB connector; - DB executes a function and passes it back to the connector; - Data is displayed
- Frontend: user requests page - Backend: controller returns page - Frontend: user inputs data in form and sends it - Backend: controller receives data - Backend: controller talks to database - Backend: controller returns page
I'm not too sure why that connector is so important in your scenario though - often you'll actually use the database for very little. You'll use an ORM tool like Entity-Framework or Hibernate to translate method calls to db queries
Here is my code: http://jsfiddle.net/de74ezo5/14/
So what I was trying to achieve here was to make the pink header collapse and stay fixed at the top of the page after scrolling past the top red header. I am using Transit with jQuery to create the transition (http://ricostacruz.com/jquery.transi...
@Phrancis I just adore the Microsoft stack, it's that easy. C# is an exquisite language, Visual Studio is by far the best editor and the combination of SQL Server, Azure, ASP.NET MVC/Web Api, Razor, etc all create an unparallelled ecosystem
while reading a data structure book, i have implemented chained hash table, i want to share the code with you and get you're opinion about it :
chained_hash_table.h
#ifndef CHAINED_HASH_TABLE_H_INCLUDED
#define CHAINED_HASH_TABLE_H_INCLUDED
#include <stdlib.h>
#include "../linked_list/linked_l...
In a previous question I posted a method for easy std::bitset IO on a bit-for-bit basis. This question was later followed up in another solution. Both of these solutions had limitations; the interface of my original solution was not pretty, and the second method was limited to 64 bit std::bitsets...
Is 4 lines of relevant code worth a review request? Basically I just want to know whether I am taking the right approach in injecting a header in my web api unit tests
Maintenance is an issue for performance, because if you can't read your code efficiently than you have a decrease in developer performance, or worse more bugs because something was read wrong. — Malachi6 hours ago
I would like to find all binary sequences from the specified range, which has low peak sidelobe level of its autocorrelation function.
Here is solution (this is simplified version of the real code) using GCC Inline Assembly with AT&T syntax. Binary sequences are represented as sequence of bits i...
I'm working on a project for Large-Scale Text Processing, and the code at the link bellow, is a first implementation of the basic idea of CSMR. CSMR is an algorithm that measures the similarity between documents by calculating their cosine in the vector space in parallel manner, using MapReduce m...
I've started learning Mithril framework, it looks pretty awesome;
I've created a basic blog app and have a few questions about code style and structure...
please, review this code:
var app = {};
app.PostList = function(list) {
return m.prop(list || []);
};
app.vm = {};
app.Post = function(d...
@KonradViltersten With the current implementation of Dictionary, I belive that requires removing items from the dictionary. But saying "I don't remove anything, so I should be fine" is relying on undocumented implementation details, and you shouldn't do that. — svickyesterday
I'm writing a basic LL(1) parser in java, but my parser class is quickly getting out of hand and becoming huge. PMD even calls it a "God class" and says that it has "Too many methods." Is there a way that I can refactor this class?
public class Parser {
private static final APValueNum NEGATI...
(Note: Even if you don't know Django, it's probably the query that needs work anyway, so you probably don't need to know Django/Python)
I have a ListView that displays all the entries in a mapping table between the pizza table and the topping table. Unfortunately, I can't just use Django's helpf...
public static void main(String[] args)
{
textbox();
}
public static void textbox()
{
String c;
int width,height;
char character;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the text to center: ");
c=sc.nextLine();
System.out.println("Enter t...
as far as I know, there are still people on that winning streak... but, it's a bit of a cheat, because they were members before the system was started to count these things.
I asked one question on code review yesterday about my code style, logic and readability of code. Hence, today I kept all those suggestions in mind while solving a new problem question.
The question is such: Given an array S of n integers, find three integers in S such that the sum is closest to...
Following up on Integrating Unit Testing functionality into an old COM-based IDE, I made quite a few changes to the UI, and now the code-behind for my TestExplorerWindow is starting to feel somewhat bloated, at least compared to what it was... I blame the added toolbar and the fancypants progress...
I want my entire node application to use one single mongodb connection, at least that's what I think is better. I wrote this little script and want some feedback on it. Especially if what I'm doing makes sense.
This is my mongodb.js file
'use strict';
// Mongodb module.
var MongoClient = r...