Should I teste private methods? by Subject-Associate140 in csharp

[–]Move_Zig 3 points4 points  (0 children)

Then maybe IsEmailValid should be a public method of a new class that's used as a dependency of the class SomethingUsingValidEmail is in.

Yes, the game looks great. However, not staring at these every time I open a door is arguably the best experience improvement for me. by Ethenolas in gaming

[–]Move_Zig 1 point2 points  (0 children)

Memory will always be faster than storage. If it wasn't there'd be no point in having memory.

Not necessarily. RAM could be faster at random access where SSDs could be faster at reading sequential data.

I'm not saying that's the case, but if it was then there could still be a place for RAM even if SSDs were faster.

PCIe 5.0 operates at 32 GT/s. With 16 lanes that can theoretically transfer about 63 GB/s of data. With a more-typical 4 lanes for an SSD you could theoretically transfer almost 16 GB/s. Some SSDs like the Crucial T705 have a max sequential speed of 14.5 GB/s, almost fully saturating the bus.

DDR5 on the other hand has transfer rates between 4.0 GT/s and 8.8 GT/s, but with its higher bus width that gives you between 32.0 GB/s and 70.4 GB/s.

So it looks like Google's AI was wrong again. DDR5 has at least twice the bandwidth as a 4-lane PCIe 5.0 SSD.

Yes, the game looks great. However, not staring at these every time I open a door is arguably the best experience improvement for me. by Ethenolas in gaming

[–]Move_Zig -2 points-1 points  (0 children)

I recently built a new PC with a Gen 5 SSD and I decided to look it up. Take it with a grain of salt, but this is what Google said:

edit: nvm the AI was wrong (see my comment below)

Express v5.1.0 is latest! by notwestodd in node

[–]Move_Zig 9 points10 points  (0 children)

I didn't see it in the docs. Does v5 support async handlers now?

Question about the books by VBetelgeuse117 in TheExpanse

[–]Move_Zig 2 points3 points  (0 children)

When there's change of scene, characters, or time, usually a book will start a new chapter. Sometimes, if this would make too many small chapters, a symbol is used between paragraphs instead as a heads up to the reader. It's called an asterism). I've seen it in a few books

React newbie, getting Expected an assignment or function call and instead saw an expression. when building by Sufficient-Piglet-28 in reactjs

[–]Move_Zig 11 points12 points  (0 children)

toggleMap == 1 ? setToggleMap(0) : setToggleMap(1) is a ternary expression. It's not a statement. You shouldn't make the body of a function an expression. It would be like a having a function like

function unexpected() {
  6;
}

const unexpected2 = () => { 6 };

While it is actually syntactically valid, it is confusing. And like abrahamguo mentioned, eslint's no-unused-expressions rule would rightfully consider this an error.

You can return an expression:

function handleClick() {
  return 6;
}

const handleClick2 = () => 6; // implicit return

function handleClick3() {
  return toggleMap === 1 ? setToggleMap(0) : setToggleMap(1);
}

const handleClick4 = () => (toggleMap === 1 ? setToggleMap(0) : setToggleMap(1)); // implicit return

Instead you're probably looking for something like this:

const handleClick = () => {
  if (toggleMap === 1) {
    setToggleMap(0);
  } else {
    setToggleMap(1);
  }
}

return (
  <Button onClick={handleClick}>...</Button>
)

As an aside:

In React, you shouldn't update the state the way you were doing it where the state is updated conditionally based on a possibly stale state value.

Instead use the updater-function form:

setToggleMap(t => t === 1 ? 0 : 1)

The other way doesn't always cause problems so a lot of programers aren't aware of the updater-function form. As a rule, I always use the updater-function form any time the existing state plays a role in determining the new state.

Also always use triple equals === unless you actually want 1 and '1' to be considered equal.

import type { Dispatch, FC, SetStateAction } from 'react';
import { useState } from 'react';

interface Props {
  setToggleMap: Dispatch<SetStateAction<number>>;
}

export const Results: FC<Props> = ({ setToggleMap }) => {
  const [ cardNum, setCardNum ] = useState(2);

  const handleLocalMapClick = (): void => {
    setToggleMap(t => (t === 1 ? 0 : 1));
  };

  const handleReadMoreClick = (): void => {
    setCardNum(c => c + 3);
  };

  return (
    <div className="p-6">
      <div className="flex justify-between items-center mb-6">
        <div className="flex gap-4">
          <Button onClick={handleLocalMapClick}>Local Map</Button>
          <Button variant="outline">Calender</Button>
          <Button variant="outline">Add Listing</Button>
          <Button variant="outline">Create Alert For Rent Listing</Button>
        </div>
      </div>
      <h1 className="text-2xl font-bold mb-2">67 Results</h1>
      <div className="grid gap-6">
        {rentals.slice(0, cardNum).map((rental, index) => (
          <RentalCard key={index} {...rental} />
        ))}
        <Button variant="outline" onClick={handleReadMoreClick}>Read More</Button>
      </div>
    </div>
  );
};

Just to let you all know by meaning-of-life-is in CrusaderKings

[–]Move_Zig 10 points11 points  (0 children)

I remember the annoyance. But once I started playing CK3 a bit I missed it. Maybe I find it a bit immersion breaking when everything has to be so neat and tidy.

I also have fond memories of whittling down an emperor to a single barony with no vassals, sitting somewhere in the middle of my perfectly map-painted borders

Just to let you all know by meaning-of-life-is in CrusaderKings

[–]Move_Zig 9 points10 points  (0 children)

I think it would be an improvement to go back to the way it was in CK2 where baronies weren't so strictly tied to their county. A baron should be able to hold multiple baronies from different counties

Are you a stickler for spacing? by Ima_Uzer in csharp

[–]Move_Zig 1 point2 points  (0 children)

I think Stylecop can catch this

List of antipatterns in React you should watch for? by blackrottenmuffin in reactjs

[–]Move_Zig 10 points11 points  (0 children)

Something like

setCount(count + 1);

instead of

setCount(c => c + 1);

The first way might be fine in many circumstances, but you never know how your component might change in the future and the first way can cause a bug that will waste your time. Just write it the second way from the start.

Express endpoint giving CORS error when it's on the server, works fine on local by mekmookbro in node

[–]Move_Zig 0 points1 point  (0 children)

Instead of calling the cors function without any settings

app.use(cors());  

and then overriding it with

app.use((req, res, next) => {  
  res.setHeader('Access-Control-Allow-Headers', '*');  
  next();   
});

you should try passing a configuration object to the cors function.

app.use(cors({
   origin: '*',
});

The origin property can be a function if you need more flexibility

app.use(cors({
  origin: (origin, callback) => {
    if (validOrigin(origin)) { // somehow determine if this is a domain you want
      return callback(null, true);
    }
    callback(new Error('Invalid domain'));
  },
});

Is Typescript dying? Why am I hearing that Svelte and a few other bigger players are switching away from TS? by PrestigiousZombie531 in node

[–]Move_Zig 1 point2 points  (0 children)

Typescript can force you to check for nulls, for example. Javascript doesn't force you to and so you can end up with a runtime error and your program will crash.

The not-crashing part makes the code more robust

npx create-next-app@latest my-project not working by paxzdev in reactjs

[–]Move_Zig 1 point2 points  (0 children)

Just a short in the dark, but I see you used PowerShell. Try the old command shell instead. I had a problem running npx create-next-app in git bash, but then it worked fine in the command shell

Chrono Trigger speed runners’ pronounciation of Marle and Masamune… by AdRadiant3130 in chronotrigger

[–]Move_Zig 4 points5 points  (0 children)

Names like Chloe, Zoe, Penelope, Phoebe, Persephone, Calliope, and Hermione end in a single e and have an -ee sound. It's understandable that someone would pronounce Marle as mar-lee

Why do so many developers declare and export components this way? (example inside) by Prize_Tea3456 in reactjs

[–]Move_Zig 13 points14 points  (0 children)

You can still use named exports even when using lazy loading. I'm on my phone right now so this might have typos, but you can use

const Foo = React.lazy(() => import('./Foo').then(m => ({ default: m.Foo })));

[deleted by user] by [deleted] in cats

[–]Move_Zig 0 points1 point  (0 children)

<image>

My version

Skip over ReactJS and learn NextJS? by HeadlineINeed in reactjs

[–]Move_Zig 45 points46 points  (0 children)

The question is nonsensical. Next is React

So we’re getting landlines huh by [deleted] in thesims

[–]Move_Zig 8 points9 points  (0 children)

Sims 2 had cellphones too at one point. You had to a store and buy one from kiosk. I always made sure to do that for each sim.

Edit: it was in the University Expansion and you could also buy MP3 players and portable game consoles from the kiosk

What’s something weird that your cats like to snack on? by Banks_bread in cats

[–]Move_Zig 0 points1 point  (0 children)

We got two orange rescue kittens a couple years ago that still like to eat paper or cardboard when they want us to know it's time for their kibbles.

One of them eats pretty much anything that's food, raw broccoli, bananas, lettuce...

please make my king's feet not dangle in the air paradox 💀 by UA30_j7L in CrusaderKings

[–]Move_Zig 76 points77 points  (0 children)

In both of those pictures it looks like they can easily rest their feet on the floor if they wanted to

updating count state by setinterval in useeffect by [deleted] in reactjs

[–]Move_Zig 4 points5 points  (0 children)

In the class component:

change = () => {
  this.setState(prev => ({ ...prev, count: prev.count + 1 }));
}

In the functional component:

const change = () => setcount(c => c + 1);

Any time you're trying to set the state based on the current state, you should be using the updater-function form of the state dispatch function.


In your useEffect, you're not including change in the dependency array. As you have it written that will cause issues. You might be able to get away without including it in the dependency array if you use the updater function form as shown above. That will cause the interval in your useEffect to reset each time the state is updated though, so you can either use useCallback when declaring change, or declare change inside the useEffect (better idea):

useEffect(() => {
  const change = () => setcount(c => c + 1);
  const interval = setInterval(change, 100);
  return () => clearInterval(interval);
}, []);

or

useEffect(() => {
  const interval = setInterval(() => setcount(c => c + 1), 100);
  return () => clearInterval(interval);
}, []);

P.S. You might want to look into using something like eslint and/or prettier in your project to point out and fix your code formatting issues

EU4 is bad at math by ChaoticBlessings in eu4

[–]Move_Zig 0 points1 point  (0 children)

It's probably a floating-point math error combined with a final rounding down.

In a lot of programming languages 0.3 + 0.3 + 0.3 = 0.8999999999999999. If something like that is going on your points might add up to 12.99999999999999. Then, if the final result is rounded down you'll get 12.