« first day (450 days earlier)      last day (3564 days later) » 

1:00 PM
it was closed (think 200_succes closed it as third and migration was rejected)
 
I could spent years refactoring my code here...
There's always something that you can you can do differently.
 
I hadn't realized it was a recent migration.
I guess I'm not the only one playing with Project Euler since their answer checking came back up.
there was a Haskel question yesterday too.
 
@skiwi Context?
 
@rolfl In a programming language, when programming
It's a very cheap and easy feature to implement and greatly enhances performance
 
It does, but, it does not help with list.removeLast() which becomes O(n) (which it would have been before, but that's OK).
It's not a complete solution.
The classic comp-sci linked list has no pointer to the end.
 
1:13 PM
How not?
@rolfl That I agree, but I doubt concrete programming languages map 1:1 to that version
 
If you remove last element, you have to scan the full list to reset the last pointer
 
Hm you've got a point there
 
unless it is doubly-linked
 
Yeah
Though in real memory and performance constrained situations, is a singly-linked version preferred over a doubly-linked, to save a few bytes?
 
yes..... if you only need a subset of features.
 
1:15 PM
@skiwi doesn't that depend on the use-case??
if you're talking about things like a FIFO queue, then a singly linked list with a pointer to the last element would be preferrable right??
 
no.
 
but for a more Array-List-Like use-case then a doubly linked list is better?
 
It also depends on how many time you want to spend on unit testing, if you decide for a more complicated solution
 
0
Q: Better code development in Python

GuforuI'm new in Python and consequently I am searching to find some specific solution for code development. I already asked today some pythonic question and want to present my whole problem. Well, I have found some solution, but I really have interest to develop easier and clearer code in Python, so e...

 
Yes, and how much functionality/performance you lose.
I have a library of util-replacement classes that are about as fast as java.util, but, for large datasets, save about 60 bytes per member for Sets and maps
when your data is a primitive, it saves even more.
So, things like a Map<Integer,Double> would save.... 120 or so bytes per member.
 
1:20 PM
@rolfl how do you get 60 bytes per member out?
 
@ckuhn203 didn't saw it either the first time I looked at question
 
or asked better, where do you save them, without loosing functionality?
 
and, if you have 100,000,000 of them, it makes a huge difference.
@Vogel612 I do lose functionality, and that's the point.
 
where, if I may ask?
 
Morning!
 
1:21 PM
s/Morning!/Monking!/
 
check me out on Programmers, I almost have a "Good Answer"
9
A: Should Android development be done on Windows or OSX? Is there any difference?

MalachiLinux I think you would want to use a Linux based OS for Developing Android applications seeing as how Android is a Linux Based OS, it's open source, it's free, and can run on a partition next to windows, and I think Mac Os as well (don't quote me on that though). it's been a while since I ope...

 
HashMap has an internal 'Node' class which it creates an instance of, for each key.
 
@Malachi It should be done on Android.
 
@Vogel612 I am not sure about using "Monking" it seems a little derogatory to me
@skiwi lol
@skiwi Android Development on Android?
 
I don't need that, I save the keys in an array, and I have a 'smart' hashing table on cached hashCodes() (or a custom hash function).
 
1:23 PM
what do we call Santa on other sites?
 
The actual data is stored in an array as well. Arrays of primitive if they are primitive types.
 
@Malachi How so?
 
@rolfl Enjoy your improved performance vs base Java libraries until Project Valhalla is completed
 
@rolfl so in fact you the do the retrieval by searching the hashes for the index of the hash, and returning the corresponding index??
@Malachi Ho Ho Ho btw...
 
@Vogel612 everyone is always calling @rolfl a Monkey... he's not a monkey! He is a Human being, a very smart one too I imagine. :)
@Vogel612 thank you
in The Whiteboard, 8 secs ago, by Malachi
thank you Santa
 
1:25 PM
@Malachi - thanks for the rabid defense.... but, I am quite happy with monkey too.
@skiwi Well, since this code has been in production for 5 years .....
 
sorry I was wrong, it wasn't a "Good Answer"
> You've earned the "Nice Answer" badge (Answer score of 10 or more) for "Should Android development be done on Windows or OSX? Is there any difference?".
 
also, it is a multi-valued map, so, instead of doing things like:
Map<Integer,Container> mymap = new HashMap<>();
 
interesting question
0
Q: Why was the first compiler written before the first interpreter?

anguyenThe first compiler was written by Grace Hopper in 1952 while the Lisp interpreter was written in 1958 by John McCarthy. Writing a compiler seems like a much harder problem than an interpreter. If that is so, why was the first compiler written six-years before the first interpreter?

 
@skiwi Just because a newer technology is available, does not necessarily mean that a project manager is going to have his people rip out the existing technology and replace it.
2
 
@rolfl well then I don't feel so bad using the term "monking"... :)
 
1:27 PM
Where Container is a class with, say, 5 fields that are stored together, like a name, first name, age, etc.
 
@Donald.McLean It's not what I suggested though ;-)
 
@Donald.McLean I find they usually wait until they absolutely have to
 
you can instead add a 'data dimension' to the new map:
 
It's just that the performance should be on par, but that doesn't warrant investing time just to rewrite it and still have the same performance.
 
There are quite a few Scala libraries that have been released since I started working on my project. I might have used them if they had existed before but what I have works just fine.
 
1:29 PM
MyMap<Integer> mymap = new MyMap<>(Integer.class);
DataColumn<String> namecolumn = mymap.addDimension(String.class);
Doing that, I can store all the base values as simple arrays linked to the same key hashtable, and share one table between multiple maps, etc.
primitive values get stored as primitive arrays.
 
It sounds pretty sophisticated there
 
it is thread safe too.
 
0
Q: Is this approach correct when testing a controller?

Katana24I'd like someone to review these tests to make sure I'm along the right lines in Angular testing. Note - They do all pass (great) but I feel like I'm struggling to understand the finer points of Angular testing. var headerControllers = angular.module('header.controllers', []); headerControllers....

0
Q: How to optimize this Linq query?

RobertI am rewriting a VB.NET application in C#. I will nut subject you to the original code because its pretty messy. Below is the converted C# code: public IEnumerable<WebQuery> GetQueries(Request request) { var queries = new List<WebQuery>(); foreach (var report in request.Re...

 
I've found some code of mine that smells
 
and, in one case, (the main reason for the system), I tuned a tuple-based dataset from about 18GB in memory to less than 1GB in memory (it had lots of primitive values), and as a consequence, even though insert and get performance was slightly slower than before, the overall performance was....
about 50% faster because GC was significantly reduced.
and the data simply fit, and did not cause the app to fail.
 
1:32 PM
Nice
public static Path getSingleFileWithExtensionInDirectory(final Path directory, final Extension extension) {
    try {
        Objects.requireNonNull(directory);
        Objects.requireNonNull(extension);
        return Files.list(directory)
                .filter(FunctionUtils.pathEndsWith(extension))
                .collect(CollectorUtils.singleElementCollector());
    } catch (IOException | UncheckedIOException | NotASingleElementException ex) {
        ManualUtils.moveToManual(Config.REJECTED_DIRECTORY, directory);
 
anyone using a HashMap with more than say, 100,000 members, is running in to problems.
 
Smells like this method is doing multiple things at once?
@rolfl In most cases you should be using a database then though
But I'm very sure you know what you are doing
 
except when the task is to load large datasets and validate them as they are being loaded in to the database
 
is there a big noticeable difference between and besides a value difference of 88?
 
I must've been smoking something really bad when I designed that method.
 
1:37 PM
there is a c99 and a c11 I didn't edit either in because I don't know which one this is I was thinking that I just put in c99 because it sounds like that is the lowest one that would be possible given your comment on @vnp's answer — Malachi 4 mins ago
 
@Malachi I think they only added a whole bunch of std:: container class and 12 years worth of development
 
@skiwi sounds like c11 came after c99 and I thought that c99 was fairly new?
 
@Malachi Oh... it's the years they indicate there after the c
 
Plus some lag for implementation....
So, C99 is the 1999 specification, and C11 is the 2011 specification
you would think they would have solved the Y2K problem in the C specification already
4
next time I see Jerry I should remind him ;0
 
@rolfl You are smart, at least you were in my previous issue
Currently I'm storing a bunch of paths to different executables (tools) in Config.xxx static fields
So I don't need to pass them into every single method (issue looks familiar to one few days ago)
But you cannot use the classes now if you do not have the Config class on your classpath and populated
I don't have problems with that situation, but it still does not sound very flexible
 
1:44 PM
Monking!
 
Monking @Phrancis!
 
@skiwi you want to use a configuration-file with hardcoded defaults again instead??
 
@Vogel612 They are temporarily hard coded in the program, but on startup they are load from a configurable file
 
so what exactly is your problem?
just verify that the stuff is loaded.
 
Might scratch it as well, passable parameters are still better
 
1:49 PM
??
missing context
 
Context was probably that I was being lazy
2
and wanted to do things easier at expense of correctness
 
shame on you..
 
I have seen your problem solved in many ways. Your current way is relatively popular.
A single class with static methods that allow remote classes to obtain configuration data.
An interesting solution I have also seen was quite complicated, but effective....
 
@rolfl Only the informal name for the C11 revision did not solve the Y2K problem :p
The official one is ISO/IEC 9899:2011. Which is far too long to be remembered.
 
write your methods 'properly', so, a method that needs a single file would take a single file argument, which makes sense.
 
2:03 PM
0
Q: What is more elegant way to generate 100 emails names using some python libs/api?mine is bruteforce

ERJANCode below generates only 10 email domains. To me this is bruteforce programming it. Is there another random integer library? Could I use something like random.seed() in c++? import random domains = [ "hotmail.com", "gmail.com", "aol.com", "mail.com" , "mail.kz", "yahoo.com"] letters = ["a", "b"...

0
Q: Is there a better way, with less graph api calls to get all likes from a news wall?

Cornelius BütikoferRight now my way gathering likes from a user wall is making a recursive call on the "/me/posts" edge and going through each post... If someone knows a better, easier way with less graph api calls necessary, please let me know! Thanks a lot ! Cornelius /* * * Count my_user_id likes in wall of...

 
Then, write a wrapper which takes an interface with a supplier method for the file. So, if the file was 'sourceDataDirectory', you would have the method:
public myMethod(File sourceDataDirectory) {...}
then you would have the method:
public mySuppliedMethod(SourceDataDirectorySupplier supplier) {
    return myMethod(supplier.getSourceDataDirectory());
}
Finally, you would then create an interface for each data type/set/subset.
 
@rolfl isn't this counterintuitive?
 
Then, implement your configuration source to implement all of the interfaces... so, you could have just one place with all the config, but, each small place gets just a subset of it.
 
That sounds a bit convuluted
 
It is, and I don't recommend it.
But, it allows you to have your config developed independently of your code, and to have some other advantages in big projects.
 
2:06 PM
0
A: Once upon a time in Stackland

MalachiFrom reading the Post, it looks like 3 things need to happen (at the least) @konijn Bot needs to be reactivated to keep the JavaScript Zombies from overtaking Code Review again The Java People need to take some time to learn a couple of other languages C# Python < joking > find a way to hide...

 
5 mins ago, by rolfl
An interesting solution I have also seen was quite complicated, but effective....
When I do these things, I use the singleton pattern though (so shoot me).
and have the config in that.
That way I can access the config in a static-like way, or as an instance that is passed between methods:
 
You do make it configurable from a file though I hope?
 
File sourceData = Config.instance().getSourceDataFile();
or
public void myMethod(Config config) { .... }
 
anyone want to look through my C# answers and vote as necessary (or appropriate)
 
youch..
 
2:09 PM
yes, but, I work on code that has legacy components, etc.
 
I see,I have a similarish approach
 
@Malachi nope, my smoking material is not finished yet..
 
I also found out the hard way that it is good to hardcode some filenames as well
Path organizationFile = path.resolve("organization-invoice.ser");
 
0
Q: Multiple SQL statements in a single transaction

ChathurangaUsing the following query I'm doing transactions with two tables BEGIN TRANSACTION UPDATE SalaryTrans SET carried_forward_amount = @carriedForwardAmount, net_wage=@netWage, processed_date = @processedDate WHERE employee_id=@employeeID AND reference = @reference DELETE FROM CarriedForward WHERE ...

 
I forgot to update this name when I updated it on another place
 
2:10 PM
@skiwi Yes, often using Java properties, but also using databases, or XML, or default values when none present.
depending on the project.
 
And last week I've been wondering why it wouldn't process it, but fixing it wasn't on the schedule yet
 
@Vogel612 I was joking about activating @konijn lol
 
I am sure there are libraries that do that sort of thing, now.
 
Okay
 
time to do some more VB.Net Development... yay :(
 
2:13 PM
@Malachi when two thirds of your answer are a joke...
well you decide what to put after that. I'm not sure what I am supposed to think of the answer..
 
^^^ my thoughts too.
 
no body else answered....
 
@Malachi the excruciating suspense ;)
2
 
yeah, I know, and I was not sure what to answer myself, at the time.
 
just because it's unanswered, that doesn't mean that you should write a mostly-joke-answer
meta is different. It's okay if some questions remain unanswered.
 
2:17 PM
I'm not against the joke answer.
meta is for community building as well.
the question is tagged .
for a reason
but, I can't bring myself to upvoted it when I know that someone has somewhere got a brilliant piece of feedback.
3
(and I featured the post, everyone who looks at the community bulletin will see it)
 
if I get onto Code Review tonight I will have to write something a little more....meaningful and thought out. I am just trying to get into gear after a good weekend of riding! I almost hit 600 miles this weekend on my bike
 
Huh, my indention is both incorrect and correct, and it confuses me.
 
@Mat'sMug speaking of mugs, where is mine?!?!?!
I am beginning to wonder if they shipped it yet or not
 
Right, I am officially changing my mental-classification of @Malachi's icon, from 'ogre' to 'hog'.
3
 
actually it's azombie.
not that it makes much of a difference...
aside: someone know how this questionmark in a diamond is called
the thing that shows up when you borked on encoding?
 
2:25 PM
@rolfl Refresh
 
I did, and nothing changed .....
 
it must not copy over to everything right away
 
I cna do that for you ... hang on...
Done
Hmmm.
There. Now it is done.
 
�
 
exactly that one..
 
2:30 PM
I had to copy past from
Specials is the name of a short Unicode block allocated at the very end of the Basic Multilingual Plane, at U+FFF0–FFFF. Of these 16 codepoints, 5 are assigned as of Unicode 6.0: U+FFF9 interlinear annotation anchor, marks start of annotated text U+FFFA interlinear annotation separator, marks start of annotating text U+FFFB interlinear annotation terminator, marks end of annotating text U+FFFC  object replacement character, placeholder in the text for another unspecified object, for example in a compound document. U+FFFD � replacement character used to replace an unknown or unrepresentable...
 
Good find
 
Lolol
 
???
people are going to wonder who the new person in chat is now. I haven't changed my avatar in a long time....LOL
 
Just on the radio, instead of normally: "There are some issues on the railroads, <insert Dutch company here> deploys extra buses!"
It now sais
"There are some issues on the railroads, <insert Dutch company here> deploys extra boats!"
(And yes, the first attempt for this went horribly wrong)
 
Hmmm... just realized that my oh-so-smart 100 gunmen answer, is actually included in a Wikipedia link from another answer.... but, I worked out the math myself, so I don't feel bad.
5
 
2:44 PM
also it's a nice answer either way...
 
wait, what answer?
 
Hey there
 
Hey there
 
Hey there
 
Hey there
 
2:51 PM
Hey there
 
@Malachi so there's only 1 thing that needs to happen then? All Java reviewers should review other languages and we're good to go?
2
;)
 
@Mat'sMug there are so many of them, if they each answered a couple more other language questions I think it would help.
 
Well, since Java programs are normally so good, it make sense to apply our good practices to other languages too.
6
 
I am thinking of learning some Python as well
@rolfl I think you forgot your sarcastic tags around that comment
 
@rolfl I think it's the Java reviewers more than Java programs ;)
4
 
2:54 PM
BTW.normal my old avatar was made on a plants vs. zombies game, so it wasn't really an ogre
 
told you 't is is a zombie.
reminds me of the song by the cranberries..
cranberries are sweet and tasty
i somehow have the feeling that tasty does not mean what I think it means...
and I also somehow have the feeling that the "architechture" for the logging in our application is broken..
and following that train of thought: what the heck?
public static void doLogDebug(@Observes @LogDebug final String message) {
		FileHandler logWriter;
		try {
			logWriter = new FileHandler("CRMDebugLog.txt", true);
			logWriter.setFormatter(new SimpleFormatter());
			LOG.addHandler(logWriter);
			LOG.log(Level.FINE, message);
			logWriter.close();
		} catch (SecurityException e) {
			System.out.println("SecurityException: " + e.getMessage());
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("IOException: " + e.getMessage());
 
@Vogel612 Oh, my goodness.
 
@Phrancis ...hey there ;)
 
@rolfl don't worry it's just duplicated for levels "LogError" "LogWarning" and "LogInfo" again
 
3:01 PM
Well, be a hero and improve log performance!
 
we got an additional log-level "LogConsole" which is nothing but a disguised "sysout"
In fact I think we should just put it all in the same log, and add a small formatter, including a timestamp and a loglevel...
 
you are really opening, writing, and closing the file for each message?
 
not me...
but.... yea.
 
^^^ fix it ....
 
hehe...
hrmph...
I was actually just writing documentation for the whole project...
and in fact, should be doing something completely different yet again..
but hey, can't leave this mess to less experienced trainees, right?
 
3:04 PM
@Vogel612 - I recommend benchmarking before and after performance.
 
@rolfl well the good thing is... our whole project has about 3 log-calls..
 
When you can say to people: I did this fix, and, it saves 1 minute from a 30 minute process.... then it makes sense.
 
all introduced in my refactoring...
 
Ahhh....
 
the bad news is. well the same.
 
3:06 PM
So, you can say to them, I saved 1 millisecond from a 30 minute process .... ;-)
 
Alright, 125 rep to 2K, gotta find something to review or to ask... maybe I'll finish revising my schema in pg and post tonight...
 
@Mat'sMug I am deleting my stupid comments on some of my answers, would you like to remove your comments correcting me???? codereview.stackexchange.com/a/45328/18427
 
Anyone want to change this title (and 'nut')?
3
Q: How to optimize this Linq query?

RobertI am rewriting a VB.NET application in C#. I will nut subject you to the original code because its pretty messy. Below is the converted C# code: public IEnumerable<WebQuery> GetQueries(Request request) { var queries = new List<WebQuery>(); foreach (var report in request.Re...

 
trying to clean up some of my answers
 
Ahhh, hog-bump time.
I see some 'obsolete' flags about to happen
 
3:11 PM
@rolfl done
@rolfl what?
 
hmmm... phrancis needs a refresher on what good titles are ... ;-)
Titles should reflect what the code does, not what the user wants to happen to the code ;-)
 
Ah
 
It is almost never good for a title to have a question mark in Code Review.
Otherwise everyone's questions will have the title: "How do I improve this code?"
2
This is worthy of a meta question.
14
Q: "Please review / critique" in question's title

Andrey TaptunovWould it be wise to consider such posts as a subject for "auto" edit or add to the faq? It seems redundant to ask for review explicitly on the site which purpose is to review the code by community. It's like starting "Please answer" in title on another StackExchange site. It's annoying because ...

 
what was wrong with my title?
 
3:17 PM
Nothing, but, you both happened to click save at about the same time....
I think Phrancis missed the notification bar, and because his changes were larger, they got applied anyway.
Stack Exchange does that.
Your revision is in the history too.
@Malachi - feel free to re-apply your title, I prefer it (sorry Phrancis).
2
 
@rolfl I saw that, and he had some good ones.
 
0
Q: Can this method be changed to remove all objects in one call?

RobertI am converting a VB.NET app over to C#. I won't subject you to the old code but the following is done in a little over 100 lines using nested loops. I am using Entity Framework 6 as my ORM. I have cleaned that up some to this: public void Remove(int key) { var myObject = _context.MyObjects....

 
Thanks, Santa!
 
@rolfl no offense taken
 
@rolfl it's actually 4 log-calls..
after I took the whole class, made it ApplicationScoped and removed the static modifier, it's 4 Errors...
that's making me sad.
 
Morning, Monking
 
Morning!
 
@Vogel612 @Observes @LogDebug???
 
Sorry, @Jamal, I can't bring myself to vote on any of those answers ..... again.
 
You might want to fix your logging
 
3:37 PM
bazola, answering swift....ly
 
@rolfl lol
 
hehe how's it going
 
@skiwi not my idea... the plan was to allow decoupling it and logging via events..
 
@Vogel612 So there's two broken ideas floating around which somehow together magically "work"?
 
the dirty way:
@ApplicationScoped
@Singleton
public class Log {

	private static final String LOG_FILE = "CRMLog.txt";

	private enum LogType {
		INFO, WARNING, ERROR, DEBUG
	}

	private final Logger LOG;
	private final FileHandler logFileHandler;

	public Log() throws IOException {
		LOG = Logger.getLogger(novatec.crm.framework.Resources.class.getName());
		try {
			logFileHandler = new FileHandler(LOG_FILE, true);
		} catch (SecurityException e) {
			e.printStackTrace();
			System.err.println("[FATAL]: Could not initialize logger");
@skiwi @Nobody used it...
 
3:39 PM
Just use log4j2...
 
it probably is....
and that's the saddest part about it.
 
@bazola - in case you did not put 2 and 2 together, that most recent answer of yours, was for a question posed by one of the mods on SO....
Uhm, not SO, SR.
 
i did not notice that actually
 
superping op.
 
I expect more questions to come in from him.
 
3:44 PM
i know that I am a beginner but I definitely want to pay back to the site for all of the awesome feedback I've gotten on my code. This place rocks
8
 
0
Q: Testing a Java Quadtree

user2813274I have created a QuadTree in Java and would like to know how I should unit test it, in addition to any other general code review suggestions. import java.util.ArrayList; public class QuadTree { private QuadTree root, parent, northEast, southWest, northWest, southEast; Point center; ...

0
Q: Inserting 1 line into a my sql database

MasonThis code is how to add code into my table really easily, however it will be called 2000+ times a second so i need to know if this is most efficient code to add it quickly to the database. <?php $site = $_GET['url']; $con=mysqli_connect("localhost","","","rocket_newsites"); // Check connection i...

 
Also, partly because of the brilliant title, and partly because of the asker, that question hit the Hot Questions list.
 
hmm, is it a bad idea to have multiple applications log to the same file via RollingRandomAccessFileAppender?
 
In general, yes.
 
well anything that draws more traffic to the site is a good thing :)
 
3:48 PM
I see my error log has missed an exception somehow, and trying to figure out why
 
This business application is so stupidly designed... to create a new invoicing batch you can't enter a dealer's ID into a field, you have to scan through the tinyest little drop-down menu through tens of thousands of account IDs. Ugh.
 
@skiwi That could explain it.
'could' being the operative word
 
@Phrancis so you don't even select a Dealer, but a DealerId???
 
Yeah, I'll need to investigate tomorrow
 
how is your company still in business?
 
3:50 PM
lol
 
Does anyone know if it is possible to send a list of data to a WSDL service accepting any number of input fields for that element?
 
Successful concurrent access to a single file, with a single insert-point ('the end') requires file locking, and other constructs. Very few log api's implement that by default because it is overhead that is not necessary when you have a single-access mechanism
 
@skiwi um. wat?
 
@bazola great! Welcome aboard!
 
honestly I think @nhgrif saved me months of banging my head against the wall, so I feel obligated :)
 
3:54 PM
@rolfl I might just log to separate files, to be sure
It's just an error log which shouldn't be filled either way
 
@skiwi you could also ...
Another dutch overengineering post?
 
@Vogel612 right. You get this tiny drop-down menu that displays like 8 entries, and you have to scan through ID numbers in alphabetical order (because they are varchar)
 
@bazola it's always nice to see a reviewee become a reviewer.. we need a higher "conversion rate" :)
4
 
@Phrancis stop, you're making my eyes bleed
 
@Phrancis
 
3:57 PM
Sorry, for the Dutch, but @rolfl should be able to read it at least!
Ugh, it doesn't end on any image format
 
0
Q: Increase the performance of a random weighted 'tick' function

njpThis is a very simple function, but it gets run on a roughly 10ms interval, so I'm looking for ways to improve it. The first obvious thing is that it has to run the comparisons nearly every time as it starts with the lowest probabilities first. Is there a way I can reverse that without breaking i...

 
 
@Vogel612 @Mat'sMug ^^ that
 
@rolfl Thanks, just was about to upload it
You know what it says? ^^
 

« first day (450 days earlier)      last day (3564 days later) »