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
sarehu
Apr 20, 2007

(call/cc call/cc)

22 Eargesplitten posted:

I'm trying to start unit testing, and I'm not sure what to use for my test cases. Should I figure out the possible cases for each button the user could push, and then test each one of those? Or am I making more work for myself than I need to?

Follow your intuitive sense for what mitigates the most risk for the least amount of work.

Adbot
ADBOT LOVES YOU

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line
I'm working on a personal project for my portfolio, something to show developers as I don't have much work experience; part of this project involves a fair amount of text manipulation by the user, and as such I'm in the process of implementing undo and redo stacks - something I haven't done before in a project. The approach I've taken is to, when a user performs an operation that changes any textual element, push a node on to the undo stack that contains an opcode, the original text values that are going to be changed (and ONLY those text values), positional data, and a boolean 'more' flag in case I want the undo/redo operation to affect multiple items in the stack. Performing the undo operation will likewise generate a node (or series of nodes) which are pushed onto the redo stack, and vice-versa when the redo operation is performed.

My question is this: what is an ideal way to handle a user performing a new operation while items are on the redo stack? Should those items be dumped? This seems to be how some text editors (this is not what I'm making) handle things like this.

JawKnee fucked around with this message at 19:47 on Feb 2, 2016

Star War Sex Parrot
Oct 2, 2003

The one time I was tasked with writing a text editor, yeah I believe that's what I did. Any time a new command was generated, the redo stack got flushed.

That behavior seems relatively standard.

Star War Sex Parrot fucked around with this message at 19:47 on Feb 2, 2016

raminasi
Jan 25, 2005

a last drink with no ice
I can't think of a redo stack I've used that didn't behave that way.

raminasi fucked around with this message at 01:07 on Feb 3, 2016

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line
Cheers. I'm mostly concerned with implementing behaviour the user expects to see, so if that's typical then that's great.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
People have tried to implement branching undo (e.g. there's a vim plugin for it), but no one's figured out a UI for it that makes it actually useable.

TheresaJayne
Jul 1, 2011
I would say you need to be careful with what you class as an undo / redo node. For instance if you stored 100 undo nodes and you tracked each letter as its own node you would lose a lot of the undoability.
Most people implement typing (any amount) as one node.so undo undoes the last section of writing.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

TheresaJayne posted:

I would say you need to be careful with what you class as an undo / redo node. For instance if you stored 100 undo nodes and you tracked each letter as its own node you would lose a lot of the undoability.
Most people implement typing (any amount) as one node.so undo undoes the last section of writing.

I've noticed that most text editors will start a new undo context when you start a new line. So if you type "foo bar" an undo will remove the whole thing, no matter how long you take to type it. However, if you type "foo<return>bar" it only undoes "bar".

Visual Studio also has some more sophisticated rules. For instance if I'm in a C# file and type "public void" and then Ctrl+Z it only removes "void". On the other hand if I type "public foo bar" and undo it removes "foo bar". It looks like it creates a checkpoint of sorts every time you type something syntactically valid.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



LOOK I AM A TURTLE posted:

I've noticed that most text editors will start a new undo context when you start a new line. So if you type "foo bar" an undo will remove the whole thing, no matter how long you take to type it. However, if you type "foo<return>bar" it only undoes "bar".

Visual Studio also has some more sophisticated rules. For instance if I'm in a C# file and type "public void" and then Ctrl+Z it only removes "void". On the other hand if I type "public foo bar" and undo it removes "foo bar". It looks like it creates a checkpoint of sorts every time you type something syntactically valid.

StackOverflow on the other hand seems to override the browser's undo/redo functionality with really lovely over-aggressive node combining that makes it nearly useless. Just checkpoint/combine on word boundaries at most. Don't be Stack Overflow.

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line

TheresaJayne posted:

I would say you need to be careful with what you class as an undo / redo node. For instance if you stored 100 undo nodes and you tracked each letter as its own node you would lose a lot of the undoability.
Most people implement typing (any amount) as one node.so undo undoes the last section of writing.

Luckily this is how my program is handling it by default, though that is more because it isn't in any way a text editor (In abstract the program involves a linked list where each partition in the list contains a vector<string>, and those strings can be operated on, with only operations that change those partitions being considered for undo/redo).

Now another, possibly frustratingly vague question; I'm nearing the point where I want to do an initial release of this program, in such a way that anyone can download, and fairly easily run it. I understand this means each new user will have to compile and link the code to any libraries or files I've included, but I've never had to do this before nor been taught how to go about it. I think I should I be packaging not only my own files and any custom libraries I'm using, but also any libraries that may only be included in development environments (as DLLs?) along with some sort of script to handle the compiling and linking for the user. Is this correct?

raminasi
Jan 25, 2005

a last drink with no ice

JawKnee posted:

Luckily this is how my program is handling it by default, though that is more because it isn't in any way a text editor (In abstract the program involves a linked list where each partition in the list contains a vector<string>, and those strings can be operated on, with only operations that change those partitions being considered for undo/redo).

Now another, possibly frustratingly vague question; I'm nearing the point where I want to do an initial release of this program, in such a way that anyone can download, and fairly easily run it. I understand this means each new user will have to compile and link the code to any libraries or files I've included, but I've never had to do this before nor been taught how to go about it. I think I should I be packaging not only my own files and any custom libraries I'm using, but also any libraries that may only be included in development environments (as DLLs?) along with some sort of script to handle the compiling and linking for the user. Is this correct?

What platform(s) are you releasing for, and are you targeting other developers (i.e. people who will be using your product to build larger pieces of software) or end-users?

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line
end-users and I'm aiming for desktop platforms (so Windows 7 and later, and the main Unix platforms - although I haven't had a chance to test on any OS-X machines yet)

ToxicFrog
Apr 26, 2008


JawKnee posted:

Now another, possibly frustratingly vague question; I'm nearing the point where I want to do an initial release of this program, in such a way that anyone can download, and fairly easily run it. I understand this means each new user will have to compile and link the code to any libraries or files I've included, but I've never had to do this before nor been taught how to go about it. I think I should I be packaging not only my own files and any custom libraries I'm using, but also any libraries that may only be included in development environments (as DLLs?) along with some sort of script to handle the compiling and linking for the user. Is this correct?

Unless your program is intended specifically for use by developers -- ideally, developers who are already using the language and toolset your program needs to build -- distributing it as source is nowhere near "anyone can download and fairly easily run it". The minimum threshold for that is usually "a zip or tar.xz files that contains everything you need to run the program in precompiled form, just unzip and run". Extra credit is "an installer or deb/rpm file that lets people install and uninstall the program properly".

E: for windows, this generally means the zip needs to contain your program EXE + all DLLs it needs in order to run

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line

ToxicFrog posted:

Unless your program is intended specifically for use by developers -- ideally, developers who are already using the language and toolset your program needs to build -- distributing it as source is nowhere near "anyone can download and fairly easily run it". The minimum threshold for that is usually "a zip or tar.xz files that contains everything you need to run the program in precompiled form, just unzip and run". Extra credit is "an installer or deb/rpm file that lets people install and uninstall the program properly".

E: for windows, this generally means the zip needs to contain your program EXE + all DLLs it needs in order to run

Okay, that's helpful, thank you. I haven't been in a position to do this before, so I'm kind of picking it up as I go.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

What's the future for JS engines in browsers?

I don't really know much about how they work, but I remember a lot of articles and the like when stuff like V8 and the monkey engines came out. So, whats the future hold? Are there any big theoretical technologies to come out or is a matter of no one has figured out the next big thing?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
ES6 support and WebAssembly are the next major things.

JawnV6
Jul 4, 2004

So hot ...
lol

quote:

Q: Doesn’t this mean other languages will take over? Won’t this cause fragmentation?
A: JavaScript has always had strong competition on the server side and in embedded programming for small hardware and robots, but in spite of many existing, viable alternatives with established package ecosystems and lots of trained developers, Node is still taking over startup and enterprise web servers at a torrential pace.
I'll admit it's pretty hard to choose between JavaScript and lesser languages for my hard real time embedded codings.

The Laplace Demon
Jul 23, 2009

"Oh dear! Oh dear! Heisenberg is a douche!"

There's already a ridiculous number of languages that compile to JavaScript as is. A low-level bytecode designed for that makes sense.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Thermopyle posted:

What's the future for JS engines in browsers?

I don't really know much about how they work, but I remember a lot of articles and the like when stuff like V8 and the monkey engines came out. So, whats the future hold? Are there any big theoretical technologies to come out or is a matter of no one has figured out the next big thing?

Microsoft recently open sourced their new JS Engine (Chakra), and has also made it (or almost done) work with Node.js.

feedmegin
Jul 30, 2008

ToxicFrog posted:

Unless your program is intended specifically for use by developers -- ideally, developers who are already using the language and toolset your program needs to build -- distributing it as source is nowhere near "anyone can download and fairly easily run it".

Ehhh, to this day it's not totally unusual for projects intended for Linux or Unix end-users - not programmers - to do source releases. Most Linux users should be conversant with ./configure ; make ; make install. Windows or Mac not so much, not least because your installation instructions then become 'First, download Visual Studio/Xcode'...

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

feedmegin posted:

Ehhh, to this day it's not totally unusual for projects intended for Linux or Unix end-users - not programmers - to do source releases. Most Linux users should be conversant with ./configure ; make ; make install. Windows or Mac not so much, not least because your installation instructions then become 'First, download Visual Studio/Xcode'...

I don't think it's some above and beyond thing to include .deb/.rpm installers for software. There's more to installing an application than just spitting out a binary.

ExcessBLarg!
Sep 1, 2001

feedmegin posted:

Ehhh, to this day it's not totally unusual for projects intended for Linux or Unix end-users ... to do source releases.
For the time investment it takes to figure out how to make a precompiled release that's tested and works on a variety of distributions, it's probably easier to just build and maintain the packages for Debian and Fedora, so users can install them directly from their package manager. Everyone else can use the source release.

fritz
Jul 26, 2003

JawnV6 posted:

I'll admit it's pretty hard to choose between JavaScript and lesser languages for my hard real time embedded codings.

Somebody dig up that article where the guy was proud of the fact that he was able to toggle a pin at speeds as high as 2kHz using javascript.

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line
Perhaps I should have mentioned that I'm using C++ for this application; if it would be better for me to take this to the C++ thread let me know - I had thought this would be more of a general question but it's seeming more and more that it isn't really.

If I'm providing precompiled headers, the rest of the code I provide will have to be compiled using the same compiler binary; this seems to indicate that I'll need to ensure the user has the right compiler (or am I misunderstanding the use of precompiled here?). How do I go about doing this? I think I need to put the requirements in a configure file, but I'm uncertain.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

ExcessBLarg! posted:

For the time investment it takes to figure out how to make a precompiled release that's tested and works on a variety of distributions, it's probably easier to just build and maintain the packages for Debian and Fedora, so users can install them directly from their package manager. Everyone else can use the source release.

If people actually use your software then someone else will do the distro packaging for you.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

JawKnee posted:

Perhaps I should have mentioned that I'm using C++ for this application; if it would be better for me to take this to the C++ thread let me know - I had thought this would be more of a general question but it's seeming more and more that it isn't really.

If I'm providing precompiled headers, the rest of the code I provide will have to be compiled using the same compiler binary; this seems to indicate that I'll need to ensure the user has the right compiler (or am I misunderstanding the use of precompiled here?). How do I go about doing this? I think I need to put the requirements in a configure file, but I'm uncertain.
Precompiled headers are just a local temporary file to speed up compilation and there's never a good reason to ship them.

JawnV6
Jul 4, 2004

So hot ...

The Laplace Demon posted:

There's already a ridiculous number of languages that compile to JavaScript as is. A low-level bytecode designed for that makes sense.
It's funny that the answer starts out "JS has competition in domains A and B," then totally drops off domain B when claiming Node's victory.

fritz posted:

Somebody dig up that article where the guy was proud of the fact that he was able to toggle a pin at speeds as high as 2kHz using javascript.
:eyepop: You're almost fast enough for a 1200bps uart.

raminasi
Jan 25, 2005

a last drink with no ice

JawKnee posted:

Perhaps I should have mentioned that I'm using C++ for this application; if it would be better for me to take this to the C++ thread let me know - I had thought this would be more of a general question but it's seeming more and more that it isn't really.

If I'm providing precompiled headers, the rest of the code I provide will have to be compiled using the same compiler binary; this seems to indicate that I'll need to ensure the user has the right compiler (or am I misunderstanding the use of precompiled here?). How do I go about doing this? I think I need to put the requirements in a configure file, but I'm uncertain.

Yeah, you don't ship a precompiled header, you just ship your project file along with your source. (The "right" way to do multiplatform source releases is with CMake, but that's a whole other toolset you'd have to learn.)

But again: You said your target audience wasn't developers, but just people who want to run the program. Shipping Windows source in this scenario is extremely unusual.

raminasi fucked around with this message at 19:54 on Feb 5, 2016

nielsm
Jun 1, 2009



JawKnee posted:

Perhaps I should have mentioned that I'm using C++ for this application; if it would be better for me to take this to the C++ thread let me know - I had thought this would be more of a general question but it's seeming more and more that it isn't really.

If I'm providing precompiled headers, the rest of the code I provide will have to be compiled using the same compiler binary; this seems to indicate that I'll need to ensure the user has the right compiler (or am I misunderstanding the use of precompiled here?). How do I go about doing this? I think I need to put the requirements in a configure file, but I'm uncertain.

Try copying just the EXE file onto another computer, one without any of your development tools installed. See if it runs fine. Otherwise figure out what to do to make it run.
If you don't have another computer handy, learn how to set up a virtual machine. VMs are a very valuable tool when working on software.

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line

GrumpyDoctor posted:

Yeah, you don't ship a precompiled header, you just ship your project file along with your source, and the "right" way to do multiplatform source releases is with CMake, but that's a whole other toolset you'd have to learn.

But again: You said your target audience wasn't developers, but just people who want to run the program. Shipping Windows source in this scenario is extremely unusual.

Right, for the Windows version using a compiled .exe which has been statically linked works (even if it is inelegant). I was referring to the approach to releasing on Linux type systems, sorry for the lack of clarity in my previous posts, and also the application was written on a Linux system, so I'm actually trying to ship to Windows from non-Windows source. I'm trying to find some resources on how to go about doing this (specifically with respect to Unix now) but I seem to be searching for the wrong things and asking the wrong questions. I've found this blog post fairly informative though I still can't quite make the jump in what the procedure is here. It seems like the user will need to compile at least some code no matter how aggressively I link libraries and push down requirements on standard libraries - and that I need to make this compilation part of the install process.

lord funk
Feb 16, 2004

If I have eight chars in an array vec, but the value represented is actually 55.0 (float). How to I get the float 55.0 out?

code:
vec[0] = 0
vec[1] = 0
vec[2] = 92
vec[3] = 66
vec[4] = 0
vec[5] = 0
vec[6] = 0
vec[7] = 0
I thought the following was on the right track, but it results in x = 23618:

code:
    for (int i=0; i<size*8; i+=8) {
        float x = vec[i] << 24 | vec[i+1] << 16 | vec[i+2] << 8 | vec[i+3];
        printf("%i:%g\n",i,x);
    }
edit: this works, and yeah it's janky because endianness

code:
        float f;
        char b[] = {vec[i], vec[i+1], vec[i+2], vec[i+3]};
        memcpy(&f, &b, sizeof(f));
        printf("%i:%g\n",i,f);

lord funk fucked around with this message at 20:25 on Feb 5, 2016

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line

nielsm posted:

Try copying just the EXE file onto another computer, one without any of your development tools installed. See if it runs fine. Otherwise figure out what to do to make it run.

This is what I did for Windows but I was under the impression this approach wouldn't work for Unix machines and I can't seem to get a straight answer on whether or not I can just port a compiled binary and have it work provided the linking is all correct (ie: all the needed libraries are either provided with the binary and linked against, or suitable versions are found on the target machine and linked against; my understanding is that the latter would require recompiling the code on the target machine, is this wrong?

nielsm
Jun 1, 2009



JawKnee posted:

This is what I did for Windows but I was under the impression this approach wouldn't work for Unix machines and I can't seem to get a straight answer on whether or not I can just port a compiled binary and have it work provided the linking is all correct (ie: all the needed libraries are either provided with the binary and linked against, or suitable versions are found on the target machine and linked against; my understanding is that the latter would require recompiling the code on the target machine, is this wrong?

In theory you can make a fully statically linked binary that depends on nothing but the kernel system call interface, that would work on any system with a compatible kernel ABI. You could also make a few more assumptions, such as the libc version and make a semi-static build, or you could even ship a tree with your own builds of various libraries. That's more or less what commercial closed-source software does, they ship a packaging of binaries for some common system configurations and anything outside those is unsupported.

In practice, the best way to go is to set up a build system that detects the system configuration and builds and links against the specific library versions found on the machine.

fritz
Jul 26, 2003

lord funk posted:


I thought the following was on the right track, but it results in x = 23618:

code:
    for (int i=0; i<size*8; i+=8) {
        float x = vec[i] << 24 | vec[i+1] << 16 | vec[i+2] << 8 | vec[i+3];
        printf("%i:%g\n",i,x);
    }

That gets the bits represented as an int32. Maybe use a union?

code:
typedef union {
   float fpart;
   int32_t ipart;
} makeFloat;

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

lord funk posted:

If I have eight chars in an array vec, but the value represented is actually 55.0 (float). How to I get the float 55.0 out?

Is there some particular reason why you're doing manual bit twiddling instead of using your language's number parsing functions? Your method is going to break as soon as you try to read an actual float rather than an integer as you're doing now. Recommend you instead construct a string from your chars and pass that to the appropriate library method depending on language (e.g. in Java it'd be Double.parseDouble(str)).

JawnV6
Jul 4, 2004

So hot ...

TooMuchAbstraction posted:

Is there some particular reason why you're doing manual bit twiddling instead of using your language's number parsing functions? Your method is going to break as soon as you try to read an actual float rather than an integer as you're doing now. Recommend you instead construct a string from your chars and pass that to the appropriate library method depending on language (e.g. in Java it'd be Double.parseDouble(str)).

He's edited in a solution, the printf was just to show what value was in x, and fritz solved the right problem the right way. How did you read an array with values 0, 92, 66, 0 as being ascii characters that represented "55.0"?

lord funk
Feb 16, 2004

I'm doing some ugly stuff with the guts of Pd (Pure Data) by exposing tables' arrays by their address. Pd is a spaghetti tangle of C structs and unions and typedefs upon typedefs with code like this:

code:
/* --------- "pure" arrays with scalars for elements. --------------- */

t_array *array_new(t_symbol *templatesym, t_gpointer *parent)
{
    t_array *x = (t_array *)getbytes(sizeof (*x));
    t_template *template;
    t_gpointer *gp;
    template = template_findbyname(templatesym);
    x->a_templatesym = templatesym;
    x->a_n = 1;
    x->a_elemsize = sizeof(t_word) * template->t_n;
    x->a_vec = (char *)getbytes(x->a_elemsize);
        /* note here we blithely copy a gpointer instead of "setting" a
        new one; this gpointer isn't accounted for and needn't be since
        we'll be deleted before the thing pointed to gets deleted anyway;
        see array_free. */
    x->a_gp = *parent;
    x->a_stub = gstub_new(0, x);
    word_init((t_word *)(x->a_vec), template, parent);
    return (x);
}
Picking it apart is headache inducing. As it turns out, the actual float array isn't a float array, but a (char *). Furthermore, the element size is 8 for some reason, not 4 like you would expect for a float.

I recognize what I'm doing with it is hacky, and not for production, just research.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

JawnV6 posted:

He's edited in a solution, the printf was just to show what value was in x, and fritz solved the right problem the right way. How did you read an array with values 0, 92, 66, 0 as being ascii characters that represented "55.0"?

Sorry, my bad: I saw "char" and leapt to thinking about strings instead of remembering that it's another term for "byte". It's Friday and I'm, evidently, more tired than I'd realized.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Fun fact about unions: writing to one field and then reading off the other is technically "undefined behaviour," even though it'll probably work in most modern compilers. Here's some random post I found on the internet which basically concludes that the memcpy solution is the best one.

Adbot
ADBOT LOVES YOU

sarehu
Apr 20, 2007

(call/cc call/cc)

lord funk posted:

If I have eight chars in an array vec, but the value represented is actually 55.0 (float). How to I get the float 55.0 out?

Use the opposite of whatever put them in that way in the first place. If you use a union or a memcpy, then your solution is platform-specific, and entirely appropriate if the behavior that put them that way was the platform-specific opposite.

Your question is really really weird because a float is 4 bytes and and an 8-byte buffer is 8 bytes (sorry). And if casting it to float is working for you, your number is not a double, because a float has 8 exponent bits but a double has 11.

The only value 4 of those bytes could possibly have would be to tell whether you should round up or down.

Edit: Oh poo poo, oh yeah okay.

quote:

code:
vec[0] = 0
vec[1] = 0
vec[2] = 92
vec[3] = 66
vec[4] = 0
vec[5] = 0
vec[6] = 0
vec[7] = 0

The four unused bytes are above the mantissa and your float is represented little-endian.

So yeah, you've got four unused bytes.

If you want to be ultra-portable you could reconstruct the value mathematically, treating the mantissa as an integer in [0, (1 << 23)), likewise get the exponent, and doing the floating point math right. And handling NaNs the right way and yuckish stuff like that.

sarehu fucked around with this message at 02:58 on Feb 6, 2016

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