/dpt/ - Daily Programming Thread

Previous thread: Type Inference Rules edition. What are you working on, Jow Forums?

Attached: 1536322071085.png (495x720, 557K)

Other urls found in this thread:

github.com/InBetweenNames/gentooLTO
twitter.com/SFWRedditImages

first for autistic sperglords arguing over types

public class FizzBuzz {
public static void main(String args[]) {
for(int i=1; i

I prefer to exactly define the types for my variables before i use them you know.

Coward. I write huge files with zero types annotation. The compiler will handle them for me.

With global type inference you get the security of static type checking without the faff of writing type signatures everywhere. What isn't to like?

I use auto for everything and it's great.

>What isn't to like?
Cniles are still allowed to program

will other programmers think its bad to put statements (with only one line of code within it) as one line like this as? personally i find it much neater and as long as the statement is only doing one thing, its still very clear what it is doing

Attached: code.png (874x280, 96K)

Threadly reminder that type inference is for retards who can't deduce a valid type for fn even after being given the type of x.

Attached: 729.gif (340x340, 137K)

fizzbuzz :: (Integral a, Show a) => a -> String
fizzbuzz n = case (n `mod` 3, n `mod` 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
otherwise -> show n

main :: IO ()
main = mapM_ (putStrLn . fizzbuzz) [1..20]

Attached: 1533593218530.gif (340x340, 148K)

Question was deduce type of x, why are you talking about deduction of type of fn, dumb nigger?

I think it's bad. Especially when there is a side effect.

>Question was deduce type of x
>Surely you can tell me the concrete type of x here
Doesn't even contain the word "deduce". Sorry, tard.

I hope you salt and hash your passwords

>Especially when there is a side effect.

well yeah if it broke something that would be bad, but i dont really see what can go wrong with assigning one variable

yes you're so smart, I'm sure you mom is really proud

>get into computing course with programming
>doing well, getting DDDDD Distinctions
>want to try making my own nought and crosses game as my first game to get into game dev
>get stuck as soon as I create the project in visual studio

What gives anons? If this was part of my assignment I would of failed easily.

How about instead of dodging the question, you actually answer it correctly?

Ok, I made the mistake of assuming the person I was talking to had an IQ of at least 70, but I forgot I was talking to a C "programmer". I'll be more considerate from now on.
So I'll explicitly state what was implicit:
Foo must be able to work with any fn.
You are not choosing the type of x, you are deducing the type of x under the constraints.

Now, as you said before, non retards are capable of figuring out their own types without automatic type deduction.
You're not a retard, right? So, you should be able to answer this pretty easily.

>i dont really see what can go wrong with assigning one variable
If it's not bad why are you hiding it?

that's some cute looking code. is that haskell?

Attached: 1541357556487.jpg (400x400, 24K)

you have to learn to think things out and plan things for yourself

university is basically just listening to lectures and doing worksheets/assignments which are all laid out for you, its easy in comparison

yes

What are some options I should be using with GCC?
Currently:
g++ \
-std=c++2a \
-O3 -flto -march=native \
-Wall -Wextra \
-pipe

gcc 8.2.0 btw

im not hiding anything? i just think its nicer to have them neatly on one line rather than needing 20+ lines to assign 7 variables

DIVIDE AND CONQUER
I know it's easier said than done, we all get through this user.

haskell flag

-Wpedantic

But where do you even start with this? Feel like such a turnip.

So try to break it down to even smaller steps? Well I guess I got to create variables so I could start with that.

Sup niggers.
I am doing python programming and I have a dictionary and in that dict I want to assign a JSON value to a key. I have converted the JSON to dict. But it is possible that the value in the JSON is not there. How can I make sure that I don't get a keyerror in an elegant way?
Example:
dict = {
'key' : JSON["var"][var2]
'key2' : 'some_other_var"
}

Change -O3 to -O2
Change -march to -mtune unless you're purposely breaking compatibility
Remove -Wextra
add -fconcepts
add -masm=intel

>dodging the question
Do you need me to remind you what the question actually was?

>Foo must be able to work with any fn.
#define foo(fn) do { \
__typeof(fn()) x = fn(); \
} while (0)

Attached: 1513683116879.png (593x321, 318K)

Start by making the first building blocks of your program.
And then you compose and build on top of them, or write more basic building blocks.

>Change -O3 to -O2
Nigga I have the entire gentoo compiled with O3 and it works.
Actually having the highest possible optimization level is the best for proper programming because it helps to catch mistakes like undefined behavior more easily.
github.com/InBetweenNames/gentooLTO

Good boy! You answered it correctly!
See? Type deduction IS useful after all!
*head pats*

Attached: 1517791989435.jpg (382x500, 34K)

For a real coder your hiding it.
Let me show you how a good coder read code.
if condition
code in the true branch
other code in the true branch
else
code in the else branch
code outside the if
Good developer only look at the left part of the code to see the flow control. Anything written after the "if" is not read, it's the condition. That condition is only examined when needed. By putting code on the if line, you're hiding it in the condition fog. So a good developer will hate your code, because cautious examination is needed just to grasp the control flow. It's a fucking lost of time. I wont; argue more, you agree, you're on the path of being a good developer. You disagree, you'll stay a codemonkey. I don't have time to explain such basic things.

>being this bad at using the preprocessor
>this contiguous space in memory sucks
Neither of you shouldn't be allowed within 10 feet of a computer

Nothing wrong with this

>and it works.
Yeah of course it will but that's not the point.
-O3 most of the time actually produces worse code than -O2.
Unless you've benchmarked and confirmed -O3 really is faster, -O2 is the best default.
And no, benchmarking with one program doesn't tell you anything about other programs.

just google (or youtube) it. nought and crosses will have tons of implementations already made. then just copy that. dont think of this as "cheating", think of it as how you learn. once you copy a few (or even just one) easy games, you should have the skills necessary to do it on your own

>Neither of you shouldn't be allowed within 10 feet of a computer
And you shouldn't be allowed 10 feet within the English language.

>-O3 most of the time actually produces worse code than -O2.
Wrong. GCC automatically chooses whatever options are best for particular code.
Just because you set -O3 doesn't mean that the suboptions of -O3 will be used in every single case

footfags pls go and stay go. /dpt/ is a boobs only programming thread

its not hidden to anyone that has eyes

You chose the code monkey path.

based and redpilled

Attached: 1519273618906.png (565x800, 371K)

>not -Os

Fine, then he shouldn't be allowed 10 boobs within the English language.

>Type deduction IS useful after all!
Non-sequitur. In any case, I'm still waiting for you to somehow counter the statement that type inference is for retards who can't deduce types on their own. Your request to "deduce the type of x" in a context where you're supposed to simply define the type of x only proves that you're retarded, as is your failure to deduce the type of fn upon being given the type of x.

Fuck. Guess I'm also too retarded to understand how C telling you exactly what it's doing is somehow bad given its runtime is literally just the hardware, plus memcmp, memcpy, memset and a couple others

He said boobs

I/O bound?

i make a lot and my job is easy so

Attached: anime wa.gif (500x289, 358K)

>type inference is for retards who can't deduce types on their own
Then deduce the type of x like you did here without using type inference.
You can do it right?

spoken like a true cnile, I'm so proud of you!

I forgot where I read it, but having too much optimizing can be a disaster because if a certain branch of code is unreachable due to a faulty or optimized conditional, that code section is not analyzed for errors. A smart compiler with less optimizations would explicitly tell you a certain section is unreachable.

Would it be possible to design an operating system and related userspace such that the operating system may interrupt the executing process, relocate it to a different region of the address space and then resume execution?

doesn't gcc produce warnings for aggressive optimizations like that?

Nah, just that code size optimizations past -O2 are still good, while ones that increase code size can be self-defeating by causing worse cache behavior.

That's what -Os is for.

>job is easy so
Yes, I know that people don't give you difficult task.

Yes, that's how memory paging works.

So I'm trying to haskell

main = print(add 2 6)

add :: (Num a)=>a->a->a
add x+y


GHC is screaming at me. What do?

Attached: 1507445208036.jpg (1152x768, 116K)

You get a LOT of side effects. It requires a very, very safe language. Like up reentrancy, as well as stuff like functional/math oriented languages that try to enforce rules that forbid you from having direct access to pointers and such.

pls respond

defaultdict or except KeyError

He probably means virtual address space.
And yes you can if you force programs to be PIC compiled.

999: the savior
Try
add :: Num a => a -> a -> a
add x y = x + y

No, you can do it fairly easily with PIC.
Just force everything to be relative lookups.

>deduce the type of x
You're seriously retarded, aren't you? Macro hacks and compiler extensions aside, your request is inherently invalid in the context of C, where you deduce types when you're writing a piece of code that has to comply with some preexisting type constraints (as you've repeatedly failed to do when calling the macro). Otherwise you're simply defining the types and creating those constraints.

I mean actually moving it around within the virtual address space. You can defer relocation until load time if you want, how about doing it at arbitrary points at runtime?
You'd need symbol tables that tell you what's a relocatable pointer and what's regular data.

be quiet pajeet

your not defining add as a function. Try
add x y = x + y

Why this works?

Please just stop, you're embarassing the rest of us.

Attached: 1500435864336.png (720x1110, 250K)

That's the point. Optimizing too hard conflicts with analysis. Like I said, I forgot where I read it, but there's certain edge cases where you get undefined or anti-programmer behavior from overly optimizing.

>deafultdict
thank you! Exactly what I was looking for

Oh, the = doesn't mean an assignment, it means what the function is. Thanks!

>your request is inherently invalid in the context of C
Because C has no type inference and that makes C a less powerful language.
Glad you admitted it.

Because it's the correct syntax.

add :: (Num a)=> a -> a -> a
add = (+)

Attached: 1525793570359.jpg (700x988, 61K)

all code needs to be position independent.
all memory accesses need to be relative to some base. local stack operations can be relative to the stack or frame pointer. All accesses that would traditionally go through an absolute pointer need to go through some base and an offset.
On a relocation, the OS would move the memory, change the heap base, stack, frame, stack base and .data base pointer.
Alternatively, you could tag pointers and change them accordingly.

for(int i=1; i

>Because C has no type inference and that makes C a less powerful language.
Sure, but how does this disprove the fact that type inference is mainly for retards who can't deduce types on their own? I mean, you have literally demonstrated it by repeatedly failing to call a macro when I supplied you with a simple type constraint, and repeatedly failing to understand the source of your error...

= is the "assignment". It's like in math.

If you write x = 3, you're just stating that x equal 3 or 3 equal x.
if you write add x y = x + y you're just stating that add x y equal x + y.

You're not assigning, you're just defining equations.

for i in range(1,101):
print("FizzBuzz"[i*i%3*4:8--i**4%5] or i)

>but how does this disprove the fact that type inference is mainly for retards who can't deduce types on their own?
So you think that a developer should do the work that a machine can do? Do you really understand what programming is about?

import edu.princeton.cs.algs4.WeightedQuickUnionUF;

I want to import stuff from either WeightedQuickUnionUF.class (or .java, not sure which) from /edu/princeton/cs/algs4/WeightedQuickUnionUF in to my java file . It isnt working for some reason. How do I do this? I have the command line and the java file I want to import it to in the seemingly correct file (the one that has /edu/...).

I want to write programs for 8 bit systems and/or non-x86 16bit systems.

I don't want to buy any hardware, it must run in emulators.

Where do I start?

write an emulator

That's a pain in the ass, my dude. You sure you don't want to start a little later? If you're a /v/irgin then there are plenty of good toolchains for more modern platforms.

QEMU and good fucking luck because it sucks ass for anything that isn't x86 or raspberry onions

>So you think that a developer should do the work that a machine can do?
No, I just think that people who can't even call a macro correctly shouldn't be able to compensate for their incompetence using technology. If it was up to me, your only option would be pure 8086 assembly, just to weed out the feeble-minded.

>haskell
>not spurdell
ddd :: ddd d => d -> d -> d

Attached: 1493079169944_spurdoandfug.jpg (420x420, 133K)

I'm starting to see.

Let's say you want to run C programs under this system. When you compile PIC C code, all global data is accessed through the global offset table. When a relocation is triggered, the OS can once more update the GOT like it does at load time.
The problem is - how do you make sure that your code won't use stale pointers? Here's an example of what such C code may compile to.
ldr r0, [pc, # 12] @ load GOT index
ldr r0. [r9, r0] @ load ptr to global symbol from GOT

@@@ Preemptive relocation happens here @@@

ldr r1, [r0] @ that GOT entry has been overwritten in the meantime - stale pointer value, probable segfault or worse
How can this be prevented from happening? It's quite a general problem too. Generally you could write anything like this
int x;
int *y = &x;
and if a relocation happens between assigning y and dereferencing it, the relocator must also be aware that y is a pointer and therefore due to be relocated.

Let's say you have an array of 10000 elements and you need to fill it with random numbers. In what range would you generate the numbers to get best average case in linear search? Given that you're searching for a random number within the same range.

>type inference is mainly for retards who can't deduce types on their own?
Then deduce type of x without type inference.

>how does this disprove
We haven't disproved it, but then again you haven't proved it either.
Lets explore two possibilities and see what they prove,

Case 1:
Premise: Type inference is for retards who can't figure out types on their own.
We see here that you needed type inference to deduce the type of x.
Therefore, you're retarded.

Case 2:
Premise: You're not retarded
Assumption: Type inference is for retards who can't figure out types on their own.
We see here that you needed type inference to deduce the type of x.
Therefore, you're retarded.
But now we see we've come to a contradiction under the assumption, which means the assumption was false.
Therefore, it isn't the case that type inference is for retards who can't figure out types on their own.

Either way, this turns out badly for you.
Which will you accept?

Answer me plz

Well shit, finally figured out how to extract ebix files.

Attached: 81iCE0VyRFL.png (512x512, 296K)

I truly admire your patience user, how have you still not given up on this troll?

Attached: 1516851656077.jpg (716x1011, 407K)