« first day (659 days earlier)      last day (3358 days later) » 
00:00 - 22:0022:00 - 00:00

12:03 AM
@SimonAndréForsberg Can you add this room back to @Duga's list?
 
@Hosch250 depends on how much @nhgrif will complain...
 
0
Q: Optimize matlab triple for loop

texasfloodI have a large matrix samples, I want to make another matrix sampleProb which is the same size, but modified as below: %samples is a 1000*1000 matrix, M = 1000 for i = 1:size(samples, 2) for j = 1:M for k = 1:M if (k ~= j) sampleProb(j, i) = sampleProb(j, i) + normcdf(sample...

 
Suppose we have a poll?
I don't see why @nhgrif cares.
It helps me know when I can vote again.
 
0
Q: How do I perform a Caesar Cipher on elements of a list using list comprehension

jdreaminI am very new to Python and have run into a road block. Is it possible to use list comprehension to perform a shift on each letter of a word in a list.? I was wondering because I know that I am able to the following: lines = [words.lower() for words in lines] Also how could I utilize ord() ...

 
12:20 AM
Off topic.
 
12:35 AM
Lady and the Tramp:
Tramp: Have you ever chased chickens?
Lady: I should say not!
Lady: We aren't supposed to.
Tramp: That's why it's fun!
 
0
Q: Laravel 5 Dependency Injecting a Repository into a controller, and depedency injecting an entity into repository

Dustin ParhamThe issue I'm having is related to injecting an entity into my repository when my repository is injected into my controller. I'm using a factory to inject the correct repository into my controller, and would like my factory to also inject the correct entity into my repository class when it's bei...

0
Q: Pollard p - 1 implementation

BentenI'm trying to implement the Pollard p - 1 algorithm seen here, in Java. It has a C implementation here. I am using it for numbers without any smaller factors so trial factorisation isn't needed. My implementation can factor numbers such as 15236506168104630133 but it takes around ten minutes. I ...

 
1:17 AM
C'mon guys, those questions haven't been closed yet?
 
1:29 AM
0
Q: VBA Save As Current Filename +01

PlainsWindI'm looking to write a macro to save my current version filename +1 instance of the version. Ex. Current = DailySheet_20150221v01; Save As = DailySheet_20150221v02 Am I on the write line to set a string to DailySheet_today's datei`?

 
1:46 AM
Time toooooo go to sleeeeeeeeeeeep *singing*
 
1:56 AM
Chorus:
I'm tired, yes, I'm tired.
It's time to go to bed.
 
I'm sorry, but I think your question is too broad. Stack Overflow is not the place to ask for general open-ended code reviews. If your code works you can ask for a code review on the Code Review Stack Exchange site, but if this is just pseudocode then your question is off-topic there too. — Martijn Pieters 1 min ago
 
2:29 AM
0
Q: binary to ASCII convertor

kyle kThis is a program i wrote to convert binary to ASCII, i am still learning ARM assembly. How can i improve my program, is there any bad programming habits in my code? @ @ ARM assembly programm which converts binary to ASCII @ written by Kyle Kersey, (C) 2015 @ .global main main: adr r2, ...

 
Off topic. This is not a code review site. Try codereview.stackexchange.com instead. — Stephen C 23 secs ago
 
0
Q: Java chess project advice

user66668I'm currently just working on a chess game project to improve my object-oriented skills. It is currently only at the starting stages and there is quite a bit missing (such as error checking) but I thought before I go any further I should get some advice on if I am using correct practices and if t...

 
2:59 AM
This might be a better question for Code Review. AFAIK, Stack Overflow is more about specific programming questions. See codereview.stackexchange.comZan Lynx 47 secs ago
 
3:11 AM
0
Q: Optimizing Diwali Lights problem in C

thebenmanI was trying to solve https://www.hackerrank.com/challenges/diwali-lights problem in HackerRank. The Code I had written is #include<stdio.h> # define MAX 10000 // assuming we need first 100 rows unsigned long long triangle[MAX + 1][MAX + 1]; void makeTriangle() { int i, j; // inietial...

0
Q: Blinking LED code at a particular frequency

sam brosteainI wrote a function that would blink an LED at port RC4 of my PIC16F1788 at a specific frequency. Let me know if there is anything wrong thanks. void fault_blink(int frequency){ /* starts the LED blinking at a particular frequency */ while(1) { PORTCbits.RC4=0XFF; // RC4 on __delay_ms(1000/f...

 
3:43 AM
how is this a code review. I tried to solve this myself and i couldnt figure it out so i asked on stack overflow. — user3368956 56 secs ago
 
3:54 AM
ACTIVITY
ACTION
 
0
Q: A* Search Python

user3424684Here is the code for an A* search that I tried to write to solve a simple maze. However, it seems to be bugged in some form, as it expands 65,000 nodes for the following maze, when it should expand ~15,000 using a null heuristic: %%%%%%%%%%%%%%%%%%%% %. ...P .% %.%%.%%.%%.%%.%% %.% % %...

 
4:28 AM
Hi.
 
Question is better suited for codereview.stackexchange.com as it is about optimization of code vs. non-working code. — Burhan Khalid 18 secs ago
Hint: try flipping the question around and looking at guy+girl pairs; but as you are not facing a problem but rather need optimization hints - this is better suited for codereview.stackexchange.com — Burhan Khalid 1 min ago
The code works, it just needs optimization. Optimization questions are best asked on codereview.stackexchange.com - because the question boils down to - "I have working code, I need to make it better". — Burhan Khalid 47 secs ago
 
4:46 AM
0
Q: Generating all size-k consecutive subsets

Kevin TindallI am interested in splitting any list into consecutive subsets based on a k-value. For example, [1,2,3,4,5] splits into [[1,2],[2,3],[3,4],[4,5]] when k=2. If k is bigger than the entire list, then an empty list will be returned. I have written code in both J and Haskell that performs this task...

 
5:37 AM
1
Q: Python: Get letter grade using eval()

Timothy OnggowasitoI understand that using eval is extremely dangerous as it can execute deadly commands as an input by the user. I'm trying to write a code to get a letter grade from a number between 0 to 1. I was trying to write it in the most elegant way. Is this safe? try: score = float(raw_input('Enter...

 
6:10 AM
-1
Q: How can I stream in a video in chunks

LanceHow can I stream in a video in chunks to my windows form? I am trying to play a video from a stream but I want to stream it in chunks so it does not clog up the RAM. Any suggestions would be appriciated

 
6:22 AM
0
Q: Laravel routes.php optimization

e4rthdogLARAVEL 5 My goal is: -Have 2 main domains .com and .dev for production and local installations -Have 2 main subdomains. One for the site and one of the application -Site must be public and application always to be secured. My take on the above are: <?php $approutes =function (){ Rout...

 
 
1 hour later…
7:23 AM
-1
Q: Customized code not calculating

GaliI customized a calculator I found online for my website, however, none of the calculations work. Where did I go wrong? <HTML> <HEAD> <TITLE>Rainfall Catchment Volume Calculator</TITLE> <SCRIPT Language="JavaScript"> <!-- function calculateTotal(frm){ var roofarea = frm.roofarea.value ...

 
8:07 AM
0
Q: Comparing two values to two other values efficiently

WolfLinkSo for an important piece in my code (thats getting called a lot) I need to compare 2 doubles (a and b) to 2 other doubles (x and y) to meet the following conditions: return false if both a and b are greater than both x and y return false if both a and b are less than both x and y return true ...

 
8:22 AM
0
Q: balanced binary tree in O(log n)?

Dr. YaghiIf I create a balanced binary tree with n vertices and save the number of children in the sub-tree for each node (i.e number of children that this node as a root has...) which of the following can be done in O(log n)? find the order of one given elements find the number between a and b (a<b) fi...

0
Q: A fixed max size container class containing unique elements with functions like push_back and pop_back and is iterate-able

Elvisjamestemplate <class T, int max_size> class FixedSizedUniqueStack { std::vector<T> m_vec; std::unordered_set<T> m_uset; public: FixedSizedUniqueStack():m_vec(max_size){} bool push(T& x) { bool success = true; if(m_uset.insert(x)) m_vec.push_back(x); else suc...

 
8:43 AM
0
Q: Java Interface: Better use of Static Factory Methods?

rayI've been working on a Java-based mathematics library focusing on vectors and matrices. I plan to use it for an important upcoming project, so the classes are analogous to data types available in GLSL (e.g. Vector2 for GLSL's vec2, Matrix4 for GLSL's mat4, and so on). I'm trying to only expose i...

 
9:16 AM
0
Q: Fast sums of power algorithm

Dulguun LstThis code reaches time limit on 1 test case. Intended to solve this challenge. Approach that I'm using is from the book "Algorithms Functional Programming Approach". It's backtracking depth searching method. How do I improve speed of this code or is there better way to do it? searchDfs :: (Eq no...

 
9:41 AM
0
Q: CRUD (database layer) for F# with TypeProviders

demasI am newbie in F# and I am thinking about use F# in my next project. The project will work the database and I need to store and retrieve instances of objects in the Db. Could you please check my code and say if there is something that I can improve? An another one question: is there is any way...

0
Q: Reading an Excel file and compares the amino acid sequence of each data pair

TimoSince I am fairly new to Python I was wondering whether anyone can help me by making the code more efficient. I know the output stinks; I will be using Pandas to make this a little nicer. from xlrd import * def main(): '''This Proram reads input (A:clone name, B:sequence, C:elisa) from an ...

 
10:26 AM
0
Q: Function to get top k words in a given String (String can be pretty long)

Piyush GuptaTwo part job. First, to identify a word and second, to find the top k words. I tried to use regex to split but its taking 10x more time when string is really long. The top k strings are found using priority queue. Create min priority queue for first k element, if the frequecy of next word is gre...

 
 
1 hour later…
11:33 AM
0
Q: Keep database lookup in memory and get values in frequent.

Dev Devonpublic string LUApplicationParams(int applicationId, string GuidId, string variable) { if (m_LUApplicationParams == null) { var blLU = new LU(); DataTable dt = new DataTable(); dt = blLU.GetLUApplicationVaribales(appl...

 
3
Q: String Token Generator for ExpressGenGen

JaDoggStringTokenGenerator is an interface (or abstract class) I've created to the specific task of generating a string token of a given character set. It allows appending characters to it and then It can be used to receive a string token. I wrote this for the second version of ExpressGenGen a code gen...

 
12:12 PM
0
Q: Reading a file into memory

yasarCan you review below code for performance and stability considerations. It is supposed to take a file name or NULL. If it is a filename, read given file into memory, if it is NULL read stdin into memory; struct file_data { char *data; size_t numChars; }; /* Read whole file into memory *...

 
Oh the invasion!
 
12:29 PM
This might probably fit better to codereview.stackexchange.com. Beside that whenever you have to many variables in on function, it is normally an indication that this function does more then one tasks and should be divided into individual functions. — t.niese 1 min ago
 
12:46 PM
No better way to wake up than reviewing @Mat'sMug's code
2
 
12:59 PM
Monking
 
Monking!
@JeroenVannevel I can think of a number of better ways to wake up.. lol
Like waking up with two new answers to your bountied question
 
1
Q: How is my voting system? Any security, design or other issues?

HarryI am currently adding a voting system to my website. Below is my voting class. I feel that it could be simplified and that there is repeated code regarding the functions, although to the best of my knowledge this is the simplest I can make it. I would love to hear other implementation ideas and s...

 
@JeroenVannevel do you think I should move the "helper methods" to a more general-purpose inspector helper, like IdentifierUsageInspector?
 
Will it be used in more than one class or is it used just in that one class?
Former: helperclass, latter: current class
Otherwise you're moving towards the "Anemic domain model" antipattern
Your logic is moved outside of the actual types and goes towards services
 
1:15 PM
I don't know yet. But there are a number of refactorings scheduled for v1.3..
Hmmm
 
0
Q: Can I be checking that buttons are pushed in a better way?

HyposaurusI made a panel of buttons which run commands when pushed. In order to not have the command run on every loop if the button is held down, I am comparing the button to a previous state and only run if it is not, like so. buttonStateR1 = digitalRead(redButton1); if (buttonStateR1 != lastBu...

 
Like, now that I can extract a method, next step is a refactoring to inline a method into its call sites
And then one to reorder parameters and update call sites - surely I'll need a solid modelisation for a "parameter" concept
 
mmm
I don't know how detailed your syntaxtree is
 
This might be more appropriate to the Code Review site. — Mike M. 27 secs ago
 
Do you have access to the Method? Which has a return type, body and method signature?
That's how I would create my tree. And then the method signature has a collection of Parameters
And each parameter has fields for ByVal, ByRef, optional, default value, etc
Those refactorings are trivial when you have a tree like that
The ExtractedParameter should probably just be Parameter since there should be no difference between both, I think
 
1:27 PM
@Mat'sMug You should've written an automatic analyzer for C# code, then it didn't matter at all how you would write that program, as long as it worked and you can run it at the end
 
@skiwi an ant should not dare stepping on R#'s toes.
 
I only now realized why R# is called ReSharper
2
 
Morning all.
 
@JeroenVannevel The generated tree is extremely detailed, but I haven't figured out whether/how it can be modified
Hi!
So I inspect the tree, decide what I want the VBA code to look like, and then I need to locate the actual corresponding code myself in the VBE, and use VBE's API to actually change the code in the IDE - at which point the parse tree's node positions are all garbage so I need to reparse
 
2:27 PM
I've voted to close this question as off-topic because it's requesting improvements to working code, so it belongs on Code Review — Rob Kennedy 1 min ago
 
1
Q: Why am I not get getting correct column positions in that parse tree?

Mat's MugSay I have a string like this: var code = "Private Sub DoSomething(ByVal foo As Integer)\r\n DoSomethingElse(foo)\r\nEnd Sub"; When I feed my ANTLR-generated parser with that string, I get a parse tree that looks something like this: [SubStmtContext] [VisibilityContext] [ArgListCon...

^^ @JeroenVannevel that's how detailed the parsed tree is ^^
 
That's pretty detailed
 
it's more than I could ever dream for!
but this bug (I think it's a bug) is going to cause issues when I'll try to refactor/rename parameter foo in a function called GetFoo
I need to be able to locate each token exactly where it is in the code file. now I only get the line number, column positions are unusable
 
2:45 PM
Start by writing some code that just prints "1" on whatever system you're using. Then extend it to print everything from 1 to 999 (hint: loops). Then worry about filtering the the multiples of 5. Or cheat and take a look at the linked question (and its counterpart on code review). — Notlikethat 46 secs ago
I'm voting to close this question as off-topic because it belongs on codereview.stackexchange.comBart Kiers 1 min ago
 
0
Q: Want my Fragment to be a little more neat

Rsq ZmnI'm basically a newbie in android app developing. So I'm not sure if this is the right way to write these codes. I have made an app called "Zconverter". It has 9 fragments and the code i m showing here is the smallest of them all. All the fragments have the same type of code. This app works just ...

 
@SimonAndréForsberg I don't mind @Duga announcing "Reload!" but all the other stuff is way unnecessary in this room.
 
3:09 PM
This question is better suited to codereview.stackexchange.com. — Andy Turner 39 secs ago
I agree. This looks like a perfect fit for CodeReview. — nhgrif 1 min ago
@BartKiers This isn't a perfect fit for Code Review, though it might be okay. But whether or not something is on-topic on Code Review should not impact whether or not you vote to close here on Stack Overflow. The only reason to vote to close a question here on Stack Overflow is because it is off-topic on Stack Overflow. Questions that are on-topic on other Stack Exchange sites are not inherently off-topic here. — nhgrif 19 secs ago
 
3:42 PM
0
Q: Same thing freezes or works in an instant

Dulguun LstBelow code solves the this challenge. import Control.Monad (guard) import qualified Data.Map.Strict as Map import Data.Map ((!),fromList,Map(..),member) -- depth first search higher order function depthFirstSearch :: (node -> [node]) -> -- successor node generator (node -> Bo...

 
> it prints the result instantly. I have no idea why it's freezing and not freezing.
VTC'd ...unclear what you're asking... but perhaps broken code would be a better close reason
 
0
Q: Java - How good is my implementation of a binary heap?

Just some guyI've read a little about binary heaps/priority queues and decided to try my hand at making my own implementation of one. I'm not the most experienced programmer and I would be really grateful if you guys could take a look at my heap class and tell me if it's a good implementation. What can I imp...

 
This is not really suited for SO, because "proper way" is almost always primarily opinion based. You might get more help on CodeReview. In your case I'd answer: Use a loop, as you're doing the same thing 3 times — kingkero 2 mins ago
On Stack Overflow, this question should be closed as Primarily Opinion Based. It might make for a decent Code Review question however. — nhgrif 1 min ago
 
4:00 PM
0
Q: C# quicksort async vs serial

Bill BarrySo I am playing with async... I figured I'd write a parallel implementation of Quicksort while trying to look at various optimizations. I want to keep the generics (and the overhead of the virtual calls going on here). Other than that I am looking for optimizations that can be made. Here is the ...

 
In that case, this question would be off-topic for Code Review. We only review code that is working as intended. I suggest learning how to use your debugger, and if you still need help from there, Stack Overflow would be the place. — nhgrif 25 secs ago
 
4:13 PM
Hi.
Seems dead here.
 
You pinged me, @SirPython?
 
Yes, sorry; it was unintentional.
 
4:29 PM
Ok
 
@JeroenVannevel Wow. What perserverence.
 
Yeah, they really went all the way with that
One sad aspect though
> we haven't gotten around to reporting the bug to Microsoft yet, I know it's on our task board. :)
That's just shitty
 
The only way they could have gone further would be to find an exploit.
 
Maybe MS will see it.
You could try to report it.
 
If I have seen it, Microsoft has too
But possible malicious users as well
 
4:40 PM
I don't think @SirPython accidentally pinged me.
 
@Hosch250 No, it was not truly an accident, but I take back whatever I said.
 
The message said "Hello, @Hosch250"
Why?
 
Because I forgot to check the time of when you posted your message, and when I did, I thought deleting the message would remove the ping; I didn't want to disturb you.
 
You only sent it 7 minutes later.
 
Oh. I thought I sent it 4 hours later.
 
4:44 PM
No.
 
Whoops! I forgot that this clock is 24 hours. Sorry.
 
5:13 PM
What's your question exactly? If you're looking for someone to review your code might I suggest codereview.stackexchange.comBono 51 secs ago
 
5:40 PM
Hello.
 
Hello, @MannyMeng
 
Hi.
 
I thinnk its for code review site — Gops AB 1 min ago
 
5:56 PM
0
Q: Trying to get flight data from delta.com using vba

PhilipI am trying to retrieve flight information from delta.com to help automate my workload (I usually have to type in all the flight data daily in excel). So far, this is what I have and it works occasionally. I stepped through it and it seems to jump all over. I figured my ifs are nested wrong? But...

 
6:29 PM
No, automated testing can only find obvious or known flaws. If you want the best results, do a code review. — Gumbo 58 secs ago
 
6:41 PM
0
Q: drawing tarot cards

EwaThis is my javascript practice project. The goal is to draw random tarot cards from the suit, number of cards is determined by the amount of html elements with 'card-container' class on given page. The deck is structred as follows: major arcana (trumps), numbered from 0 to 21 minor arcana hav...

 
Afraid your question is a bit too broad for Stack Overflow, as well as slightly off-topic being a review-type-question. You could try CodeReview SE, but be sure to include your code and be specific about the type of feedback you're looking for. — Jeroen just now
 
Dead again.
 
you are voting, you set put on hold. this is doctorate . @Jamal, fuck you. — Dr. Yaghi 6 hours ago
 
@Jamal this is doctorate!
 
He gave you a PhD?
 
6:55 PM
@Jamal Someone got up on the wrong side of the bed today!
 
I went to flag it, and it was already gone.
Did you delete it?
Or did they?
If you did, expect a new one shortly.
 
No, the community cast flags on it. Delete votes can be put on the question itself, or I can delete it. I don't think the OP is interested in improving the question.
 
I don't have the option to delete it, even though I have 4k rep.
Or an I missing something?
 
It has to be -3 or lower.
 
Ok.
1 more delete vote.
 
7:10 PM
@Jamal That's harsh.
And he only just joined today
 
Some people think they rule the universe.
And looking that question over, I think it is from an exam.
Maybe a take-home midterm
 
I'm not quite fond of the "I'm voting to close" text, especially since my votes are binding. I may just leave it out altogether.
 
Since this is his first SE site, maybe he was unfamiliar with the rules(he might've come from another forum-like place where profanity was allowed) and he didn't recognize Jamal as a figure of power.
 
7:25 PM
If this code is working to the best of your knowledge, and you would like to know about improvements, you can post it on Code ReviewHosch250 46 secs ago
 
So today I'm reading from beginner Java guide, going through exercises but trying to expand them a little bit... this is super-newbie code but I'm mostly wanting to make sure my variables are scoped in the right place
public class GallonToLiter {
    public static void main(String args[]) {
        final double CONVERSION_RATIO = 3.7854;
        double gallons = 3.827;
        double liters = gallons * CONVERSION_RATIO;
        System.out.println(gallons + " gallons equals " +
                           liters + " liters.");
    }
}
 
@Phrancis You want those to be global variables?
Or only accessible in main?
If you want them to be global variables, put them in the class, not in the method.
 
Well right now this is completely self-contained file
 
Doesn't matter.
 
I'd recommend moving CONVERSION_RATIO to a field of GallonToLiter and adding the public modifier.
 
7:27 PM
Only main can access those variables.
 
I first had CONVERSION_RATIO in the class, would that be smarter?
 
@Phrancis One way to try the variable scope would be to just try to move them to a lower scope if possible until you get a compiler error :p
 
@Phrancis Yes.
 
I see ok
 
though conversation ratio would be better of as private static final double CONVERSATION_RATIO = 3.7854d; on class level
 
7:28 PM
Something like that?
 
Global variables are best off as final
Yeah, something.
 
public class GallonToLiter {
    public static final double CONVERSION_RATIO = 3.7854;
    public static void main(String args[]) {
        double gallons = 3.827;
        double liters = gallons * CONVERSION_RATIO;
        System.out.println(gallons + " gallons equals " +
                           liters + " liters.");
    }
}
 
One thing you could consider is creating a method to convert it and call it from main
That is definitely what I would do.
 
If the code works and you want to improve it, then the question belongs on Code Review. — 200_success 54 secs ago
 
^ That sounds smart. Haven't really got that far into the book yet
 
7:30 PM
Yeah, if you know any real language, it should be easy for you.
If this is your first, take it slow and don't move on until you understand everything (assuming you already know this, just a good reminder).
 
Just working on basic operators but I'll probably have more questions as the day goes by :D
 
Just don't post them on SO.
 
@Phrancis We'll be here for you!
 
The Java crowd is vicious.
 
@Duga Retracted, as the question is borderline hypothetical.
 
7:33 PM
1
Q: Grid walk problem and solving it recursively (without success)

Rishat MuhametshinOn CodeEval, there's a Grid Walk challenge: There is a monkey which can walk around on a planar grid. The monkey can move one space at a time left, right, up or down. That is, from (x, y) the monkey can go to (x+1, y), (x-1, y), (x, y+1), and (x, y-1). Points where the sum of the digits ...

 
Is Math imported automatically by Java by default?
 
I don't know.
 
Well this works without importing anything so I'm going to assume yes :D
public class PowerOf {
    static double base = 100;
    static double exponent = 3;
    static double result = Math.pow(base, exponent);
    public static void main(String args[]) {
        System.out.println(base + " to the power of " +
                             exponent + " equals " + result);
    }
}
Meh, something tells me that it is ugly lol
 
0
Q: OSGI bundle and threads

FortranI am new in OSGI and i have current aim. I have 10 threads, it's writing their names in a file. After recording thread sleep random 0..1 sec. This all must be a bundle. I create it, but i'm not sure Is this correct. Can any comments? package helloworld; import org.osgi.framework.BundleActivator;...

 
7:53 PM
Why do you have so many static variables?
 
Good question. I'm afraid the best answer I have is "Dunno"
What do you recommend instead?
 
Variable's scope should be as limited as possible.
4
 
So it'd be better to move all these into main in this very small example?
 
public class PowerOf {
    public static void main(String args[]) {
	double base = 100;
	double exponent = 3;
        System.out.println(base + " to the power of " +
                             exponent + " equals " + Math.pow(base, exponent));
    }
}
But realistically, you're not actually going to want to do a whole lot in main.
But that's a discussion that I think requires quite a bit more understanding of OOP.
 
Yeah I've heard that many times before, I'm sure the book will cover that in a few chapters
 
7:57 PM
The fact that "everything is a class" is one of the things that I don't like about Java as a learning language.
 
@nhgrif I had trouble with that at first too, but it actually is easier now that I am used to C#.
 
What is easier?
 
That everything is in a class.
 
It's not easier.
 
It isn't so procedural that way.
 
7:59 PM
You are forced to learn bad habits and hopefully you'll learn to break those bad habits later.
Because you have to learn some extreme basic first. Then you have to learn about writing functions. And then you can learn about writing your own custom classes.
But if you're learning a class-only language, like Java, then you can't learn the extreme basic or writing functions without simultaneously writing classes.
But you just ignore the concepts of writing classes... you're thrust into OO programming without having a clue what you're doing in any regards to anything.
 
I'm past those basics now, so maybe that is why I like it.
 
But how well do you understand OOP?
 
Pretty good.
I learned on C++.
 
I don't hate it because I'm not beyond the basics. I hate it as a learning language because it teaches bad habits.
 
I get what you mean.
I wasn't thinking of learning it, I was more thinking of using it.
 
8:03 PM
Because main is in a class and main is a static method. static methods can only reference other static methods or static variables. And until you start learning OOP, this makes no sense as to why this rule exists (I had a teacher who couldn't even sufficiently explain it).
 
Yes, that is a pain.
 
So what do you do? You try to write non-OOP code, just as you might if you were learning with C++, except you have to use the static keyword with all of your "functions" and "variables".
 
When you are beginning.
 
And that's the bad habit I'm talking about.
 
Yes. I did that in Java.
Once you know what is actually happening, it makes sense.
 
8:06 PM
And in non-"everything is a class" languages, sometimes we take a look at a class and say "This shouldn't be a class at all", and we say that because all of the methods are static and all of the variables are static. If that's your class, it shouldn't be a class.
Unless you're writing Java.
Because in Java, you have no other option.
That's why there's a Math class. There's never any point in instantiating a Math object (and as such, in any other language, we'd say that Math probably shouldn't be a class), yet in Java it must be a class loaded with a bunch of static methods.
 
It makes sense both ways, because you have the unit "Math"
 
How is "Math" a unit?
 
"Math" is not a "Person"
It has its own properties.
 
-1
Q: Hacker earth Challenge - Number of Interest

arindrajitI am facing a rather humiliating problem. There is a challenge which I have solved but when I submit the code I am getting a score of zero. But it seems to be producing correct output when I am running it on my local machine. Although my program is giving the correct outputs when tested on a Comp...

 
"Math" is nothing more than a collection of functions.
Java can't have functions, so "Math" has to be a class so that what would otherwise be functions can be static methods.
 
8:11 PM
No, Math has final variables too.
Like pi
 
It has static final variables.
So it's a collection of functions and constants.
 
Just like every other class in any language.
 
In any non-"everything is a class" language, this is not justification for a class.
No, not at all.
 
The only difference is that there is no reason for the variables/methods to be instantiated multiple times.
 
No...
There is zero justification for "Math" to be a class.
It is only a class in Java because there is literally no other option.
Consider C++ or Objective-C. There is no "Math" class. It makes no sense for there to be a "Math" class. You would never instantiate a "Math" object (that would never make any sense) (and the need to instantiate an object to represent an instance of the class is the reason you make classes... other wise it's a collection of functions and constants).
In C++ or Objective-C, you #include/#import the Math header, "math.h"
 
8:16 PM
That is because Java thinks of classes differentl.
 
No, it's because in Java, everything is a class and there is no other option.
And therefore, learning Java as your first programming language teaches bad habits.
And it teaches you to think about classes in the wrong way for any language other than Java.
 
A class in Java is just a series of related methods/variables, whether it makes sense to instantiate multiple objects of the class or not.
 
Exactly. And why? Because there is no other option.
 
A class in C++ is a group of variables/functions that make sense to be instantiated multiple times.
 
And this is unique to Java. And thinking about classes in the way you have to think about them in Java is the wrong way to think about classes in any other language.
 
8:18 PM
Not quite, C# also requires it.
 
Which is my entire point: learning Java as your first language will teach you bad habits.
No it doesn't. You can have Modules.
Or is that purely VB?
 
In C#, as far as I know, you have namespaces, which have classes, which have everything else.
 
@nhgrif I disagree with this statement. I believe it would be a lot more confusing to have a bunch of math functions floating around, and it would be less confusing if they were under a class.
 
They're not floating around.
They're in a header in languages like Objective-C and C++.
C# doesn't actually have modules.
So C# is the same as Java.
 
Syntactically, generally, are one-liners discouraged? Like if(foo > bar) System.out.println("foo is greater than bar");
 
8:22 PM
@Phrancis Always use braces.
 
@nhgrif That's a good point, but in your code, they are floating around. The functions may have their separate and isolated header file, but when they are pooled together with other header files, they start to float around.
 
@Phrancis Never omit braces.
 
Ok. I'm guessing, never omit line breaks either?
 
@SirPython In some programming languages, you have name spaces you can put them behind. What you want are namespaces.
Keeping it on one line is okay-ish, but I'm not sure it looks that great.
Particularly after you add the braces back around it.
 
@Phrancis I personally don't like omitting line breaks because it looks kind of ugly(to me) to have both opening and closing braces on the same line.
 
8:23 PM
So, if you think of it this way, in C#/Java, the Math class is sort of like a namespace inside a namespace.
 
No it's not.
 
OK thanks @nhgrif @SirPython
 
And regardless, my point still stands.
 
Not quite the same, but not too different either.
 
It's drastically different if you're writing any other language, and that's the point.
You do it this way in C#/Java because you have no other option.
But if you've learned on these languages, then you carry your bad habits over to other languages.
 
8:25 PM
And then you come to Code Review to get them fixed :)
 
And hopefully your habits can be broken, hopefully.
 
I must say, @nhgrif, you do provide a very strong argument.
 
But if you learn on a language like C++, or Objective-C, you can learn to do it the right way. And when you move from these languages to C#/Java, you can't do it the wrong way for those languages because the language simply won't let you.
 
I think the "right way" is subjective.
 
C++ will let you do it the Java way, but that doesn't make it right. Java won't let you do it the C++ way.
The "right way" is different for each language... that's the point I'm making.
 
8:27 PM
Oh, yes.
 
But if you come from Java to C++, C++ will let you do it the Java way... but that's the wrong way for C++. Java won't let you do it the C++ way, so your habit is force-broken by the rules of the language.
 
But, one of the main reasons people dislike C++ (people to do dislike it, that is), is that it is not OO enough.
 
C++ won't force break your Java habits (in this regard).
 
That it does let you do procedural programming.
 
It doesn't matter why people like or don't like any languages.
What matters is that you'll write in different languages.
 
8:28 PM
0
Q: Get the pixel data of an image without using pointer to a struct

Bogdan DimovI hope someone can help me with this. What I want in a few words is get the color of every pixel of an image and assign its red, green and blue values to the variable pd. But instead of using a pointer to the structure Bgra I would like to copy the RGB values into the array byte[] rgbValues, like...

 
Most likely.
How will your habits from your original language effect your ability to write good code in any language after that?
 
@Hosch250 Isn't C++ multi-paradigm, so it allows for different styles?
 
@SirPython Yes. That is one of people's main complaints against it.
They say that it should remove the OO part, or the procedural part.
 
@nhgrif That is true for learning any language, Java or not.
 
I like it, but it is easier to program it C# because C++ gives you too much control sometimes.
 
8:33 PM
It is true for any language yes, but with Java, I've seen it put some really bad habits on such fundamental things because you get forced into OOP before you even understand what's going on even remotely.
 
Yes, I had a hard time switching to full-OOP
 
The best thing to do, if you're going to learn Java, you should always have two files.
 
I think it was good for me to start in C++, and I still have a bit of a procedural mentality.
 
And just start full-fledged OOP from the get-go
 
So, just so I can get into the habit or breaking stuff down in methods instead of doing stuff in main... What would be a more OO way to write this?
public class PowerOf {

    public static void main(String args[]) {
        double base = 100;
        double exponent = 3;
        double result = Math.pow(base, exponent);
        System.out.println(base + " to the power of " +
                             exponent + " equals " + result);
    }
}
 
8:35 PM
That is what I really hate about Java, besides overloading operators.
 
@Phrancis give me a few seconds.
 
Take your time friend
 
First, split that off into a separate method.
 
@nhgrif OOP is a hard thing to start out with in general. That's why languages like Python and JavaScript are popular starter languages because you can still code efficiently and easily while being oblivious to OO aspects.
 
You don't want main to handle the logic of your program, really.
You use Main to get into your program, mostly.
 
8:37 PM
In any real application, main is pretty much just a 1-liner.
 
@Hosch250 And that's why I love OOP
 
So I've heard, just never have really done it
 
In my main for the page in my application, I just do a bit of initialization, and that is it.
I could even split that off into a separate method, but it should never be called anywhere but from main, so I haven't.
 
@nhgrif I'd like to hear more about this two-file thing
I'm practically a blank document right now (other than my SQL habits) so any way that I can learn some good OO habits from the get-go will make these silly simple exercises much more "in context" I think
 
public class PowerOf {
	double base;
	double exponent;
	double getResult() {
		return Math.pow(base,exponent);
	}
}

public class PowerOfTest {
	public static void main(String args[]) {
		PowerOf p = new PowerOf()
		p.base = 100;
		p.exponent = 3;
		System.out.println(p.base + " to the power of " +
                             p.exponent + " equals " + p.getResult());
    	}
}
The top class should be one file, the bottom class should be another file.
And excuse any syntax errors... I wrote that in a notepad...
 
8:43 PM
@nhgrif Shouldn't that be static because there is no sense in ever creating multiple instances?
 
0
Q: Is this query good?

php_nub_qqI have two tables for storing comments comments CREATE TABLE `comments` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `text` text NOT NULL, `author` int(10) unsigned NOT NULL, `time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 commen...

 
This is exactly the problem with Java.
And this example is a little contrived.
The best way I've found to learn OOP is to make a fraction class.
 
In this instance, I would probably just put that in a separate method.
 
However, if the PowerOf class was slightly different, it can kind of make sense as a class as is.
 
Yes, it could.
 
8:44 PM
For example...
 
If you needed it to store the data, then definitely do not make it static.
 
I first caught on to OO aspects when I tried to create simulate a Town. The Town had to have Stores and Houses, which all had People working for them and living in them.
 
When I learned OOP, I had to create a Library, which contained Books and Patrons.
The Library had to handle checking in/out books, the Book had to have an ISBN, and the Patron had to have outstanding fees.
This was in C++.
 
public class ScientificNotation {
	public double base;
	public int magnitude;
	public double getValue() {
		return base * Math.pow(10,magnitude);
	}
}
 
All this reminiscing reminds me of the excitement I got when I first typed in console.log("hello world") and "hello world" came up on the screen.
 
8:47 PM
Now our ScientificNotation class can be use to represent numbers in scientific notation.
 
Or, you could create a RomanNumerals class.
You enter a number in Arabic (as an int) or Roman (as a string).
 
public class ScientificNotation {
	public double base;
	public int magnitude;
	public double getValue() {
		return base * Math.pow(10,magnitude);
	}
	public String toString() {
		return base + " x 10^" + magnitude;
	}
}
 
The class converts it and stores it in both notations, which can be gotten as needed.
 
@nhgrif Should there be an @Override over toString's signature, or is that no longer needed in Java 8?
 
Yes, something like that ^
 
8:49 PM
I don't know.
I'm not really a Java person.
There is also Engineering notation, which is similar but distinctly different from Scientific notation.
 
Engineering notation has the power only divisible by 3.
So you can have 1^3, 10^3, 100^3, 1^6....
 
Right.
 
I wonder why that was created.
 
Because of the metric system.
3.45 x 10^-8 meters?
34.5 x 10^-9 meters = 34.5 nanometers.
It's easier to say "thirty-four-point-five-nanometers" than it is to say "three-point-forty-five times ten to the negative eight meters".
 
Yeah.
 
8:54 PM
And in Engineering, you're always dealing with units of measure basically.
 
-8 has a name also, but it isn't used nearly as often.
It was in my Physics book.
 
For completeness, ScientificNotation would need base to be private, and throw exception if you tried setting base to a value >= 10 or <= -10
OR... it could just automatically resolve the issue.
 
True.
Which to use would be dependent on its use.
Some systems it would be better to reject it, others it would be better to resolve it automatically.
Some, it would be best to allow the user to set it either way.
 
@nhgrif That's perfect, thanks a lot for the example. That helps me understand better :)
 
0
Q: VBA: Sort data by date , then by user for an unknown number of rows then summerizing by week and user

brandieThis is the code I have so far: Private Sub SortButton_Click() ' Sort Data by date ' Sort Data by Inspector Dim lastRow As Long 'determin # of rows in sheet Set lastRow = ActiveSheet.UsedRange.Rows.count Columns("A:I").Select ActiveWorkbook.ActiveSheet.Sort.SortFields.Cl...

 
9:24 PM
0
Q: Beauty and the Strings in Haskell

Kevin TindallI decided to make a solution in Haskell to a problem that I found on another post here at CodeReview (link: The Beauty and the Strings) I would like suggestions on how to improve letterFreqs. I have tried searching for mutable arrays that could help with performance. But is it worth it? The ar...

 
OK so am I applying OO semi-intelligently in this?
// GallonToLiter.java
package Chapter1;

public class GallonToLiter {
    final double CONVERSION_RATIO = 3.7854;
    double gallons;
    double getResult() {
    	return gallons * CONVERSION_RATIO;
    }
}

// GallonToLiterTable.java
package Chapter1;

public class GallonToLiterTable {
	public static void main(String args[]) {
		GallonToLiter gallonToLiter = new GallonToLiter();
		for (int counter = 0; counter <= 10; counter++) {
			gallonToLiter.gallons = counter;
			System.out.println(gallonToLiter.gallons + " gallons equals " + gallonToLiter.getResult() + " liters.");
Not sure why the indentation got weird in the 2nd class
Looks fine in Eclipse. blames chat
Would it make more sense to just use gallonToLiter.gallons as the incremented variable in the for loop?
 
9:47 PM
@Phrancis Yes, that would make more sense; it would also save space, getting to remove a variable.
 
I did something like that instead, since I wanted to go down into decimals...
// GallonToLiterTable.java
package Chapter1;

public class GallonToLiterTable {
	public static void main(String args[]) {
		GallonToLiter gallonToLiter = new GallonToLiter();
		for (double counter = 0; counter <= 100; counter++) {
			gallonToLiter.gallons = counter / 10;
			System.out.println(gallonToLiter.gallons + " gal. = " + gallonToLiter.getResult() + " l.");
		}
	}
}
 
00:00 - 22:0022:00 - 00:00

« first day (659 days earlier)      last day (3358 days later) »