/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Other urls found in this thread:

github.com/rust-lang/rfcs/pull/2088
graydon2.dreamwidth.org/253769.html
en.wikipedia.org/wiki/Incremental_build_model
rustbyexample.com/crates.html
twitter.com/NSFWRedditImage

First for fuck C

t. pajeet

Rust > D

Why D is dead?

because it was never alive.

So there's no way to do this without using some pajeet's library?

I have found something to dislike about Rust... or rather, its build system, Cargo.

Where I come from in the land of C, C++, and Makefiles, there is a notion that if you make an alteration to one source file (a .c or .cpp file), there is not necessarily a need to recompile the rest, so long as you have not deleted the intermediate .o file. In a large project of perhaps hundreds of files, this saves time on compilation for each small change.

In Rust, there's a number of different but sort of similar ways to handle compilation of multiple files. You can compile to .o and the like to fit into a C project just fine or produce a library, but this doesn't carry the type information over. Instead, modules are preferred.

Within a Rust program, you can declare that you are using code from another compilation unit either using the mod keyword or extern crate. With the latter, you supply a .rlib file to rustc and it links it in as if it was a normal .a library with built-in type information. Pretty nifty. One would think that the natural way to do things would be to use .rlib as an intermediary format for every .rs source file, and everything would be handy dandy. If you actually did this, however, you'd find it would be dependency hell to manage in your build script/makefile/whatever.

Instead, what everyone uses is the mod keyword. If Rust sees something along the lines of "mod foo;" it means to look in either foo.rs or foo/mod.rs. The problem with this, of course, is that modules are not compiled individually. In essence, the compiler is #include-ing those files, just without the multiple #include problem. If you have two files, a.rs and b.rs, and a.rs uses b.rs, you will have to recompile both even if you only change a.rs.

Scale the problem up, and it will suck. So what does everyone do? Use shitloads of libraries, just like in Node.js. Seriously, go build a random Rust project and see how many libraries you'll end up downloading; it's absurd.

This is a really bad and completely not convincing "argument".

Also Rust is an abysmal language by default so your argument's kinda redundant / beating a dead horse

Hey it's me again
I got my program to work.
I need some advice about the amount of words you can enter in because my program need to have no more than 1000 entries.

they are reworking the mod/crate part of the language. 19 releases into the stable "1.0" :)

They are? Is there like an issue tracker I could use to follow this rework?

void definitely_not_strcpy(char *dest, const char *src)
{
while (*src != '\0') {
*dest = *src;
++src;
++dest;
}

*dest = '\0';
}

github.com/rust-lang/rfcs/pull/2088

this is what I was thinking of, but it wouldn't solve your/the problem. at least I don't think so (the thread really took off...).

the micro-lib ecosystem with a tiny standard library is the least attractive part of Rust, in my opinion. but its what the community is used to.

you should rewrite this as
while (*++dest = *++src);

one-liners with ++ and dereferencing triggers me.

If its not in the top 5 in github or being massively shilled, its dead to /dpt/. But in reality its far from dead, desu.

Okay I finally gave in and imported your shitty fucking gay library.

But it still doesn't add the characters, so I'm hoping you could again explain where I'm fucking up
char buffer[50];
strcpy(buffer, nouns[RAND_NUMBER_RANGE(0, num_nouns)]);

if (RAND_NUMBER_RANGE(0, 2) == 1) {
//find out whether we need to add "s" or "es" to the end
int len = strlen(buffer);

if (buffer[len] == 's')
buffer[++len] = 'e';
buffer[++len] = 's';
buffer[++len] = '\0';
}
printf("%s ", buffer);

What kinds of algorithms would be used in dwarf fortress / factorio?

akari is cute
code is cute too

None that you would understand

...

Clean as hell. Though I don't like dereferencing a ++ either.

I know this is a stupid question...

can someone explain what's happening here? line by line.

#include
int main() {
print f ("hello, world!");
return 0;
}

i know this might seem silly to most of you, i'm having a bit of trouble understanding exactly what each part means

where do you define the structure of a structure? globally, above all your functions, or in main?

If every translation unit needs to know the layout of the struct, in the header, otherwise, I put it in it's translation unit at the top.

>.b
1. you're including the standard in-out header for your compiler to reference for printf
2. youre declaring the entrance point of your program, it takes no arguments and is expecting an int return value
3.youre calling the 'print f" function (which won't compile because of the space) with "hello world"
4. youre returning 0 signifying your program exit'd successfully

To add to this user's answer, should be

thanks

>can someone explain what's happening here? line by line.
No, we can't. Explaining those details properly involves explaining a bunch of concepts that you will undoubtedly see in later chapters.

I can give a rough overview of the parts you can understand at this point, though:

>#include
This indicates that you want to use a bunch of input/output-related standard functionality in your program. Having this line at the start of the program makes the `printf` function on line 3 available, as well as a ton of related functions.

>int main() {
>...
>return 0;
>}
I can't really explain this part yet. For reasons that your textbook will explain later and that for now you can consider unexplained magic, everything between here is the real content of your program. What exactly this means will follow soon, I'm sure.

>printf ("hello, world!");
(Note the missing space between `print` and `f` -- it should not be there.)
This line "prints" (which, in programmer terminology, means "displays on the screen", not "print on paper using a printer" -- the term derives from the historic machines that DID have a printer and did NOT have a screen, for which a program like this would actually print on paper) the text between the double quotes to the screen.

For now, the `printf` line is the only part you can really understand. Everything else, I suggest you take on faith for now, until your textbook gets to it.

Fact: People who argue about languages are people who aren't able to build anything with them.

Hrm... maybe this might make it easier to use .rlibs everywhere instead of modules. Doesn't seem that great though. If I ever make my own language, I'll need to remember "module system that doesn't suck" on the list of features to add.

Also, Rust's standard library isn't that small... It's just that it's not Java huge.

trying to write tetris in C

>add to this user's answer, should be
user caught it just fine. seems you missed it in his post.

i'm doing multithreaded parallel prefix sums computation in C with a barrier, but it wants me to print the array at the end of every round. how should i approach that? it doesn't specify that you have to write it all on the same line in order, but that's how i interpreted it.
should i just print the index and value, and the round number? only thing other than that i can think of is it's going to have to use two barriers and wait for one of the threads to iterate over the array

graydon2.dreamwidth.org/253769.html
is an interesting read about modules.
(from the original creator of Rust, back when it was written in OCaml..)

...

This

Are you seriously saying CMakeLIsts.txt autism is any good?
I HATE CMakeLists with a fiery passion.

hi pajeet. how's getting paid 15k/year to write 100 lines of java shitcode everyday going for you?

Pretty good, how's that $12/hr burger flipping job at McDonalds going, autist?

Cool keep us posted.

It honestly isn't really bad. The complexity comes from the portability requirements.

> The complexity comes from the portability requirements.
I don't care, a standard build system would not prevent portability at all

I actually found a solutions C++'s nomodules problem.

Write your main function in D, the rest of the project in C++

thank you 4friends (that was a word play on "Sup Forums" and "friends")

business idea: write your whole project in D

>start first job out of college doing embedded dev a year ago at a small business
>other programmer I was supposed to work with eventually gets fired, because he can't actually program
>start to juggle 3-4 projects at a time, because my boss has ADD
>end up getting lead dev duties after a few more months
>start having to talk to customers, manage interns working on desktop software, give estimates, organize large codebases, along with working on my other projects
>slowly start to fall behind on my other projects
>get stressed out
>ask boss if I can have interns help work on firmware
>he said no, because he's scared of having students touch firmware
>ask him if I can get a full time programmer to help with firmware
>he said he doesn't have the money.

Do I just give him my 2 weeks and tell him to fuck off? The pay isn't even good, it's only on par with other fresh college grads.

My only problem is I would feel bad for leaving, since there's a lot going on that needs my help, but at the same time, I could work another job that's less stressful and with more pay.

There are many alternative build systems to CMake if you're building C or C++ programs. I just personally prefer it because it manages internal header dependencies better than just a standard Makefile, and is also able to handle nuanced differences in compilation across different platforms.

But regardless... you must admit that recompiling an entire project just for changing one source file is a bit ludicrous, right? Especially when you take into account Rust's compiler being notoriously slow already.

That'd be nice, I'm looking forward to their new automem go get into the standard

>There are many alternative build systems to CMake if you're building C or C++ programs.
Like meson? Depending on python to make your C++ work? I find that embarassing for purist languages like C++.


> you must admit that recompiling an entire project just for changing one source file is a bit ludicrous, right?
It is, don't they have incremental builds? Did you consult their IRC?

You don't know what portability means then. It's not just a matter of the input but of the ecosystem too. Languages like Rust or Go can afford these things because they are new enough to (almost) have a single implementation.

youre getting squeezed lad, get out.

a unique situation has come up that has me traveling, but i still need to work on my cross-platform app using VS.

normally, everything is at home and the iMac is attached to the same network as my win10 machines and it's all gravy.

however this time, it would be very burdensome to take the iMac along. i really don't want to buy a new macbook just for this.

can i use a hackintosh laptop (T-420?) or would OSX 'know' and disallow the remote access needed by VS?

Correct me if I'm wrong, but Rust is hosted on all LLVM supported archs, right? It's pretty damn portable if you ask me, why should standard builds suffer for the sake of niche arch portability in the first place?

>look at javascript code
});
});
});

Every. Single. Time.

Learning tkinter

>use a language that can compile to JS
>Never have to look at pajeet-S ever again

>t i still need to work on my cross-platform app using VS.
Judging by your post, you would be the perfect fit for the kind of people that carry their macs

that's funny.
you're clever.

Have to write a report for data stored in a sql database.

I have an initial population of people and 36 metrics that are stored across close to 30 different tables. Some of the population will have some of the metrics while others don't.

How should I write this?
1) Just one big ass query hitting everything I need
2) Create an initial population temp table and then apply the data points for each section as I go

There may need to be the need for an ETL process for this at some point.

For you, everyone is clever

>Rust is hosted on all LLVM supported archs
Rust's back-end is LLVM, doesn't mean it will work well on all LLVM supported architectures (see their website for the full list). You still have to properly wire your front-end into it and there are platform specific considerations to have (for function passes among other things). And then there is how the OS lays libraries out, the standard library etc... Like I said, portability is not just a matter of the language.
>why should standard builds suffer for the sake of niche arch portability in the first place
Rust is an example of language where "portability" only depends on the arch. For other more mature languages, you also have different compilers, ABIs, etc.
Your opinion is valid if you only want your language to be properly supported on a few platforms, and a standard build system is nice, I'm just saying it's not always realistic to have. Adding a "build system" into the C++ standard now for example would probably break many projects in regards to forward compatibility.

sounds like a game of Guess Who

rust is shit

Meson, Make, Rake, Autotools... whatever you prefer, really. A build system is just a configuration file or script to describe how the program is built. And it can be in Python, that's fine. It'd be a bit silly if the build script was a .cpp file, no?

>don't they have incremental builds?
I'm pretty sure "incremental builds" is not what we're talking about here.
en.wikipedia.org/wiki/Incremental_build_model

>Did you consult their IRC?
Nah. I consulted one of the more commonly used Rust books:
rustbyexample.com/crates.html

>If some_file.rs has mod declarations in it, then the contents of the module files will get merged with the crate file before running the compiler over it. In other words, modules do not get compiled individually, only crates get compiled.

Could anyone good with Verilog help me out?

I have a module with an input in bits, and I don't know the syntax to give that input with individual bits. (Basically, I'm implementing a multiplexer.)

//partial code

module Mux(
input [2:0] Select
);

//stuff happens
endmodule

//S1, S2, and S3 are output regs declared elsewhere. They all contain either 1 or 0.

module ExecuteComponents();

Mux m( .sel[0](S1), .sel[1](S2), .sel[2](S3) ); //my guess for how it would look

endmodule


It doesn't compile correctly. How should I be passing in the individual bits of Select?

>Rust's back-end is LLVM
I made one of the mistake I hate. I meant rustc's back-end is LLVM. Although since it's the only implementation the amalgam isn't too harmful.

Correction: .sel should say .Select. I changed the code to be more descriptive here, but didn't finish that part.

alrighty I gotta question. Which lang should I learn next: Haskell, scala, elixir, nim, crystal, go or rust. You decide.

we need more nim posting.

You should learn more about the languages you've already learnt.

Go is a shitty meme.
HASKAL is good if you want to be a professional blog writer.
Rust is okay, but has an actual cult around it.
Dunno about the rest, but they're probably fine.

I know shit all about verilog, but I recall two ways from when I fucked around with it for a bit:
Mux m( { S1, S2, S3 } );

or:
wire [2..0] mux_shit;
assign wire[2] = S1;
assign wire[1] = S2;
assign wire[0] = S3;
Mux m( mux_shit );


Not sure whether those bits should be in left-to-right or right-to-left order. It's been a while.

Rust

Whoops
wire [2..0] mux_shit;
assign mux_shit[2] = S1;
assign mux_shit[1] = S2;
assign mux_shit[0] = S3;
Mux m( mux_shit );


Of course, the real answer is that Mux should not take an array in the first place, but rather three separate inputs.

my aero model is written in fortran 77 and its pissing me off

Yup, I just tried something similar to the top one and it compiles.
Mux m( .Select({S1, S2, S3} );


I'll figure out the bit order sometime soon, thanks.
The sample code I was given for the module has Select written like that, so I'll keep it that way.

>pure functional
>object-oriented functional
>concurrent functional
>concurrent imperative
>object-oriented
>concurrent imperative
>whatever Rust is
Make your mind up. Also learn J, Prolog and Erlang.

Rust is the autistic, bastard child of functional and imperative.

bump for wasting money on a macbook/wasting a day getting hackintosh working.

Not correct behavior.
Fixed:
while (*dest++ = *src++);

Just use a VM you mong

If you pass in a pointer to an unterminated char array, you deserve to SIGSEGV!

VS doesn't allow emulation via VM, you turd.

then dont use VS?
Stop being a brainlet.

i have a perlin noise function in C, when i call it twice in a row with the exact same arguments and everything, the return value of the second time is double that of the first.
Can someone explain to me what witchcraft is happening here?

So basically completely new to programming, everyone is telling me to start with C. What is the best place to start?

Sure, let me just summon my dark spirit to peer into your code. But maybe instead you could quit being a baka and include it.

line 5

javascript or php, don't listen to the trolls

>VS doesn't allow emulation via VM, you turd.
Top kek wincucks are the weakest cucks of the world

Fuck off with the disinfo /wdg/

Should I buy a book? Use codecademy? I want to start from the basics so I don't get fucked later

physical books are comfy.
But what kind of dev do you want to do lad?

yeah use code academy to learn php or javascript. or both! best of luck, good friend

double noise(double x, double y, double z, int seed) {
int perlin_ywrapb = 4, perlin_ywrap = 1

Probably make mobile apps and websites since those have the most demand, but preferably something pajeets cant shit out in 2 seconds, any books you recommend to start? I don't really know what I liked yet so I would be open to try different languages

Are you being ironic?

if you are new and don't know where to start, try freecodecamp .org? .com?
easy to do and should you complete it, you would have enough skill/experience to do some basic freelance work to build your portfolio. plus it gets your brain in logic mode so you can add other languages later.

>use C and work with hardware every day for work
>kind of want to learn a desktop-friendly language and maybe contribute to FOSS

What should I learn? I'm thinking about either C#, C++, or Rust, but I'm afraid that C# gets me cucked by Microsoft, C++ is ugly as shit, and Rust will probably end up dying.
Are there other languages worth learning?