/dpt/ - Daily Programming Thread

Previously What are you working on, Sup Forums?

Other urls found in this thread:

git.musl-libc.org/cgit/musl/tree/src/math/pow.c
github.com/p-e-w/ternimal
pastebin.com/qLNGEsUn
0.30000000000000004.com/
twitter.com/SFWRedditVideos

rust

Java > Rust > C

>tfw slowly start to realize Rust is, actually the future

C > Java > Rust > C

Yeah, Java is higher level than both Rust and C. Everyone knows that

That's the "greater than" sign, user.

worst syntax ranked:
php > perl >>>>>>>> c++

Is there are more elegant solution to this, preferably without any library functions?
//lenght of longest growing sequence in an array
int len (int array[])
{
vector tmp, tmp2;
tmp.push_back(array[1]);
for (int i = 0; i < 9; ++i)
{
if (array[i] < array[i+1])
tmp.push_back(array[i+1]);
else
{
if (tmp2.size() < tmp.size())
tmp2 = tmp;
tmp.clear();
tmp.push_back(array[i]);
}
}
if (tmp2.size() < tmp.size())
return tmp.size();
else
return tmp2.size();
}

where did rust come from and why is it so popular here?

>int len (int array[])
Where is your array size?

fixed to 10 for simplicity

>tfw impl Trait
>tfw NLL
>tons of other rfcs just coming into view
rust is only just beginning

idk, I almost never see rust code posted here.

protip: you should also just take in a vector, not an array

rust is just a meme

repost for new thread
>Question: i'm a beginner programmer who just mastered the basics, how do i move on to making real useful programs?
>Answer:JUST STUDY SOURCE CODE LMAO

is there a way on how to actually learn how to code useful software that isn't a fucking command line program?

this

What you are looking for is a cookbook.

>is there a way on how to actually learn how to code useful software that isn't a fucking command line program?
You aren't ready to understand GUI right now

>tfw you've taken the rustpill

where do I find projects to learn and test my skills?

so im learning rust. please justify my decision for me.

okay, what are you trying to make? Sounds like you just need to learn a library.

game: SDL, SFML, love2d
application: Qt, FLTK

This shit I guess, couldn't think of any real projects lately

>tfw know how to program but not what to program

Don't learn Rust until you have done at least one C++ project that others use

I feel you

>pic

No. I want actual projects.

I'd say don't use rust yet, the language is still gaining features and ergonomics. Relatively early adopters like me have had to deal with a lot of shit that's been recently patched out, and there's tons more in the pipeline. I know a lot of rust things that I really don't think are needed unless you're super into it.

C++ is _not_ a prerequisite for learning rust, just like C is not for C++.

Only C/C++ cucks will know

>not mentioning gtk
thank you. people like you make the world a better place.

int len(int array[], std::size_t l)
{
int n = array[0];
int rv = 0;
int ll = 1;
for(int i = 1; i < l; ++i)
{
int new_n = array[i];
if(new_n >= n)
{
ll++;
}
else
{
if(ll > rv)
{
rv = ll;
}
ll = 1;
}

n = new_n;
}
if(ll > rv)
{
rv = ll;
}

return rv;
}

what's wrong with gtk?

Object oriented programming in C is terrible, and by extension gtk is terrible.

there are a few brainlets who try all sorts of different languages and they shill the language they're currently using (rust now, used to be various languages like haskell, F#, D, racket, nim, red)

Suck a dick for free

ocaml was another big one, and erlang

just kinda sucks to use. Using Qt feels kinda like a set of C++ features that it could have had in the first place, plus a bunch of GUI stuff.
GTK is just this awkward C API and frankly I hate what the developers did with gtk3.

Is Erlang worth learning?
I want to learn a new language and Erlang looks appealing.

what's the point of pointers in C/C++?

why not use something like java or c#? not trolling just curious why you would choose to use a library like qt rather than a language that includes a standard library with most of those features already

>slap mutex infront of all calls that modify state
>module is now supposedly thread safe
that felt too easy, am i missing something?

So you don't have to waste time and resources copying, shuffling around and synchronizing larger data structures.

yeah, why the fuck do they exist?

Not sure if you know this, but they are also for accessing various parts of memory. Figured I'd add to -> .

Ever since I started working as a programmer 7 years ago I've been daydreaming about a simple, mind-numbing, 0 responsibility, lowpaid job. Like retail or something. Now I am stuck.

How do you "create" a delay in C?. I have to turn some leds sequencially but the time between leds must increase from 10ms to 1 second. The only clue i have is using a _delay_ms(1) and call it a lot of times but i cant come up with a proper way of doing it

sleep()?

Not really sure what features you're talking about here, but I'll bite. Java and C# both enforce an object model, are garbage collected, and overall don't have a good way of expressing what you want to do with memory. They just don't appeal to me.

Let me say this: I work a basic-ass job, but I still have responsibility. We care about each other, we care about not making it a shit place for everyone to work. It's much better than being slaved around.

while(delay_in_ms-->0) _delay_ms(1);
or most likely _delay_ms takes the number of milliseconds to pause as a parameter
are you an AVR?

*on AVR as in programming an AVR chip

>wanting someone to spoonfeed you ideas

The catch is that threads are going to have to wait for each other if they all try to access the same things at the same times. If you're not careful, your program could lock up entirely.

finish the GNU Hurd

probably not, the haskell retard from a couple of years ago was memeing, it doesn't take much to know which state you're sharing between threads and to avoid race conditions on initialization etc, it's pretty basic stuff

I'm using ATmega128-B

yeah you should be able to call _delay_ms with the number of milliseconds you want to wait

When did you guys realize you are too low IQ to work on interesting CS research/cutting edge tech at some major company and are doomed to wringing together APIs for enterprise systems/mobile apps on some local software factory while fully aware that this job could easily be automated in less than a decade or done by pajeets for a fraction of your salary?

Responding seriously, I never expected otherwise, but I expect myself to do said task automation instead of waiting for someone else to do it while rotely repeating them in the way you imply, at least.

Around 3rd year of my software engineering degree.

>the haskell retard from a couple of years ago
explain this? how has /dpt/ culture been changed with new languages coming out
that isn't even bad. you can retool and get another job. think of people who are truck drivers and aren't going to get anymore employment at all once we've got automation for them

same

Wew, marvel at my abomination:
fn longest_growing_seq(seq: &[i64]) -> &[i64] {
(0..seq.len())
.map(|idx| {
let mut first = seq[idx];
let end = &seq[idx..]
.into_iter()
.take_while(|&&elt| {
let temp = first;
first = elt;
elt >= temp
})
.count() + idx;
&seq[idx..end]
})
.max_by_key(|subseq| subseq.len())
.unwrap_or(seq)
}

fn main() {
println!(
"{:?}",
longest_growing_seq(&[1, 2, 6, -1, 0, 1, 2, 8, 5, 1, 2, 3])
);
}
Output: [-1, 0, 1, 2, 8]
On the plus side, no allocations are made

some guy thought there was some big problem about multithreaded state or something and that haskell magically solved it

ok sure, but it also borrows the sequence lol. At least one of that length is trivially copiable. Protip: just use a damn vector

I'll ask that too but frame another way: is there any good example of *great* source code? Like where other programmers go "I read this code to learn about X because it was that good"?

How would Sup Forums write an exponentiation function with only +-*/ and loops that behaves the same way exponents work in math? As in, simply calling "x*x" recursively is not enough; for example, exp(2.53,(-(1/2))) should produce 0.6287 and exp(2,2) should produce 4.

Doom 3 for game engine stuff

simple
git.musl-libc.org/cgit/musl/tree/src/math/pow.c

It's neat, go for it.
Fells like a one trick pony though.

github.com/p-e-w/ternimal
neat

>simple
what a disgusting piece of code

>// FIXME: instead of abs(j) use unsigned j
shig

nice, though I'm a bit confused why he doesn't just use libraries for some of this

b8'd

nice and simple, although it's written like govnocode

>govnocode
Well, I am wearing a track suit after all.

>
/* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax - bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = 1.0/(ax+bp[k]);
ss = u*v;
s_h = ss;
SET_LOW_WORD(s_h, 0);
/* t_h=ax+bp[k] High */
t_h = 0.0;
SET_HIGH_WORD(t_h, ((ix)|0x20000000) + 0x00080000 + (k

>tfw never actually completed one of these

>37
Nope.

no wonder you haven't completed one with that attitude

>mastered

what the fuck why is sepples the only language that gets 0.1+0.2 right?

also, does these errors give a security hazard on your software?

I'm learning some C from a book. One of the assignments is giving me some headache. The task is to implement a single-linked circular linked list by using just plain C int arrays (no pointers). The book mentions some example program output but I can't seem to replicate it with my program and can't figure out the problem.

Example output from book:
Item: 1 2 3 4 5 6 7 8 9
Next: 1 7 5 5 5 7 7 7 1


Output from my program:
Item: 1 2 3 4 5 6 7 8 9
Next: 2 2 8 6 6 6 8 8 8


My scribblings so far:
pastebin.com/qLNGEsUn

A lot of the projects on there are kinda shite desu. It needs a v5 rewrite

0.30000000000000004.com/

C++ doesn't really get it right either lol, it just cuts off the digits. You have to use decimal floating-point numbers to get that behavior right.

learn about floating point math

>does these errors give a security hazard on your software?
not always security related but it's a common source of bugs for obvious reasons, always test and never assume "it's just working"

need to return containers with stuff from a c++ dll exported api
ABI issues means i cant use STL, whats the standard way?
its looking like reimplementing a bunch of containers, which kind of sucks
std::string str = "key=value";
str.split("=") // What type would split() return?

you didn't show what the book says but it looks like you're off by one. subtract 1 from each output and shift it left by 1 to get the book's output

the printed output is rounded and displayed in base 10, it's still the same "error"

int len(int array[], std::size_t l)
{
int n = array[0], rv = 0, ll = 1;
for(int i = 1; i < l; ++i){
int new_n = array[i];
if(new_n >= n) { ll++; }
else {
if(ll > rv) rv = ll;
ll = 1;
}
n = new_n;
}
if(ll > rv) rv = ll;

return rv;
}

>follow tutorial when learning new framework
>shit's deprecated everywhere I look
fug

the standard way is not to pass c++ objects across dll boundaries

most of those frameworks are so full of shit, learn to look for quality, just because you see something on the internet doesn't mean you have to use it

more like gtk's flavor of object oriented programming is terrible
qt seems at least as bloated and fragile as gtk

To be fair, I can't help but wonder how large, complex C++ projects are even possible. Seems hellish.

i see lots of people criticize java/c#/etc in favor of c++ because they are bloated and slow. but then those same people turn around and use qt and boost in every c++ project. doesn't that add a bunch of slowdown and bloat? not to mention qt adds a lot of non-standard things and uses its own build system. why not just pick a language that includes a lot of those features you find in boost/qt in its standard library?

You asked me this same question but with different wording, and I gave you my answer.
Overall though, I'd like to add that Boost and Qt do not add anything close to the same set of features that you'd get in C#, I don't really know where you got that idea. Just including the libs doesn't give slowdown, either; in properly compiled langs (unlike java), you generally don't pay for what you don't use.

>those same people turn around and use qt and boost in every c++ project
[citation needed]
boost is not needed. anything of merit has been merged into the newer C++ standards. qt is just for GUI which is not very performance sensitive

which is why i didn't direct it at you this time

>Overall though, I'd like to add that Boost and Qt do not add anything close to the same set of features that you'd get in C#, I don't really know where you got that idea.

thats my point, you have to go find a bunch of libraries to cover the same functionality that comes with c# or java

what functionality?

anything that comes standard with java/c# that isn't included in boost/qt?

>zerop