/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

play.rust-lang.org/?gist=f4131a4bbfe0dd06be6bbc39a741ef84&version=stable
twitter.com/SFWRedditImages

What percent of scientists actually make their own software?

I love Rust!

What's a good language for studying numerical methods?

...

I hate C++ but can;t stop using it

Have you read your SICP today?

I love Rust but write c++ at work.
>tfw

Yep. Still progressing through it very slowly though.

>mfw writing java
words words words words words

Keep at it user. You'll get there in the end.

yeah, common lisp really is the best language.

Same, but I also contribute to some Rust projects on github in my free time.

Not even the best lisp.

>Start software development job
>Need to change something in the build system
>It's a network of makefiles calling shell scripts calling makefiles calling docker calling shell scripts calling cmake calling make and all sorts of garbage
>It takes fucking ages to compile, and even when calling it from already built, it still takes several minutes
Why the fuck do people do this to themselves?

scheme and clojure are not lisp. Common Lisp is the only properly still existing.

>Scheme is not Lisp
>C++ommon Lisp is

Daily reminder Common Lisp standard from 1994 defines 950+ symobols, which is more than C++14 stadard. I bet all of these 950+ symbols are required for a language to be a proper Lisp.

I have a question, though.
Exercise 2.4 asks you to define your own cons, car, cdr procedures using closures. It seems like it'd also be convenient to define struct-like procedures in a similar and general way.
(define (make-struct a b c)
(lambda (member) (cond ((eq? member m-a) a)
((eq? member m-b) b)
((eq? member m-c) c)
(else (error)))))
Is there a succinct way to define "constants" that won't compare equal to anything else like these m-a, m-b, m-c?

have fun reimplemeting even the most basic stuff.
Scheme's standard is small because it doesn't provide enough functionality. Every scheme implementation ends up providing as much as common lisp but in non portable way.

>muh "moan ads"
>muh "lamb duhs"

Hey /dpt/, can I ask you guys for some quick help with my embarrassing math question. I'm in the first week of a programming course for beginners at my uni and I never programmed before. We got to do some exercises but my math is a little rusty and I'm too dumb to figure this out on my own.

We're supposed to write a program that approximates ln(2) using a alternating harmonic series, i.e 1 -1/2 +1/3 -1/4 etc.

Our program should give the results for 3, 9 and 15 summands(!) which sounded easy enough at first glance until I asked myself: Wait a minute, what exactly counts as 3, 9 or 15 summands? Is 1 - 1/2 + 1/3 -1/4 + 1/5 -1/6 + 1/7 three summands? (+1/3 +1/5 +1/7) or does 1/2 + 1/3 count as two since 1/3 is added to 1/2?

I know this is a very basic math question but my highschool math days are pretty far behind me and I'm a little rusty. Can anybody help me out?

How many people on your team? I think you're my coworker. Welcome aboard.

1 - 1/2 + 1/3 -1/4 + 1/5 -1/6 + 1/7
1 + (-1/2) + 1/3 + (-1/4) + 1/5 + (-1/6) + 1/7

_you'd assume_

Email your professor and ask. It's a programming course you're not expected to know every math term there is.

About 50 or so in the entire company. I'm transferring to software development from a support position.

Nevermind then, you're not my guy.

so, /dpt/, why is it that c++ can't have RAII and try-finally at the same time?

Because C++ is a very poorly designed language.

I'm not far enough through the book to know if you can define constants like that, sorry. But going by analogy with the car/cdr example you could use integers: 0 for m-a, 1 for m-b, 2 for m-c, ...

C++ doesn't have try-finally because C++ never ends, it just continues further into unlife

The same reason it doesn't have Go-style defer - you just don't need it if you have RAII.

So, you'd assume that every single number counts as a summand?

I gotta hand this in tomorrow I'm afraid he won't answer me in time.

How does Go-style defer work? Is there a runtime cost?

Since people are memeing about common lisp for some reason; I'm gonna post some erik naggum quotes.

Much could be said about this affliction of the mind that causes people to assume that what they do not understand does not matter, that they have reached such a level of omniscience that they no longer need to observe and listen and learn. Having learned enough, some people evidently stop learning altogether. What they learned first is the standard for everything that comes later. That the probably only _truly_ random element in anyone’s life is the order in which they experience things, seems not even to be understandable — they somehow believe that the order they run into them is universalizable and important, that first impressions really tell you everything you need to know about something. I have seen people who have the mental capacity only for the transition from “have not experienced” to “have experienced”, and who are unable to make a distinction between their observations and their conclusions, such that they are unable to change their conclusions about what they observed. They walk around like they had CD-Rs for brains.

>Is there a runtime cost?
Yes. But there's no EXTRA cost. All it does is this:

conn := OpenAConnection();
defer conn.close();

// some code

--- The deferred code gets executed here.

You fucked up. Should've started sooner... kiddo.

Let this be a lesson then, retard.

>So, you'd assume that every single number counts as a summand?
Not him, but yes. Subtracting a number is still "summing" it.
Even if you do get it wrong, you would probably get most of the marks.

i appreciate that RAII is good and better than using try-finally constructs for everything a la java, but i'm thinking of circumstances like using C apis that require freeing of resources (especially from windows apis). the more lines you write the more bugs you introduce, so it would not be such a great inconvenience to introduce a way of ensuring resource release and exception safety without writing error-prone class wrappers that is common in other languages that feature exceptions.
i just realised i'm trying to make sense out of c++ and its standards committee, which is fighting a losing battle

I don't know but I think not, if the compiler knows the function to call at compile-time it only has to put the call in all the returning paths. In C++ you would just assume the destructors are inlined, and Go's defers is a poor's man RAII.

It's not that perl programmers are idiots, it's that the language rewards idiotic behavior in a way that no other language or tool has ever done.

something important happens when a previously privileged position in society suddenly sees incredibly demand that needs to be filled, using enormous quantities of manpower. that happened to programming computers about a decade ago, or maybe two. first, the people will no longer be super dedicated people, and they won’t be as skilled or even as smart — what was once dedication is replaced by greed and sometimes sheer need as the motivation to enter the field. second, an unskilled labor force will want job security more than intellectual challenges (to some the very antithesis of job security). third, managing an unskilled labor force means easy access to people who are skilled in whatever is needed right now, not an investment in people — which leads to the conclusion that a programmer is only as valuable as his ability to get another job fast. fourth, when mass markets develop, pluralism suffers the most — there is no longer a concept of healthy participants: people become concerned with the individual “winner”, and instead of people being good at whatever they are doing and proud of that, they will want to flock around the winner to share some of the glory.

I've done everything else already. This is the last thing I have to do. It's pretty straightforward, I'm just not 100% sure how to interpret the instructions.

That was my first intuition as well, but then I started to second guess it. But I guess that makes sense, I'll go with it and hope for the best. Thanks for all the help guys, much appreciated.

english

Unique_ptr has `deleter` template parameter and shared_ptr accepts deleter as an argument, so you can use RAII without writting wrapper classes.
>i just realised i'm trying to make sense out of c++ and its standards committee, which is fighting a losing battle
Actually it's the over way around, the more you read the standard and watch the presentations, the more sense it makes.

you become a serious programmer by going through a stage where you are fully aware of the degree to which you know the specification, meaning both the explicit and the tacit specification of your language and of your problem. “hey, it works most of the time” is the very antithesis of a serious programmer, and certain languages can only support code like that. over time, you get a good gut feeling for the failure mode of your assumptions, and when you can trust that you are unlikely to make grossly invalid assumptions, the dangers that people run into in the absence of that trust vanish in a puff of standardization: it’s the kind of trust you buy from somebody who claims to be conformant. non-conformance is about violating this sense of trust. certain languages support serious programmers, and others don’t. e.g., I don’t think it is at all possible to become a serious programmer using Visual Basic or Perl. if you think hard about what Perl code will do on the borders of the known input space, your head will explode. if you write Perl code to handle input problems gracefully, your programs will become gargantuan: the normal failure mode is to terminate with no idea how far into the process you got or how much of an incomplete task was actually performed. in my view, serious programmers don’t deal with tools that _force_ them to hope everything works.

In the much-lamentable Old Days, when fewer programmers could get at the source code, it had higher quality and was better to learn from. As more people with less commitment to quality and much less attention to detail got involved in writing it, its educational value diminished, too. It is like going to a library full of books that took 50 man-years to produce each, inventing a way to cut down the costs to a few man-months per book by copying and randomly improving on other books, and then wondering why nobody thinks your library full of these cheaper books is an inspiration to future authors.

I tried to recreate a primitive defer in Rust
struct Defer(F);

impl Drop for Defer
where
F: FnMut(),
{
fn drop(&mut self) {
(self.0)();
}
}

macro_rules! defer {
( $x:expr ) => {
Defer(|| $x);
};
}

fn foo(v: &mut Vec) {
defer!(v.clear());
}

fn main() {
let mut v: Vec = vec![1, 2, 3];
foo(&mut v);

assert_eq!(v, vec![]);
}

eww

this one's long

All in all, a hostile request for references is a pretty indecent and
dishonest way of derailing the open information exchange: Instead of
letting people think aloud freely, the likes of our resident nutcase will
jump up and ask for references for anything at all, but randomly. Such
hostility has a much stronger effect on how people feel about posting and
contributing than a strong, directed response to particular issues. It
is a systematic attack on those who have independent ideas, and only
those who are so much in the mainstream as not to be worth listening to,
go free of such passive-aggressive attacks. Given an unexpected, but
correct answer to a question, the reference-requestor will ask for
references, but not for the expected, but incorrect answer. It matters
more to people who know the correct answer to document it than it does to
people who post incorrect answers -- the result of not caring much about
anything to begin with. It usually takes much more time to look things
up than to answer from memory, but this confidence and trust is shot to
pieces by the reference-requestor cum nutcase, who prefers that people
who do not have correct answers post their random guesswork. In my view,
the motivation for asking for references is to make it easier in the long
run for the nutcase to spread dis- and misinformation and not be opposed
-- also notice how the resident nutcase requests references only when he
wants the opposite position to be true, but does nothing to show that.

cont.

The same issue that I discussed about people who ask for proof all the
time applies to references. Very little of what we know to be true can
be _economically_ proven to be so. That is, even if you could prove it,
it is not in the interest of an open information exchange to raise the
cost of posting to that which requires proof. What we do is let people
post various things they believe to be true, and then debunk it if it is
not, with real facts and references. So little is provably true, but so
much of what people believe is provably false, that it is far more
productive to let people think freely and meet resistance than it is to
force people to subject their opinions to resistance before the fact,
which is what providing an iron-clad proof essentially is. The key is
not to repeat known falsehoods. People who do that, however, do have a
tendency to demand proof and references from those who debunk them. Our
resident nutcase has done this several times, and things have just died
or turned ugly because people tire of explaining the same things to the
same guy over and over. Through the persistence of unchecked stupidity,
it would appear in google searches and the like that the nutcase wins by
number of matches, unchallenged claims, and the like. This is a fairly
sinister way of attacking the base of a community's common trust in what
it knows to be true. Then again, the nutcase lost his faith in Lisp and
did not follow up by moving to another community, such as Python's, so
one has some reason to suspect sinister, long-term destructiveness just
there.

So if you want references, provide references for your own views. Look
things up to debunk what other people have posted. If you ask others for
references, but do not actually document your need for them, and do not
thank the person for providing them, etc, it is only hostile.

APL, unironically

unique_ptr's deleter argument isn't perfect because it leaves you no way to report errors except for assert/std::abort. maybe this is just me being paranoid about every single possible error though

Thoughts?

and finally

Using such inferior languages is like asking a chef who could have done wonders with any kind of raw materials, to use a dirty kitchen, a broken refrigerator with food that is about to die a second time, broken tools, and brownish tap water that tasted of swamp land. His first task would be to clean up the place. Creating food in there would be the furthest from his mind. That’s how I feel about Perl and C++. I prefer to call it “good taste”, not “tunnel vision”. I don’t like rap, either. Call me intolerant.

This language should be banned.

Only it was never better then. You had a lot more people who were blagging their way into the industry with relative ease compared to now.

but why

Is this good code?

There's no point tho, defer is a hack for schizophrenic languages like D and Go, which have GC but pretend they're system programming languages for some reason. In C++ and Rust you would just use a proper RAII.

What era are you talking about?

That won't actually work, and trying to make it do anything useful is an exercise in self-flagellation. Generalizing over arbitrary closures is really hard.

Guy sounds like he feels himself to be superior to the vast majority of humanity and has to display it by using the lowest imaginable vectors: sarcasm and irony.

Yeah, i just tested it, it doesn't actually work. Better just use RAII.

D has RAII though.

>schizophrenic languages like D and Go, which have GC but pretend they're system programming languages for some reason
Y-you're hurting their feelings! Stop saying they're not good enough! Any language can be a systems programming language if it tries hard enough... every language is special...

It appears to be working just fine play.rust-lang.org/?gist=f4131a4bbfe0dd06be6bbc39a741ef84&version=stable .

Is this autism

>Guy sounds like he feels himself to be superior to the vast majority of humanity
It's not hard to be superior to the vast majority of humanity.

>using the lowest imaginable vectors: sarcasm and irony
Maybe you can't appreciate those things because you're a brainlet?

I am the author of that snippet.
What i meant is this fails:
struct Defer(F);

impl Drop for Defer
where
F: FnMut(),
{
fn drop(&mut self) {
(self.0)();
}
}

macro_rules! defer {
( $x:expr ) => {
Defer(|| $x);
};
}

fn foo(v: &mut Vec) {
v.push(4);
defer!(v.clear());
v.push(5);
assert_eq!(*v, vec![1, 2, 3, 4, 5]);
}

fn main() {
let mut v: Vec = vec![1, 2, 3];
foo(&mut v);
println!("{:?}", v);
assert_eq!(v, vec![]);
}

like every single software engineering job near me needs Java and JavaScript
I know some decent java
But for these jobs am I going to have learn everything about HTML and CSS to do the JS stuff?

I don't know about D, but Go is indeed "special".

Oh, right, you have to assign it to some variable overwise the lifetime of the temporary ends right there, calling the destructor immediately.

Is /agdg/ right about Nene?

>le Canadian Aboriginal Syllabics faec

Yes that everyone should strive to be engine devs if they want to make games.
No, for wanting to work for somebody else. Japan still has a pretty traditional games industry though. Though i wish we had as strong a doujin/fan-scene as they do.

What IDE to use for C++ on Windows? Preferably something not bloated.

notepad

> What IDE to use for C++ on Windows?
Visual Studio.
> Preferably something not bloated
This meme again, go use edit.exe if you don't want B L O A T.

>something not bloated
Then why are you using the most bloated language in existence?

Code-blocks.

Visual Studio Community or install Bash on Ubuntu on Windows and g++ and vim.

visual studio

I already installed it and this happened. I have to install some shit which I'm not interested in just to run hello world.

it takes effort to fuck up the installer you dense cunt

>the absolute state of windows
you need to install a windows update.

>I want to write in C++
>I'm not interested in compiler

also
>i'm not interested in the windows sdk to compile programs for windows

You don't pay for what you don't use.

Why the fuck do I need 8.1 SKD to run hello world? I already have Windows 10 SDK installed and I'm on Windows 10.

read the fucking error message then and change sdk version

This argument is retarded and has been debunked countless times.

is there a name for the phenomenon where people don't seem to read things that are staring them in the face or look it up themselves and instead 99 out of 100 times feel the need to ask someone else to solve their problems for them

Acute brainletitis.

please help me i want to write fractions in c

I found out what's causing a major slowdown in my image processing program.
For one stage of the processing, it compares two lists of colours, to see which colours appear in both lists.

The current method is extremely inefficient: It compares every item in list A with every item in list B.

What's a faster method of comparing the lists?

use a hashset

I want to fuck that girl (male).

>What's a faster method of comparing the lists?
The quickest and most braindead solution would be to sort them. That'll bring you down from O(n^2) to O(n*log(n)).

I don't see what's wrong in having a lot of symbols defined in the standard library. The language is still way more consistent than C++.

Reimu isn't a trap.