Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
nielsm
Jun 1, 2009



ViggyNash posted:

Ok, I did that and now it compiles, but when I run the program it can't find the dll. I tried registering it, but it just reports a problem about the dllregisterserver. What reason would cause a problem with registering a dll?

"Registering" a libraries on Windows is only a COM thing, which is rather specific. If the library isn't a COM thing it doesn't make any sense to attempt to register it.

Instead, place the DLL file somewhere the executable loader can actually find it:
1. Best location, same directory as the EXE file
2. Bad location, the Windows System directory
3. Poor location, the current directory
4. Bad location, some other directory listed on the PATH environment var

2 is bad because you shouldn't be placing things inside the Windows System directory, that's only for internal use.
3 is poor, because if you're going to distribute your program you can't necessarily control what the current directory will be very well. (And it's easier to just place it in the same dir as the EXE file anyway.) It can be acceptable for your own testing while developing, if you don't want to have multiple copies of the DLL around.
4 is bad because either you have to assume something about what directories are on PATH, or you have to modify PATH.

Adbot
ADBOT LOVES YOU

ViggyNash
Oct 9, 2012
I had put the dll where I thought the exe was, but I guess it wasn't the right place and I assumed that wouldn't work. I dumped a copy into each folder and subfolder I could find within the project and it seems one of them was right because the program works now. Thanks for the help.

raminasi
Jan 25, 2005

a last drink with no ice
You can use Process Monitor to watch a program as it searches for DLLs it needs. I've used it several times to solve this kind of problem in the past.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
Is there any way to plop a single push or pop into a 64 bit program with Visual Studio? As far as I know there's no way to do 64 bit inline assembly or specify naked calling. I know there's no good reason to do this, but I wanna do it anyways.

ToxicFrog
Apr 26, 2008


hooah posted:

Why do most command-line utilities use either a dash or slash to precede switch arguments? Is that just to differentiate switches from other kinds of arguments?

The existence of the prefix in general is to differentiate switches from other kinds of arguments, yes. The exact character used depends on historical convention; DOS and windows use / and *nix uses - and --. From a programming perspective, it's easier to parse, and from an end user perspective, it makes it obvious on reading which arguments have special meaning to the program.

On Linux, at least, the conventions are actually fairly well nailed down these days:
- single-character switches use a single dash, such as "-r" or "-a"
- you can (usually) combine these, if they don't take arguments: "-ra" is the same as "-r -a"
- longer switches use a double dash, such as "--recurse" or "--archive"
- "--output filename" and "--output=filename" are synonymous, as are "-o filename" and "-ofilename"
- "--" on its own means "stop looking for switches and process everything after this as a plain argument, even if it looks like a switch"

There are still plenty of programs around that don't follow these conventions, though. "find" uses single-dash exclusively, so "find -name" instead of "find --name"; "dd" doesn't use prefixes at all, instead going with a key=value system ("dd if=/dev/zero of=/dev/sda") for everything.

Peristalsis
Apr 5, 2004
Move along.

ToxicFrog posted:

The existence of the prefix in general is to differentiate switches from other kinds of arguments, yes. The exact character used depends on historical convention; DOS and windows use / and *nix uses - and --. From a programming perspective, it's easier to parse, and from an end user perspective, it makes it obvious on reading which arguments have special meaning to the program.

On Linux, at least, the conventions are actually fairly well nailed down these days:
- single-character switches use a single dash, such as "-r" or "-a"
- you can (usually) combine these, if they don't take arguments: "-ra" is the same as "-r -a"
- longer switches use a double dash, such as "--recurse" or "--archive"
- "--output filename" and "--output=filename" are synonymous, as are "-o filename" and "-ofilename"
- "--" on its own means "stop looking for switches and process everything after this as a plain argument, even if it looks like a switch"

There are still plenty of programs around that don't follow these conventions, though. "find" uses single-dash exclusively, so "find -name" instead of "find --name"; "dd" doesn't use prefixes at all, instead going with a key=value system ("dd if=/dev/zero of=/dev/sda") for everything.

Thank you (ahd hooah) - that's something I've been wondering about lately, but haven't bothered to research.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

ToxicFrog posted:

The existence of the prefix in general is to differentiate switches from other kinds of arguments, yes. The exact character used depends on historical convention; DOS and windows use / and *nix uses - and --. From a programming perspective, it's easier to parse, and from an end user perspective, it makes it obvious on reading which arguments have special meaning to the program.

On Linux, at least, the conventions are actually fairly well nailed down these days:
- single-character switches use a single dash, such as "-r" or "-a"
- you can (usually) combine these, if they don't take arguments: "-ra" is the same as "-r -a"
- longer switches use a double dash, such as "--recurse" or "--archive"
- "--output filename" and "--output=filename" are synonymous, as are "-o filename" and "-ofilename"
- "--" on its own means "stop looking for switches and process everything after this as a plain argument, even if it looks like a switch"

There are still plenty of programs around that don't follow these conventions, though. "find" uses single-dash exclusively, so "find -name" instead of "find --name"; "dd" doesn't use prefixes at all, instead going with a key=value system ("dd if=/dev/zero of=/dev/sda") for everything.

It's worth pointing out that there is nothing enforcing any of this except convention, which is why you do get those differences from time to time. Every C program (other languages are similar) starts with

C++ code:
int main(int argc, char **argv)
Which gives you the number of arguments and an array of strings which was constructed from the entire command (including the name of the command) split on the space character (so ["clang", "-o", "butts", "butts.c"]. It's up to you to make sense of what you get on the other side, and if for some reason it made perfect sense to have your users prefix your switches with BUTTS then that's what you would look for.

ExcessBLarg!
Sep 1, 2001

carry on then posted:

It's worth pointing out that there is nothing enforcing any of this except convention,
Well, there's the libc getopt (POSIX) and getopt_long (GNU) functions, so most programs aren't implementing this behavior entirely from scratch either. Would be a lot worse if everyone did.

qntm
Jun 17, 2009

ToxicFrog posted:

The existence of the prefix in general is to differentiate switches from other kinds of arguments, yes. The exact character used depends on historical convention; DOS and windows use / and *nix uses - and --. From a programming perspective, it's easier to parse, and from an end user perspective, it makes it obvious on reading which arguments have special meaning to the program.

On Linux, at least, the conventions are actually fairly well nailed down these days:
- single-character switches use a single dash, such as "-r" or "-a"
- you can (usually) combine these, if they don't take arguments: "-ra" is the same as "-r -a"
- longer switches use a double dash, such as "--recurse" or "--archive"
- "--output filename" and "--output=filename" are synonymous, as are "-o filename" and "-ofilename"
- "--" on its own means "stop looking for switches and process everything after this as a plain argument, even if it looks like a switch"

There are still plenty of programs around that don't follow these conventions, though. "find" uses single-dash exclusively, so "find -name" instead of "find --name"; "dd" doesn't use prefixes at all, instead going with a key=value system ("dd if=/dev/zero of=/dev/sda") for everything.

Wait so does "-ofile" become "-o file" or "-o -f -i -l -e"?

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 🙏
Taco Defender

qntm posted:

Wait so does "-ofile" become "-o file" or "-o -f -i -l -e"?

depends whether '-o' takes an argument

omeg
Sep 3, 2012

GrumpyDoctor posted:

You can use Process Monitor to watch a program as it searches for DLLs it needs. I've used it several times to solve this kind of problem in the past.

Or use GFlags and enable "Show loader snaps" flag for the executable. Then you can use a debugger or DebugView to see loader's diagnostic output.

This can also help understand why some DLLs fail to load.
code:
0614:06c4 @ 12725329 - LdrpRunInitializeRoutines - ERROR: Init routine 0000000077256B88 for DLL "C:\Windows\system32\USER32.dll" failed during DLL_PROCESS_ATTACH
0614:06c4 @ 12725329 - LdrpInitializeProcess - ERROR: Running the init routines of the executable's static imports failed with status 0xc0000142

omeg fucked around with this message at 15:06 on Jul 1, 2015

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED
Not very programming related but since I don't know where else to post computer science questions --

Does anyone have recommendations for books on logic? I found these, not sure which one is best though.

http://www.amazon.com/Mathematical-Logic-exercises-Propositional-Completeness/dp/0198500483
http://www.amazon.com/Logic-Computer-Science-Modelling-Reasoning/dp/052154310X
http://www.amazon.com/Mathematical-Computer-Science-Mordechai-Ben-Ari/dp/1447141288

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
The only thing I can tell you is that I like the organization and physical size of the Springer books I've read, but the cover of that second one is too funny to not mention.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

dougdrums posted:

The only thing I can tell you is that I like the organization and physical size of the Springer books I've read, but the cover of that second one is too funny to not mention.

The only word for that is Preposterous.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Pie Colony posted:

Not very programming related but since I don't know where else to post computer science questions --

Does anyone have recommendations for books on logic? I found these, not sure which one is best though.

http://www.amazon.com/Mathematical-Logic-exercises-Propositional-Completeness/dp/0198500483
http://www.amazon.com/Logic-Computer-Science-Modelling-Reasoning/dp/052154310X
http://www.amazon.com/Mathematical-Computer-Science-Mordechai-Ben-Ari/dp/1447141288

Why are you trying to learn logic and what's your math background look like?

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED
I don't know, just seems like a cool field and like it has some interesting applications to computer science. I liked the math classes I took as pre-reqs for CS but didn't take any classes outside of those. Now that I'm out of school I occasionally work through textbooks when I have time.

Hadlock
Nov 9, 2004

When you guys write something new from scratch, do you just hammer out some giant awful mess of one or two original files + some helper libraries until it's working, and then refactor about half the code in to a bunch of separate maintainable files, or; do you know better to use all of the correct programming practices from the start? I've gotten better knowing how I want to structure a series of functions and methods but I still end up refactoring big chunks of it for efficiency later on I've noticed. I haven't written anything over about 3000 lines of code though.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Hadlock posted:

When you guys write something new from scratch, do you just hammer out some giant awful mess of one or two original files + some helper libraries until it's working, and then refactor about half the code in to a bunch of separate maintainable files, or; do you know better to use all of the correct programming practices from the start? I've gotten better knowing how I want to structure a series of functions and methods but I still end up refactoring big chunks of it for efficiency later on I've noticed. I haven't written anything over about 3000 lines of code though.

Any time I need to do something that could be described discretely and requires more than 3 lines of code, I'm at the very least spinning it into its own function.

Sometimes you don't realize something fits that bill until you realize you've coded it three different ways in the same program though.

Shaocaholica
Oct 29, 2002

Fig. 5E
Does it add any value to compare file size along with hashes for determining if multiple files are the same using a relatively strong hash? Seems like it would be faster to compare size first and if that even passes then compare the hashes. No reason to even bother computing the hash if the size is different.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Shaocaholica posted:

Does it add any value to compare file size along with hashes for determining if multiple files are the same using a relatively strong hash? Seems like it would be faster to compare size first and if that even passes then compare the hashes. No reason to even bother computing the hash if the size is different.

Yes, that's definitely an optimization. The file system has precomputed the size for you, so you have a very small constant look up time.

mobby_6kl
Aug 9, 2009

by Fluffdaddy

LeftistMuslimObama posted:

Any time I need to do something that could be described discretely and requires more than 3 lines of code, I'm at the very least spinning it into its own function.

Sometimes you don't realize something fits that bill until you realize you've coded it three different ways in the same program though.

What I sometimes observe is that if I do split things out and try to organize everything early, it turns out to be suboptimal later anyway :negative:

Shaocaholica posted:

Does it add any value to compare file size along with hashes for determining if multiple files are the same using a relatively strong hash? Seems like it would be faster to compare size first and if that even passes then compare the hashes. No reason to even bother computing the hash if the size is different.

Yeah I see no reason for always doing both unless you are deliberately hashing similar documents identically somehow, which you say you aren't.

fritz
Jul 26, 2003

Hadlock posted:

When you guys write something new from scratch, do you just hammer out some giant awful mess of one or two original files + some helper libraries until it's working, and then refactor about half the code in to a bunch of separate maintainable files, or; do you know better to use all of the correct programming practices from the start? I've gotten better knowing how I want to structure a series of functions and methods but I still end up refactoring big chunks of it for efficiency later on I've noticed. I haven't written anything over about 3000 lines of code though.

If the right thing to do is easy, I'll do that, and if I'm doing something haram I'll try to do it in a way that I won't hate myself too much for next week.

Hadlock
Nov 9, 2004

So my object "Jet" has many properties, but a couple of them are going to be queried frequently; in particular these three:

-arrival
-departure
-hold

Is it better to create a single property as a string or int (
[string] Jet.status = "arrival"/"departure"/"hold" -- or --
[int] Jet.status = 0 / 1 / 2 )

Or should I set each property as a bool (
[bool] Jet.arrival = 0,
[bool] Jet.departure = 1,
[bool] Jet.hold = 0 )

Orrr since arrival/departure are standard and "hold" is kind of the exception state, two Bools,
[bool] Jet.status = 0 / 1,
[bool] Jet.hold = 0 / 1

The problem I have with the last setup is that I have to remember if arrival = 1 or 0 and vice versa, and trying to keep track of that definition when debugging this sounds like nightmare fuel as there's no obvious 0 or 1 analog.

Hadlock fucked around with this message at 09:29 on Jul 5, 2015

Loezi
Dec 18, 2012

Never buy the cheap stuff

Hadlock posted:

So my object "Jet" has many properties, but a couple of them are going to be queried frequently; in particular these three:

-arrival
-departure
-hold

Is it better to create a single property as a string or int (
[string] Jet.status = "arrival"/"departure"/"hold" -- or --
[int] Jet.status = 0 / 1 / 2 )

Or should I set each property as a bool (
[bool] Jet.arrival = 0,
[bool] Jet.departure = 1,
[bool] Jet.hold = 0 )

Orrr since arrival/departure are standard and "hold" is kind of the exception state, two Bools,
[bool] Jet.status = 0 / 1,
[bool] Jet.hold = 0 / 1

The problem I have with the last setup is that I have to remember if arrival = 1 or 0 and vice versa, and trying to keep track of that definition when debugging this sounds like nightmare fuel as there's no obvious 0 or 1 analog.

Are these states exclusive, in that the jet can only live in one of these states at a point in time? If yes, I'd suggest using enums. If your language lacks them, I'd do something like this:

code:
// Example in Java

public class Jet {

  public class JetStatus {
    public static final int ARRIVAL = 1;
    public static final int DEPARTURE = 2;
    public static final int HOLD = 3;
  }

  private int status;

  //...

  public void setStatus(int status) {
    this.status = status;
  }

  public int getStatus() {
    return this.status;
  }
}

public class whatEver {
  Jet jet = new Jet();
  Jet.setStatus(JetStatus.ARRIVAL);

  if (jet.getStatus() == JetStatus.HOLD) {
    // OH Noes!
  }

Hadlock
Nov 9, 2004

Yes, enums is exactly what I was looking for, thanks! Since I only had three elements I started googling for qubits and trinary variables which led me down the wrong path I think. Thanks for understanding, translating and answering the question I didn't know how to ask :)

feedmegin
Jul 30, 2008

ToxicFrog posted:

The existence of the prefix in general is to differentiate switches from other kinds of arguments, yes. The exact character used depends on historical convention; DOS and windows use / and *nix uses - and --.

Caveat ; -- and long arguments are specifically a GNU extension (and GNU is, of course, not UNIX). Old-school commercial UNIX utilities only have the single-letter options with one dash. Generally GNU versions of standard utilities will support both a single-letter version of each option (for compatibility with UNIX) and a more readable -- version; e.g. -v and --verbose tend to mean the same thing.

Disharmony
Dec 29, 2000

Like a hundred crippled horses lying crumpled on the ground

Begging for a rifle to come and put them down
More of a WP question but can anyone help me find the pagination and next link selector from my theme's CSS code?

http://urlgone.com/b263a6/

Boz0r
Sep 7, 2006
The Rocketship in action.
I've got a bunch of data structure classes in one project, and a deleter class in another project. All these classes should be deleted in different ways, and right now the deleter class has an ugly method where it tests the type of the class given, and calls another delete function in the deleter class. I can't implement a delete method on the data structure class, so how should I do this in a neat way?

baquerd
Jul 2, 2007

by FactsAreUseless

Boz0r posted:

I've got a bunch of data structure classes in one project, and a deleter class in another project. All these classes should be deleted in different ways, and right now the deleter class has an ugly method where it tests the type of the class given, and calls another delete function in the deleter class. I can't implement a delete method on the data structure class, so how should I do this in a neat way?

What does "delete" mean in this context? What language are you using? There's a bit of a difference if you're talking about freeing memory in C++ or implementing your own ORM in Python.

Boz0r
Sep 7, 2006
The Rocketship in action.
This is in C#, but the delete functions do a lot of stuff. I'm looking for a sort of design pattern or something.

nielsm
Jun 1, 2009



Why does an object not know how to delete itself? Why is it a separated out responsibility? Is there ever a case where two different classes need the same deleter?

If you really want a pattern I think what you're aiming for is some sort of Strategy Pattern, where you'd have a Deletion Strategy for each object. That becomes Extremely Enterprise and massive overkill, and most likely misuse.

To me it sounds like "separation of responsibilities" taken several steps too far.

Maybe look up the role of IDisposable in .NET land.

Boz0r
Sep 7, 2006
The Rocketship in action.
When the objects are deleted, they delete some appropriate files and directories. I didn't design this mess, I'm just trying to clean it up a bit, but I've been told that I can't implement delete methods on the data structure classes because they can't access file functionality.

ToxicFrog
Apr 26, 2008


qntm posted:

Wait so does "-ofile" become "-o file" or "-o -f -i -l -e"?

Depends on whether -o takes an argument! If it does, it's "-o file". If it doesn't, it's "-o -f -i -l -e".

If -o doesn't take an argument but -f does, it becomes "-o -f ile".

This is why I pretty much always include the space when writing my scripts.

nielsm
Jun 1, 2009



Eh okay. Some kind of Strategy Pattern is probably the best way to handle it. The Deleter code might be able to be restructured in a nicer way using the dynamic dispatch features introduced in C# 4.0.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Boz0r posted:

When the objects are deleted, they delete some appropriate files and directories. I didn't design this mess, I'm just trying to clean it up a bit, but I've been told that I can't implement delete methods on the data structure classes because they can't access file functionality.

Can't access file functionality for actual technical reasons, or because the person who told you to do this is an idiot? If an object's responsibility, on deletion, is to delete some files, it should absolutely be that object's responsibility to delete files. If for some reason they know the filenames but aren't allowed to touch the file system, have them pass a list of files to be deleted to a method or class that is allowed to delete files.

raminasi
Jan 25, 2005

a last drink with no ice

Boz0r posted:

I've got a bunch of data structure classes in one project, and a deleter class in another project. All these classes should be deleted in different ways, and right now the deleter class has an ugly method where it tests the type of the class given, and calls another delete function in the deleter class. I can't implement a delete method on the data structure class, so how should I do this in a neat way?

You can use dynamic for this. Instead of manually introspecting types, cast objects to dynamic so that dynamic dispatch can send them to an appropriate overload in the deleter.

C# code:
private void Delete(DataStructureA obj);
private void Delete(DataStructureB obj);
private void Delete(DataStructureC obj);

public void Delete(DataStructureBase obj)
{
    Delete((dynamic)obj);
}

nielsm
Jun 1, 2009



GrumpyDoctor posted:

You can use dynamic for this. Instead of manually introspecting types, cast objects to dynamic so that dynamic dispatch can send them to an appropriate overload in the deleter.

C# code:
private void Delete(DataStructureA obj);
private void Delete(DataStructureB obj);
private void Delete(DataStructureC obj);

public void Delete(DataStructureBase obj)
{
    Delete((dynamic)obj);
}

Perhaps use different names for the public wrapper and the private implementations, just to avoid an infinite recursion if you manage to call Delete with an unhandled subclass.

TheresaJayne
Jul 1, 2011

LeftistMuslimObama posted:

Can't access file functionality for actual technical reasons, or because the person who told you to do this is an idiot? If an object's responsibility, on deletion, is to delete some files, it should absolutely be that object's responsibility to delete files. If for some reason they know the filenames but aren't allowed to touch the file system, have them pass a list of files to be deleted to a method or class that is allowed to delete files.

I was going to say this ....

The classes delete themselves but if they have to call FileManager.deleteFiles(List<File>) Then so be it.

of course if you have a collection of objects you want to clear then you iterate calling delete() on each entry.

The current way sounds like coding i did when i was 11 years old

TheresaJayne fucked around with this message at 10:22 on Jul 7, 2015

pram
Jun 10, 2001
Does anyone have any hot tips for cache invalidation. I'm currently using redis to cache some json, it works like this:

pre:
request -> is the key there -> yes -> serve key
                       |
                       V
                       no -> hit database -> serialize and put json in redis -> serve key

update -> delete key
It's simple, but it's also kind of a pain in the rear end. I have to manually keep track of the relationship between keys when they're updated. Updating one thing might change 3 other things, so those keys need to be deleted as well. Basically the GET part works really well, but the DELETE part sucks.

Maybe it would be better to use a document store or something for the serialized data?

Adbot
ADBOT LOVES YOU

csammis
Aug 26, 2003

Mental Institution
It sounds like you're describing a situation where you update object X, object X's update also changes "other things" behind the scenes, and then object X is left holding the bag for those other things' key deletion.

Instead of doing updates behind the scenes you should go through your own API for updates. Your API for updating an object already has logic to delete the relevant key xo problem solved. If going through your API is complicated when you're already "in" your API then it's probably time to factor out some business logic so it can be called in multiple ways.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply