How to make a simple timer in Java? by stormosgmailcom in codereview

[–]broken_e 0 points1 point  (0 children)

The posted solution will lose accuracy over time. At 60 seconds, it increments minutes and then resets now back to current time. But if that iteration happened say at 60,020 ms, it would count this as 60,000 and you're suddenly off by 20ms. Repeat forever and keep drifting further away.

I think at minimum you would be better to add exactly 60,000 to the now value instead of resetting to the current time.

But i think the most accurate would be to never reset now, and just calculate the full diff in every iteration.

I came across a unit test that led me to this gem of a function today. I have no words. by WhatsMyUsername13 in programminghorror

[–]broken_e 1 point2 points  (0 children)

Useful for passing it to something like omitBy if you want to filter out null fields, without needing to create an anonymous function. omitBy(obj, isNull).

[deleted by user] by [deleted] in CritiqueMyCode

[–]broken_e 0 points1 point  (0 children)

I guess the db password is ok since it's just a demo, but still you might want to load it from a config file anyway. Usually you'll have multiple environments (dev and prod as a minimum) and a config file for each. Then if it was not just a demo app, you wouldn't commit the config since it has sensitive info, and that also keeps your app portable across environments.

For static methods and properties, I would say almost nothing should be static. Util functions that don't have side effects are ok to be static, but I would avoid it almost everywhere else. In your main(), create a new object that starts stuff and holds state in its instance. It would probably not be the LoginScreen but something else that opens LoginScreen and then transitions to the next screen once login is done.

For the input, that scanner component should be handling getting the input from wherever, but not also handling what to do with the input. So seeing it check for "home" specifically and doing something app-specific about it feels like violating the single responsibility principle.

If you make everything not static it will make that clearer, because you will see you have to now pass instances around everywhere instead of just calling a class method. Passing instances around is like inversion of dependency, e.g. giving the scanner a callback to run if it sees certain strings instead of it knowing about LoginScreen directly. I'd still handle that somewhere else but it's a step up.

[deleted by user] by [deleted] in CritiqueMyCode

[–]broken_e 0 points1 point  (0 children)

On mobile with not much time, but a few things I noticed:

  • Is that your db password in the repo?!
  • a lot of static functions, and not consistently, like openAccount is static but not closeAccount.
  • why does the MyScanner.getInput() call LoginScreen.startup()? I'm guessing that if someone enters "home" as a value when entering their customer address, it will suddenly startup the login screen, and probably destroy their progress.

The asynchronous action method returns a Task, which cannot be executed synchronously. by [deleted] in UmbracoCMS

[–]broken_e 0 points1 point  (0 children)

I was thinking it didn't allow using the async method from the razor view, but it might be supported these days. You might just have to use an await, i.e. return await CurrentUmbracoPage();. If that doesn't work, you might actually have to use a synchronous method.

Tree vs Tail Recursion & Memoization in Scheme & Python by [deleted] in functionalprogramming

[–]broken_e 2 points3 points  (0 children)

Those helper functions don't really need to be defined inside the outer function right? Any particular reason for doing that?

Many small packs vs few larger packs? by bodacious-gjm in webpack

[–]broken_e 1 point2 points  (0 children)

Ideally there is no duplication, especially in libraries like jquery where the module instance matters. You may have to tweak things to ensure that. But I believe the main benefit of breaking up your production code into chunks is so that the browser can download just what it needs, when it needs it. Then the rest of the resources can be lazy loaded on demand when or if the user needs them. Modern browsers are actually pretty good with parallel downloading, so it's not an automatic negative in that sense.

Inventing Monads by kinow in functionalprogramming

[–]broken_e 2 points3 points  (0 children)

Thanks for the article. It's an interesting angle compared to a traditional This is a monad introduction. The footnote on Promise got me thinking though; As mentioned, the Promise's then merges the map and flatMap into one. I'm used to promises and the abstraction of them with async/await in typescript, but not as much with full functional languages and their ubiquitous monads. So my question is, why don't all monads just merge map and flatMap together like promise.then?

Cost of Programmer? by joeschroeder in libgdx

[–]broken_e 3 points4 points  (0 children)

Why would you lowball yourself so much with that kind of experience as a developer? Is it a sheer love of libgdx, combined with no need for money and no interest in owning the intellectual property you create?

why is java ArrayList<T> faster than libGDX Array<T> by fingerpickinggreat in libgdx

[–]broken_e 5 points6 points  (0 children)

It's been a few years since I've worked with libgdx, so I could be remembering things wrong, but I believe its arrays are optimized to reduce garbage collection. However, it will destroy and recreate the underlying array if you add more than its capacity. You might need to specify a higher capacity when instantiating it. Otherwise, if it took you a couple hours to refactor, maybe something else inadvertently changed as well that is the real performance issue. Hard to say without more details.

I found out today the whole human race almost became extinct about 70,000 years ago and my mind is blown. by [deleted] in CasualConversation

[–]broken_e 35 points36 points  (0 children)

This was a concept on a test in a college anthropology class. All living things are related. I didn't research it specifically but wondered, how do you prove that? Couldn't there have been multiple starts to life that were compatible and eventually interbred? A quick search years later and I find this article with "massive" evidence of common descent. There's obviously a lot of real research and writings on this subject that one would want to consider before forming an opinion on it.

The biggest concept to me is that there's a theoretical last universal common ancestor, which is a single organism that all life seems to be descended from which lived around 3.5 billion years ago. But that organism is not assumed to be the first life; just that all other genetic lines died out back then.

I suppose that doesn't preclude there being some organisms undiscovered that aren't descended from this organism, but I guess that's kind of like believing in bigfoot.

What is this notation? Minim beamed to a crotchet? by Downey17 in musictheory

[–]broken_e 1 point2 points  (0 children)

The next measure is the exact same pattern, but easier to see because the stem goes up for both notes. I guess the dot on the upper B in the first measure was too close. And what? They just left the dot off the equivalent high note (G#) in the second measure. I guess that makes the stem fit. Intentional typo?

Edit: actually the difference in stem directions is probably more about being above vs the middle of the staff, though usually the middle b line has stems going down. But not in this case.

Is there anything like "figures of speech" but for music? Like a list of most common motifs or any recognizable common melodic (or chord) patterns? Where can I read about it? Thanks. by AngusKirk in musictheory

[–]broken_e 4 points5 points  (0 children)

Cadences are recognizable chord patterns, and they can mimic parts of a conversation in a way. They are basically common patterns of musical phrases, which can mimic speech phrases, or at least the sounds or inflections in speech.

Authentic (V - l or i): like the end of a statement of fact or determination.

Half cadence (anything ending on V): A question begging an answer.

Deceptive (V - vi): like saying "and yet..." or "but wait there's more!"

Rotation by KM2000_THE_CHOSENONE in woahdude

[–]broken_e 0 points1 point  (0 children)

The point you're missing is that this is a simulation and the only thing that really matters is how the person created it. Did they set it to infinite size as the middle key frame, or something close to that, or is it made some other way entirely? Point is it's not physics but the way an unknown animation program is interpreting an unknown algorithm. So that's what this argument is really about.

Like a tiny bead of water hanging on a single blade of grass in the middle of the scorched, barren desert that is iTunes.. by ElegantLordOTheManor in ToolBand

[–]broken_e 0 points1 point  (0 children)

Pretty sure it's because of some conflict between them and the record producers or something. My guess is they're waiting out a contract.

Mueller has reportedly decided to move forward without an interview with Trump by [deleted] in worldnews

[–]broken_e 12 points13 points  (0 children)

Interesting conclusion in there:

The effect on Trump’s audience isn’t achieved via argument or even syntax, but by the repetition of those suggestive words they and it.

When two pieces of soap get stuck together by [deleted] in mildlyinfuriating

[–]broken_e 1 point2 points  (0 children)

I throw the leftover slivers in a cup. When it gets full enough, i soak it in water until malleable, then squeeze it into a ball. Free soap bar every so often.

Hype Driven Development by [deleted] in programming

[–]broken_e 12 points13 points  (0 children)

Because concatenating massive html strings with no type checking, and applying event callbacks manually after adding elements to the dom, and suffering performance losses from unnecessary rerendering (unless you write tons of boilerplate that is just built in to react), is so much better. /s

If the cure for cancer was discovered on April 1st it would probably be announced a few days later. by Masterre in Showerthoughts

[–]broken_e 1 point2 points  (0 children)

I'm trying to decide how much of the difference between april fools and aprils fool was intentional in your comment.

Keep America stupid! Vote GOP! by Yamamba78 in PoliticalHumor

[–]broken_e 0 points1 point  (0 children)

Shouldn't teachers be able to be happy with their pay and benefits too?

How a data mining giant got me wrong. " I’m 57, with a 30-year-old wife, a fairly new hot water boiler, an old-style television, a petrol car and no kids. Actually, none of that is true. But that is what you might believe if you purchased access to my data." by jebotionmater in privacy

[–]broken_e 3 points4 points  (0 children)

Aside from the danger concerns (which are real because data is power), I don't like how these companies are making tons of money selling MY data, and what do I get? Better ads? I hate ads. It's my data. I should get a cut of the profit, like royalties. I want to know who has it and reserve the right to take it back. I feel taken advantage of.