/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1560614080878.jpg (1024x768, 139K)

Other urls found in this thread:

eloquentjavascript.net/
blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
twitter.com/SFWRedditImages

Why haven't you signed up for your free z/OS mainframe access anons?

Hiya, Anone! I came to check on you! How are you JavaScript studies going?

Attached: a639aa4140b5ae8fe90ba10a4806a197.jpg (1362x2048, 170K)

FUCK javascript and FUCK you

optimizing backend for compiler
I think I'm a bit retarded though

pretty good since I decided to only write what I was taught in eloquentjavascript.net/ and maybe some mithriljs. If I need to do more than that, I'll learn a real language that compiles to JS.

for how many dollareedoughs?

>It does not contain exercises, therefore it is not good for learning.
You can always make up your own exercises (or rather play around with the code) if the book doesn't have them. I learned the most from JoC by reading it cover-to-cover to acquire an overview of the language features, then later using it as a reference when I introduced unfamiliar concepts to my own programs.

IMO I think exercises can be more annoying than useful if they don't have much thought put into them (ie. I think Get Programming with Haskell is a bad example of exercise usage, while SICP is a very good example, being central to the book).

how the fuck can I get python to sort through directory contents in proper numerical order instead of jumping from 1 to 10 to 100 as opposed to 1,2,3...? Shit is irritating me when I try to merge video files. They get merged out of order.

Should I learn C or Rust?

int getrandom(void)
{
int n;
return n;
}
rate my rng

"Am I a retarded compiler optimizer test?" in one question:
1. your language has a fixed-width signed integer type with undefined behavior on rollover (i.e., what happens depends on the machine you're compiling to, so theoretically in 3000 years 0x7FFF_FFFF + 1 -> 0x8000_0000 might not happen, for 32-bit ints.). you find a loop that runs until x < 0. You can see that x is statically set to 1. Do you
a. eliminate this loop for being dead code
b. eliminate the test of the loop, turning it into an infinite loop, since x < 0 can never happen
c. do nothing: the programmer is obviously just aware of some properties of the machine he's compiling to
d. do nothing. your compiler is also aware of some properties of the architecture you are actually targeting
e. issue a warning: this is undefined, bro, it might change in 3000 years

C

>FUCK me
anone ecchi >.< kyaa~~

>You can always make up your own exercises (or rather play around with the code) if the book doesn't have them.
Absolutely, and I have done this several times. It's better than nothing, but it's not a perfect substitute.

>caller has to give up ownership to make it efficient
>even though the callee never needed the ownership to begin with
Yep, you're never gonna make it. Take it by const reference or take an std::span, you FUCKING IDIOT.

the answer to "Should I learn C" is always yes. No matter what meme lang you pick up, learning C is going to be helpful to it. Lots of other people's code is written in C, lots of reference material, and even when you're using a meme lang you might want to write some C to do some real work.
"some real work in C" won't happen as often with Rust but you've still got a C FFI for working with C libraries and you'll want to know C just to understand what you're working with.
(don't learn Rust. you'll turn gay.)

B, obviously.

Just imagine tricking a freak girl like Kaos and making her believe you really like her. You stomach a few dates with her and pretend her autism doesn't gross you out. Make sure you take her shopping and to get ice cream, cutesy date stuff that she is sure to like. Humor every story she tells, laugh when she tells jokes, even if they suck. You don't have to stomach this for long, so just deal with it.

Then, one day, you take her on a hike deep in the woods. You tell her you love nature and hope to see animals or some shit, who cares. She goes along and looks so happy she could die. You cringe at the thought of loving her even a tiny bit, autistic girls like her and other retards don't deserve love or affection.

Once you get sufficiently deep in the wood, you stop and turn to her. You call her out for being a dirty, disgusting, ugly little freak that was deluded if she thought someone like you could ever "love" her. You tell her this is where she's going to stay, in the woods, alone, because normal people don't want to look at her. Then, take some rope out of your backpack along with some sleeping pills and a knife. Throw them at her feet and tell her if she follows you back you'll put her down yourself.

Then hike back. After a few hundred feet you won't hear her sobs anymore and by that evening you'll know she's gone from this world for good.

congratulations! That was the only "you are definitely a retard" answer!

>not throwing her a copy of SICP
>not staying to help her learn it
why are you so cruel, user?

>kaocels actually believe this

Elaborate.

b is the only correct answer.

No, you are the definite retard.

you are always compiling for a particular architecture. both you and the programmer are aware of the actual properties of the architecture. the whole reason that 'undefined behavior' even exists as an idea is to permit the compiler to do the right thing per architecture instead of mandating a language that will be massively inefficient or retarded if used for some novel bit of hardware. with 'b' you've blatantly broken the programmer's code, and with an optimization that only makes sense on hardware that doesn't exist.
(also I forgot to mention that the loop increments x. It only starts as 1.)

>with undefined behavior on rollover
>depends on the machine you're compiling to
iirc it has well-defined behavior, just per-arch. my targets are limited: x86, x86-64, arm, aarch64, rics-v. unless Mill happens in my lifetime, I have no intent to care for anything else. So I would make that defined behavior and also provide checked arithmetics variants.
>you find a loop that runs until x < 0. You can see that x is statically set to 1,
if it's statically set to 1 and never modified then it's dead code
if it's modified only by increment, then according to my specs it's c/d are same
in a world of C's retard specs, e is the right answer

this is why C's turning to shit. grandpa came up with nasal demons as a joke, but now kids are literally worshipping it and offering up unwanted newborns to it. If you rely on undefined behavior, you're UNCLEAN. You DESERVE TO BE PUNISHED.

>if it's statically set to 1 and never modified then it's dead code
fug, not dead code but infinite. I hate "until"

I find her autism extremely cute and I want to cuddle, protect, and love her!
You're a complete degenerate, hang yourself.

>you've blatantly broken the programmer's code
the only person responsible for breakage here is you, stop being retarded and start reading up on your language specs

Kaos please stop posting, you aren't even allowed to post here.

>If you rely on undefined behavior, you're UNCLEAN. You DESERVE TO BE PUNISHED.
No shit, retard. You should be writing correct standards-compliant code.
Look, if you're not interested in performance even the slightest, just straight up say so, it's okay.
Now that we've gotten that out of that way, fuck off out of this thread forever. Inefficient code isn't programming.
You should have a restraining order of 1km from any computer for the rest of your life.

where in the rules is Kaos not allowed to post here?

>>you've blatantly broken the programmer's code
No, the programmer broke it herself. The compiler was just following the standard and generating efficient code like it should.

>Look, if you're not interested in performance even the slightest,
THE WHOLE REASON UNDEFINED BEHAVIOR EXISTS
IS TO ALLOW COMPILERS TO DO WHAT THE MACHINE DOES
INSTEAD OF DOING SOMETHING ARTIFICIAL
that it is.
There is no magical benefit from it otherwise.
C is not 'fast' because compiler writers have become retarded. Rather, this retardation actually harms efficiency. There are now programs that are best compiled under GCC 2.xx

it's because you can't define all the behaviour retard

thanks for repeating what i said
read this
blog.llvm.org/2011/05/what-every-c-programmer-should-know.html

She's underage v&.

I have a static struct A that has a field B,
B is an array of pointers to other structs that have fields called size, which i want to access
Why is A.B[index]->size wrong?

Just because you're fucking retarded using outdated compilers doesn't mean optimization is going backwards.
Optimizing compilers have improved a lot, you're just a brain dead fucking idiot who can't even fucking program properly. Stop posting and fucking learn to program already, fucking idiot.
You have a huge fucking self-importance problem. You think what you _think_ the code should do (which is wrong) is more important than what the standard fucking says the code does. You are programming in a fucking language defined by a standard, you are programming to the fucking standard. Compilers follow the standard, not the arbitrary fucking retarded ideas idiot programmers like you have that btw can vary.
Fucking learn the language you're programming in or fuck off to another language. Don't fucking complain when the compiler does something different than what you expect because YOU yourself don't fucking know the language and then have a fucking hissy fit over it instead of just fucking pulling the stick out of your ass, learning the fucking language, and writing correct standards-compliant code.
Fuck off, idiot.

>sees someone say undefined behavior is obviously just to permit machine behavior
>"oh gosh, you're so wrong, you should read this chick tract"
oh yeah I'm just NOT AWARE of that retarded C people think. That's how I came up with such an accurate "am I retarded compiler optimizer" test in one question.

Any Go folks here? What do you think about the (restricted) either monad I've been implementing?

Attached: Screenshot from 2019-08-10 06-38-32.png (1440x2560, 237K)

Sorry, quoted the wrong post.

Python is the best language ever and C sucks.

post code

>You think what you _think_ the code should do (which is wrong) is more important than what the standard fucking says the code does.
Oh yeah, I just think the code should do something, and the standard just says it should do something else. That's why I keep saying "machine", "machine", and why the standard keeps saying "undefined", "undefined". It's not that I actually completely agree with the standard and that the standard is actually blatantly giving way to the hardware on a question. You've an amazing grasp of the dynamics of this conversation.

>Python
Wrong thread, this is the programming thread.
>C
Wrong thread, this is the programming thread.

it's not the compiler's job to babysit mentally deficient programmers like you

post code

you can

After I graduate my diploma I'm gonna read 40 computer science textbooks cover to cover.

start with Knuth.

>I just think the code should do something
How about instead of playing pretendsies you actually fucking learn the language?

Why is /dpt/ so stupid? Are you all kikes and shitskins?

Is it possible to model the following file structure in cabal:
/
-> Main.hs
-> Library.hs
-> Tests.hs
-> ...

I don't know how to put the Library.hs file at the same level of the Main.hs file.

No you fucking idiot, stop thinking Haskell is a useful language and learn a real programming language.

If he wants a useful language he should learn Python and import all his troubles away.

at least you're not one of those tards who think there's nothing more to learn once they get their degree

sure, why wouldn't it?

$ ipython
Python 3.7.4 (default, Jul 9 2019, 18:13:23)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import hookers
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import hookers

ModuleNotFoundError: No module named 'hookers'

In [2]: import girlfriend
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import girlfriend

ModuleNotFoundError: No module named 'girlfriend'

In [3]:

It's free from IBM (Master the Mainframe, ignore the context and just do the learning one)

>implement a quad tree based collision detection system for my asteroids clone
>it runs slower than just putting everything into an array and iterating with a for loop

Why the fuck did you fags meme me into learning about algorithms?

Attached: 1503226066-723.jpg (957x621, 90K)

>Python
Read the fucking thread title and get out.

I think I messed up somewhere. I started a new project and this works perfectly fine:
executable blah
main-is: Main.hs
other-modules: Library
-- other-extensions:
build-depends: base >=4.12 &&

>trying to import girlfriend after importing hookers
Python isn't a pure language, user. The girlfriend is clearly aware of what you've been doing.

post code

How many objects are there?

Classic

keep learning. what you've just learned is that scale matters. a technically superior algorithm isn't superior at all scales.
also, simple arrays are hard to beat.

ride sharing app for my University

I did. That's why I didn't suggest C.

hurr durr

>asteroids clone
How many objects could have an asteroids clone?
Or maybe your quadtree impl is just shit.

What is Python even used for why is it so popular? Im learning it just to ass to my CV but the syntax is pretty annoying

Why is this thread so full of idiots like you. Don't discourage him from learning algorithms. That's how you end up with slow software like windows 8. This thread is the worst place for a programmer to be.

I just got my degree and think I just started and know far too little (prob cause it was a meme university)
Self learning is kind of hard though since vidya and movies distract me

It's fast in terms of development. If you want to quickly make an application that just werks that's what Python is for. As long as you use good algorithms it will run smoothly too.

>"keep learning"
>WHY ARE YOU DISCOURAGING HIM
yeah, so, the reason simple arrays are hard to beat is that sequential access is much, much faster than random access.

Having a bit of trouble with curses. After I finish my application, the terminal output gets mangled. Here's my setup/teardown functions. Any suggestions to how to fix this?

def initialize_curses(self):
self.screen = curses.initscr()

# Enable color support, if available.
curses.start_color()
curses.use_default_colors()

# We want to be able to "hide" keypresses until we want to display them
curses.noecho()

# We want to react to keys instantly, not waiting for "Enter" to be
# pressed.
curses.cbreak()

# Be able to read from the keypad (arrow keys).
self.screen.keypad(True)

# Nonblocking getch
self.screen.nodelay(True)

return self.screen

def end_curses(self):
self.screen.clear()
curses.nocbreak()
curses.echo()
curses.endwin()

Attached: Screen Shot 2019-08-10 at 11.13.35 AM.png (1872x174, 43K)

>syntax is pretty annoying
do you need a safe language to cater your needs?

O(log(n)) will always be faster than O(n) array operations in the large scale. You should always strive for O(log(n)) unless you know your data will be small.

Unless you implemented your quad tree with contiguous spaces of memory it's going to perform awful compared to a nice cached array.

Why is "front end" even a thing?
People should've already came up with modern looking drag and drop tools like winforms functionability but nice looking as opposed to old shit instead of writing the same code for buttons and textboxes over and over and over again.
Seems to me like a waste of time/conspiracy by front end shitters to keep their shitty useless jobs.

Can it be used to make simple CRUD applications with a modern looking GUI fast too? What would I use for this?

>O(log(n)) will always be faster than O(n) array operations in the large scale. You should always strive for O(log(n)) unless you know your data will be small.

Not true at all.

O(n) Linked list traversal is slow as fuck compared to
O(n) Array traversal

Big O is not a measure of reality when it comes to how memory and cpus work.

front end shitters of the past
>don't use Tk, it doesn't look native
front end shitters today:
>let's use electron. it's easy and it looks the same on all platforms!

>Self learning is kind of hard though since vidya and movies distract me
install an obscure OS (linux is not obscure) and cancel all your streaming services/private tracker accounts.

are you sure end_curses() get called at program exit? that includes in signal handlers for SIGINT and stuff.
as for your terminal you can use the reset command to fix it if you didn't know.

Neither of those are O(log(n)), retard.

>>better complexity will be better on large data
>not true because this one with the same complexity is faster

Attached: 1562575877342.gif (500x382, 167K)

I've never had to do that so I'm not sure what resources to suggest but I know people who have done that in Python.

Why are Pytards so arrogant? Don’t get me wrong it’s a fine language and I use it to make excel reports all the time but it’s not the end all be all. Bragging that you only know Python is like bragging that you still drive a 1996 geo prism

Yes if you use a framework. Django is a python web framework that’s pretty easy to learn. You could technically build an entire web app with just python and HTML, but you are going to want to learn JavaScript if you want to load data without reloading the page

How long will it take me to learn Electron

is Django or Flask easier to use and make a fully working app that just werks?

>start learning x
>switch to y
>switch to z
>...

fuck why can't I stick to something till the very end

Since this is the programming thread you're obviously talking about programming languages.
Which means the only language you could possibly be talking is C++, so I have no idea what you mean by switching, as there's nothing else to switch to.

>learn common lisp
>try to go back to normal languages
>always end up back with common lisp
god I hate myself for learning lisp. I almost got fired the one day because i went on a rant about how we should integrate more lisp into our work.

It takes a SPECIAL kind of retard to believe that people who talk about complexity think that it's the entire picture and disregard memory access times.