[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: 316
Thread images: 41

File: 1504642852106.gif (930KB, 640x480px) Image search: [Google]
1504642852106.gif
930KB, 640x480px
What are you working on, /g/?

Old thread: >>62470536
>>
Is rust worth learning?
>>
>inb4 GHC Generic is metaprogramming
>>
>>62477179
No
>>
>>62477169
i have an interest in lisp programming how useful it is in modern time.
>>
>>62477179
perhaps
>>
>>62477192
All of the trivial features that aren't in Lisp are metaprogramming, anon
>>
File: perpetual-thinking.gif (617KB, 498x498px) Image search: [Google]
perpetual-thinking.gif
617KB, 498x498px
Waiting for any muh-type-system poster to provide a working implementation for this:
>>62476836

(Preferably in a muh-type-system language that anyone has ever heard of, but that's not a strict requirement.)
>>
>>62477179
Rust itself, not necessarily. Substructural type discipline and liveness? Very much worth knowing.
>>
>>62477179
yes
>>
>>62477244
Your impatience suggests that you are not open to learning and instead just want to shitpost about how great Lisp is. That all said, I will when I get to my PC.
>>
>>62477268
>you are not open to learning
But that's not true at all. If anyone posts a working example using type system magic instead of metaprogramming or classic reflection, I will definitely be interested to learn how that works.
>>
>>62477244
https://wiki.haskell.org/GHC.Generics#Complete_working_example

Was that so hard? I'm not that guy you're baiting by the way.
>>
>>62477297
That's not an implementation of what I asked for. Why are you so reluctant to do it if it's so easy in Haskell?
>>
>>62477293
Then be patient.
>>
>>62477179
depend on your gender pronouns
>>
>>62477331
>Then be patient.
I wasn't setting a time limit, anon. Just checking if anyone else is willing to give it a honest shot in the meanwhile.
>>
I got a website hosted by OVH. For some reason one day some part of it went down due to the database with this error :

>Error: Unable to connect to MySQL. Debugging errno: 1203 Debugging error: User already has more than 'max_user_connections' active connections

Ofc I reviewed the source code and all connections are closed once the queries are made.
Problem is that I can't access it via the phpmyadmin interface neither so can't see what are those active connexions.

It's a small website for an association so there isn't much traffic (~80 per day) and active connections are supposed to be closed after a few minutes of inactivity anyway (or maybe ovh default config are retarded?). It's been a day like this and it's a little bit annoying

Any idea where it can come from ?
>>
>>62477337
he/him/his (female)
>>
>>62477179
Do it, fgt
>>
>>62477346
Nobody with any experience with non-trivial static type systems will bother because there is a very high probability that you would move the goalposts if a working solution were posted.
>>
>>62477464
I'm the anon who offered to write up a solution with dependent types. It's not even difficult (I'm talking like a couple dozen lines), I just don't want to write code with my phone keyboard and this shitty app.
>>
>>62477519
Then I hope the other anon is genuine.

Some dynamic language fans remind me a little of some creationists, in both their zealotry and their intellectual dishonesty.
>>
>>62477548
>dynamic language fans
These exist?
>>
>>62477562
It surprised me too at first.
>>
How are huge voxel datasets usually stored? Is it just a sparse structure or do they use some kind of virtual memory system like megatextures?
>>
>>62477604
Just use Lego
>>
>>62477562
Lisplets plague /dpt/ although only Racket-kun really posts anything.
>>
>>62477604
chunks (3d array) in a tree structure
>>
>>62477628
Lisp is a special case I think.
>>
>>62477604
A generous helping of both for very large sets.
>>
>>62477464
>there is a very high probability that you would move the goalposts if a working solution were posted
I won't; but even if I do, I'll just look like an idiot, and any honest onlooker unfamiliar with the power of "non-trivial static type systems" will have a non-meme incentive to give them a serious consideration. Just to be clear (and this is not a new requirement): a solution that amounts to emulating runtime reflection doesn't cut it.
>>
>>62477636
Even so, there is still the "but (my limited conception of) a static language (that is no more powerful than Java) can't do this!!!" screeching.
>>
>>62477636
Not really.
>oh look i can write a basic interpreter / parser in x amount of lines
>but that's about the only special niche my language can do
>>
>>62477650
Come to think of it, virtual memory is already a sparse data structure, so there you go.
>>
>>62477666
Lisp is also useful for keeping away people who only know Python/Ruby/JS.
>>
File: larry.jpg (16KB, 220x309px) Image search: [Google]
larry.jpg
16KB, 220x309px
>>62477562
But you could do extreme programming. In fact, I had a college buddy I did pair programming with. We took a compiler writing class together and studied all that fancy stuff from the dragon book. Then of course the professor announced we would be implementing our own language, called PL/0. After thinking about it a while, we announced that we were going to do our project in BASIC. The professor looked at us like we were insane. Nobody else in the class was using BASIC. And you know what? Nobody else in the class finished their compiler either. We not only finished but added I/O extensions, and called it PL 0.5. That's rapid prototyping.
>>
Hello, /dpt/
I want to get back to programming. What language should I use? I've heard that common lisp is powerful language. What about the new meme languages like rust and go?
>>
I lurk on dpt because to pretend I'm learning while browsing 4chan instead of actually reading a book,practicing.
>>
>>62477693
Go is shit. Learn rust
>>
>>62477688
You can do extreme programming with static languages too.
>>
what the hell is extreme programming anyway
>>
>>62477548
>>62477562
>>62477574
>>62477628
>>62477636
>>62477665
>all that butthurt
How come only one anon is willing (supposedly, sometime in the future) to give my simple exercise a shot? You don't seem very eager to illustrate the incredible merits of your favorite type system. I guess you're too busy shitposting?
>>
>>62477802
>it's another Lisp autist only proposes the one thing Lisp is half-decent for
zzzzzzzzzzzzzzz
>>
>>62477660
>a solution that amounts to emulating runtime reflection
What are your criteria for this? While I'm not confident that Idris (for example) will monomorphize types depending on compile time constants and thus remove any sort of RTTI, it is not an inherent limitation. It could be done in anything with dependent types. Actually, it doesn't even need them. You could do it in Haskell with heterogeneous lists and spreading a single function definition across a few instances.
>>
>>62477738
extreme
>>
File: black magic.jpg (1MB, 1200x1600px) Image search: [Google]
black magic.jpg
1MB, 1200x1600px
the best functional programming language is...
>>
>>62477802
maybe noone cares about your daily autistic ramblings
>>
>>62477852
agda, desu.
>>
>>62477819
>the one thing Lisp is half-decent for
Well, anon was asserting that advanced static type systems eliminate the need for metaprogramming, so there should be a good way to accomplish my example task.
>>
>>62477820
>What are your criteria for [runtime reflection]
Relying on runtime knowledge of the structure of an entity to iterate through its fields, in this case. If you have to do that to get the job done, how exactly does it illustrate the merits of a static type system?
>>
>>62477901
And there is. Perhaps you should learn an advanced static type system.
>>
>>62477978
>And there is.
Alright, show me. You make it sound trivial, but then spend hours shitposting just to avoid proving that you know what you're talking about by actually implementing it. Why?
>>
File: 1501917691145.jpg (117KB, 680x924px) Image search: [Google]
1501917691145.jpg
117KB, 680x924px
>>62477169
I'm still hacking on my amazingly autistic framework.

I want to make an argument for how different the world could have looked if Java took a different approach in about 2005 or so after Generics were released.

I propose that instead of the NoSQL revolution, and the XML-Everywhere fad, what would have happened if people instead decided to go with RDBMSes as the Standard Solution for Storing Stuff, or S4. So everyone actually knew SQL. Now, if everyone knows SQL, and everyone knows Java, there's the O/R impedance mismatch, right?

So what if we instead of thick complex objects in Java went with small lightweight stateless objects instead? You know, like we (try to) do today?

Instead of Hibernate making it big, you'd instead demand better support for views/window functions/something similar, and we'd just put views in front of our selects from Java.

And if that was the case, imagine how smooth the data layer would be? You could in fact imagine a DSL emerging that created the Bean, the Value Object (and those two could act as each other's factories for updating purposes) and the DAO.

Now imagine this. The complexity of storing and retrieving data is now firmly shoved into the database.

The data layer is a translation layer that creates simple lightweight objects that everyone understands, and the business layer can operate on.

I'm doing this as part of a larger point about solving the wrong problem, and how we're making all these advanced tools to make our bad decisions less painful, but how they just provide aspiring for our self imposed headaches.

And in order to show that, I need to show a way to do things people aren't intimately familiar with so they can critique it without criticizing their own favourite methodologies.

I'll also argue things like how IntelliJ's support for refactoring extending to Spring xml files being both useful and a mercy, but also a TERRIBLE TERRIBLE IDEA.
>>
>>62477901
Only type systems with first-class types do because that's the whole point.
Why anyone thinks you don't need templates in a regular old imperative strong static environment is a baka.
>>
I am so fucking lazy
>>
>>62477971
Oh, you don't. It could be completely static but also doesn't preclude a situation where you do want it to be dynamic. The type depends on the description, not the other way around.
>>
>>62478042
me too, i just posted on freelance.com to see if someone would do my work but i only see pajeets

can i trust them?
>>
>>62478065
>Oh, you don't. It could be completely static
If it doesn't rely on runtime knowledge of the structure of the entities and actually accomplishes the task as stated, it passes.
>>
>>62478128
Like I said, I am not confident that Idris would erase the constant descriptions at runtime (thus unfolding the interpolation function for each description) but there is nothing stopping a language with dependent types from doing so.
>>
File: 1470792067398.png (36KB, 268x237px) Image search: [Google]
1470792067398.png
36KB, 268x237px
Employed Haskell programmer here
>>
>>62478180
https://restaurantjobs.mcdonalds.com/
>>
>tfw want to become a programmer so I can get a decent paying job
>tfw not autistic enough to enjoy programming

Fuck. What do I do?
>>
>>62478180
Learn a real programming language, rajeet. I'm guessing you get 20k each year.
>>
>>62478279
Programming isn't the only decent paying job.
>>
>>62478292

Yea but I'm already studying it so cba to change.
>>
File: 1499833277578.jpg (100KB, 605x776px) Image search: [Google]
1499833277578.jpg
100KB, 605x776px
>>62478279
no one is enjoying programming

people enjoy solving problems and creating shit
>>
File: DHLrMYbUwAQjAdE.jpg (17KB, 364x362px) Image search: [Google]
DHLrMYbUwAQjAdE.jpg
17KB, 364x362px
>>62478180
Employed Java programmer here.
>>
>>62478334
I enjoy programming both by producing something and the beauty of how i did it. Same as regular writing.
Find a new hobby, lad.
>>
>>62478166
>but there is nothing stopping a language with dependent types from doing so
I'll give you the benefit of the doubt. Post something that works and I'll look into it.
>>
File: india.png (19KB, 525x268px) Image search: [Google]
india.png
19KB, 525x268px
>>62478367
Go to sleep, Reyansh.
>>
Fuck I'm going to change to using jvm as platform instead of trying load shared libraries from other shitty dynamic languages.
>>
File: 1499367228125.jpg (110KB, 605x789px) Image search: [Google]
1499367228125.jpg
110KB, 605x789px
>>62478373
>and the beauty of how i did it
but your code sucks ass and you know it, Dave
>>
cout makes me cringe
why is that
>>
>>62478373
>Find a new hobby, lad.
Try professional programming my man! Will hate it in no time.
>>
Reminder that Javascript is neither a """dynamic""" nor """interpreted""" language.
>>
>>62478486
>Try professional programming my man
why in the world would i ever want to do that.
working for anyone but yourself in this age is brainlet-tier.
>>
>>62478508
I agree, yeah. No welfare checks for me unfortunately. A man must ship to eat.
>>
>>62478505
What is it then?
>>
>>62477179
It depends.

Do you want to work for Mozilla?`
Yes
No / I am a white, non-trans middle class straight male and don't see any problem with that.
>>
>>62478508
>working for yourself
>in reality begging for clients
>and being subject to their nonsensical requirements
>>
How would you name the following objects:
{ // name the root
"data": { // name the child
"data": [{ // name the childs children
}]
}
}
>>
QA here. Your shits broken and this is a blocking ticket.
>>
>>62478539
But slowly more and more companies want rust developers and the language looks interesting.
>>
>>62478619
For example: how would you name this hierarchy:
final case class Response(
data: ResponseData
)

final case class ResponseData(
children: List[ResponseDataChildren]
)

final case class ResponseDataChildren(
data: ResponseDataChildData
)

final case class ResponseDataChildData(
title: String
)
>>
>>62478442
The only story I have heard about Indian programmers involve C, JavaScript and developing libraries for a set top box.

It ended about as hilariously as you would imagine. But are there really that many Indians writing Java? I mean, Java is not hard to learn, and H1B1 Visas are for people who do jobs that Americans are unable to do. So if there's a bunch of Indians in the US on H1B1 Visas, doesn't that mean that Americans are incapable of writing Java?
>>
>>62478735
I honestly hope so. We need a modern replacement for C++.

But currently, things don't look like that's how it will be to me. Most developers I've seen can't deal with the borrow checker properly, and some weirdness like immutability and crutches like split_at() vs split_at_mut().
>>
>>62478736
Response = List[String]
>>
File: 1433503114222.jpg (44KB, 680x765px) Image search: [Google]
1433503114222.jpg
44KB, 680x765px
how do you handle the discouragement that came from constant failures /dpt/? whenever I try to do something I always ended up panicking over my code and even when looking the problem up it's going to make things even complex. I think I'm actually a brainlet retard idk. it sucks
>>
>>62478886
>how do you handle the discouragement that came from constant failures /dpt/?
Do something you're actually good at? (Which, apparently, is not programming)
I'm not even trying to be a dick. If you struggle with it and not getting better, there's no reason to subject yourself to constant failure. Do something you're naturally predisposed for.
>>
>>62479043
I think you're the one who has never done any serious programming. If you're not failing 99% of the time, you're not doing anything innovative.
>>
>>62478886
Don't do ambitious projects. Do something in your comfort zone.
>>
>>62477179
yes
>>
>>62478886
Give it 5-10 years and the pieces will fall into place.
>>
Do your C programs still work on big-endian systems?
Do you always write endian independent I/O code?
>>
>>62479043
just English I guess. Give a kid who doesn't speak the language a shit-ton of movies in his early days and you got yourselves an bilingual after a few years.
still doesn't change the fact that I'm pretty much skill-less
>>
File: vid_1505663190.webm (560KB, 702x627px) Image search: [Google]
vid_1505663190.webm
560KB, 702x627px
I am debuging some powershell script i am working on and just found out this strange thing

it seems that when I am assigning return value from a function in to a variable I cant fucking debug the function by checking value of stuff inside it.. wtf is going on?
Does this have a name, purpose?
>>
>>62479241
>Do your C programs still work on big-endian systems?
no
>Do you always write endian independent I/O code?
no
>>
File: faggot.jpg (72KB, 277x280px) Image search: [Google]
faggot.jpg
72KB, 277x280px
>>62479135
>I think you're the one who has never done any serious programming.
>If you're not failing 99% of the time, you're not doing anything innovative.
I think you're the one who has never done any serious programming, because you unironically seem to believe that 99% of the work involves doing "something innovative". But even then, your "innovative" ideas are trash if you have to try a hundred times on average before one of them actually works.
>>
>>62479242
>still doesn't change the fact that I'm pretty much skill-less
Skill is acquired, but is there nothing you have talent for?
>>
File: 1445975383791.jpg (17KB, 385x387px) Image search: [Google]
1445975383791.jpg
17KB, 385x387px
>learning C
>everything going along nicely
>sprintf
>sscanf
>>
>>62479386
use snprintf instead
also, remember that snprintf can return values larger than the max size you pass to it
>>
>>62479317
Or maybe only 99% of them are? In which case he should try to fail faster so he can get to that 1% nugget of gold faster.

>>62479386
What are your problems with those? They seem perfectly straightforward to me.
>>
Learning clang from K&R's book right now, but I'm confused on post-fix unary operators.

It says that the increment only counts after the variable has been used, does this mean
int x = 1
x++

X is only 1 until it's used in an expression or called by a function? If so, what's the use in this? I can only think of trying to squeeze one less bit in, but that seems stupid because memory space is statically allocated by declarations.
>>
>>62477216
it's useful to know one functional language to know the mindset (it also helps you in non-functional languages), and the macros in Lisp are quite interesting. Don't count on getting a job in writing Lisp though
>>
>>62479417
>In which case he should try to fail faster so he can get to that 1% nugget of gold faster.
Or perhaps he should learn to think things through and filter more of the bad ideas so that he could make better use of his time, instead of literally wasting 99% of it. Just a thought, anon.
>>
>>62479512
You don't get to have a filter for your ideas unless you have something to train it on.
>>
>>62479245
alright, faggy powershell needs to use Write-Host and not just write-output or echo or plain "blab"
>>
>>62479484
int x = 1;
foo(x++);

The value foo receives as an argument is 1.
>>
File: desprate.jpg (1003KB, 4500x4334px) Image search: [Google]
desprate.jpg
1003KB, 4500x4334px
>>62477169
Newfag here. I'm trying to use vectors to print out a list of statements. Everytime I run the program, the list is not in synch with the vector array.
>>
>>62479496
>google "clojure jobs"
>hundreds of results
>"Don't count on getting a job in writing Lisp though"
>inb4 clojure is not a lisp
>>
>>62479484
x++ increments x immediately but as an expression evaluates to the original value. ++x increments x and evaluates to its new value.
>>
>>62477169
Next time please don't forget to also link the /g/ approved Code of Conduct!
>>
>>62479544
>You don't get to have a filter for your ideas unless you have something to train it on
Sure, but you don't need to repeat your mistakes dozens and dozens of times over the period of years before you learn to think things through. If 99% failure rate represents your entire programming career, you are either new or extremely incompetent.
>>
>>62479241
>big-endian systems
stop with this meme already
>>
>>62479569
You've never had a job, have you?
>>
>>62479484
>If so, what's the use in this?
It allows for elegant things like
i = array1; j = array2;
while (*i && *j)
*(i++) = *(j++)

If you used something else you'd have more lines, e.g.
while(*i && *j) {
*i = *j;
i = i + 1;
j += 1;
}

Of course tis specific piece of code should be implemented with a for loop, but I hope you get the idea.
>>
>>62479484
>X is only 1 until it's used in an expression or called by a function?
No.

When you use x++ as part of a larger expression, it has the OLD value of x, rather than the new line. For example:

int x = 1;
printf("x = %d\n", x);
printf("x = %d\n", x++);
printf("x = %d\n", x);


This will print "x = 1, x = 1, x = 2".

Whereas:
int x = 1;
printf("x = %d\n", x);
printf("x = %d\n", ++x);
printf("x = %d\n", x);

This will print "x = 1, x = 2, x = 2".

This distinction never matters when you just write x++; as a statement. Only when you use x++ as part of a larger expression is the distinction relevant.
>>
>>62479615
Is that really your best attempt at explaining away the fact that there exist quite a few jobs for lisp programmers?
>>
>>62479563
Post code, newfag friend
>>
>>62479657
Typical job advert mentioning Clojure:
>we use java/ruby
>we need someone to help us migrate away from our old php codebase
>we're especially interested in people with experience in other jvm languages e.g. groovy, scala, clojure
>>
char s[100];
int fd;

while (1) {
scanf("%s", s);
if (*s == '\0') break;
write(fd, msg, strlen(msg));
}

The string doesn't terminate and I get garbage from previous calls to write().
When I input
>foobar
>baz
I get
>foobar
>bazbar
Also, the loop never breaks.
>>
>>62479335
I just told you man, English is my second language but I never had any hard time learning it. I think that constitutes as a "talent"
>>
>>62479703
Here:
int main() {
vector <int>answer = {1,2,3,4,5,6,7,8,9,10 };

cout << "Enter an amendment form the Bill of Rights: \n";
cin >> answer[i];
for (unsigned int i = 0; i < answer.size(); i++)
{
if (i=1) {
answer[0] = 1;
cout << "Amendment 1 guarantees freedom of religion, speech, press, assembly, and petition.\n";
cout << "Try another admendment: \n";
cin >> answer[i];
}
if (answer[1]==2) {
cout << "Amendment 2 guarentees that the right to bare arms will not be infringed.\n";
cout << "Try another admendment: \n";
cin >> answer[i];
}
if (answer[2] == 3) {
cout << "Amendtment 3 guarentees that no soldier will be quartered in any house, without the consent of the owner.\n";
cout << "Try another admendment: \n";
cin >> answer[i];
>>
>>62479562
>>62479590
Cool shit
#include <stdio.h>

int main()
{
int x = 1;
printf("%d\n",foo(x++));
printf("%d\n",x++);
printf("%d\n",x);

/*Prints:
1
2
3
*/
}

int foo(bar)
{
return bar;
}

>>62479629
I think I get the general gist of it, but I'm not at pointers yet so I can only assume.
>>62479630
So "x++" wouldn't really be used literally in expressions, but part of some black magic voodoo for variable definitions?
>>
>>62479793
>Amendment 2 guarentees that the right to bare arms will not be infringed

God bless America
>>
>>62479657
see >>62479739
and also hundreds of jobs around the world is not something I'd describe as "quite a few"
>>
>>62479739
>cherrypicking irrelevant results
Wow, that sure showed me.
>>
>>62479630
>>62479808
>So "x++" wouldn't really be used literally in expressions, but part of some black magic voodoo for variable definitions?
Actually, I can see a use case for using x++ in an expression for something like "elegant" incrementation.
>>
>>62479777
help?
>>
>>62479785
>I think that constitutes as a "talent"
Have you ever considered doing something with it, then?
>>
File: maxresdefault[1].jpg (111KB, 1280x720px) Image search: [Google]
maxresdefault[1].jpg
111KB, 1280x720px
>>62479816
What did I do wrong? The code is bad.
>>
>programming in C
>need to walk directories, need hashmap, need sockets
The fuck! Either I have to implement everything myself or use some bloated and convoluted library that redefines all the basic types like int and such. Or use million little libraries that have not been updated in 5 years.
>>
>>62478818
ya the borrower is really annoying
>>
>>62479629
I think your "elegant" example causes undefined behavior.
>>
>>62479945
>sockets
just #include the windows/posix stuff and #ifdef around them
>>
>>62479974
Who cares, it's a shitty example to show that it can make the code shorter.
>>
>>62479945

> Either I have to implement everything myself

The exact meaning of C is roll-up your own solutions from scratch (or almost...)
If you want abstraction, then go to some high level language.
>>
>>62479974
Why?
>>
File: 1503119252137.png (227KB, 635x661px) Image search: [Google]
1503119252137.png
227KB, 635x661px
>>62479793
send help
>>
>>62479945
>walk directories
this is like 10 lines of code using POSIX functions, and windows does support the POSIX functions in this case to make it even simpler

>hashmap
one of the more simple data structures to implement, if you can't just look it up and take some pajeet snippet from stackoverflow

>sockets
no cross-platform stuff by default but you just need some simple ifdef guards if you intend for your program to be cross-platform, POSIX sockets and windows sockets are both pretty simple
>>
>>62480018
>Why?
Actually, maybe I'm wrong. There's no sequence point between i++ and j++ (so you don't know which side-effect happens first), but I guess it doesn't matter, since the old values are used on both sides. It would've been undefined behavior with ++i and ++j, though.
>>
>>62479793
What is this shit?
>>
>>62480138
Me attempting to store numbers in a vector so when I enter a number a message comes out based on the number. The problem is that the numbers no in sync with the iteration. I'm required to use a vector so I can link it to another complier that translates roman numerals
>>
>>62478539
>I think Rust is a shit language because a few of the developers have political views that I disagree with.
>>
>>62477169
How the fuck do people make big programs using just text editors like vim/emacs/sublime/code/etc?

I was just watching Jonathan Blow do some shit and I just can't stand it. No autocomplete, no jump to definition no "find usage". How the fuck is this superior than using an IDE?

I guess I'm just a brainlet IDE baby.
>>
>>62480010
Just because you're close to the hardware doesn't mean you have to reinvent the wheel.
>>
>>62480052
>supporting only POSIX platforms
not portable
>>62480010
dumbfuck
>>62479986
>using #idfdef instead of using proper library
>>
>>62479957
I'll admit that the ergonomics of the borrow checker is kinda lacking, but it is something they're trying to improve. However, I'm glad to fight with the borrow checker (at least for the first week of learning). I'd much rather it catch all my fuck ups and not compile than either:

1) compile with memory unsafe code
2) change my code to become safe, possibly subverting my expectations for logic flow
3) have the overhead of a GC

I really like Rust, and I think the borrow checker arguments are really overstated. The REAL problems with the language all come back to how young it is and the lack of company support:

- Few mature tools
- Quite literally no jobs outside of Mozilla and one or two hipster companies
- Lack of battle tested and robust crates (there are some and lib blitz is doing more, but it's still far behind Java and C++ obviously)
- No well defined styles, patterns, or practices (rustfmt exists but is always in flux, there was a design patterns repo but it was barren and now dead, and most reading material is on learning rust)

That's what really sucks. Once you hit that intermediate stage, you find that nothing caters to you because the community is mostly geared towards new learners. That's not necessarily bad but, outside of a few blog posts, you just feel like there really isn't anywhere to go from where you are currently. There's no job at the end of it, so once you stop having fun with Rust it's pretty much over.
>>
>>62480205
>No autocomplete
RTFM
>no jump to definition no "find usage"
grep
>How the fuck is this superior than using an IDE?
It forces you to pay attention when programming. No ctrl+space until your code magically works.
>>
>>62480203
>implying people that are dumb enough to have political opinions i disagree with are competent enough to design a good programming language
Political brainletism implies general brainletism.
>>
File: 1504469269956.png (1MB, 582x847px) Image search: [Google]
1504469269956.png
1MB, 582x847px
>>62480335
God bless Anon
>>
>>62479793
#include <vector>
#include <iostream>
#include <string>
using namespace std;

vector<string> stuff = {
"Amendment 1 guarantees freedom of religion, speech, press, assembly, and petition.\n",
"Amendment 2 guarentees that the right to bear arms will not be infringed.\n",
"Amendment 3 guarentees that no soldier will be quartered in any house, without the consent of the owner.\n"
};

int main()
{
int index = 0;
cout << "Enter an amendment form the Bill of Rights: \n";

while (1)
{
cin >> index;
index -= 1;

if (index > 0 && index >= stuff.size()) {
cout << "Haha lol nope\n";
continue;
}

string answer = stuff[index];
cout << answer << std::endl;
cout << "Try another admendment: \n";
}
}

here you go friend :^)
>>
>>62480288
>RTFM
I know what I want to write, I just don't want to write it all.
>grep
What I do in QtCreator:
1. Hold Control
2. Click the symbol I want
What using grep would require:
1. Switch to terminal (cost of this depends on the environment/OS)
2. Type "grep" and type what I want to search (possibly a regex if I want exact results)
3. Wait for grep to find the result because the files are not indexed
4. Go back to the editor and manually open the file then go to the line reported by grep and pray it wasn't an #ifdef'd out definition
>It forces you to pay attention when programming. No ctrl+space until your code magically works.
Control+Space isn't magical, I don't know where you got this from.
>>
>>62480205
It's something you get used to, but please don't ever hold yourself to the standard of Jonathan Blow.

The man is one of those genius autistics who somehow has enough social skills to get by. You're doing a hundred meter dash while he's in an F1 racer.
>>
File: 43.jpg (50KB, 620x348px) Image search: [Google]
43.jpg
50KB, 620x348px
I wish I could have a drink with Andrei. His talks are so good.
>>
>>62480388
actually that should be index < 0 ||
>>
>>62480388
>string
>uses "" instead of ""s
>>
Got done rewriting my server's front end, it now uses win ioctl and linux epoll for TCP connections. Next gotta do some other changes to how the processes in the server are organized and then I can start writing a database server which I've never done before.
>>
>>62480390
Instead of posting inane comments, try it out yourself.
>>
File: 1494424889978.gif (2MB, 480x270px) Image search: [Google]
1494424889978.gif
2MB, 480x270px
>>62480427
shame about his language though
>>
>>62480426
>You're doing a hundred meter dash while he's in an F1 racer.
It seems different from my point of view. It's like we're in a race and I'm using a popular car that will fail halfway thru the race and he's using a DIY-dragster that will blow up after he crosses finish line
>>
What's the most pajeet thing you've ever seen in production /g/?
>>
>>62480497
Pajeet
>>
>>62480264
The Rust community has really only 2 divisions. You have the people learning the language and the people working on the language. That's the issue, but it is in its infancy so it's kind of to be expected.
>>
Why do languages still force you to write getters and setters? Why can't they just include a specific keyword for access control like
>readonly
>writeonly
>readwrite (default)
>>
>>62480497
>catching NullPointerException
>catching IndexOutOfBoundsException
>CMS which required the user to edit the JSON file directly
>creative implementations of the builder pattern
>>
>>62480495
I wasn't talking about the editor, I was talking about how autistic this guy is. He lived in an empty apartment without internet for 5 years because a cable company made him mad. Of course he can get away with just using text editor, he's stubborn and autistic.
>>
File: sm.gif (927KB, 640x480px) Image search: [Google]
sm.gif
927KB, 640x480px
>>62477169
I redid that gif to get rid of that little bit of wall under Usagi's right pony-tail, it annoyed me.
Didn't notice it when I first made the gif.
>>
>>62480583
C# has something like
property int something { get; }

I think
>>
>>62480583
The alternatives are worse.
>>
>>62480264
I think right now the intermediate stage is figuring shit out yourself. Design patterns for Rust haven't really stabilized yet, so blaze your own trail, figure out what works and write articles about it so that other people can follow your lead.
>>
>>62480621
What is that some PC-98 game?
>>
>>62480702
Right, that's what I'm getting at. At that point it's all about you having fun and enjoying the practice of programming.
>>
>>62480234
There's no such thing as a truly portable way to walk a directory because it is OS-dependent.
>>
File: typical PC98 game.jpg (305KB, 1280x960px) Image search: [Google]
typical PC98 game.jpg
305KB, 1280x960px
>>62480731
Yes.
>>
>>62480751
But there's no reason to exists library that abstracts that away and refuses to compile for platforms that do not support directories.
>>
>>62480772
>>62480621
wtf is that square thing she's holding?
>>
>>62480583
Access control isn't the answer. What you want is the ability to enforce invariants.
>>
>>62480388
How do you get it to be initialized by 0?
>>
why are these the same
/* functions as arguments : way 1 */
#include <stdio.h>

int add(int x, int y){ return x*y; }

int apply(int (*func) (int, int), int a, int b){ // takes a function (which takes two ints and returns an int) and two ints
return func(a, b);
}
void main(){
int res;
res = apply(add, 5, 6);
printf("%d\n", res); // prints 11
return;
}

/* functions as arguments: way 2 */
#include <stdio.h>

int add(int x, int y){ return x*y; }

int apply(int (func) (int, int), int a, int b){ // takes a function (which takes two ints and returns an int) and two ints
return (*func)(a, b);
}
void main(){
int res;
res = apply(add, 5, 6);
printf("%d\n", res); // prints 11
return;
}


why are these the same? this doesn't work for non-function arguments. if you declared an int* for a function, you must still dereference it to get the value. declaring it as an int or int* doesn't change the value being passed. with function pointers. it's as if you're dereferencing it in the parameter declaration. wtf is that? the more i look at it the less sense it makes
>>
>>62480931
What do you mean?
>>
>>62480902
How do you do this?
>>
File: this geimu.png (153KB, 644x484px) Image search: [Google]
this geimu.png
153KB, 644x484px
>>62480772
I mean what's that on the background?
>>
>>62480944
using a function pointer formerly required a dereference operator. In new versions of C it's implicit.
Additionally, the dereference operator is implicit when the function pointer is a parameter (simply to "arrays" in function parameters being interpreted implicitly as pointers).
The "true" way to write this function would be as follows.
int apply(int (*func)(int, int), int a, nt b)
{ return (*func)(a, b); };
>>
>>62480952
Use a better language.
>>
>>62480946
When I enter 0, I get the first amendment. I want to shift the vector so that way I can have the first amendment pop out when I type "1"
>>
>>62480388
>using vectors instead of a linked list of structures holding strings, or just a simple array of char pointers

this is why c++ is cancer
>>
>>62480944
There isn't really a difference between a function and a function pointer anyway.
>>
>>62481019
>linked lists are the only data structures Cniles understand
lol
>>
>>62479793
>BARE ARMS

WHAT IN THE NAME OF EUGENE STONER ARE YOU SMOKING
>>
>>62480549
What's nice though is that Mozilla as a company is designing AND using their language in their browser, which is one of the largest and most important softwares on the planet.

It's not like how the web used to be under the W3C where people who never made a website decided on arsinine standards that were neither pleasant to use nor low level enough fully solve the problem.
Mozilla has to taste their own medicine.
>>
File: 1408038165538.gif (71KB, 864x496px) Image search: [Google]
1408038165538.gif
71KB, 864x496px
>>
>>62477169
Waiting to upgrade my pc with a 1050ti and move all my other old components to a new case.
>>
>>62481027
at least im not a faggot

checkmate n00b
>>
>>62480982
thanks, i knew there was something fishy going on
>>
>>62481003
just subtract 1 from the value you read in from cin, since vector[0] is the first element

>>62481019
I would have used an array of const char ptrs if the other anon wouldn't have specifically wanted vectors
>>
fuck opengl though
>>
>>62480621
spent solid 2 minutes looking for what you changed, thanks
>>
reposting, anyone want to freelance? a decent programmer could probably do this in a weekend or two

its a hard project for me because im shit at it and dont have enough time, but its actually a small project. basically i want a demo showcasing what a particular java library can do, you would pick some small, well documented tutorials and demos from the internet and stick them together. you would need to know java and javascript

[email protected]
>>
>>62481035
I'm dreaming of a WebAssembly and WebGL internet. I'm sick of slow ass JS and shitty HTML/CSS. Let the good times roll.
>>
>>62481158
Signed you up for a gay black dating site, senpai :^)
>>
>>62481184
>gay black
gay nigger*
>>
>>62481184
You fool, that may have been what he wanted all along!
>>
>>62481158
>do my homework for me
lmaooooooooooooooo
>>
So using the strategy pattern, i can switch algorithms for a component during run-time?
>>
>>62481158
>freelance
>free
>work for free
no
>>
>>62481244
>strategy pattern
has object-oriented programming gone too far?
>>
>>62481158
How much per hour?
>>
>>62481158
What's the pay?
>>
>>62481264
not if you wanna job
>>
File: 1496772534156.jpg (26KB, 433x380px) Image search: [Google]
1496772534156.jpg
26KB, 433x380px
>>62480388
>>62479793
Why don't you just use a switch statement?
>>
>>62481303
I've worked in an OO language professionally for five years and I've never used a "strategy pattern".
>>
>>62481307

Less Conditionals = Reduce Cyclomatic Complexity = Better Performance.
LUT tables are one example.
>>
>>62481244
Yes. The idea is to abstract out what the algorithm actually does to an interface. Since the calling object doesn't care about the implementation, only the interface, you can swap out the algorithm for any other object that implements the interface at run time.
>>
>>62481342
policy pattern?
>>
>>62481277
>>62481283
i would be willing to pay 200 bucks maybe, depends on how its done and how long it takes you. but i seriously think it should be really easy if you know what you are doing, in fact i already did the app, it's just that i don't like how it ended. honestly you could just take my code and improve or fix it, i would actually prefer it
>>
>>62481420
How do you plan on paying?
>>
>>62481413
Never used one of those either.
>>
>>62481430
>>62481342
baka code monkey
>>
>>62481427
paypal, bitcoin? how would you want to be paid?
>>
If I use a library distributed under the Apache license, what attribution do I need to include with my software?
>>
>>62481447
slaves
>>
File: ibm-hot-chips-power7-power9.jpg (80KB, 720x392px) Image search: [Google]
ibm-hot-chips-power7-power9.jpg
80KB, 720x392px
>>62479613
>big endian is a meme
The world's best CPU is big endian.
https://en.wikipedia.org/wiki/POWER9
12 MiB L2 cache
120 MiB L3 cache
230 GB/s memory bandwidth
4 GHz base clock
>>
>>62481437
Hardly.

"Patterns" are only necessary in inflexible and limited languages.
>>
File: 1486941686983.jpg (204KB, 900x973px) Image search: [Google]
1486941686983.jpg
204KB, 900x973px
>Tfw learning Git is harder for me than learning c++ or java
>>
File: 1493538842227.png (441KB, 1048x587px) Image search: [Google]
1493538842227.png
441KB, 1048x587px
>>62480493
I like D, but instead of arguing about it like I've dead every other thread, I'm going to instead worship Karen.
>>
>>62481531
>D
>dead
how appropriate
>>
>>62481481
patterns arent about the languages themselves you retard
>>
>>62481466
More like Big Indian lol
>>
>>62481484
It suddenly "clicks" along the way in my experience, just keep going
>>
File: 1369189402282.png (336KB, 1100x850px) Image search: [Google]
1369189402282.png
336KB, 1100x850px
>>62481484
>>
File: ....jpg (18KB, 480x270px) Image search: [Google]
....jpg
18KB, 480x270px
>>62481547
Whatever makes you feel like your worth something, anon.
>>
>>62481555
Didn't say that

They're independent of language, but only necessary in poor languages
>>
>>62481589
you're*
>>
>first class functions are a pattern in OO languages
Howling
>>
>>62481617
you sure you ever worked in an office before?
>>
>>62481675
Yes.
>>
File: 1484409041274.png (548KB, 960x540px) Image search: [Google]
1484409041274.png
548KB, 960x540px
>>62481636
Thanks, anon.
>>
>>62481692
any time :^)
>>
>>62481689
That didnt have rats?
>>
>>62481713
There were no rats or any other sort of vermin.
>>
File: 1503659746434.jpg (44KB, 640x360px) Image search: [Google]
1503659746434.jpg
44KB, 640x360px
>>62481692
I think it's time for you to leave
>>
File: 1484622985684.png (356KB, 599x510px) Image search: [Google]
1484622985684.png
356KB, 599x510px
>>62481733
This is a no-bully zone, buddy.
>>
Reminder:
Still waiting for any muh-type-system poster to provide a working implementation for this:
>>62476836 →

(Preferably in a muh-type-system language that anyone has ever heard of, but that's not a strict requirement.)
Sure taking the type system wizards a long time to implement something that can be done in a dozen lines:

(defn lerp [a b k] (+ a (* (- b a) k)))
(defn nop [a b k] a)
(defn interp-func [name] (if (= name :linear) 'lerp 'nop))

(defmulti ent-interp (fn [ent1 ent2 _] [(type ent1) (type ent2)]))

(defmacro defent [type-name & field-defs]
`(do (defrecord ~type-name
~(into [] (map first field-defs)))
(defmethod ent-interp [~type-name ~type-name] [~'a ~'b ~'k]
(new ~type-name ~@(for [[field-name {:keys [interp]}] field-defs]
`(~(interp-func interp)
(~(keyword field-name) ~'a)
(~(keyword field-name) ~'b)
~'k))))))

;; Usage:

(defent Ent
(foo)
(bar {:interp :linear})
(baz {:interp :linear}))

(ent-interp
(Ent. 1 2 3)
(Ent. 4 5 6)
0.5)
>>
>>62477169
I'm trying to learn C by working through K&R 2e and just got to the bitwise operators section. When introducing the AND (&) operator they use the example:
"The bitwise AND operator is often used to mask off some set of bits; for example,
n = n & 0177;
sets to zero all but the low-order 7 bits of n."
Could someone explain to me what is going on here? I realize 0177 is 127 in octal, but I don't really understand what else is going on here.
>>
>>62481768
What does it do? I don't know lisp
>>
>>62481768
Still here. Still not at my PC.
>>
What is the difference
char *string[10]
char *string[10][10]

Why would I ever use the second?
>>
>>62481840
>I realize 0177 is 127 in octal, but I don't really understand what else is going on here.
0177 also 00000000 00000000 01111111 in binary. ANDing any number with that will obviously nullify all but the first 7 bits.
>>
>>62481888
meant
char string[10][10]
>>
>>62481886
>static typelets can't even write code without a computer
btfo, lisp wins again!
>>
>>62481888
https://www.tutorialspoint.com/cprogramming/c_multi_dimensional_arrays.htm
>>
>>62481909
One is an array of pointers to chars.
The other is an array of arrays of chars.
>>
>>62481888
10 element array of pointers to a '\0'-terminated string somewhere in memory

>>62481909
10 element array of 10 element character arrays, stored right next to each other in the memory location where the array is stored
>>
>>62481890
Oh shit I think I see now. So ANDing basically goes through and compares each corresponding digit of two numbers, producing a third number where any given digit is the result of applying the AND logical operation on the corresponding values of the original two numbers
>>
>>62481879
>What does it do?
It's a stripped-down version of a networked game entity definition macro. It gives you a syntax to define a networked struct with interpolation type per field, and automatically creates the interpolation method. The original also generates delta-compressed network serialization and deserialization methods for networked fields, and produces different versions for the client and server which contain only the relevant fields.
>>
>>62481985
Correct. That's what it means to do a bitwise operation. The operation is performed on each pair of corresponding bits of the two sequences.
>>
>>62481761
Karen is a filthy dumb breeding sow that deserves all the suffering in the world.
>>
Looking for language for host program that will work as plugin manager for shared libraries and provide some API because fuck C libraries are not portable.
Chapel seems decent though not really mature.
swift might be ok but I don't trust apple to care about portability, also swift doesn't use statement terminators which renders it as bad as python.
ATS would be perfect by the features the language supports but the syntax is absolutely horrible.
>>
File: hJGdgqF.png (183KB, 386x406px) Image search: [Google]
hJGdgqF.png
183KB, 386x406px
Do you guys add "m_" to member variable names?

Also, do you have some good style tips for writing readable C++?
>>
>>62482026
>readable
>sepples
does not compute
>>
I'm writing a switch function but when I the default case is used, it prints out the statement times
int value(char romanChar) {
switch (romanChar)
{
case 'I':return 1;
case 'V':return 5;
case 'X':return 10;
case 'L':return 50;
case 'C':return 100;
case 'D':return 500;
case 'M':return 1000; //cout << "Sorry, '" << romanChar << "' is not a Roman numeral. Please enter a Roman numeral :";
default:
cout << ":)";
break;
}

}
>>
>>62482002
Most appreciated anon.
>>
Fixing bugs on my online tool for putting together formatted date strings in SQL Server.
>>
>>62482026
No, that's dumb. If you want to emphasize that it's a member, use this pointer everywhere.
>>
>>62482026
No. That's bloat.
>>
>>62482026
I always access fields using this->field.
>>
>>62482035
Please breathe for a minute then post again.
>>
File: 1494313932846.jpg (41KB, 394x353px) Image search: [Google]
1494313932846.jpg
41KB, 394x353px
>>62482013
Did you forget to eat your Lainos, anon?
>>
>>62482026
>Do you guys add "m_" to member variable names?
I always prepend <Foo>ClassMember<TypeName>_ just to be extra clear, as suggested by the C++ design committee guidelines for writing maintainable code.
>>
>>62482026
no exceptions, no templates, no iostream, no multiple inheritance, no operator overloading, no RTTI, no C++11, avoid STL
https://www.youtube.com/watch?v=rX0ItVEVjHc
https://gist.github.com/bkaradzic/2e39896bc7d8c34e042b
https://archive.is/2016.08.07-162105/https://namandixit.github.io/blog/nominal-c++/
https://flohofwoe.blogspot.ca/2013/06/sane-c.html
>>
>>62482053
>No. That's bloat.
>t. C brainlet
You are obsolete.
>>
>>62482080
Karen was a mistake. I bet "she" programs in sepples.
>>
File: 1496998730043.jpg (33KB, 493x386px) Image search: [Google]
1496998730043.jpg
33KB, 493x386px
>>62482111
>good style tips for writing C++: don't write C++
The only people who follow these tips don't need them in the first place.
>>
File: c++17.png (216KB, 1908x1198px) Image search: [Google]
c++17.png
216KB, 1908x1198px
>>62482106
>as suggested by the C++ design committee guidelines for writing maintainable code
just off yourself

here's an example of what Bjarne's "design committee" considers to be readable and maintainable
>>
Nice
Just found an easy way to enforce struct endianness
struct __attribute__((packed, scalar_storage_order("little-endian"))) mystruct {
uint16_t a;
uint32_t b;
uint64_t c;
};

Added bonus: only compiles with glorious free as in freedom GCC, not capitalist pig clang or MS C compiler
>>
>>62482073
Fuck I'm such a dunce.
I'm writing a switch function but when I the default case is used, it prints out the statement 3 times

int value(char romanChar) {
switch (romanChar)
{
case 'I':return 1;
case 'V':return 5;
case 'X':return 10;
case 'L':return 50;
case 'C':return 100;
case 'D':return 500;
case 'M':return 1000; //cout << "Sorry, '" << romanChar << "' is not a Roman numeral. Please enter a Roman numeral :";
default:
cout << ":)";
break;
}

}
So it prints out ":):):)"
>>
any good books on concurrency and simd and shit(C++ preferred)
>>
>>62482119
>t. Hasklet

Enjot doing nothing of utility.
>>
File: 1449700279793.png (74KB, 300x256px) Image search: [Google]
1449700279793.png
74KB, 300x256px
>>62482111
>no templates
>no C++11
>>
File: wtf-am-i-reading.png (67KB, 404x404px) Image search: [Google]
wtf-am-i-reading.png
67KB, 404x404px
>>62482162
>an easy way to enforce struct endianness
Okay, and what happens when you "enforce" the opposite struct endianness from what your machine uses and then modify these fields as usual?
>>
I have some file with some commands in them and im trying to have stdout print to their respective out puts but it just writes all stdout to both net.out and drives.out and i cant figure out why. can someone tell me why im so fucking stupid?

net
ifconfig

drives
cat /etc/fstab


import subprocces

files=['net', 'drives']
temp_path="/tmp/tmp_path/"
def main():
data=[]
try:
os.mkdir(temp_path, 0755)
print temp_path, "created"
except:
print temp_path, "exists"
pass
file_path= ['config/' +x for x in files]
for f in file_path:
with open(f,'r') as commands:
for cmd in commands:
print '[*] Executing', cmd
try:
cmd =cmd.split()
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
data.append(proc.communicate()[0])
for write_file in files:
with open (temp_path+write_file+'.out', 'a') as t:
for x in data:
t.write(x)
except:
pass

proc.stdout.close()

>>
>>62482205
GCC automatically reverses the byte order whenever you access a struct member. This can be a performance consideration, though not in my case. Firstly because my program merely reads a lot of structs, modifies them once, and writes them back to disk. Secondly, most likely nobody will ever use my program, but if they do, it should work on PowerPC.
>>
>>62482156
You sound angry, Linus. Is it C's lack of modules?
>>
>>62482147
this is real c++:
https://github.com/minexew/TempleOS/blob/master/TempleOSCD/Downloads/Linux/TOSZ.CPP
>>
>>62482245
>GCC automatically reverses the byte order whenever you access a struct member.
Oh. That's actually pretty comfy.
>>
pls no bully
https://git.io/v5Fcl
>>
File: 20170917_144930.jpg (1MB, 2560x1440px) Image search: [Google]
20170917_144930.jpg
1MB, 2560x1440px
I know value is 2 and reference is 8 (pretty sure) but what about the other two? my brain hurts
>>
>>62482261
That's the only kind of "C++" I can put up with, I'll give you that.
>>
Are there any guarantees about what queues will be supported in Vulkan? Am I guaranteed at least one transfer queue?
>>
>>62482245
No it doesn't. Where did you learn that from?
>>
File: Top_9_InDemand_Languages2017.jpg (139KB, 600x300px) Image search: [Google]
Top_9_InDemand_Languages2017.jpg
139KB, 600x300px
would you say this is accurate?

http://www.codingdojo.com/blog/9-most-in-demand-programming-languages-of-2017/

If I wanted to get a job ASAP, what should I go with?
>>
>>62482369
>If I wanted to get a job ASAP, what should I go with?
Haskell.
>>
>>62482390
What kind of work would that get me?
>>
>>62482414
Haskell programming work.
>>
>>62482369
>http://www.codingdojo.com/blog/9-most-in-demand-programming-languages-of-2017/
>tfw teaching myself python atm
>two classes with sql next semester.

I dont want to be a code monkey though. hope I can get into data analysis.
>>
>>62482414
Professional blog writer.
>>
>>62482424
>t. pajeet
Why do you keep spreading memes and lies? Most Haskell programmers are employed and doing serious work.
>>
>>62481768
Interpolator : Type -> Type
Interpolator a = Float -> a -> a -> a

data Desc : Type where
End
Field : (a : Type) -> Interpolator a -> Desc -> Desc

entity : Desc -> Type
entity End = ()
entity (Field a _ d) = (a, entity d)

interpolate : (d : Desc) -> Interpolator (entity d)
interpolate End _ () () = ()
interpolate (Field _ f d) t (x, e) (y, e') = (f t x y, interpolate d t e e')

Example of use:
lerp : Interpolator Float
lerp t x y = x * (1 - t) + y * t

entDesc : Desc
entDesc = Field Float lerp (Field Float lerp End)

Ent : Type
Ent = entity entDesc

-- interpolate 0.5 (1, (2, ())) (3, (4, ())) = (2, (3, ()))

It's rather easy to extend. Here's an SOA implementation.
entities : Desc -> Nat -> Type
entities End _ = ()
entities (Field a _ d) n = (Vect a n, entities d n)

interpolateMany : (d : Desc) -> Interpolator (entities d n)
interpolateMany End _ () () = ()
interpolateMany (Field _ f d) t (xs, es) (ys, es') = (zipWith (f t) xs ys, interpolateMany d t es es')
>>
>>62482512
Typo.
data Desc : Type where
End : Desc
Field : (a : Type) -> Interpolator a -> Desc -> Desc
>>
>>62482512
That's not the same thing at all.
>>
>>62482555
Another typo:
-- interpolate entDesc 0.5 (1, (2, ())) (3, (4, ())) = (2, (3, ()))

If you used an inductive type definition instead of an eliminative type definition for "entity" you wouldn't even need to pass around the description.

>>62482588
How?
>>
>>62482512
Can you do this with something that actually works like a structure and has named fields? Surely you'll agree that what you did isn't particularly usable.
>>
>>62482368
>No it doesn't. Where did you learn that from?
Yes, it does. Where did you learn that it supposedly doesn't?

#include <stdio.h>
#include <stdint.h>

struct __attribute__((packed, scalar_storage_order("little-endian"))) le {
int16_t x;
} le;

struct __attribute__((packed, scalar_storage_order("big-endian"))) be {
int16_t x;
} be;

void hexdump(const char* prefix, uint8_t* a, size_t len) {
printf(prefix);
for (size_t i = 0; i < len; i++) {
printf("%02x", a[i]);
}
printf("\n");
}

int main() {
le.x = 123;
be.x = 123;
hexdump("le", (int8_t*) &le, sizeof(le));
hexdump("be", (int8_t*) &be, sizeof(be));
return 0;
}


Output:
le7b00
be007b


Your turn.
>>
*
le 7b00
be 007b
>>
>>62480203
Would explain why nobody likes ruby
>>
>>62482599
>named fields
For what purpose in a game? You are creating entities in an editor or with data, not in code. It would be easy to do, though. You can simply represent an entity as a function from names to values instead of a list of values. Construction would be a lambda that pattern matches on the names, and accessing a field would be calling the entity with the field's name.
>>
>>62482659
>You are creating entities in an editor or with data, not in code.
Which, by the way, would also utilize the description mechanism.
>>
>>62482659
>For what purpose in a game?
So that you could actually access, say, the position field in the code by name and not by memorizing its position in a list?

>It would be easy to do, though.
Then do it. Jesus fuck...
>>
>>62482599
>Can you do this with something that actually works like a structure and has named fields? Surely you'll agree that what you did isn't particularly usable.
I FUCKING SAID YOU'D PROBABLY MOVE THE GOALPOSTS >>62477464
>>
New thread:

>>62482830
>>62482830
>>62482830
>>
>>62481342
unless you were just a code monkey, you probably implemented it at least once without realizing memers call it "strategy pattern"
>>
>>62482824
>I FUCKING SAID YOU'D PROBABLY MOVE THE GOALPOSTS
Are you shitting me, anon? Even if you took "fields" to mean "items in a list", and thought that accessing "fields" by memorizing their position in a list is sane, and thought that changing the order of the fields should silently break the program, the code I posted as an example of what needs to be done clearly uses actual named fields, and I posted it before this guy posted his code.
>>
>>62482414
McDonald's burger flipper.
>>
>>62482694

Just write a function to access it
Thread posts: 316
Thread images: 41


[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.