/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Other urls found in this thread:

youtu.be/nZNd5FjSquk
mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html
en.wikipedia.org/wiki/Bunched_logic
discord.gg/4TuhPhr
emulator101.com/introduction-to-chip-8.html
stephendiehl.com/posts/vim_2016.html
twitter.com/SFWRedditGifs

First for Haskell.

good thread. Second for rust.

I have a long ass char array in C. How can I turn it into an array of words? Is this possible? I'm losing my mind with these seg faults and I kind of just want to switch to a different language if I can't figure this out.

How many stars do I need on my github repo in order to make it?

Make it on Python.

Yes, it is possible. Easy even.

You should probably use a different language though, unless your objective is to learn C.

array of pointers
*char[]

Protein synthesis looks mighty lewd

First, what exactly is in the long ass char array?

That's DNA transcription, not protein synthesis.

you sound like a bitch

iterate and convert?

Still hot

The Java compiler doesn't optimize until code has been run like 10k times right?

Does that somehow carry across deployments?

Some companies do like 20 releases a day. Does that mean it's all unoptimized?

Nice coloring. I've masturbated to Yuno's shorts in that pic many times in black in white, this should be a treat.

i have this function that replaces all occurences in a filename
if (string_tags.find(':') != std::string::npos)
{
std::replace( string_tags.begin(), string_tags.end(), ':', ';');
}

and these characters to replace
: ? / \ " * < > |
writing 9 IF/ELSE statements would be silly. same for making 8 || in the IF itself. is there a good way to squeeze it in one, short line of code?

This is going to sound kind of stupid, but does anyone know a good way to make an equation that fits a given set of points?

Like, find a function that fits the points (1,20), (2,5), (3,54), (4,90), and (5,32).
I don't care what the graph looks like, as long as it matches those given points.

I've tried polynomial regressions, but I tend to get lots of off by one errors if I try to fit it for more than 5 points.

>watch talk
>guy has a demeanor that makes you think he's just spitting hot air
>goes through things very quickly
>realize that he's actually describing this stuff very well
youtu.be/nZNd5FjSquk
Good talk.

Why do you check before you replace? Why don't you just replace unconditionally?

that will still give me 9 lines of code. is there no machine way?

A loop?

You can loop and declare the different replacements in an array (I'd do two, one for the symbol to be replaced and one for the replacement).

Though really what you want is to replace all the characters as you see them. 9 scans through the loop is silly.
I'm not aware of any c++ standard library functionality that does this

if you have an idea of a good looking loop, share it
yeah, i thought so

>through the loop
Through the string i mean.
>good looking
Franky I think any of these loops look like shit. If the standard library doesn't have this and I needed it I'd write my own multi-replace function.
Also I'm not an expert on the standard library by any stretch. So don't take my word for it.

I am doing some javafx gui, what is the best pane to work with from a design point of view. Something that keeps the layout uniform and symmetric? I usually put everything in vbox and hbox nests. Is there a better option?

>I'm not aware of any c++ standard library functionality that does this
Lookup table?

No. What were talking about is a function to apply to std::string that replaces occurrences of characters with another set of characters.
But it doesn't iterate through the string more than once. A lookup table can be part of the implementation.

oh well, whatever. i'll just write 9 lines

Oh, in that case I don't think there's a standard library function that does that. Does such a function exist in other languages?

or i'll just replace every occurence with the same character

I don't know of any but it's so primitive I'd expect most to have it.
I hardly ever work with strings though.
Maybe it's more of a systems programmy thing to worry about how many times you iterate through the string to do replacements and other languages just do 9 replacements.

Anyone?

I don't know math but here's a function in python. I'm sure there's some mathematical formula to match.

def f(x):
if x == 1:
return 20
if x == 2:
return 5
...

I'm not remembering well but doesn't it match exactly if you have the same amount of terms in your polynomial as you do points?
But if this is for such a small set I'm wondering why you would want this.

I remembered this now.
Might be of interest.
mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html

Yeah, that's what I'm trying to avoid.
Also,
>not using elif

It's not for a small set.
I'm trying to make a function that will print obfuscated text.

Here's some shitty code that I've been testing on:

#include
#include
using namespace std;

int main()
{
char out;

for(int i=0; i

>off by one error
>I'm using an integer type
Ah. Consider rounding instead of truncating.

Have you tried strtok?

That only helps so much.
If I use characters that are too far apart, or more than ~5 the error winds up being to much.
After all, the error has to be

>Easy even
Could you give me a basic pseudo-code or something? Because I know it's simple and I can do it in Java or something but no matter how many different variations I try on C I just can't get it. Here is a basic algorithm of what I'm trying to do:
int j = 0;
for(i = 0; i < stringSize; i++){
if(isalpha(buffer[i]))
words[j][i] = buffer[i];
else{
j++;
}

a bunch of data I collected from a web page (I'm building a web crawler)

(program name here) 1.27

i'm not the only one who does this, right? you change your version each time you modify the code, right?

Nope.
I've got (program name) WORKING and (program name) TESTING

Granted, I haven't done anything yet that really would warrant versioning, just a bunch of super simple things.

I guess there's some Japan inside us all

I'm back with my roguelike from a few days ago, I've implemented:
>monster data handling
>monsters spawning at game start
>extremely rudimentary monster AI, either sit still or wander radomly
>player killing monsters
Everything I've put in so far is really simple, but I feel like I did a decent job making things general and consistent enough so that in the future, after all this groundwork is laid, I can have fun just writing modular AI functions and plugging them into different monsters to make them behave differently. Should be the same with item behaviors eventually.

Thanks. Wish I knew this existed, yes I was googling it but somehow never found this. My issue is solved with:
//Set delmiter to white space
const char delim[2] = " ";
char *token;

//get the first token
token = strtok(buffer, delim);
//walk through other tokens
i = 0;
words[i] = token;
while(token != NULL){
i++;
words[i] = token;
token = strtok(NULL, delim);
}
words[i+1] = 0;

>tfw launched my product and already made 100k in 2 months

Am I moving too fast if I want to start learning to create GUI stuff with C++?

Started learning on and off about a month ago, but I think I'm kind of losing interest only fucking with shit in the command line

I've been looking around on Google and it seems most people seem to just recommend learning JavaFX or Javascript if I want to make more interactable stuff

What is it user?

>people still pay for software

What kind of job can 300 stars on my github repo get me? What about 1000 stars?

lol the java compiler doesn't really do any optimization.

it's the java runtime. and it's started fresh on every startup of the software package

void do_some_operation (some_big_data_container * pointer_to_big_data_container, bool some_condition, int some_index){
int my_local_variable = (*pointer_to_big_data_container)[1][some_index].yada_yada;
//....
//operations on my_local_variable
//....
(*pointer_to_big_data_container).[1][some_index].yada_yada=my_local;
};


In the above, given that it's not a recursive function, I am declaring my_local_variable just in order to have ease of reading instead of writing out (*pointer_to_some_big_data_container)[1][some_index].yada_yada several times. Is there any reason not to do this, if it is improving readability of the code?

COMPLEXITY FOR THE SAKE OF COMPLEXITY
LIFE IS A FUCK
TEN MILLION LINES OF CODE
EARTH IS 100% IDIOTS

The compiler will surely optimise out any extra copy, so it's completely fine to do that.

its JIT warmup and optimizations, something about hotspots of code that can statically analyzed to be ran multiple times in the main execution branch

just google it, it doesnt take that long especially if it never even leaves through garbage collection

ok, thank you

def f(x):
return 20 if x == 1 \
else 5 if x == 2 \
else 54 if x == 3 \
else 90 if x == 4 \
else 32 if x == 5 \
else x

Not that kind of function. I'm talking about a mathematical function.

Like f(x)=13x^3+24x^2-4x+74

See

And what was the problem with lagrange interpolation?

It's called a nonlinear piece-wise function, user. Maybe you heard about them in middleschool?

>delim " "
If you're reading sentences you'd have to get rid of all non-word text first to make this work.
For instance
strtok("Hello, this is a sentence.", " ");
Gives you back
Hello,
this
is
a
sentence.
If you wanted to get rid of the comma and period you could either replace them with space before you use strtok. Or pass them along aswell if they're not valid 'word' characters. As double delimiters don't give any output.

Why would you use elif if the first branch returns?

Linear types will save systems programming

Do we have a discord?

Linear types are fucking trash. At least use bunched implications.

>Linear types are fucking trash
why do you have this naive opinion?

Wrote my own "eso"lang, based on Reverse Polish Notation.
Factorial:
func 1 fact
: 0 = if ! 1
else : 1 - fact * end
end
5 fact prn 10 prc

Because I am familiar with other substructural logics.

en.wikipedia.org/wiki/Bunched_logic

discord.gg/4TuhPhr

Yeah that's what I did, neglected to mention but before reading all the text on a web page I first check to see if it's a letter and if it's not I put a white space into the buffer instead of a character.

where my / g o l a n g b o y s /

Anyone use Vim for Haskell? Any advice to get it set up nicely as far as plugins, macros, etc go

Who is correct? are there no such things as fast and slow languages, just better compilers? is python fast because it has numpy or doesn't that count?

If i copy some broken string like this �f]?P_˵3'8�|._o�jY� and then paste it somewhere are the bytes in those characters copy pasted correctly? Like for example if it was a password and i pasted it into the password field would it work?

That last post sums it up well, of course in a purely abstract sense there is no such thing as a fast/slow language, however in practical terms there is due to the language lending itself to optimizations, and whether the canonical implementation of the language is natively compiled, optimized, interpreted, etc.

I love CS theory, but it's fucking stupid when people go on triades about theoretical differences when it's a distraction from a discussion about practicalities (hello stack overflow.)

Would depend on the program copied from, to, and the clipboard functionality of your OS/shell. Best to test it and check in a hex editor IMO.

Wow... I've merged an icon with an exe file.

Took only about 3 hours.

still not 100% accurate, but more or less straight. needs a little more tweaking

Do OSes have a significant effect on performance compared to a program running on bare metal? I know there can be concerns about things like the scheduler interrupting your program for hard realtime applications, but as far as actual performance goes, is it significant? Assuming you're just doing like basic number crunching and not actually using any OS-provided functionality.

>DEJA VU!

Everywhere I see always says to contribute to open source shit but I literally have no idea how to go about this. There is nothing I use where I have found a bug, etc and I don't know where to search for things like this

try adding a feature that you'd like to have, even if it's very minor

Learning x86 Assembly so i can understand bit of reverse engineering plus do some lower level stuff using C.

What should i expect? Got this large book about MASM which is 600+ pages

Lurk more, figuratively speaking.

Try using a polynomial function (of high order, around 5 like it was suggested) and find the coefficients using the Mean Square Error.
Read up about it, it is pretty simple if you are familiar with some linear algebra.

Python Integer type is a object instead of 8byte match ALU make it 50 to 100 times slow, Python lack native contiguos memory structure aka Arrays. Numpy begins high performance Arrays interact with Python.

import array

A better way to break lines in python is to just wrap the expression around parenthesis, those backslashes are fucking ugly. Just sayin' :^).
def f(x):
return (20 if x == 1
else 5 if x == 2
else 54 if x == 3
else 90 if x == 4
else 32 if x == 5
else x)

>sepples doesn't have POD struct template parameters
Should I try D? Does it really achieve Better C?

A program's performance ultimately depends its machine code.
However, while it's true that there are different implementations of the same language that can offer very different performances (think about SBCL and CLISP for Common Lisp: the former compiles to native code and runs almost ten times as fast in benchmarks), it would be a lie to say that some languages are not inherently easier for a compiler to optimize.

Just take for example Python and C++: in Python, since the same variable can hold values of different types during program execution and the same operators can mean different things based on the operands' types, the runtime has to check the types each time. Even if you were to compile Python to native code, the compiled code would still have to perform these checks to provide the same functionality an interpreter provides.
But with C++, all types are determined at compile-time, and so are functions and operators, input and output types, and so on. Hence the code that is eventually generated doesn't need to check types every time, because each operation has been determined to be semantically correct during compilation.

So in the end, both are true in a way: a program's performance ultimately depends on the language's implementation, not the language itself, BUT some languages are easier to optimize than others by design.

How is Yuno so cute, it's unbelievable

Guys, I need to come up with a object-oriented project idea written in C++ for my university.

Altough it shouldn't be too complicated, I would like this to be something actually useful, and not some sort of shitty game or boring cliche "Library managment system". Any ideas?

I got you covered my brother of African descent.
The project you're looking for is a basic Chip 8 emulator. Here is a useful guide: emulator101.com/introduction-to-chip-8.html

Trust me, it's easier than it looks and it will stand out among your mates' "library management systems". Not only that, it will teach you a lot if you've never written an emulator before.

As for object-orientation, you can easily model each hardware component as an object.

I can't imagine how sick professors are of seeing Chip 8 emu #134123213219143258342

Try this boi's advice: stephendiehl.com/posts/vim_2016.html

a basic neural network solver. you can show all the relevant OOP ideas with it, the most complicated part is the back propagation algorithm but you can just look it up. I wrote one in university and really isnt that complicated.

Emulate a basic MIPS system instead

//returns a function that evaluates to the interpolated polynomial
template
auto Lagrange(const vector& numbers){
return [numbers](T x){
T y = 0;
for(size_t k = 0; k