[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 326
Thread images: 30

File: prog.jpg (105KB, 473x496px) Image search: [Google]
prog.jpg
105KB, 473x496px
What are you working on, /g/?
Previous thread: >>61183729
>>
Dynamic "typing" is trash
>>
File: japanese anime.png (1MB, 1280x720px) Image search: [Google]
japanese anime.png
1MB, 1280x720px
Reminder that Japanese anime is cute and cool
>>
File: cchan.jpg (58KB, 190x291px) Image search: [Google]
cchan.jpg
58KB, 190x291px
Monads are only necessary in a language where immutability, statelessness, and purity are concerns.
In other words, a shitlang, because computers fundamentally don't work that way, and any language that insists on working that way cannot go fast.
Correctness, readability, and going fast are the only three things that matter. Imperative languages with mutable state are better for going fast. Hasklel, Lithp, and I[dr]SIS are better for correctness and readability, but anyone who is not a brainlet can write correct and readable code just as well in an imperative language with mutable state. If you're especially not-stupid, you can even write *gasp* type-unsafe code that's correct, readable, and more efficient than its type-safe equivalent.
>>
>tfw you solve a bug in 5 minutes in the morning after sitting on it for several days
>>
Implicit type conversions damage brains.
>>
>>61187090
No. As long as you don't use a shitlang like Python, you have the full power of static dispatch available to you.

# GADT equivalent in Julia using abstract and parametric types.

abstract type expr{T} end

struct In <: expr{Int64}
int::Int64
end

struct Bo <: expr{Bool}
bool::Bool
end

struct Add <: expr{Int64}
a :: expr{Int64}
b :: expr{Int64}
end

struct Mul <: expr{Int64}
a :: expr{Int64}
b :: expr{Int64}
end

struct Eql{T} <: expr{Bool}
a :: expr{T}
b :: expr{T}
end

# Haskell type signature would be calceval :: expr{T} -> T
calceval(e::In) = e.int
calceval(e::Bo) = e.bool
calceval(e::Add) = calceval(e.a) + calceval(e.b)
calceval(e::Mul) = calceval(e.a) * calceval(e.b)
calceval(e::Eql) = calceval(e.a) == calceval(e.b)
>>
>>61187125
 int i = 5;
long u = i;
writeln(i,u);
>>
>>61187135
Trash
>>
>>61187148
I don't like it
>>
File: 1498022934481.jpg (781KB, 1188x990px) Image search: [Google]
1498022934481.jpg
781KB, 1188x990px
What is the best micro to attatch a camera and a wireless transmitter to? I want to practice with Assembly and video streams.m
>>
>>61187121
>coding to the hardware
You can produce even faster code by using assembly, but nobody does that, and there's a reason for that that you would do well to learn.

>readable code
>imperative language with mutable state
No.

>type-unsafe code
>more efficient
No.
>>
>>61187090
>things which do not exist

>>61187125
I would be interested in your reasoning.

>>61187121
>Monads are only necessary in a language where immutability, statelessness, and purity are concerns.
They are not always necessary in such languages either.
>>
>>61187153
I get to have GADT's so that I can combine parsing and type checking in one operations if I decide to implement a parser for my own domain specific language.

Your language does not have this unless it is Haskell or OCaml, which do not also have Lisp macros that make type-checked DSL's useful.
>>
>>61187200
He's a brainlet who thinks his spaghetti code is just as readable as well-crafted, maintainable code, because he is unable to understand the latter.
>>
>>61187194
>You can produce even faster code by using assembly, but nobody does that, and there's a reason for that that you would do well to learn.
The reason for that is because assembly is not abstracted enough to be usable.
Compiled imperative languages with mutable state are.
Any further abstraction is nothing but a waste, because the threshold was waaay farther back along the road.

>>readable code
>>imperative language with mutable state
>No.
Yes.

>>type-unsafe code
>>more efficient
>No.
Yes.
>>
>>61187228
Completely incorrect.
>>
>>61187224
>well-crafted, maintainable code
>cannot go fast
These contradict each other.
I don't care how maintainable your code is, if it's not fast, it's not """"well-crafted.""""
>>
>>61187243
No, I'm actually right.
>>
>>61187247
If you think fast code cannot also be well-crafted and maintainable, then I think you ought to go back to school.
>>
>>61187228
>>>type-unsafe code
>>>more efficient
>>No.
>Yes.
This does not make any sense.

>>61187247
>>cannot go fast
[citation needed]
>>
>>61187262
>If you think fast code cannot also be well-crafted and maintainable,
I didn't say this though
>>
I like dynamic types because I can't be bothered getting the types right, I just want to get shit done.
>>
File: jldcsa.png (118KB, 825x470px) Image search: [Google]
jldcsa.png
118KB, 825x470px
>>61187271
>>>>type-unsafe code
>>>>more efficient
>>>No.
>>Yes.
>This does not make any sense.
Word manipulation.

>>>cannot go fast
>[citation needed]
pic related
>>
business idea: a language where mutability can only happen in pure functions
>>
>>61187296
>dynamic types
>things which do not exist
???

>I can't be bothered getting the types right
Meaning?
>>
>>61187074
hax my anus, anon. hax my anus ;_;
>>
>>61187307
>pic related
This only compares implementations

>Word manipulation.
Wut?
>>
>>61187338
>This only compares implementations
>i-it's just an implementation
>hurrr

>Wut?
Machine words.
Manipulating them.
Faster than always manipulating the right types.
Types are useful for prototyping, but after that, any mature adult would redo it in terms of words.
>>
>>61187354
>>This only compares implementations
>>i-it's just an implementation
>>hurrr
Are you retarded?

>>61187354
>>Wut?
>Machine words.
>Manipulating them.
>Faster than always manipulating the right types.
>Types are useful for prototyping, but after that, any mature adult would redo it in terms of words.
This makes no sense.
>>
>>61187296
Then use type inference.
>>
>>61187364
>Are you retarded?
>IT'S JUST AN IMPLEMENTATION BRO

>This makes no sense.
It does, you're just dumb.
>>
>>61187383
>>IT'S JUST AN IMPLEMENTATION BRO
Yes? How is that wrong?

>>61187383
>It does, you're just dumb.
Well, you are wrong.
>>
>>61187371
I still get type errors if I do that.
>>
>>61187397
>Yes? How is that wrong?
Your """"""""""""""""""""""pure"""""""""""""""""""""" shitlangs cannot be implemented efficiently without changes to the hardware. This is because the languages themselves are shit from a perspective of realism about how computers work. This will be true until you can show me an implementation of Haskell as fast as GNU C.

>Well, you are wrong.
How is it wrong to say that it's more efficient to manipulate an object of any given type as an array of machine words?
>>
>>61187423
That's good, you're writing code which is objectively wrong.
>>
>>61187444
It's not wrong if it works
>>
>>61187442
>Your """"""""""""""""""""""pure"""""""""""""""""""""" shitlangs cannot be implemented efficiently without changes to the hardware
[citation needed]

>This is because the languages themselves are shit from a perspective of realism about how computers work
Again, [citation needed]

>This will be true until you can show me an implementation of Haskell as fast as GNU C.
This makes no sense though.

>How is it wrong to say that it's more efficient to manipulate an object of any given type as an array of machine words?
I do not think that you understand how type safety works. If you did you would understand that how objects are manipulated in a lower level is irrelevant.
>>
>>61187442
>Your """"""""""""""""""""""pure"""""""""""""""""""""" shitlangs cannot be implemented efficiently without changes to the hardware.
Reminder that Lisp machines did exist, and were disposed of for a good reason.
>>
>>61187491
lmao dude everyone knows passing void* is faster than passing int32_t*
>>
>>61187507
1: This makes absolutely no sense
2: The standard says nothing about that
3: This is irrelevant to our discussion.
>>
>>61187491
>[citation needed]
observation
>Again, [citation needed]
observation
>This makes no sense though.
typical hasklet can't rhetoric
?I do not think that you understand how type safety works. If you did you would understand that how objects are manipulated in a lower level is irrelevant.
This kind of attitude is the reason our technology is slow. How objects are manipulated at a lower level is ALWAYS relevant, because speed is paramount in importance in the general case.
>>
>>61187544
(the ? was supposed to be a >)
>>
>>61187074
I am trying to understand hierarchy.
in Java.
And I am still recalibrating on my antidepressive (zoloft).
I am battling my lack of want and yet am stopped by my empty thoughts.
>>
>>61187544
>observation
No such observation.

>How objects are manipulated at a lower level is ALWAYS relevant
I meant that it is irrelevant in regards to type safety. Nobody stops you from using whatever method you want in the lower level when you use a type safe language.
>>
>>61187580
>Nobody stops you from using whatever method you want in the lower level when you use a type safe language.
Wrong, the language does. And that's what's wrong with your "functional" languages.
>>
>>61187576
you mean class hierarchies?
>>
>>61187593
>Wrong, the language does
How so?
>>
>>61187595
yes.
keywords like super, this, implements, interface.

My head is sluggish though and I have difficulties grasping the concepts.
>>
>>61187593

Type safety is about being able to declare what operations are valid or invalid. Type safety does not imply slow execution.
>>
>>61187612
>How so?
By way of the implementation being slow.
>>
>>61187617
Like all things, it makes more sense when you see it in practice.
>>
>>61187638
You are really not making any sense. You claim that type safe languages magically stop you from using any underlying mechanism you want because their implementations are slow, W A T?
You don't seem very bright.
>>
File: 1476195160683.jpg (26KB, 320x395px) Image search: [Google]
1476195160683.jpg
26KB, 320x395px
are there a lot of you in this thread that use haskell or is it one guy against the world? Seems like every day I come in here and some guy is giving it his all defending haskell but I've seen like 1-2 industry use-cases total and they're for DSL's.
>>
>>61187693
I use Idris mostly but sometimes when I feel like slumming it I'll use Haskell
>>
>>61187693
haskell is a social construct made by math grads whose worldviews resonate well with it
nobody actually uses haskell
>>
>>61187712
Could you explain monads to me?
>>
>>61187712
what sort of work do you do if you don't mind me asking? I work in data science so most of the languages I work with are ones that have implementations that accommodate scale. Usually I have to deal with Java/Scala/Python folks or people writing C/Rust for CUDA gpu clusters. I've setup frameworks for Haskell but my understanding was Idris is still relatively formative implementation-wise
>>
File: terry vs toady.png (2MB, 1703x1524px) Image search: [Google]
terry vs toady.png
2MB, 1703x1524px
hasklelfags can't write a compiler in 3 days
>>
Hey Haskell and Lisp fags, how is the job hunting going? Picking the right offer? :DDDDDDDD
>>
>>61187442
>2017
>Still worries about minute differences in efficiency

Fast as possible doesn't matter. All that matters is that it's fast enough. A faster computer/server is cheaper than paying programmers.

When it comes to consumer software, there's only one point that speed absolutely matters: UI. As long as everything else processes unperceptively quickly, it doesn't matter if it takes two times or 100 times as long, 1ms and 10ms doesn't make a difference, 100ms is fine as long as your UI is responsive.

When it comes to server software, as long as your server meets demanded capacity, all's fine.

Go ahead, write in a slow language. If you need efficiency, like a loop takes up a significant portion of time, then write that part in C or whatever.

Back in the 80s, C was a slow as fuck language unless you had a fancy processor like the 68k. 6502 ran C like shit.

And really, until the *implementation* of C was improved like mad with GCC and its optimizations, along with good cross-platform library support, C ran well on only a handful of the most expensive computers. If you wrote your program in C, you still typically optimized performance-critical parts with hand written assembly.

The reason C is such a fast language today is because modern processors are designed around C's computing model.
>>
>>61187731
Fuck you! Haskell is NOT a social construct! It's a real programming language, and it's fast, and it's pure and stateless and it's fucking better and more efficient than any retarded imperative shitlang! Computers are pure and stateless and so is Haskell! State is a fucking lie! They made it all up! Kill yourself!
>>
>>61187815
monoids in the category of endofunctors
>>
>>61187194

Sometimes it's just convenient to write in assembly on an embedded computer. You don't have to guess how long something will take to run. You can get the exact behavior that the datasheet is talking about.

and it isn't that hard
>>
>>61187862
It's funny, most companies I go to want people who know Python and other OOP stuff just because that's the easiest thing for most teams to adopt. The interviews are usually pretty boring but every now and then some old lead dev will see that i write Lisp and his eyes will light up then get a really sad look in them.

I'm employed ATM, deffo not for my Lisp.
>>
>>61187886
Haskell is more efficient than assembly
>>
File: le lol over lisp.png (162KB, 571x307px) Image search: [Google]
le lol over lisp.png
162KB, 571x307px
>>61187862
>comparing lisp with haskek
I'll have you know Common Lisp is a robust, industry-grade imperative multi-purpose language that is hardly comparable to the purposeless autism that is Hascuck. A shame people only know it through the two kikes that wrote SICP.
>>
>>61187905
>Haskell is more efficient than assembly
>>
>>61187835
Idris compilers

I sometimes worry I've cornered myself into a very niche sector
>>
>>61187919
>>Haskell is more efficient than assembly
>>
>build a state machine
>pretend it's stateless
lmao functionaltards are funny
>>
>>61187942
<Haskell is more efficient than assembly
>>
>>61187912
CL is crap compared to Scheme.
>>
>>61187862
>languages are difficult to learn
???
>>
>>61187919

Yes, let me just spout a meme from my asshole as well:

Go is better than C because C stands for Cuck
>>
>>61187900
It's absolutely fucking tragic

Sure, it might be 10x harder to find developers proficient in Lisp, but they'll generally be 11x as productive. Businesses don't want that though, they want easily-replaceable cogs, because perish the thought that an individual lowly worker (y'know, someone who actually produces stuff) might be essential to the business
>>
File: 1474605792939.png (52KB, 363x403px) Image search: [Google]
1474605792939.png
52KB, 363x403px
Common Lisp is for the common man. The refined aristocrat prefers a better Scheme.
>>
>>61187951
A COMPUTER IS NOT A STATE MACHINE!
IT IS FUCKING STATELESS!
"RAM" AND "PROCESSORS" ARE A FUCKING LIBFAG COMMUNIST LIE, OPEN UP A COMPUTER AND SEE FOR YOURSELF IT'S TYPED LAMBDAS ALL THE WAY DOWN YOU FUCKING NECKBEARDED FAGGOT!! (but when you get that far down the industry just calls these lambdas "circuit components")
HASKELL IS EFFICIENT!!!!!
>>
File: 1496419947075.gif (935KB, 500x250px) Image search: [Google]
1496419947075.gif
935KB, 500x250px
>>61187940
>works with Idris
>Idris compilers
>worried if it's too nich

>woman bursts in to room
>covered in blood
>holding young man
>he seems unresponsive
>she screams
>"I NEED SOMEBODY WHO CAN WRITE ME AN IDRIS COMPILER"
>>
>>61187951
Nobody pretends that.

>>61187871
>>61187992
Nice falseflagging. (not really, it's shitty and you are shitposting)
>>
>>61187987
it's really true. I know that if I do my job the right way when it comes to writing code in Python, it's so that when I leave it's easy for somebody else to work on the code. The language certainly has that benefit for enterprise.

I genuinely enjoy writing Lisp. If I get to write some tooling in it I will (where appropriate). The most enjoyable thing about it is somewhere in it's approach to solving problems. I feel like it turns on a different part of my brain that other languages simply due to the interesting outward-reaching nested list structure
>>
File: doom trashman.jpg (58KB, 700x479px) Image search: [Google]
doom trashman.jpg
58KB, 700x479px
>>61187961
>>61187991
>have to mimic iteration using tail recursion
>no do, loop or format
>no vectors, streams, packages, OOPOO
>no regular macros, has to handhold you with "safe" ones like a baby
sure thing body
>>
>>61187991
The refined aristocrat is a fat lazy bastard who lives off the backs of the poor.
The poor are pure, clean skinned, clean blooded, innocent, and hard working. The dirt a poor man wears on his skin takes from him like the rich do, but the man himself is still clean, whereas the rich ARE the filth that sullies their own selves.
The poor -- the pure -- the victims -- the real human beings, with real souls and real lives -- prefer C.
>>
>>61188048
>write lisp interpreter in python
>write the rest of your code in lisp and include it as resource files
>later your entire codebase is in lisp and it would be too expensive and time-consuming to change it
>switch from the python interpreter to sbcl
>management can get fucked
>>
I want to get into programming, but it seems very intimidating. Is there something easy for a novice to work with?
>>
>>61188101
SICP then HoTT
>>
>>61188028
It's true though, if you think about it, circuit components are lambdas. They're function objects: they accept parameters, they return a result, and you can compose them, curry them, map them, etc. In this sense, lambdas, functional programming, and statelessness are the reality, and a """"computer"""" is just an imperative lie built on these truths.
>>
>>61188065
>>have to mimic iteration using tail recursion
And this is good
Or you can make a macro if you want (loop is a macro in CL, same for the rest of the things that you mentioned)

>no vectors, streams, packages
False

>OOPOO
??

>no regular macros, has to handhold you with "safe" ones like a baby
Why are you lying?

>>61188070
>The poor are pure, clean skinned, clean blooded, innocent, and hard working
Lmao, no
The poor are dirty, stupid and with pitchforks.

>prefer C.
C is the anvil, Lisp is the sword.
>>
>>61188135
>The poor are dirty, stupid and with pitchforks.
The poor are pure and clean. The dirt is not a part of them. It's the rich who are truly dirty, because there's dirt in their souls.
They aren't stupid, they're smarter than the people who take advantage of them.
>>
>>61188165
If they were smart they would not be taken advantage.
>>
>>61188165
t. commie
>>
>>61188181
>Science: "Rats are closely related to primates, which are much smarter than birds."
>(You): "If the rat were smarter than the owl then owls would not be able to eat rats."
This is how retarded you're being.
>>
>>61188101
http://htdp.org/
>>
>>61187951
>build an out of order machine
>pretend it's in order
>>
File: old_hag_langs.png (173KB, 600x355px) Image search: [Google]
old_hag_langs.png
173KB, 600x355px
>>61187121
>>61187951
>fart on the toilet
>accidentally take a shit
Oh look it's functional programming.
>>61187873
In theory yes, but in practice the category of types for the language won't be closed compact monoidal unless you make it so rigid that it's basically a proof checker like Coq.
>>
>>61187848
Perelman isn't a neet. He is secretly working as a software consultant in Sweden, I met him a while ago.
>>
File: smug_mouko.png (93KB, 264x264px) Image search: [Google]
smug_mouko.png
93KB, 264x264px
>>61187848
>Ted Kaczynski, activist
>>
>>61188234
Some birds are pretty smart, like parrots

(and parrots are vegetarian, maybe we could learn something from them)
>>
>>61188408
why is his/her (you can never tell with anime) hand green?
>>
>>61188430
Pretty sure that's a Pepe hand.
>>
>>61188430
It's a him.
>>
>>61188413
Agreed. The vegetarian parrots in new zeeland leaned that they can improve their diet by eating sheep. Alive. They just land on the sheep's back and start eating:

https://www.youtube.com/watch?v=o8mQiXKKfWw
>>
>>61188430
Xe is possessed by pepe.
>>
Imperativefags have no answer to this: >>61188126
>>
>>61188458
#notallparrots
>>
>>61187135
Wait, so it's like a GADT but you are free to add cases to a type you don't own, and overload functions to cover that case? That's a pretty neat solution to the expression problem.
>>
File: get rekt functional faggots.png (12KB, 577x129px) Image search: [Google]
get rekt functional faggots.png
12KB, 577x129px
>REMIND
>>
Friendly reminder that cybersecurity is a meme.
>>
File: wrong.jpg (81KB, 716x378px) Image search: [Google]
wrong.jpg
81KB, 716x378px
>>61188126
The circuits themselves are completely hardcoded in machine language in reality, which means that they still require states in order to act and exist. What you're describing are logical abstractions of the circuit elements.
Fucking retard functionfags.
>>
>>61188126
The circuits are preconnected, and outside of FPGAs there's no way to compose them together outside of the way it's built. The only way to compose together these fixed-function blocks is with stateful registers.
>>
>>61188586
This is inaccurate. The circuits themselves are not "hardcoded in machine language." If you could describe them as being "hardcoded in" anything, it would be copper, silicon, and electrons, which aren't even a language.
>>
>>61188637
I meant that it's implemented in machine language.
>>
>>61188101
C
It has a very simple syntax and doesn't have a fuckton of useless features to overwhelm you. C only gets complicated when you move on to very large projects where it's easy to lose a few pointers, if you just want to learn the basics of programming then C is a very good choice.
>>
>>61188631
>stateful registers
But this is assuming a computer, which I just said is an imperative lie made of circuits.
Your code will be much more efficient, elegant, and readable if you write it in the beautiful functional language of literally fucking building your own circuits from scratch without using a processor or ram at all.
>>
>>61188650
That's getting a bit metaphysical.
And also probably wrong.
>>
>>61188664
>elegant
Subjective.
>readable
For retards maybe.
>efficient
Yeah you're a fucking idiot rofl.
>>
>>61188664
If you're building the hardware yourself or using programmable hardware like FPGAs, then yes you can build a functional machine. That doesn't work well for general purpose computing. An imperative ISA works much better for that.
>>
>>61188656
To do anything nontrivial in C you need to use macros since it doesn't have templates. You lose a lot by not having templates.
>>
When did dark color schemes become fashionable? The majority of pictures from the 90's show a light color scheme being used.
>>
>>61188586
>>61188650
This makes no sense.
>>
File: homu_off.png (460KB, 800x600px) Image search: [Google]
homu_off.png
460KB, 800x600px
>>61188672
>metaphysical
Do you even know what the word means? It's as if I'm talking to a schizo
>>
>>61188695
to save power
>>
>>61188694
>templates
You lose a lot by not having parametric polymorphism along with type inference.
>>
>>61188698
Whatever helps you sleep at night.
>>
>>61188718
>parametric polymorphism
Is what templates are
>type inference
is what auto is
>>
>>61188725
Well, it still does not make any sense, combined with the fact that it's simply wrong.
>>
>>61187121
I like you. I can't find any faults in what you said.
>>
>>61188734
Whatever helps you sleep at night.
>>
>>61188728
>Is what templates are
No

>is what auto is
Can you use it for arguments? If not it's mostly useless.
>>
>>61188681
>>elegant
>Subjective.
It's really not. An electrical component is a pure function. It can be defined purely in terms of its inputs and outputs and has no side effects that affect program flow. It's even properly black-boxed, if you know how to use plastic and electrical tape. The same cannot be said for ANY implementation of ANY programming language.
>>efficient
>Yeah you're a fucking idiot rofl.
No, it's true. If I manually build a circuit that does just one thing, I have the freedom to make it much more efficient than your computer program that does the same thing but has to do it through a computer.
>>61188687
>then yes you can build a functional machine.
Not even what I'm talking about. I'm talking about the universe itself being a machine, and circuits being programs for that machine, written in the functional assembly of electrical components.
>That doesn't work well for general purpose computing. An imperative ISA works much better for that.
Bitch the universe is the best general purpose computer out there. My circuits I build may not work well for general purpose computing, but they're not supposed to, because they're programs, not computers.
>>
>>61188746
Shitposting won't make you correct.
>>
I can write in c++11 kinda ok, but i want to kinda consolidate my c++11 and what i know about the STL, best resources to look into?
After i've done that i am moving to c++14 and 17 and whatever, but first i want to be good at c++11 and STL.
>>
>>61188763
Whatever helps you sleep at night.
>>
>>61188586
>>61188650

Not really. I get what the other guy is saying -- it really is actually a functional construct. It's a series of logic gates with a "function applied," you put in the same inputs, and the result is the same *every time*. Then it uses parts of that, along with an external source of inputs, takes a new cycle, and applies the function to the logic gates again with new inputs.

Which... is actually how Haskell kinda views the world.

Computer hardware really *is* functional, only made imperative by applying the same function with different inputs every clock cycle.
>>
>>61188769
If you make a 4th shitpost your mother will die tonight.
>>
>>61188783
Haskell doesn't compile to functional circuits, it compiles to imperative assembly.
>>
>>61188765
cppreference.com for a quick rundown
>>
>>61188761
I wanted to use FPGAs to program my programs actually, would be interesting to run /bin/bc for example and have the program executed in its own fpga.


>>61188802
>Haskell doesn't compile to functional circuits
What stops it from doing so?
>>
>>61188802
>Haskell doesn't compile to functional circuits, it compiles to imperative assembly.
Not him but this is a real problem!
I bet a Haskell implementation that compiled to functional circuits would be fucking amazing.
Probably even faster than C.
Only thing is, if you wanted to run the resulting program, you couldn't do it on a computer. You'd have to do it on its own terms.
... I guess you'd also need a hardware peripheral to build the circuits for you.
>>
>>61188802
Well, good thing I didn't say Haskell compiles to functional circuits, and only drew comparisons between how computers operate and how Haskell conceptually handles mutation.
>>
>>61188799
Damn you got me
>>
>>61188819
Nothing.
That would make it useful, rather than an exercise in orthogonality.
>>
So basically coding in C is basically like coding in java, only in a imperative, procedural way, no classes, no java libraries, pointers being used as raw shit, no pointer C++ BS, pass arguments a values, no strings or objects.

I'm sort of right, right?
>>
>>61188841
Sure whatever.
>>
Reminder that Scala > node.js

https://vimeo.com/216330850
>>
File: is this nigga serious.jpg (59KB, 1280x720px) Image search: [Google]
is this nigga serious.jpg
59KB, 1280x720px
>>61188841
>so basically coding in C is basically like coding in java but completely different
Yeah you're right alright.
>>
>>61188841
You missed a really important part -- in C you also suck your own cock because you don't believe in finding a library to do that for you.
>>
>>61188802
Not entirely true. There are Haskell to FPGA circuit compilers, and there are Haskell inspired hardware description languages like this one: http://www.clash-lang.org/
>>
>>61188858
Perfect, that seems exactly the sort of thing a functional language should be used for.
>>
>>61188858
>Haskell inspired hardware description languages
Well, that wouldn't mean Haskell compiles to "functional circuits", right? Ie. you could technically create a modern Intel CPU with that description language.
>>
I am stupid /dpt/.

Why am I so stupid?

Assignment:
Firstly, develop a class which implements the interface LabeledDataSeries. The constructor of this class get's a Filename assigned as a Parameter and reads the Dataseries line by line from a Textfile with following formatting:

Title of dataseries:
42.5 Europe
111.3 Northamerica
21.85 Southamerica etc.

To make it easier, the Textfiles will never have more than 100 lines.


interface DataSeries {
int getItemCount ();
double getItem (int idx);
String getTitle ();
}


interface LabeledDataSeries extends DataSeries {
String getLabel (int idx);
}


public class DatafileReader{
//(?) DatafileReader(In.open("cities.txt")){

//}


}

I don't know man, how would you have done this?
>>
>>61188820
The only thing is, Haskell is typed, and if we think of the language of circuit design as a pure functional programming language, the only type it supports is bool. It actually isn't even a pure functional programming language, just a pure programming language, because functional would imply functions are objects, but really all function manipulation has to take place at "compile time," and at "runtime" there are no function objects, because electrical components have no way of representing other electrical components, only of representing bools.
Hmmm.
>>
>>61188125
Thanks.
>>
Do anyone knows any good sites for data structures and algorithms practice? Is possible, for C/Java/Python languages.
>>
>>61188906
Well, after I got over the wat aspect, at some point you'd have to be axiomatic and say, "that series of bools represents this in Haskell."
>>
>>61188906
>>What are opcodes?
>>
>>61188125
>>61188101
Unless your math is strong, SICP is going to be pretty fucking intimidating. Try "Learn Python the Hard Way," then maybe pick up SICP. If your math is strong, then just go ahead and try SICP I guess.

(let "math is strong" (complete calc3))
>>
>>61188982
something you don't have access to if you're working with pure circuits without a computer involved
>>61188955
that makes sense
which means you would end up having to have something like opcodes after all but you'd have to implement them yourself if you don't want your circuit to depend on there being a computer
>>
>>61189008
I'm an idiot and that pseudo-Scheme makes no sense.
>>
 
* extensions for x86 and ppc32 would want a larger alignment than this, but
* we don't need to do better than malloc.


It's this kind of shit why we can never have anything nice.
>>
File: smug_ran1.jpg (180KB, 1732x1593px) Image search: [Google]
smug_ran1.jpg
180KB, 1732x1593px
>>61189008
>complete calc3
Seriously? Aside from the fact that the calc sequence literally doesn't help you in understanding lambdas completing it by no means makes your math "strong". It's the most basic of the basic.
>>
>>61189009
>which means you would end up having to have something like opcodes after all

And now you're getting it! A modern computer is nothing but a function applied to (an) opcode(s) repeatedly.
>>
>>61189009
Assembly language is untyped as well, but types are still important. You don't want to accidentally feed a sequence of bits representing an int into a circuit that expects a float. You want to prove at compile time that this never happens accidentally.
>>
>>61189059
>And now you're getting it! A modern computer is nothing but a function applied to (an) opcode(s) repeatedly.
Yeah but the function is bloated with artificial notions of state in order to be turing complete
The language of circuit design is already complete enough on its own, you don't have to re-implement it in itself
And for what purpose even
Just so you can do things by sitting and typing instead of with hard work?
Just so you don't have to get your hands dirty?
I mean shit man
Programmers would probably be healthier on the whole if we had stuck with implementing programs as custom circuits
>>
>>61189044
The programming part of SICP, including lambdas, aren't the hard part for someone with "bad" math. But SICP was written for STEM majors at MIT, most of which completed the calc sequence, and uses those sorts of problems for examples.

If you can get past the first chapter or two, it's pretty smooth sailing past that. But for a beginner programmer, I think it's better to focus on programming first instead of having to work through math *and* programming.

That's why I also said try LPTHW first, then come back to SICP -- he'd have the basics of programming down and can focus on tackling the math, and skip parts of the chapter with math he can't be fucked to figure out and not lose out on too much other than some basic practice with programming.

I suppose calc 3 might be a bit high, but definitely need relatively strong math to get past that first chapter.
>>
>this is the average /g/tard in the wild
Explain yourselves

>>>/pol/132134631
>>>/pol/132130008
>>
File: 1145.jpg (9KB, 229x266px) Image search: [Google]
1145.jpg
9KB, 229x266px
>>61189273
>/pol/
>>
>>61189273
>/pol/ uses a nazi flag for germany
>/pol/ uses a communism flag for russia
the degree to which this website is a shithole never fails to amaze me
>>
>>61189331
/pol/ introduced user-selected flags a while ago.
>>
>>61189348
oh
>>
>>61189348
/pol/ had user-selected flags long before it added country flags.
>>
>>61188941
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8
>>
File: Untitled.png (41KB, 394x706px) Image search: [Google]
Untitled.png
41KB, 394x706px
>>61189328
>>61189331
>he doesn't go to pol
>>
what's a good c++ library for parse html files?
>>
>>61188894
>I don't know man, how would you have done this?
It's for an Intro-level class. You should be aware that that means that you have been given enough information.

How do you write a constructor at all? What's the first idea you've got for what you might want to do in that constructor? How might you save the information?

What *really easy* thing are you missing from your DatafileReader class?
>>
>>61188894
Implement the fucking interface.
1. getItemCount()? What should this do? Read the fucking file and count the number of lines that are not "titles".

2. getItem(nth)
what should this do? Return the fucking n-th line, retard.

3. getTitle(), getLabel(index)
lord. jesus.
>>
>>61187074
reading this https://www.securecoding.cert.org/confluence/display/c/SEI+CERT+C+Coding+Standard so i won't end up writing code like a pajeet
>>
>>61187307
clang > gcc
>>
File: As3wTMC.gif (2MB, 292x200px) Image search: [Google]
As3wTMC.gif
2MB, 292x200px
Anyone know of a *good* proven example of a working Entity–component–system implementation?

All I can think of at the moment is the system in unity. There are tons of other implementations out there of course, but I really have no clue if they are good or not since they rarely have any good examples of games implemented using them...
>>
>>61189273
>these are the people who make fun of women programmers
lol
>>
>>61190130
>>>/vg/agdg
>>
If the name of an array variable in C is a pointer to the first item in an array, what is the practical difference between a 1-dimensional array and a pointer variable in C? Automatic memory allocation for the array?
>>
>>61190130
No.
>>
>>61189273
>/pol/
I wouldn't go there. It's an incredible waste of time consisting in interacting with morons who are pretty OK at pretending they're smart. They're repeating things and using the words they think are good.
It's just not worth it because you might fool yourself and think there's a brain behind these posts.
I would expect nothing less of C# programmers. They must feel very threatened by just about every rising demographic in programming.
>>
>>61190219
you can do size of array to get the whole array size.
>>
>>61189864
CPParseHTML
>>
>>61190130
thief the dark project
>>
>>61190219
>If the name of an array variable in C is a pointer to the first item in an array,
It isn't. This is a commonly held misconception.
Array variables are implicitly converted to pointers to their first element. If you declare a
int foo[5];
then foo is an array of 5 ints. But when you try to do
foo[2] = 4;
foo is converted to a pointer before the indexing operation occurs.

Also, array declarations as function arguments are flat out lies.
void bar(int baz[]);
counterintuitively declares a pointer rather than an array.
>>
>>61189849
>going to /pol/
It's like going to /b/ back in the day. A dirty pleasure at best. A skeleton in the closet realistically.
>>
>>61190323
Would you consider it a good strategy to never use arrays and only use pointers?
I don't like multiple ways of doing similar/the same thing.
>>
>>61190400
No, stack-allocated arrays are immensely useful. The only real alternative is malloc'd "arrays" and they're wasteful. You shouldn't be using dynamically allocated memory if there's an easier way.
>>
File: 1489173956495.png (215KB, 585x439px) Image search: [Google]
1489173956495.png
215KB, 585x439px
I made the mistake of offering my help to someone in my C class, they're fucking retarded and keep wasting my time with the same questions over and over trying to get me to write everything for them. How do I get them to fuck off without telling to fuck off because I have to sit next to them every day.
>>
>>61190462
Should've just pretended to be retarded.
>>
>>61190462
tell them to read the C programming language book.
>>
>>61190462
Tell them to piss of with their dumb shit and that they are wasting your time.
>>
>>61189273
I'm still waiting for him to explain why the fuck he wrote a function that only does typecasting.
>>
>>61190462
Ignore them
Also, C class in July? Wut?
>>
>>61190323
>>61190425
Thanks for explanation.
>>
>>61190462
Obviously they're just using you to do their homework.

Grow a spine and tell them, "that's something you need to do yourself," pretend to work on your own homework and be a bro and give them fair tips and help when genuinely needed.
>>
>>61190425
Can't I just alloca?
>>
>>61190462
Yeah I did this mistake in grade school. Happy I learned it then when my tolerance as so low.

You're gonna have to tell them you don't have time. And don't be sneaky about wasting your time. They should get the message. If they confront you tell them you're not really interested in helping anymore. It takes too much of your time.
>>
>>61190720
alloca works but has slightly different semantics (function scope rather than block scope). Also it's a bit ugly.
>>
>>61190542
I know C I just need the beginning class prerequisite so I'm taking a short summer class
>>
>Windows 8.1 x64
>MinGW

I think I somehow fucked my MinGW installation, not sure how to fix.

The other day it was fine, but now I am getting the errors:

fatal error: SDL2/SDL.h: No such file or directory
#include <SDL2/SDL.h>
^


even though the SDL2 folder with the headers has been untouched in my include folder.
>>
>>61190762
>ugly
Not uglier than mixing arrays and pointer types like I'd have to.
>function scope not block scope
I'm fine with that. I'm sure I could implement a freea() (compiler specific obv) if I really have to do that. Or just leave that as the one case where I have to use arrays. Situations where it matters doesn't come up often enough.
>>
>>61190782
Do you have SDL2 added as an include directory or do you include it through environment variables? Maybe you modified the environment variable and didn't save it?
>>
>>61190834
I edited the PATH variable, but I did not remove the location of MinGW's bin folder, I only moved it somewhere else
>>
>>61190782
win-x, c
gcc and make sure you still have that.
>>
>>61190889
i'm sorry, the what? I still have gcc.exe
>>
>>61190918
hit windows key+x
release and then hit c for the cmd
And then type gcc to make sure its path is still correct.
>>
>>61190782
lmao retard install linux fag.
>>
>>61190971
yeah it still works

I saw on stackoverflow that it somehow might have moved to the lib folder somehow, and I found "snapshots" (at least thats what I think they are) in the lib folder with include folders of their own, that didn't work either.
>>
File: 1495422385388.jpg (65KB, 411x412px) Image search: [Google]
1495422385388.jpg
65KB, 411x412px
How does one actually start programming? Do I need to read some books and get familiar with computer fundamentals before starting an actual programming language book?
>>
>>61191003
depends on what you want to be programming, it's a means to an end after all.

There's nothing wrong with learning the basic principles by experimenting with toy programs in python for example. There are tons of books and online resources for that.
>>
>>61191003
https://en.wikibooks.org/wiki/Haskell
>>
>>61190994
just install code blocks then.
You can directly link in project settings and youll no longer have to deal with make files as well.
>>
>>61191003
If you can copy and paste commands into command prompt and half-understand what's going on, you know what you need to.
Programming is not IT.
You can start learning something like Python now, and you'll learn everything else you need as you go.
>>
What's the alternative to hundreds of fprintf() statements if I need to generate HTML pages in C?
>>
>>61191108
Buffer one long string then print it? idk
>>
>>61191003
code.org, do the angry bird tutorial
>>
>>61191003
make pong, then breakout then tetris then mario then a rpg.
>>
Learning Pointer arithmetic

void
PrintArray_SingleForLoop(int a[NUM_ROWS][NUM_COLS]) {
int * p;
int counter = 0;

puts("Array contains the numbers:");
for (p = &a[0][0]; p <= &a[NUM_ROWS - 1][NUM_COLS - 1]; p++) {
printf("%d", *p);
++counter;

if (counter == NUM_COLS) {
counter = 0;
printf("\n");
} else {
printf("\t");
}
}

puts("");
}
>>
>>61191294
That's not how arrays as parameters work.
>>
>>61191128
I guess that's better than what I have

>tfw no html generating library in C
>>
>>61191038
no I like using notepad++ instead

I added -v to my compile script, and saw something for strawberry perl, which I dont think I ever used in years, so somehow it had taken over gcc

having issues about void's now instead of the include problems. I will try posting the results in the next post.
>>
>>61191338

Part I

Using built-in specs.
COLLECT_GCC=gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls : (reconfigured) ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 5.3.0 (GCC)
COLLECT_GCC_OPTIONS='-g' '-O0' '-o' '..\bin\mineral.exe' '-v' '-mtune=generic' '-march=i586'
c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/cc1.exe -quiet -v -iprefix c:\mingw\bin\../lib/gcc/mingw32/5.3.0/ controls.c -quiet -dumpbase controls.c -mtune=generic -march=i586 -auxbase controls -g -O0 -version -o C:\Users\Faggot\AppData\Local\Temp\cc25M9Cd.s
GNU C11 (GCC) version 5.3.0 (mingw32)
compiled by GNU C version 5.3.0, GMP version 6.1.0, MPFR version 3.1.3, MPC version 1.0.2
warning: GMP header version 6.1.0 differs from library version 5.1.2.
warning: MPFR header version 3.1.3 differs from library version 3.1.2.
>>
>>61191338
Just nuke ming,sdl and the like and do it fresh.
Also please take further shit to /sqt/
>>
>>61191338

Part II

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/5.3.0/include"
ignoring nonexistent directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/5.3.0/include-fixed"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/5.3.0/../../../../mingw32/include"
ignoring nonexistent directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
c:\mingw\bin\../lib/gcc/mingw32/5.3.0/include
c:\mingw\bin\../lib/gcc/mingw32/5.3.0/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/5.3.0/include-fixed
c:\mingw\bin\../lib/gcc/mingw32/5.3.0/../../../../mingw32/include
End of search list.
GNU C11 (GCC) version 5.3.0 (mingw32)
compiled by GNU C version 5.3.0, GMP version 6.1.0, MPFR version 3.1.3, MPC version 1.0.2
warning: GMP header version 6.1.0 differs from library version 5.1.2.
warning: MPFR header version 3.1.3 differs from library version 3.1.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7cd4969658477d55b298dfed5a318eb7
>>
File: 1497946111800.png (19KB, 160x186px) Image search: [Google]
1497946111800.png
19KB, 160x186px
What if...
Object Oriented Assembly?
>>
>>61191367
well this is about programming, but I probably will

so just reinstall MinGW, more or less?
>>
Making summer task for university. Needs to be done using java and mvc. I've chosen to do platformer and fucking my god using mvc in games is buttstretching [spoiler]or I am doing something wrong could be that[/spoiler]
>>
>>61191382
Give us a sample.
>>
>>61191398
Yeah, its usually easier than trying to hunt down the specifics in windows.
And maybe possibly look into using conan or somethting
>>
>>61191382
That's what Java bytecode is.
>>
>>61191424
There isnt really one that I know of besides >>61191444, but >Java
>>
>>61187121
>Lisp
>Functional
>>
>>61191321
https://kore.io/
https://balde.rgm.io/
http://libchl.ml/
http://www.coralbits.com/libonion/
>>
>>61191382
HLA?
>>
what are some programming challenges to learn algebra, trigo, calculus and linear algebra?
>>
>>61191003
You don't need any prerequisite knowledge except for basic typing skill and problem solving you'd learn early in school to do programming.
There's some ideas of how to design programs you may wish to learn at some point to move forward to more complicated programs but for the basic stuff you learn you don't need it.

You don't need 'computer fundamentals' at all unless you're doing very low level programming.
>>
>>61191444
No. Not at all actually.
>>
is project euler good?
>>
>>61191003
Can only tell from my experience but here is how I went:
>get matlab from university (or take the language you want to learn)
>dick around with some very basic commands like if, defining functions, using variables
>set some easy tasks e.g. a function for multiplying 2 vectors. I liked reproducing functions that are already implemented.
>repeat some easy tasks - use stackoverflow for problems - they have a solution for everything
>you are now confident in the basics and can try with a bit wildier ideas


t. just a hobby programmer

TL;DR: I read not one book - just trial and error
>>
lads what distro should i install to procrastinate thats not gentoo?
>>
>>61191588
Technically, any.

I wrote a matrix package in Pascal to get behind it for my exams (decades ago), I would now route for python.

Some people might answer MATLAB, but I wouldn't. It has everything already in it and you'd end up not implementing but merely using.
>>
>>61191686
is there a place with a list of them?
>>
>>61191709
Last one I actually particpated was numerai, kaggle before, but they may be too advanced (as in, give no guidelines and are solvable without knowing the basic stuff). As I said, I made my own challenge up with implementing a package to use for myself.

A good site for smaller challenges however is for example
https://coderbyte.com/challenges
>>
File: pike_logo_big.png (21KB, 360x155px) Image search: [Google]
pike_logo_big.png
21KB, 360x155px
Has /dpt/ heard of Pike? It is a dynamic programming language that looks a lot like C-family languages. Has anyone used or even tried it?
http://www.gotpike.org/
>>
>>61191444
no.
>>
>>61191775
>dynamic programming language
wut
>>
File: 2017-07-02-161931_1440x900_scrot.png (166KB, 1440x900px) Image search: [Google]
2017-07-02-161931_1440x900_scrot.png
166KB, 1440x900px
wow, this is fun.
>>
>>61191888
>youre on python now
So did you just completely give up on gamedev?
>>
>>61191934
I'm focusing on math and coding until december, next year I'll focus on art and music.
>>
>>61191496
Too heavy for my case but I appreciate it
>>
>tfw my first open source program just got its first confirmed user
>tfw he posted a feature request
>tfw I was able to add it in a couple hours

wow, I like this feel. I'm now waiting for him to check it out and I'm fucking scared because I don't know if he'll like it.

>>61191949
>precalculus
are you an HS student or an HS dropout or what?
not trying to be mean, i am an HS dropout and had to learn my basic math on my own too
>>
>>61192078
never put attention to math in HS.

trying to study everything again from basic arytmethic.
>>
>>61191888
lmao wtf is this shitty editor?
>>
>>61192139
>never coded in python before
>>
>>61192176
I did, just not in an editor like that, Cristina.
>>
>>61192200
>he doesn't know the default editor that comes when you install python
why lie though?
>>
>>61192305
>default editor that comes when you install python
Wut? Can't see any such thing on my system.
>>
I'm trying to crack some shitty Linux software, and I think my crack is working but the software is just broken.

I hate when that happens, because I'll never be 100% sure it's not my crack that broke things.
>>
>>61192325
install IDLE.

It comes with the windows installer by default.
>>
>>61192393
Thanks Cristina, I knew I could count on you.
Still, why don't you use a better editor such as Emacs?
>>
>see job posting
>must write bug-free code
>>
>>61192421
I'm not austistic enough.
>>
File: 1488394166701.png (457KB, 600x450px) Image search: [Google]
1488394166701.png
457KB, 600x450px
>>61192176
>not writing python in your favorite text editor + console
>>
>>61192502
>>61192200
>>61192176
Python is for children and you should be ashamed
>>
>>61192523
t. professional fizzbuzzer
>>
I wanna die.
>>
>>61192550
same

why tho
>>
>>61192555
I will never be a good programmer.
I don't have motivation.
I will dissapoint my parents.
>>
>>61187442
Abstraction is efficiency (portability, for example). Having the right amount is the question, which will always be contextual.
>>
In C, if I do:
char a[100];


Will every element in the array be zero?
>>
>>61192748
no
char a[100] = {0};


or
memset(a,0,100);
>>
>>61192748
>61192523
No. If you do
char a[100] = {0};
, it will though/
>>
File: 73543532.jpg (4KB, 299x169px) Image search: [Google]
73543532.jpg
4KB, 299x169px
Okay gentlemen, Im feeding a c# dictionary<string, object> into another class, but it keeps coming out null when Im debugging. Is there anyway around this besides making it static?
>>
>>61192758
>>61192767
you can also use calloc, apparently(NOT malloc)
>>
>>61192795
That's heap allocated, so that's different.
>>
>>61192807
Why would you allocate a 100-byte array on the stack?
>>
>>61192774
depends on the context of what exactly you're doing and how you're passing(what you mean by "feed to"; is this a constructor? is this a dynamic function(i.e. determined at runtime?) etc.). for a generic answer, have you tried passing by ref or are you passing in the dict data itself?
>>
>>61192421
IDLE isn't and editor, it's a REPL, and ipython is god tier compared to IDLE.
>>
>>61192829
Why would you allocate 100 bytes on the heap?
100 bytes is fuck all. Once you get to 1 MB size arrays, that's when you should consider the heap.
>>
>>61192829
because system calls are expensive.
>>
>>61192807
yeah, i was just listing another operation that would result in zeroed memory for completeness.
>>
>>61192829
Why would you not?
>>
>>61192807
The standard says nothing about heaps.
>>
>>61192843
>>61192858
Because you're very rarely going to run into a case where you need anywhere near 100 bytes, but know for a fact that you won't need anything more. It's not that the stack can't handle that many bytes, it's that stack allocation is static so you're always going to be allocating 100 bytes, even though for large arrays you very rarely know the needed size at compile time.
>>
>>61192879
"The heap" implies "malloc", you turbo autist.

>>61192912
>it's that stack allocation is static so you're always going to be allocating 100 bytes
Is this 1989?
>>
>>61192912
>Because you're very rarely going to run into a case where you need anywhere near 100 bytes
False, I can think of many cases like that, such as buffers, cryptographic keys, etc.

>it's that stack allocation is static so you're always going to be allocating 100 bytes, even though for large arrays you very rarely know the needed size at compile time.
Nobody stops me from using VLA.

>>61192923
>"The heap" implies "malloc", you turbo autist.
Malloc as defined by the standard does not force the use of any heap nor does it imply anything about it.
>>
>>61192923
>"The heap" implies "malloc", you turbo autist.
You do realize that calloc ALSO allocates on ``the heap"? And regardless, it's still true that the standard does not require the existence of a ``heap", but still does require a manually managed memory area.

>Is this 1989
Please show me how you can dynamically allocate an array on the stack just because it's %CURRENTYEAR%.
>>
>>61192969
>You do realize that calloc ALSO allocates on ``the heap"?
And "calloc" also implies "malloc". Also, please don't use fag quotes.

>Please show me how you can dynamically allocate an array on the stack just because it's %CURRENTYEAR%.
int main(int argc, char *argv[])
{
int array[argc];
}
>>
>>61192947
>buffers, cryptographic keys
Cryptographic keys are the one use case where static arrays make sense, however you're not going to need 100+ bytes unless it's a 1024-bit key or longer. And with buffers you rarely know for sure how much data they'll need to be able to store ahead of time.

>Nobody stops me from using VLA
Weren't they removed in C11? And is there any way to guarantee that a VLA is zeroed ahead of time anyway?
>>
>>61192991
>And "calloc" also implies "malloc".
False
>>
>>61192858
i could be wrong, but i believe if for some reason you have to create the array in dynamically(in response to some external input or result at runtime) and can't simply re-use the same array as a universal buffer(maybe you need more than one data container), you're going to have to use calloc/malloc.

so that's one reason if i'm not mistaken.
>>
>>61192991
>And "calloc" also implies "malloc". Also, please don't use fag quotes.
No, it does not ``imply" malloc. Nothing in the standard requires calloc to call malloc internally. In fact, one of the main advantages of calloc, as opposed to malloc+memset, is that calloc lives inside the memory allocation subsystem and can give you an already-zeroed block already, if one is known to exist, rather than give you memory of unknown state and then memset it.

>>Please show me how you can dynamically allocate an array on the stack just because it's %CURRENTYEAR%.
Now make it so that every element in that array is zeroed.
>>
>>61193010
>Weren't they removed in C11?
No, they were made optional. Some people (I think from embedded compilers) were complaining that they are hard to implement, and they wouldn't use them anyway.
It's the same reason that the complex number stuff was also made optional.

A compiler that targets desktops or whatever, and already supported C99 was expected to continue supporting VLAs.
>>
>>61193028
#include <string.h>

int main(int argc, char *argv[])
{
int array[argc];
memset(array, 0, sizeof array);
}
>>
File: 1457114437643.jpg (44KB, 600x600px) Image search: [Google]
1457114437643.jpg
44KB, 600x600px
>>61192834
I have a dictionary of type string and custom server class declared in my main class form presentation layer

Dictionary<string, Server> serverList1 = new Dictionary<string, Server>();

When I click the add server button im feeding user input into a method in my helper class

private void mBtnAddXpac1_Click(object sender, EventArgs e)
{
string serverName = mTxtAddNameXpac1.Text.Trim();
string serverLoc = mTxtAddAddressXpac1.Text.Trim();
string serverSite = mTxtAddSiteXpac1.Text.Trim();

MessageBox.Show(helper.addServer(serverName, serverLoc, serverSite, serverList1, lBoxXpac1));
}

Helper class method -

public string addServer(string servName, string address, string site, Dictionary<string, Server> dict, ListBox lBox)
{
///////
else {
s = new Server(servName, address, site);


dict.Add(servName, s);
msg = added;


lBox.DataSource = new BindingSource(dict, null);
lBox.DisplayMember = "Key";
lBox.ValueMember = "Value";
}
return msg;
}


Im trying to feed the dictionary info in directly, but it keeps coming out null when hitting the add method (telling me that "dict" is an null object).

I dont want to try make the dictionary static in its own dedicated class because it needs to be called from non-static functions.
>>
>>61190130
>Entity–component–system
Just use one that's already been made. Making one of those from scratch is an absolute nightmare.
>>
I'm gonna have a quiz-like interview with questions from maths/CS. What kind of questions should I expect for the CS part?

I was thinking stuff like explaining OOP concepts (encapsulation, inheritance, polymorphism), explaining sorting algorithms (insert/selection/merge/quick sort), search algorithms like binary search, maybe some questions about linked lists? Graphs/trees (DFS/BFS/Prim/Djikstra/Kruskal)... What else?

Note that it's a quiz done through video chat, no blackboard so no actual coding
>>
>>61193010
>however you're not going to need 100+ bytes unless it's a 1024-bit key or longer
Consider a hash function like Salsa20 where it has an input of 512 bits and an output of 512 bits. There are many cases like that in cryptography where you could use 1024 bit+ stack allocated areas.

>And with buffers you rarely know for sure how much data they'll need to be able to store ahead of time.
With buffers you usually store their size in a #define or something so you decide at compile time.

>Weren't they removed in C11?
No, just made optional.

>And is there any way to guarantee that a VLA is zeroed ahead of time anyway?
Not to my knowledge, you would have to memset or something.
>>
>>61193032
>No, they were made optional. Some people (I think from embedded compilers) were complaining that they are hard to implement, and they wouldn't use them anyway.
They should have made them optional only for free-standing implementations. Hosted ones can trivially implement it on top of malloc.
>>
>>61193088
>Calling malloc behind your back
No. That's not very "C like".
>>
>tfw writing C gives you a headache
>doesnt happen with any other language
>>
>>61193114
The compiler is free to do whatever the hell it wants as long as the result produced is valid.
>>
>>61193142
People have expectations of their C compilers, mainly that it won't hide a bunch of shit from them.
Calling malloc for you is taking that too far, in my opinion.
>>
>>61193076
>With buffers you usually store their size in a #define or something so you decide at compile time.
Yeah but if you're using a buffer to store user input, or to intermediate results of a complex calculation, there's simply no way of knowing ahead of time what the maximum will be. And if you allocate space for the maximum, you'll be wasting lots of space in the average case.
>>
>>61193139
>any other language
lol yeah right. You probably have used 2 other languages.
>>
>>61193172
>Calling malloc for you is taking that too far
Why?
>>
>>61193225
Malloc is an expensive operation. Incrementing a stack pointer isn't.
>>
>>61193042
that array would be local to the process it was created in. you may want to create multiple arrays for example to process data from user input in sequence, in which case i don't believe this would work.

probably more core to the problem the above can result in, if we can assume there could be situations where you WOULD need an unknown amount of arrays at runtime for any given reason, then isn't allocating to the stack simply a mistake because of risk of stack overflow? i'm legitimately asking the question because i'm not sure due to lack of experience and dumb.
>>
File: Haskell-purple.sh.png (16KB, 650x650px) Image search: [Google]
Haskell-purple.sh.png
16KB, 650x650px
*floods your RAM with thunks*
>>
>>61193253
also, i assumed there that your answer code was somehow implying that you should create the new array in a new function/process. if not, then i don't think there's a way to dynamically allocate+assign multiple arrays like that whose values are accessible(meaning, the arrays are referenceable/deferenceable) outside of the scope of their value assignment(although you can do it for one).

also something nobody's mentioned is the new keyword but i'm not sure if that zeroes memory or not offhand.
>>
>>61193259
what is seq
>>
>>61193259
based
>>
>>61193253
Stack overflow is an issue, but it's really a question of how much you trust your input. If it's "raw" user input, maybe you should go through some sanity checks before you make a VLA. Although you would probably do the same for malloc as well.
VLAs aren't appropriate for every situation. It's just sometimes, when you can reason about the maximum size of your inputs, you can use them and have it be more efficient than malloc.

Recently, I wrote some code which needs to copy the content of some image into another buffer, so the data layout could be correct and some padding could be added, so it could be handed into some library function.
Due to me knowing that it the image was a cursor (and I was limited by the hardware anyway), I could easily reason that in an extremely unlikely worst case, I was working with a 128x128 image. At 32 bpp, and that's only 65kB.
>>
>>61193047
I'm not entirely sure myself but I suspect that you're right in that you're going to have to define that dictionary as static if it's being declared outside of the function it's being called in. Or alternatively, you could store the dictionary/data in some Form variable(I'm assuming you're using Windows Forms here; you don't have to make it visible to have it store data if that matters to you) and then retrieve the data inside of the mBtnAddXpac1 function(possibly reconstruct the dictionary).

Either way, yes, if you're trying to refer to a global dictionary variable outside of your interactive button functions, the problem is most likely that you're not defining it statically, which should be possible but may require you to re-work your code a bit due to the way Forms/C# scoping works.

If that doesn't work one thing to do would be to try iteratively testing what's happening to the dictionary every step of the way so you at least know exactly where the problem is. For example, try to get an item out of the dictionary just after the mBtnAddXpac1 and print it using MessageBox, although I'd assume you've already done that.

Good luck in any case, I may not be around much longer today.
>>
let mut v = vec![1, 2, 3, 4, 5];

let first = &v[0];

v.push(6);


error[E0502]: cannot borrow `v` as mutable because it is also borrowed as
immutable


This is some next level masochism
>>
New thread:
>>61193427
>>61193427
>>61193427
>>
>>61193420
This is helpful, thanks bro
>>
>>61192969
>manually managed memory area
that's what a heap is whean talking about memory: a memory area for dynamic allocation.
>>
>>61193047
To be a little more specific, the way I understand it you have
//global dictionary declaration
Dictionary<string, Server> serverList1 = new Dictionary<string, Server>();

private void mBtnAddXpac1_Click(object sender, EventArgs e)
{
//calls dict in local function scope
//...etc
MessageBox.Show(helper.addServer(serverName, serverLoc, serverSite, serverList1, lBoxXpac1));
//...etc
}
}


public string addServer(string servName, string address, string site, Dictionary<string, Server> dict, ListBox lBox){
//tries to access and modify non-globally-defined(static) dict variable passed by a function that was accessing it outside of local scope
//...etc
dict.Add(servName, s);
//...etc
}


Excuse the messy code, but tl;dr yes, not defining it statically is likely the problem.

However, another potential issue may be that the dictionary being modified inside of your helper function(addServer) may be a copy of the dictionary object being passed to it and not the dictionary itself, in which case the modifications being made to it may not be reflected outside of addServer's scope unless you return the dict and reassign(which you can't do in your implementation there because your intent is to returning a string). In languages dictionaries are mutable outside of local scope(if not defined globally) and I don't know if things work that way in C#, but in any case if you're going to pass addServer the dictionary, modify it, and not return it, I would advise passing it using the ref keyword since that specifies the functionality you seem to be aiming for directly(as opposed to not passing it by reference which, depending on language specs, may be passing a copy).
>>
>>61193525
One more thing, specifically, although in some languages/variants of C/situations(or for some object types) declaring a global object like that may be sufficient to access, modify, or assign it in a function, depending on the actual structure of the total program/class/namespace code and placement, because of the way Windows Forms and .NET/managed code works(which I don't even fully understand myself) static declarations(and even then only static declarations in the proper scope(with Forms)) are generally required to access external variables inside of functions. Just speaking from practical experience, I'm no professional so take anything I say with a grain of salt.
>>
>>61193525
Bad typo...
> In SOME languages dictionaries are mutable outside of local scope
>>
>>61187074
Haskell faggot here.
Can someone explain why zipWith . uncurry has type (a -> b1 -> b -> c) -> [(a, b1)] -> [b] -> [c]? I'm trying to wrap my head around composition but I'm dumb as fuck
Thread posts: 326
Thread images: 30


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.