/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

ideone.com/kZOiqP
youtube.com/watch?v=JpkjOkiu-fA
youtube.com/watch?v=3hviD9fuuSc
tldp.org/LDP/abs/html/dblparens.html
stackoverflow.com/questions/4071633/python-turtle-module-saving-an-image
twitter.com/NSFWRedditGif

...

Haskell!

What's the best programming language, and why is it a functional one?

see the post above yours

I saw an HTTP server written in prolog once, I don't understand you people

When books say that function variables are declared "on the stack", do they mean they're stored in the computer's actual hardware stack, or that they're just represented in a stack data structure?

I'm just wondering, because if you try and access the first variable declared in a function, does the OS (or whatever deals with the low-level shit) have to pop all the other variables off and then push them back on?

every program running has it's own stack, there's a bit of boilerplate ASM that gets created to make this happen even if your C program does nothing but return 0.

Back in the day I used to draw in BASIC with commands like POINT, LINE and such.
Does there exist a Python library which would let ne do this? I'd like to save my pictures in some vector format, though.

I need some help senpais i'm learning c and the book gives a program for listing prime numbers, I wrote my version and the console output was wrong after changing things and making sure it was perfect console output was still wrong. So i copied the code from the ebook still dodgy console output what's wrong?? Here is the code

// Program to generate a table of prime number

#include

int main (void)
{
int p, d;
_Bool isPrime;

for ( p = 2; p

lacking some braces there

Do people need to learn how to program?

None, they're all retarded and chaotic. Haskell being """pure""" is just a meme.

can you check my original code because i'm pretty sure that is right but had same console output

// Program to generate a table of prime number

#include

int main (void){
_Bool isPrime;

for ( int p = 2; p

My math bud says that "programming is basically accounting, everyone can do it after a week or so", I don't consider that bullying because he's extremely autistic

Haskell is statically typed functional language. There is nothing special about that, aside from utility. Dont know why you're talking about "purity," whatever that means.

what is accounting even?
it's just counting and making sure money wasn't lost between the cracks

You can fill the array manually while declaring it, in C, like this
int array[] = {4,6,7,3};

can I fill it in the same manner but form a file without using loops?

yes, but why would you want to?

People rather use Excel than programming to perform accounting though.

You're resetting the isPrime state, notice line 14.
ideone.com/kZOiqP

>what is programming even?
>it's just counting and making sure data wasn't lost between the cracks

Trying to threadsafe a mutex method with a c# control. Failing miserably.

No, you can only initialize arrays with constant literals. I/O is not constant by definition, so you still have to parse the stream before filling your variables.

youtube.com/watch?v=JpkjOkiu-fA

ironic that an animu poster is such a SJW

In this case, programming in C can't ever be called programming.

purely functional i would guess
WHICH IT IS

haskell isnt pure.

What do you mean by "pure?" Haskell is just a statically typed functional language.

whats your pleb definition of 'pure' in the context of (functional) programming languages?

It's pure if unsafePerformIO is used correctly or not at all. Otherwise laziness would not work.

no mutation of external state, deterministic execution, etc.

CPUs don't work this way, so claiming to do pure programming is fucking stupid.

check this one
youtube.com/watch?v=3hviD9fuuSc

wrong.gif you can model proper hask code as a purely rewriting system, no von neumann bs

That is not what purity means. Purity means you get equal output given equal input.

from a file? if you really do mean "in the same manner" (as in direct initialization) then... sort of, haha. technically you can add a file with just comma-delimited values in it to your include directory, and then do

int array[] =
{
#include "values.txt"
};


the values will be included at compile time, though, and changes to the values will require rebuilding, so this probably isn't a good idea

the only video from the conference that i couldn't finish, only because the accent was so horrendous

Why not VSCode?

What is vscode?? I've wanted to learn c for a while want to get into 3ds and vita homebrew

>started CS
>never did programming before
>just read the book and do all exercises before labs
>have almost no problems during lab because ironed out syntax errors in book exercises
>people who sit near me struggling to write simple shit and say stuff like
>"wow, user, you must have a lot of programming experience"
>hear other people say
>"wow bro this is so hard I don't understand anything lol"
Why do these people even attend collage?

What do I use to git gud at C++?

Learn Rust instead.

parents forced them, computer jobs are all the rage
not everyone is cut out for college
the sad part is everyone will automatically assume you're as stupid as the lowest denominator of compsci student

But I want to learn how to handle memory allocation.

>Why not VSCode?
shills please leave

Makes me so mad when I see CS students with computers

You don't use a computer to learn CS

You use pen and paper

CS is proofs, not programming

You're not proving anything hard/complex enough to require any automation in an undergrad program

maybe in 1960

CS is a programmer degree now.
You might have math up to physics, but they still expect you to learn how to program, because otherwise you're fucking useless.

cppreference.com
Herb Sutter's GotW series
Jason Turner's C++ Weekly series
CppCon and BoostCon presentation videos
Books by Stroustrup, Sutter, Meyers, Alexandrescu
to name a few

I don't understand what you're saying.
Everyone uses a computer in collage. Writing reports, mail. And the how are you supposed to program without a computer? You're not making any sense.

If you're talking about math, then yes there is 0 need for a computer.

Trying to figure out can bus with stm32 and its fucking weird

CS is a subset of math

>finally figure out how to work with file data embedded into a program

I feel like a fucking god

CS is the intersection of math and programming.

rust has a macro for that

>muh dreamland autistic purity
>muh made-up completely subjective redefinition of common term
Classic hardcore autist behaviour. Ignore it.

On the contrary, it's the intersection of art, Engineering, and math. Pretentious fuck

I would recommend getting familiar with C before you start writing C++.

C++ started as a fancy macro set on top of C. Once you understand C structs and memory use, then C++ is both easy and clearly seen as completely fucked up from an ecosystem standpoint.

Then you'll probably want to learn Rust. If you're wanting to learn C++ for game dev, you'll still be very well served by learning C first.

that's cute. personally i prefer to generate my data procedurally at compile time with constexpr

>then C++ is both easy
hahahaha
>and clearly seen as completely fucked up from an ecosystem standpoint
sure, when you don't actually know it

Why do people still talk about Rust?
Is it some sort of thing where people think it's better because it goes full babymode?

This is a very basic snippet from the python script I am writing:

running = True
while running
usri = input("Do you want to proceed? (y/n): )
if usri == "y":
function()

It says the namerror: y is not defined. I looked it up on my favorite search engine and learned that this has to do with the scope of the variable. But, usri = input and the if-block resides in the same block, how is this possible?

> semantics

Cringe so hard. Who cares? Everything is defined differently by the *context* in which you're viewing it.

CS is whatever the university system decides it is. The science of computation. Nothing more, nothing less.

jesus fucking christ if that's your top just kill yourself immedietely

>C meory use
What you people mean by this? Declaring variables, manipulating arrays etc right?

>Avoided Java for the longest time because people shit all over it
>Using it for my data class
>Loving using it

Why'd you guys lie to me?

Semantics are important in CS. You should know that.

allocation, stack and heap. pointers.

>FOSS
>shill

????

Sure. *In* CS. Not when discussing CS itself.

>If you're talking about math, then yes there is 0 need for a computer.
lot of my math professors use CAS (computer algebra systems) and matlab/octave for numerical number crunching.

computational maths is getting bigger and bigger.
you can use it for example to sanity check some idea you came up with. or look at large numbers of examples to try to find patterns

tl;dr "no"

why's it always print yes?
read input
if ((input == 'Y' || input == 'y'))
then
echo "YES"
else
echo "NO"
fi

tfw banned from using rtti ever again on production

language is bash btw

it's unnecessarily verbose and has "corporate" written all over it.

what other languages do you know of that you can compare it to?

Count the quotes.

this is my first language

Java is a creepy fucker because it looks like a great language until you're sitting on a few thousand lines of it. Then you realize you're in a curry smelling kafkaesque code monkey distopia.

good

Maybe you misunderstood.

C++ is easy to understand.

You just have to untangle 30 years of ecosystem changes to be productive in it. Multiple standards, multiple template libraries, build systems that are absolute anus (looking at you, autoconf; or hell, CMake which has the shittiest documentation I've ever seen), etc.

Fundamentally simple. Just shit on top of shit.

Java is the best programing language, hands down.

This will always echo YES because you can put anything inside those parens and it'll evaluate truthily.

I mistyped it here. It is correct in the original script.

C# is better tho. wouldn't make much difference earlier on, admittedly, but check it out down the line sometime if you ever feel like you're hitting a ceiling

tldp.org/LDP/abs/html/dblparens.html

use square brackets for these conditionals, see also
$ man test
I think double braces are used for bash-arithmetic, but maybe I'm wrong. Also string comparison is done via "=", not "==" (at least in test)

the C# ecosystem is full of proprietary tools, the Java ecosystem is full of open source tools. And dont get me started on trying to use mono if you're on linux.

My CompSci starts with C and then Java right after and no C++ at all.
I don't get it, wouldn't C++ be better since we already learned C?

Not that guy, but basically that. Your teachers are lazy and C++ is a two book subject. Like physics. Good idea to learn for yourself though.

Then all languages are pure. Given the same CPU/memory/HDD state they will yield the same value

A program might be pure but purity of individual functions is much more rare (except in Haskell, for instance).

I am that guy and I'll echo the sentiment. C++ is too complicated to teach students. There's so much history to unfold that it's simply not possible to teach it *well* to a class of undergrads.

I honestly think that this is why it's probably on its way out. Ain't nobody got time for that.

cool thanks

How does GHC work?

On x86, , "the stack" is just RAM like any other.

It's not magic in any way. It's exactly as if you had implemented a stack using an array and a size. Pushing is array[++size]=42; Popping is --size;

And of course, reading the Nth value from the top is array[size-N], no popping required.

>not copy pasting
First year is going to be hard. Count colons.

saying my program is gpl but I'm not going to release the source code when anyone asks

based

stackoverflow.com/questions/4071633/python-turtle-module-saving-an-image

Not at all. Take getch().

How doesn't it?