/dpt/ - Daily Programming Thread

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

Haskell

Still working on my C imageboard.
The actual web page displaying part isn't written yet.

Why C?

I don't want to learn PHP to write CGI scripts.

And node.js is gross.

The correct sentences would be:
Why are you using malloc if you want to write C++?

>it's another Cfag jealousy episode

kill yourself

>not using spring boot with h2 database and angularjs
Die

You're , aren't you?
Do you not realise what the premise of this website is?

>premise of this website
there's no such thing

every board is different

I'm learning C. I get that other languages are easier, but realistically is there any reason I *shouldn't* be learning it? I'm hoping to go into game development but general software dev is fine as well. I figure the skills I learn are pretty language agnostic.

>every board is different
All I see is shitposting anywhere I go so no. This is the thread where we shitpost about programming.

oop is good

This thread is older and therefore legit

>You're → , aren't you?
no

(if i were, i would call it fag shit instead of weeb shit)

So what are you working on, Sup Forums?

Game development is usually C/C++(more C++) but there is stuff like Unity which uses C#.

Learning C will make you hate other languages because they're so easy.

I was going to write an imageboard in rust but got bored.

C++ is more common for game dev and software in general

>Learning C will make you hate other languages because they're so easy.
Wut? C is one of the easiest languages in existence.

also the skills you learn in C are not very language agnostic because you'll be stuck in the C mindset and you probably won't understand the benefits of things like OOP

Honestly, I dig learning new things/ways to make my programs more efficient or look cleaner, so I think I'd be fine if I moved to an OOP language.

Only one I've used before this is Python, and I wasn't taught "OOP" so much as I was taught "this is a class".

>OOP
meme

Can someone link me to a good article/book that explains corotuines in C++? I need to use them in my program, and I don't want to install a massive, bloated library.

Visual studio has an experimental, non-standard extension for coroutines that microsoft are going to propose for C++19/20

Beginner.
Made a prime decomposition program in Python.
It first worked like a charm but then things started randomly breaking and I blindly added more stuff until I got this mess.
print('Lists all prime numbers in a number.')

negativeNumber = False

correctInput = False
while correctInput == False:
correctInput = True
n = input('Enter a number: ')

if n == '':
correctInput = False
print('...')
print('You didn\'t enter anything.')
print('Try again.')
continue

n = n.strip()

while n[0] == '-':
if negativeNumber == False:
negativeNumber = True
else:
negativeNumber = False

n = n.replace('-',' ',1)
n = n.lstrip()

for x in n:
if ord(x) == 44 or ord(x) == 46:
correctInput = False
print('I haven\'t implemented finding \
reciprocal prime numbers of decimals yet.')
break

if ord(x)57:
correctInput = False
print('Not a number.')
print('Try again.')
break

n = int(n)

if (n == 1 and negativeNumber == False) or n == 0:
print(str(n) + ' is ' + str(n) + '.')
print('What am I supposed to do with it?!')
else:
if negativeNumber == True and n != 0:
print('-1 (1)')
if n>1:
i = 2
counter = 0

while i 1:
print(n, '(1)')

Also, why aren't there shortcuts for code and math tags?

Also been reading my SICP. Got stuck on exercise 1.5.
Miffed that I had to look up the answer. I sort of get it now but not really.

Why is the ternary operator ?: not more popular?

More limited use than if/else if/else, as it can only really do if/else which is less common in larger programs (you're more likely to want else if as well).

>things started randomly breaking and I blindly added more stuff until I got this mess.
And thus you learned the value of versioning. What breaks exactly?

Because people abuse it.

>It first worked like a charm but then things started randomly breaking and I blindly added more stuff until I got this mess.
P Y T H O N
Y
T
H
O
N

is the gif 60 fps or 30? looks smooth

>ord(x) == 44
Fucksake this is harder to read and to write, just use x == "," pls.
>inb4 yes it's legit in Python

But I'm using Code Blocks.

Haskell confirmed a table of truth

>negativeNumber = False
Fuckssake, int does this builtin

Way C, use a real language, Moo! language

30 ms per frame according to gimp so 33 fps

SICP 1.5:

We have:
(define (p) (p))

(define (test x y)
(if (= x 0)
0
y))


Now the question is what would be the difference in evaluating (test 0 (p)) under applicative order and normal order.

Applicative order means that you evaluate the arguments and then substitute the results in the definition. Normal order means you just subtitute, no evaluation.

So under normal order we get:
(if (= 0 0)
0
(p))

The 'if' statement will evaluate the first argument, and depending on the result evaluate either the second or third argument and have that be the result of the 'if' statement. 0 is indeed 0, so it evalutates to the second argument of the 'if' which is 0.

However under applicative order, something else happens. The arguments are first evaluated before they are substituted. The first argument is 0 which evaluates to 0 and is substituted. The second argument is (p) which evaluates to (p) which evaluates to (p) which evaluates to (p) etc.

So the arguments are never evaluated because evaluating (p) is an endless cycle, and the command will never be fully evaluated.

>What breaks exactly?
Well, it's basically the printing of answers: I originally had it just spew out 2s, 3s, 5s and the rest of the prime numbers before clumping them in a primeNumber (numberOfOccurences) fashion.
When I decided to change it, the last prime wasn't printing. I didn't give it much thought, changing this, that and the other.
And then, after a while, I changed the while i

>What are you working on, Sup Forums?
just finished type inference (minus some of the more advanced features, which come later down the pipeline)
i guess it's time to make the lexer and parser? ill probably hold off until later today to work on that, but it feels nice having this much of my compiler done so far. plus im extra happy because i cleaned up all the really ugly parts of my type system with the last couple commits, so it should be a lot nicer to extend in the future

So close

Coding is fun and challenging
I am right now learning about value methods in java.
I have not always the time to sit down and code.
Nonetheless I want to learn more about programming better and understand it more deeply.
As I am learning Java, I really want to concentrate myself on this language for now and get used to the new features, I am looking for something I can read on the go.

Do you have any good texts and links I could inform myself?

are you messing with ASLR or something?

Trying to generate proper GDT entries for a kernel.

k&r, you fucking pajeet

>int does this builtin
Would that be the __ge__(0) method? I don't see one specifically dedicated to giving a boolean depending on whether the integer is positive or negative.
Regardless, at that point, I was still working with the input as a string (because I'm too stupid to try/throw/catch exceptions to check user input): it's easier to scan the beginning of the string for dashes and weed out non-numerals further along than to... I don't know how else to do it.

>In applicative order evaluation, you evaluate the arguments and then substitute the results in the definition
>you evaluate the arguments (the x y of (test x y)) before substituting
>In normal order evaluation, you substitute first
>Which means, when running test under normal order evaluation, you don't get to (p)
I think I get it now although I'll likely need to reread the bit about applicative-order and normal-order evaluations again.

and, bingo!

Xinu based OS project. Porting a lot of old code from OSDev followings. Probably going to do PE instead of elf as I have a PE bootloader finished.

>2016
>putting the burden of memory management on the programmer

Absolutely disgusting.

Is it realistic to use IPFS as a video streaming platform?

i = 100000000

while i:
i -= 1


$ time python test.py
python test.py 12.07s user 0.00s system 99% cpu 12.092 total


kore i wa 100000000 desu

while i
{
kore i wa i - 1 desu
}

$ time ./interpreter test.fs
./interpreter test.fs 7.90s user 0.92s system 99% cpu 8.823 total


>tfw even your shitty inefficient toy language is faster than Python

How do i write c++ code in c style? I need a static global variable, but i really don't want to make any ever again.

>$ time python test.py
>python test.py 12.07s user 0.00s system 99% cpu 12.092 total
that's not how you benchmark a script, you dumbass

Noice, weeb.

Well you're talking about the language that had to iterate over an array of numbers in a for loop at one point.

I know.
I just implemented while loops and wanted to get some idea about the performance of my interpreter.

Hey lads I'm learning C right now and got confused by something involving main.

How come I can write main() { ... } without int or void and have it compile fine?

I can't tell if I'm using C90 or C99 which are different apparently or if they affect anything

But that's the proper way to iterate over arrays.

convenience
sometimes you just want to write a shitty toy program and the function declaration would be longer than the program

...And I lost the code to the bootloader.

i think he's talking about it actually creating an array of numbers which it then iterated over, just having a for loop could make it crash from running out of memory

Oh, lol.

It's technically not allowed but GCC isn't strict because it kept compatibility to compile stuff from before C89 back in K&R C. The standard only explicitly states two signatures and any equivalent as long as it doesn't break the standard is also allowed.

Most languages:
>int i = 0; int i < 5000; i++
>checks if i < 5000 and increments it

Python:
>for i in range(0,5000)
>creates an array [0,1,2,...,4998,4999] and iterates over it

Anyone?

kek

It actually doesn't do that anymore in 3.x, unless you specifically ask for it

up to version 2, but that's a good point.
just use xrange, but that's a stupid default. And python is pretty stupid in general.

this compiles even with -std=c90 -pedantic
main(i)
{
i = 100000000;
while (i--);
}

do you know what google is, you fucking retard

>google for me pls

Can you do an algorithm thingy even if you are not inside a data structure packet container linked to the server client model server asynchronously?

That's because there are no builtin coroutines in C++. You can have coroutines, but only with a huge library that leverages platform-specific shit. If you want to read about this, the doc for Boost.Coroutine explains what it's doing under the hood very well IMHO, so go read that, it's most probably the best you can get.

Fuuuuuuck. I don't wanna use Boost.
Oh well, thanks user.

Boost it a tool, therefore using it isn't automatically bad ; abusing it is.

Hahaha oh wow

Using boost is the same as abusing boost.

Nothing right now. Kind of "finished" consuming an api a week ago. It does what it does(Searching jobs in Sweden via the swedish employment office).
What do you think about the user interface?

I'm aware that the dates in listview aren't formatted. Just too lazy for that.

The method populating the listview is embedded in another thread because the frame freezed when consuming the api.

This is created in JavaFx.

Do you have any advice what to do next? Something thread heavily and useful would be great.

>not using recursion

Who /codetriage/ here?

It's a leftover from pre-standard C.

Functions with no return type used to mean int, but I think that since c99 this is not the case?

Please, it's not THAT much of a toy language.

map

map isn't iteration, you want fold

The fact that you have implemented while loops as a basic functionality just shows that it is a toy language

>while loops
>toy
Go back to "programming" your recursive fibonacci in Haskell please.

Nah, too easy.

if i install a debugger plugin on sublime text that calls itself a ruby debugger, does that mean that it won't work at all for other languages?
I'd like a debugger for C, C++, Java and/or python that allows me to click on the line number to set breakpoints and that shows me the value of each variable for every step.

Just use an IDE.

in Haskell loops et all are just higher order functions

You know, this is why Ken Thompson, Rob Pike and Robert Griesemer created Go.

Each individual writes better C than all of Sup Forums combined several times over, but they know it isn't the best tool to write web servers and that all other alternatives are bloated shit, overengineered or incomplete.

Fun fact: Go literally has no reason of existence.

>it won't work at all for other languages?
The plugin? No it won't. Sublime? Yes it will. It can handle it; don't be stupid. Also note that it deprives you of your freedoms.

>and you probably won't understand the benefits of things like OOP

Which kind of OOP? Inheritance-based OOP is only really useful in a very, very limited amount of situations, and 90% of that is UI and video games (things where you have clear-cut entities, and even then that's no excuse to use it everywhere in those types of software).

Functional and imperative people usually recognize that OOP can help in those situations, while OOP people try to hammer OOP into every fucking thing out there.

Go was designed for people who aren't capable of understanding better languages.

>Which kind of OOP?
Java and C#, duh. OOP is the best solution to 99.993% of programming problems.

this

Anybody here use Geany for Python and C++?