[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: 349
Thread images: 27

File: lain.jpg (270KB, 1920x1080px) Image search: [Google]
lain.jpg
270KB, 1920x1080px
What are you working on, /g/?
old thread: >>61560889
>>
>>61564958
Lain is a fucking slut
>>
anime != proper
>>
>61564842
>61564892

If rust really not having a String::reverse function then you can always just add:
trait Reverse {
fn reverse(&self) -> Self;
}

impl Reverse for String {
fn reverse(&self) -> Self {
self.chars().rev().collect()
}
}
>>
>>61565038
>having to implement basic things yourself
man its like im really using C
>>
>2 threads
sort it out /g/
>>
>>61564958
Currently trying to make a bullshit mario clone with SDL in C++

I wish I had a better grasp on designing my codebase though. I keep wondering how physics should be done. I have an InputHandler, should that talk to some kind of PhysicsHandler?
>>
>>61565046
Are Rust strings used in UTF-8? Then it is non-trivial to reverse a string because there are multi-byte characters.
>>
>>61565046
>waaah why do I have to write a one line function
>>
>>61565058
Anime or screencaps of code are the only acceptable /dpt/s

Hijab and Koding shit is not
>>
>>61565063
>InputHandler
>PhysicsHandler
so this is...

the power of...


OOP...
>>
>>61565063
lol, this was literally my final project in graphics class

everything has a hitbox. something isn't hitting something, it's falling.
>>
>>61565046
let reversed: String = my_string.chars().rev().collect();
>>
File: 1501010074092.jpg (35KB, 500x375px) Image search: [Google]
1501010074092.jpg
35KB, 500x375px
>>61565120
in python this is just
reversed = reversed[::-1]
>>
>>61565063
Cut out the unnecessary oop shit. The ONLY things you should have for oop are the blocks and the enemies. Things with both unified-interface behaviors and state. Not sprites. Not menus. Not mario even. Not "InputHandlers" not "PhysicsHandlers."

Have a loop that looks something like this:
int player_x; //Protip these should have subpixel precision. Mario bros uses 256 coordinates per pixel
int player_y;
int dz;
int dy;
void loop() {
while(game_running) {
apply_gravity();
if(letter_pressed('d'))
dx+=acceleration_speed;
dx = clamp_speed(dx);
x += dx;
//.... blah blah blah
}
}

t. minecraft clone guy
>>
>>61565171
>256 coordinates per pixel
?
>>
>>61565165
In python this is just
>uses tons of memory and has to allocate fucking integers on the heap
>>
>>61565165
In brainfuck that is just
>,[>,]<[.<]
>>
>>61565171
>Cut out the unnecessary oop shit
Am I being meme'd on by this fuck then? http://gameprogrammingpatterns.com/command.html

Honestly, I feel the more direct way makes sense anyhow, but I thought if I had to live in a world of OOP, maybe I should learn to implement "proper design patterns."
>>
>>61565191

 def foo(str):
... return str[::-1]



assembly code
 2           0 LOAD_FAST                0 (str)
2 LOAD_CONST 0 (None)
4 LOAD_CONST 0 (None)
6 LOAD_CONST 2 (-1)
8 BUILD_SLICE 3
10 BINARY_SUBSCR
12 RETURN_VALUE
>>
>>61565182
Mario games (most games) use euler integration for physics. If game physics position was merely what pixel was occupied then it would be too inaccurate to be playable or fun.

Since mario's 8 bit they do something like this
int x;
int x_subpixel;
void integrate_x(int speed) {
x_subpixel+=speed;
if(carry_flag_set()) {
x += sign(speed);
}
}
>>
File: sbnal.png (512KB, 587x399px) Image search: [Google]
sbnal.png
512KB, 587x399px
For those who want more instant feedback, we have an unofficial Discord where we make an attempt to discuss programming:

https://discord.gg/gpbTFe
>>
>>61565283
botnet
>>
>>61565283
discord is trash, use irc
>>
>>61565235
Command pattern is great but it's functional programming. The classes used to implement it are a vestige of oop languages either not having first class functions or dogmatism about objects.

I wouldn't worry about the command pattern until you actually have multiple commands to assign to different buttons, i.e. for a menu screen.
>>
>>61565263
intersting
>>
>>61565283
Fuck off to /v/, you proprietary cuck.
>>
>>61565235
OOP is garbage anon. Everyone learns this the hard way eventually.
>>
>>61565263
I am pretty sure 8bit marios do not do that.
>>
>>61565319
Believe me they do.
http://tasvideos.org/GameResources/NES/SuperMarioBros2.html#SubpixelCarryover
>>
>>61565287
IRC is an easily monitored communications channel, and is quite literally just as much of a botnet as any other program in existence.
>>
>>61565336
Oh, I am mistaken. Thanks!
https://www.youtube.com/watch?v=JisFSMHn8tY
>>
>>61565337
a server operator can choose to spy on you, but that is an issue with a specific server rather than the protocol itself - you can use a FLOSS client to connect to a trusted server running a FLOSS ircd through a secure connection and you can have 100% confidence that you are not being spied on. as it is an open (and very simple) protocol you are free to write your own implementation if you do not trust any of the existing irc daemons/clients, and then host your own server

there is nothing inherently botnet about the IRC protocol, whereas discord is proprietary trash and everything you send through it is probably being stored on some chink/government server somewhere
>>
>>61565316
Gospel of OOP welcomes everyone. I pray that you will find your faith back.

Remember developers, a virtual call is a good call.
>>
>>61565467
>program procedurally for 10 years
>eventually start using objects and methods because I'm developing more complex programs that need to be better organized and more mantainable
>experience no problems
>come online
>everyone hates OOP for some reason
>????
>>
>>61565492
They are just lost, I feel bad for them.
>>
>>61565492
Hey, I didn't say he should get rid of all the oop, just the bits of oop that made no sense to be oop.

Use the right tools for the job.
>>
>>61565492
Imperative OOP is POO
Functional and pure objects are the truth.
>>
>>61565467
I laughed harder at that than I should've
>>
>>61565543
really?
>>
>>61565556
really
>>
>>61565583
damn
>>
>>61565492
>10 years ago everyone loved oop
>better organized
>more maintainable
lol
>>
i survived /dpt/
>>
>>61565641
yes, using abstractions when appropriate make your code more organized and maintainable
>>
File: a.png (325KB, 1008x645px) Image search: [Google]
a.png
325KB, 1008x645px
Which denomination are you belong to /dpt/?
>>
>>61565677
>are you a retard or an idiot?
>>
>>61565677
First you have to tell me which paradigm would be this philosopher: https://en.wikipedia.org/wiki/Diogenes
>>
>>61565677
Kay's school is fucking retarded so the other one.

But fuck inheritance. Inheritance should not be a feature. Only interfaces for statically typed languages.
>>
>>61565657
not yet nv

you must implement a haskell compiler in javascript
>>
>>61565883
implement my dick in your ass
>>
>>61565883
*invoke
>>
>>61565945
I don't have an ass

your move
>>
>>61565959
do you shit out of your vagina?
>>
>>61565665
that qualifier makes all the difference anon. Eating shit when appropriate can save your life. Eat shit everyday.

>>61565677
Personally I keep each variable in it's own object and the only way to access it is to use a special message.
>>
>>61566112
abstractions aren't 'eating shit', if you think abstractions are bad go code everything in assembly
>>
>>61566132
Too abstract, I prefer pure machine code
>>
>>61565959
8008135
>>
File: 2bc.jpg (9KB, 399x388px) Image search: [Google]
2bc.jpg
9KB, 399x388px
>be me
>using Go
>work on handling JSON server-side extensively in order to display stock data on the front-end
>using GO'S BUILT IN ENCODING/JSON PACKAGE
>json.unmarshall(...)
>graphs displaying spastically
>check console log
>Go is randomizing the order on unmarshal
>check Go forums
>"yeah are you sure you need to use json why not just use something else it's not Go's fault it's your fault use some other method why not implement it yourself" etc
>all this blind side turned toward this """feature"""
>>
>>61564972
You shut up about my daughterfu
>>
>>61566278
>webdevs need to post on forums about frameworks to handle simple text data formats
>>
>>61566290
r u god?
>>
File: playedyourself.jpg (82KB, 800x434px) Image search: [Google]
playedyourself.jpg
82KB, 800x434px
What's more:
>check googlesource
>someone offered a change that maintains order for JSON decoding
>Rob Pike: "this makes this too complex sorry"
>closed

>>61566304
>he doesn't understand how ridiculous it is that a builtin designed to handle data for processing randomizes it

I wouldn't have a "webdev" problem if Go had LITERALLY ANY decent GUI package.
>>
>>61566344
>In JSON, they take on these forms:
>An object is an unordered set of name/value pairs
>unordered
use an array if you want it to be ordered, dumbass
>>
>>61566366
>stock data given in ordered JSON format
Sure let me just call every major data source and get them to change that. Thank you!!

>order can't be baked in via structure of the JSON itself
>this order can't be broken down by half-baked generalized de-serializers
Why am I still replying?
>>
>>61566412
objects are unordered. arrays are ordered. this is how json works. if the go parser is unordering arrays it's objectively broken. I suspect you're just using objects and expecting them to be ordered and complaining that they're not, however
>>
Why doesn't C++ have
 template <this>
yet, and when will it?
class example {
private:
int the_member;
public:
template <this>
decltype(the_member) &member() {
return the_member;
// int const & if instance is const
// int & otherwise
// same with volatile and restrict
}
};
>>
>>61566470
The solution to that is not template<this>. C++ gave you brain damage if you thought that was the solution.

The solution is to properly handle const, restrict, and volatile in a sane way.
http://yosefk.com/c++fqa/const.html#fqa-18.1
>>
Why would I use something like Java or C# when I could use something like Ruby or Python? Speed rarely matters for anything.
>>
>>61566639
Because finding out about type errors at runtime is really boring and tedious
>>
>>61566470
>>61566600
>restrict
C++ doesn't have restrict.
>>
>>61566743
>What are ClassCastExceptions
I rarely get type errors anyway because I'm not a pajeet.
>>
I'm a programmer
>>
>>61566756
you rarely get type errors because you don't write interesting code
>>
>>61565882
this is the only right answer
>>
>>61566639
>Speed rarely matters for anything
>People stop caring about speed
>Shit starts to get slower
>lol just upgrade your shit to 32gb loser, no one has 16 these days
>>
>>61566782
I create interesting projects in Ruby, C# and C, and I still never get type errors in any of the languages.

>>61566807
I said speed rarely matters for most things, I didn't say that speed was shit. Speed rarely matters, but when speed is needed, it is needed badly.
>>
File: advanced-collision-detection.webm (993KB, 800x608px) Image search: [Google]
advanced-collision-detection.webm
993KB, 800x608px
My new collision resolver is complete. I can now do collision detection on any arbitrary shape as long as it's closed over by a finite number of aabbs.

>>61566639
I like Java more than python, never used ruby or C#. But you're right speed usually doesn't matter that much.

The game logic of pic related including the now complex collision detector is running in Scheme, and believe me it uses a fuckton of map, filter, append, and all that other O(n) shit that treats data as if its disposable and leaves a huge mess for the garbage collector to clean up.
Thread "FPS": 1875.244661
Thread Frametime: 533263

Wow it's hurting my performance so much. The biggest performance killer has been the C code that's controlling the renderer (written in C because in that case performance does actually matter).

Without fail every time there has been a performance problem, the solution was not in the Scheme part of the codebase, but in the C.
>>
>>61566892
Wow anon, impressed with your progress so far.
>>
>>61566892
>speed doesnt matter
>making a minecraft clone
>minecraft, programmed in java, runs at 25 FPS with huge pop-in even on high-end rigs
please stop
>>
>>61566933
More like Notch was a shit program who made spaghetti code and all the other devs at mojang had to work around it.
>>
>>61566956
if you're programming collision detection using map and filter, actually if you're programming collision detection using any heap-allocated data at all, you're a bad programmer
>>
>>61566986
The issue is not heap allocation but data alignment and cache accesses. Something you don't have control over with Java.
>>
>>61566933
What part of "every time there is a performance problem, it's the performance critical code's fault" do you have trouble with anon?

And yes there are performance challenges because worlds have fucktons of mutable data that has to be dynamically loaded onto the graphics card. This isn't a pretty corridor fps where you can load up the megabytes of data before gameplay starts.

This scene is half a million objects, which in order to not be naively rendered, have to be heavily preconditioned.

To get the 200fps I get on this intel 4400HD integrated graphics card, I've had to do lots of intense culling, sorting, and data conditioning, all in C.

>200fps
The performance gains for optimizations often doubled the fps at minimum. The worst is yet to come too. Doubling the view distance would multiply the objects in the scene by 8. So I actually have more optimization to go, but that's GPU optimizations, much of which I'm going to have to write in C (glmultidraw & occlusion culling need to be done at least partially in C).
>>
>>61567041
don't start the data-orientated meme here please, that only really applies when you're doing simple batch processing over thousands of objects (rendering) instead of fairly complex processing over tens or hundreds of objects (physics)
allocations can cause the garbage collector to shit the bed, but worst of all is doing O(n) things which when you have multiple objects working turns into O(n*m) and tanks your performance
dont talk about how performance doesn't matter when you have ONE object moving in an empty world
>>
>>61567049
unless you intend to only have ten characters running around, collision detection is performance critical
>>
What is so special about the C programming language? I mean, other languages like Algol 68, Fortran, PL/I etc. yet C somehow managed to remain popular. Was this because of the popularity of UNIX or is it something more?
>>
>>61567125
>only 500k nanoseconds spent by the CPU per frame
>some of which is C
>some of which is spent doing other things
>the program is still single threaded
Wew. Also adding more physics entities should be only slightly above O^n with proper algorithms.

>>61567131
Yeah Unix.
>>
>>61567131
Because the syntax clicked with enough people and people enjoyed it enough to copy it for every new language aside from some special snowflakes like perl and python.
Also, the language's simple ABI, anemic standard library and lack of complexity means it's relatively easy to get a compiler up and running for your platform.
>>
>>61567131
I feel C was the turning point between "ancient" and "modern" languages. It's technically not the first language of its kind, but it's the most notable and influential.
Nobody wants to use your dinosaur languages.
The UNIX things certainly helps, though.
>>
>>61567041
>>61567049
I've heard that linked lists in scheme with a copying collector can be plenty fast wrt cache locality, since allocation always takes the next available spot in the nursery (so copying/mapping a list would put all of the conses next to eachother). And since copying collectors don't even scan over objects without references, if you e.g. map a 100-element list twenty times, the garbage collector will still only copy 100 conses
>>
>>61567193
>with proper algorithms.
yes, those algorithms don't use map and reduce
and once again, you have ONE object
>>
>>61567232
Map and fold are replacements for loops not algorithms baka. Did you get raped by Gerald Sussman when you were a kid or something anon?
>>
>>61567284
dont know who that is, and they're bad because they're inefficient and leave behind lots of data to clean up, as you said
>>
https://sourceforge.net/projects/ivm/files/ivm/IVM%20Initial%20Developer%20Source%20Release/

ntended as a hybrid between C++ (syntax) and Java (virtual machine) that isn't C#, Internet C++ is an "operating environment"1 based around a C++ virtual machine. Splendid Systems created the project with a similar philosophy as Java but with goals of fast execution and a smaller learning curve. To that end, they claim that no porting is required from NetBSD code and have provided a gcc extension to compile for the platform.

Some weirdos got together in 2001 and tried to join Java with C++.
>>
File: Legit hieroglyphics.png (174KB, 1836x798px) Image search: [Google]
Legit hieroglyphics.png
174KB, 1836x798px
Boy this is actually pretty intriguing, as in I'm all down for trying to learn the ins and outs of this beast. The only programming experience I have is entry-level python and c++.

Solid question, is it wrong if I am this motivated to learn any programming language just so I could understand this? Wanna learn reverse-engineering too.
>>
>>61567377
Strange thing to reverse engineer but usable knowledge is inherently good so nah as long as you gain usable knowledge.
>>
>>61567377
what am i looking at here senpai
>>
Red pill me on smalltalk /dpt/
>>
>>61567417
looks like metal slug
>>
>>61567420
It's old, it's POO, it's shit.
>>
>>61567312
>join Java with C++
That seems like the worst possible place you could start from.
>>
>>61567377
You could start by doing simple things. Like implementing a trainer for your favorite game. I had a hard time understanding how multi level pointers looked on memory. So I disassembled quake 2 to find out how items worked. As a result wrote a trainer to set infinite ammo per ammo type and life.
>>
Can someone explain why pointers have their own types in C? i.e. I can't just dereference an int that I shoved a memory address into, it has to be a pointer to an int.

I'm not sure if it's an intentional restriction for the sake of better code or I'm too retarded to get the logic behind it.
>>
>>61567626
(int*) p = 1000;
(char*) q = 1000;

q + 1 = 1001;
p + 1 = 1004;
>>
>>61567626
Pointers are special, they are a by product of the type system and shouldn't be considered separate types.

I could add 20 indirection operators to a variable and it would qualify as a separate type to one that uses only 19 stars.
>>
>>61567410
Alright, thanks.

>>61567417
Apparently a disassembled libAppMain.so from Metal Slug Attack's apk. Trying (repeat, TRYING) to make it offline for personal reasons. Just found out this might not be what I'm looking for, but I still want to learn x86 assembly.

>inb4 that shit's server sided, don't bother
I don't care, I could still learn a thing or two here. Besides SNK doesn't future proof its stuff, there was a time Lucky Patcher worked flawlessly, or give yourself unit pieces by finding out the unit address using cheat engine of all things or exploit the receipt system to pay nothing for premium currency. All of the aforementioned exploits occurred with a server-sided verification system implemented, so I can have the benefit of doubt that there's a chance I could find something exploitable here because it's not normie-tier hax I'm pulling here.

>>61567454
That sounds fun, just googled it and found out maybe I need a debugger in my case but I'll definitely try making a trainer.
>>
>>61567626
Because dereferencing a char* is different from dereferencing a int*; the former only fetches one byte while the latter fetches 4-8 bytes
>>
>>61567626
Pointers are addresses.

Think of dereferencing as driving to an address.

If suzie gives you her address, you have a pointer to suzie. You can dereference her poointer by driving to her house.

It's meaningless to try to dereference suzie.
>>
>>61565337
Nigger what are you talking about? Do you not know what SSL is?
>>
>>61566440
He just said the APIs he uses give his data as ordered objects. They were obviously designed by retarded webshits but this doesn't change the fact that he has to deal with their stupidity somehow.
>>
>>61566933
>25 FPS with huge pop-in
What the fuck are you doing anon? It runs at 60FPS on all of my machines and chunk loads are only visible on the MacBook.
>>
File: FF3.png (170KB, 1357x931px) Image search: [Google]
FF3.png
170KB, 1357x931px
>>61564958
tryin to get better at reversing

someday i'll port nes games to calculators
>>
>>61568112
You are a strange creature because minecraft is well renowned for running like absolute dogshit.
>>
>>61564958
I'm making a python script that copies all the files in a directory into another directory. My friend backed up her phone to her computer but all the pics are in individual folders and she hates that, but doesn't want to manually move all of them to another "Pictures folder". Shouldn't be too hard.
>>
>>61567310
Please enlighten me, anon. I was under the impression that the following two are equivalent:

reduce(map(f, Xs), g)


acc = f(Xs[0])
for x in Xs[1:]:
acc = g(acc, f(x))


This doesn't look particularly inefficient to me.
>>
>>61568139
You did install OptiFine, right?
>>
>>61568174
A-Are you a girl? Can you program in other languages? What is your favorite programming language?
>>
>>61568188
Yes, but I shouldn't have to, and it improves fps considerably but not enough.
>>
File: disdain_intensifies.jpg (66KB, 730x960px) Image search: [Google]
disdain_intensifies.jpg
66KB, 730x960px
>>61568174
>girl
>doesn't have an iphone
>>
>>61567310
>he doesn't know about foldr/build and map/./id rewrite rules
>>
Language that's like C but more efficient. I'm calling it E.
Variables are immutable unless explicitly declared mut. (So it's like the opposite of const. The keyword const itself doesn't exist because it's the default.)
Everything is passed by reference implicitly and unconditionally, so the fact that variables are const unless explicitly declared mut makes it easy to let the compiler just copy the parameter by value if the value is small enough to make it so that would be more efficient.
Things are even returned by reference. Instead of being a statement, the return keyword is a reference (e.g.
return = 0;
instead of
return 0;
). Its address is in the prior stack frame. So instead of copying return values, it just sticks them where they need to go in the first place.
Heap allocation is unsupported. Stack reallocation and static reallocation, however, are fine. Static reallocation of course technically entails that E code is self modifying at runtime in some small way, since sections of the loaded program text may expand or contract. Manually freeing stack memory or static memory (except insofar as is achieved through reallocation) is of course off limits, as is resizing to 0.
>>
>>61568174
literally just
rsync -arv /directory/to/phone /directory/to/save/at
>>
>>61567626
It's a deliberate restriction so you don't accidentally fuck up. You can totally do it though:

long x = &val;
assert(*(int*)x == val);


Be careful, though - side effects may include fever, segfaults and Linus Torvalds murdering you in your sleep.
>>
>>61568178
I guess it depends on the compiler for the language, it could inline it all to be just as fast as an ordinary loop
>>
>>61567626
because it holds a memory location.

an int is its own type because it holds an integer. a char is its own type because it holds a byte.

a pointer is its own type because it holds a memory location
>>
>>61568234
Stupid Unixfag, we /g/entoomen are much too intelligent for such plebeian endeavours as using code someone else wrote to perform simple tasks. You cannot call yourself a true programmer unless you periodically reinvent the wheel. What nobler human endeavour can there be?
>>
>>61568174
give me your friends number I will be her tech support so that you dont have to struggle making a shoddy python script
>>
>>61568218
>another fucking "lets make the fastest language possible with no convinence features" language
just use asm you autist
>>
>>61568282
umm... using the already perfectly functioning wheel and inventing something new?
>>
>>61568218
>So instead of copying return values, it just sticks them where they need to go in the first place.
You do realize most return values never even touch memory, right? Your idea is literally a performance downgrade.
>>
>>61567900
>implying int can't be 16bits long
>>
>>61568218
>Everything is passed by reference implicitly and unconditionally
Disgusting. I'd be fine if you could specify by value for mutable data.
>no heap allocation
Fucking useless
>self modifying code
Performance murdering.
>self modifying data segments
Oh boy I can't way to copy 100mb of data 4 bytes over because I needed another int in an array. I can't wait to then pause execution and recompile the code segments with all the new offsets to the data. This is so fucking impractical that I have to wonder... have you actually ever used assembly?

The solution to that problem is... you guessed it, a heap.
>>
>>61568218
>Language that's like C but more efficient
doubt it.
>>
>>61568321
>implying ints aren't more commonly 8 bit than 16 bit
The Z80 and other 8 bit cpus are still used in embedded systems. Your DVD reader probably has one. Find me one (1) 16 bit CPU that's used in a modern piece of technology.
>>
>>61568330
>self modifying code
diy pipelines for timing sensitive shit on your 80s arch
>>
>>61565084
>one line
You're forgetting the 4 lines of type bullshit and the 2 lines of nothing but brackets. Welcome to Rust!
>>
>>61568364
Standard says that it must be at least 16 bits dumb fuck.
PIC18 has 16bit int.
>>
File: shameless duck.png (175KB, 458x438px) Image search: [Google]
shameless duck.png
175KB, 458x438px
>>61567995
Apparently I failed to grasp the fundamental concept of abstraction.
>>
>>61568403
>>61568364
the size of an int in C is totally dependent upon your architecture and compiler.

the authority on this matter is calling sizeof(int)

it is often 4 or 8 bytes. on 32 and 64 bit machines respectively
>>
File: 1474178742681.jpg (54KB, 700x350px) Image search: [Google]
1474178742681.jpg
54KB, 700x350px
What *should* I work on today, /dpt/? I'm extremely tired and depressed, and can't be bothered to go back to the React Native webshit clusterfuck I'm supposed to be building.
>>
>>61568433
most generally it is 4 bytes tho,

my 64 bit cpu compiled with gcc sizeof(int) returns 4
>>
>>61568428
So you have a bunch of ram with addresses.

0 -> H
1 -> O
2 -> L
3 -> Y

Then you have an address with a number living in it. It's like a note on the door.

4 -> 0

Number tells you where to go. It's a pointer.

4 -> 0 -> H
>>
>>61565677
Kay, obviously. Stroustrup is just implementation.
>>
>>61565665
What do you mean by 'abstractions'?

An abstraction is a distillation to the relevant essence of a particular thing, not "lawl virtual inherited observer factory" horseshit OOP vicars would force on you. If the thing you're calling an "abstraction" doesn't perform the task you need effectively then, clearly, what you've implemented is not an abstraction in the perspective you need.
>>
File: RAM.png (18KB, 708x293px) Image search: [Google]
RAM.png
18KB, 708x293px
>>61568513
I actually think programmers should start with assembly so they realize nobody's simplifying or dumbing things down or "abstracting" when they tell you ram is just a bunch of boxes with numbers in them.
>>
>>61568473
I know, I get the idea. What isn't so clearly explained is how pointers are part of the type system and not just a catchy name for operations that can be used on any kind of variable.

C is a very simple language so it can be hard to tell when some limitations are intentional or not.
>>
>>61568561
I mean that's what ram is but assembly still magics away:
>pointers
>page tables
>caches
And maybe some other things I'm not remembering.
>>
>>61568580
0s and 1s abstract away electrons
>>
>>61568561
or ohms law, kirchhoff's laws and what the fuck are logic gates and transistors
>>
>>61568614
matter abstracts away energy
>>
>>61568658
energy abstracts away quantum phenomena
>>
>>61568658
>tfw when everything we ever knew is just another dirty abstraction
>>
File: AZN7wsuV4ibdyh5kHS8wbPFjo1_500.jpg (90KB, 500x334px) Image search: [Google]
AZN7wsuV4ibdyh5kHS8wbPFjo1_500.jpg
90KB, 500x334px
>>61568442
Work on not being tired and depressed.
>>
>>61568652
keep your crusty breadboards out of this nigger. i said programmers.
>>
>>61568668
Gee, thanks, excellent advice. Now that I know I shouldn't be constantly tired even after 8 hours of sleep I definitely won't be!

I'm going to the gym, eating balanced protein-rich meals and will go get some blood tests soon. In the mean time, I'm here in my office with a computer. What do I do to keep myself busy instead of aimlessly fucking around on 4chan?
>>
>>61568698
>falling for the bodybuilding meme
>>
>>61568694
>breadboards
Fucking kids these days. Is soldering too hard for you?
>>
>>61568717
i'm just gonna crimp wires and shit
i don't know whats chemistry, could be xenoestrogens
your probably gay from the fumes
>>
File: 1481708013587.jpg (59KB, 781x399px) Image search: [Google]
1481708013587.jpg
59KB, 781x399px
>>61568760
>solder fumes make you gay
I've seen some stupid shit on this website but this is on a whole different level
>>
>using a programming language
>not just programming with 0s and 1s
Fucking brainlets
>>
>>61568929
It's actually not completely out there anon...

There are chemicals which cause sex hormone imbalances. It's pretty common for fish and frogs near cities to end up sterile and intersex from all the shit in the water.
>>
>>61568376
>4 lines of type bullshit and the 2 lines of nothing but brackets
It's like you've never programmed before. This isn't exclusively a "problem" with Rust, you idiot. And I'm not even a Rust shill/user.
Fuck off and kill yourself, idiot.
>>
>>61564972
BTFO
>>
>>61565165
[user0@primary tst1]$ time -p ./rust
Hello world
real 0.00
user 0.00
sys 0.00
[user0@primary tst1]$ time -p python python.py
Hello world
real 0.02
user 0.02
sys 0.00
>>
>>61569013
I don't program in idiotic languages that make you write 3 lines of boilerplate for each line of actual code. Go write C++ and Java somewhere else, faggot.
>>
>>61569122
>2ms of startup time
Are you seriously bitching about this in a world where people think HotSpot is fast?
>>
>>61569125
Python babby detected.
>>
>>61569145
Hotspot is faster than python interpreter
>>
File: 1478742659016.png (11KB, 399x103px) Image search: [Google]
1478742659016.png
11KB, 399x103px
Why would you ever use an implicit integration method when it seems to be way slower and way more complex than an explicit method?
>>
>>61569156
Good argument, anon. In fact, the power of your unsubstantiated, pointless and inaccurate ad hominem attack has convinced me to switch to C++. Off to write some templates!
>>
>>61569175
I was talking about start up times. HotSpot is obviously faster than CPython.
>>
>>61566278
>Go
kek
>>
>>61568299
>>another fucking "lets make the fastest language possible with no convinence features" language
>another
I can't think of many languages that fit that bill.
>>
>>61569212
CPython/PyPy are not real python, they are neutered down, unsupported subset of python
>>
Is there any way of using mmap() to share memory between two unrelated processes?
I just want to get a memory area mapped into both a server daemon and a client
>>
>>61565165
In Haskell this is just
reverse str
>>
File: 1498978588475.jpg (438KB, 1200x707px) Image search: [Google]
1498978588475.jpg
438KB, 1200x707px
>>61569258
>CPython is not Python
>>
>>61569297
Refute
>>
Wish me luck
>>
>>61569291
Yes, that's one of the main uses of mmap.
http://man7.org/linux/man-pages/man7/shm_overview.7.html
>>
>>61569300
https://en.wikipedia.org/wiki/CPython
Are you using some weird definition of "Python"? Please be more specific.
>>
>>61569336
>Unix
Absolutely disgusting.
>>
>>61569362
Go home, wincuck.
>>
>>61569336
>The Unix Environment
What is this, the 1980s?
>>
>>61569367
>using an operating system that needs 3rd party software to draw things to the screen
>using an operating system that needs 3rd party software to use a database
>using an operating system that needs 3rd party software to perform RPCs
>using an operating system that needs 3rd party software to use graphics hardware
>using an operating system that needs 3rd party software to safely exchange rich data between programs
>using an operating system that needs 3rd party software to display user interfaces
>using an operating system that needs 3rd party software to do literally anything more useful than searching a file for some text
>>
>>61569426
This post is so retarded, I can't even begin trying to reply to it properly.
>>
>>61569455
Don't even try. Win32 is too superior to construct counterarguments for.
>>
>>61569426
there's no first party GNU/Linux components you dumb manchild retard.
>>
>>61569426
it's so much easier to set up a dev environment in linux tho.

windows has some neat programs from back in the day like your debugging nintendo emulators but it's a secondary os for me.
>>
File: 1402882854675.jpg (107KB, 750x750px) Image search: [Google]
1402882854675.jpg
107KB, 750x750px
>>61569469
>kernelspace font rendering
>>
>>61569469
the only cool thing about the windows api is that i can compile windows 3.1 shit and it still works on windows 10.
>>
>>61569477
Well, there is Linux.
>>
File: 1483659130874.png (14KB, 166x166px) Image search: [Google]
1483659130874.png
14KB, 166x166px
Thanks to macros you can now have python list/dict comprehensions in Rust: https://docs.rs/cute/0.3.0/cute/
>>
>>61569495
from the perspective of a GNU system, linux is third party software
>>
>>61569426
Does Windows still require a 3rd party PDF viewer these days?

That shit was annoying, when I last used Winblows.
>>
>>61569487
It's for maximum performance. As a Linux user you wouldn't know what that is.

>>61569514
No, but the default one is cancer.
>>
>>61569510
Shouldn't that be
> GNU is third party to Linux
>>
>>61569487
How do you think framebuffer console in Linux works? It literally renders fonts in the kernel space.
>>
>>61569523
GNUfags will never understand this. Don't bother.
>>
>>61569523
what are you going to do with just a kernel?
>>
>>61569297
Python is not a language, it's a software application. The python ""standard"" is however the software functions at the current moment.

Or maybe I'm thinking of perl. Either way use lua.
>>
>>61569524
Linux is not touching that shit in gooey code.
>>
>>61569501
Why tho? A chain of .map().filter().zip() is just as good and only slightly more verbose.
>>
>>61569541
Well, nothing. Doesn't change the fact that Linux is a space which GNU inhabits, and not vice versa.
>>
>>61569564
You mean GNU is a space which linux inhabits.
>>
>>61569564
Gnu is not a complete operating system without facebook. Call it Gnu + Facebook.
>>
File: KNOPPIX_booting.png (23KB, 641x515px) Image search: [Google]
KNOPPIX_booting.png
23KB, 641x515px
>>61569545
With framebuffer console, Linux kernel does the drawing, including font rendering, whatever it draw complex GUI or not is irrelevant. Who do you think draws the Tux in picrel? The kernel does.
>>
C novice question
Say you have the structs p1 and p2, which have the member x.
If you do
p2.x = p1.x++;

it modifies x not just for p2, but also p1, but if you do
p2.x = p1.x + 1;

Then p1.x isn't altered. Why is this the case?
>>
>>61569501
> an add-on for list comprehension

In Haskell this is just
[ x*x | x <- [1..10]]
>>
>>61569625
That's what ++ means. It doesn't just happen with structs.
postfix ++ returns the value it refers to, and then increments the underlying value.
>>
>>61569633
And it only produces 1Gb of garbage per second.
>>
File: retard master.jpg (206KB, 808x446px) Image search: [Google]
retard master.jpg
206KB, 808x446px
>>61564958
I think I've finally been redpilled about memory allocation

like 99% of the time your problem has concrete bounds. if you find them, allocate a block of memory exactly that size once, and then carve it up as needed, your so much better off for it

maybe this is really obvious but it never occurred to me. I've always been taught to malloc on an as-needed basis
>>
>>61569625
the first will increment p1.x by 1 and then assign it to p2.x
the second will assign the result of the expression p1.x + 1 to p2.x
>>
>>61569594
No, I'm pretty sure something else it putting the penguin there.
The kernel is not the only thing which has access to the framebuffer.
>>
>>61569633
>GC
>>
>>61569643
>>61569652
Ah, ok. Ty. Just found the wikipedia page on the operators.
>>
>>61569625
Because the p1.x++ modifies in situ, whereas the p1.x simply returns a value, which is then added to.
>>
>>61569649
That's highly dependent on your use case.
All you're doing is implementing a memory allocator on top of a memory allocator by doing that, but sometimes it's justified if you can optimise it for your memory usage patterns better.
>>
Any Rust fag here? So you put all the related methods on an impl block, right?
struct Complex {
real: i32,
imaginary: i32
}

impl Complex {
fn new(a: i32, b: i32) -> Complex {
Complex{real: a, imaginary:b}
}
fn to_string(x: Complex) -> String {
format!("{} + {}i", x.real, x.imaginary)
}
fn add(x: Complex, y:Complex) -> Complex {
Complex{real: x.real + y.real, imaginary: x.imaginary + y.imaginary}
}
fn times(x: Complex, y: Complex) -> Complex {
Complex{
real: x.real * y.real + x.imaginary * y.imaginary,
imaginary: x.imaginary * y.real + x.real * x.imaginary
}
}
fn abs(n: Complex) -> f64 {
(((n.real)^2 + (n.imaginary)^2) as f64).sqrt()
}
}
>>
>>61569693
Yeah but it's a contiguous block of memory that won't have any nasty surprises.
>>
>>61569695
Rust has standard traits for most of the shit you're doing there.
>>
>>61569706
No, no, It's just for learning purposes
>>
>>61569701
Again, it depends on your use case for whether that's important or not.
>>
>>61569524
There's a vast difference between the kernel blitting some bitmap fonts to the framebuffer and the kernel running a fucking TrueType VM.
>>
>>61569524
By blitting simple bitmap fonts.
Bitmap fonts are very different to truetype fonts, which are vulnerable to exploits.
>>
>>61569695
I am interested in Rust but never studied it much. I know very little terminology, but do you define the interface in the struct block and the functionalities in impl block?
>>
>>61569426
>>using an operating system that needs 3rd party software to draw things to the screen
Linux can draw to the screen just fine without third party software. See the DRM/DRI.

>>using an operating system that needs 3rd party software to use a database
Seems right.

>>using an operating system that needs 3rd party software to use graphics hardware
Windows also requires third part software for this.
>>
>>61569777
Traits (aka Interface) is described in a separate block. I am new to Rust myself. A trait only contains a description of methods, that is, their type declarations or
signatures.

struct Alien {
health: u32,
damage: u32
}

impl Alien {
fn new(mut h: u32, d: u32) -> Alien {
// constraints:
if h > 100 { h = 100; }
Alien { health: h, damage: d }
}
fn attack(&self) {
self.health -= 10;
}
}
trait Monster {
fn attack(&self);
}
>>
>>61569695
You haven't defined any methods, only associated functions. Methods have
self, &self or &mut self
as the first parameter.
>>
>>61569828
I don't know many things about methods and classes, I only understand structs and member functions
>>
>>61569821
Linux does but the reply chain that post is from was about Unix.
>>
>>61569825
That's not how you use a trait.
>>
>>61569828
So in >>61569825, attack was a method and new is a normal function? Is that how constructors work?

Is there any equivalent of static variable?
>>
>>61569846
Associated functions are just functions namespaced under the types name, methods are functions defined on concrete instances callable with dot-notation syntax, e.g.:
struct Foo(u8);

impl Foo {
fn assoc() {
println!("In associated function");
}

fn method(self) {
println!("In method with value {}", self.0);
}
}

fn main() {
Foo::assoc();
let f = Foo(2);
f.method();
}
>>
>>61569893
oh boi
thanks
>>
>>61569893
Thanks, man.

When would one use an associated function vs. a method?
>>
>>61570455
When do you use a static method vs an instance method?
>>
>>61570455
Most of the time, an associated function would be some form of constructor.
>>
>>61569426
>using an operating system that needs 3rd party software to draw things to the screen
you can write to the framebuffer directly
>use a database
???
>perform RPCs
that's a good thing
>safely exchange rich data between programs
dbus?
you can send "rich" data over named pipes if you want
>display user interfaces
same as your first point
it's a good thing though, since servers don't need UI stuff anyway
>do literally anything more useful than searching a file for some text
this is pointless
all operating systems are useless by themselves

8/10 would reply to this obvious bait again
>>
>>61570651
ODBC. The registry is also arguably a key-value database.
DBus is third-party Red Hat trash fire software and needs to die.
Win32 includes an entire graphics toolkit and you're telling me "just draw to the framebuffer lol" is an acceptable alternative?
>>
what's the best color scheme to prevent eye strain for sublime text 3? is afterglow any good?
>>
>>61570732
anything with a low contrast
>>
>>61570732
I'm not a Sublime Text user, but I like pitch black themes.
>>
I'm starting to learn Python (i'm a beginner to programming)

I'm confused by left shifts, specifically the example given 2 << 2 being 8

How does it get 8?
>>
>>61570782
0100
>> 2 (right shift)
0001
>>
>>61570782
Learn binary representation of integers.
>>
>>61570706
>Win32 includes an entire graphics toolkit and you're telling me "just draw to the framebuffer lol" is an acceptable alternative?
They are COMPLETELY different things, and comparing them is just plain retarded.
Also, direct framebuffer drawing is a very outdated way of drawing directly to the screen and has a lot of limitations. The way to do it this way is through the Linux DRM system.
>>
>>61570732
soda light + tomorrow
>>
>>61570818
>DRM inbuilt into linux
FLOSS fags on suicide watch
>>
>>61570818
The way to do it these days*

>>61570840
Direct Rendering Manager.
FreeBSD copied it too.
>>
>>61570799
Okay, I think I get the concept now. So it just shifts the integer to the direction given? But then how does it know to move the 1 and not the 0s?
>>
>>61570855
The zeros ARE being moved. There are just new zeros being inserted into the gap they left behind.
>>
>>61570855
A bitwise right shift drops the last N items and inserts N 0's in the front.
>>
File: troglodyt.png (81KB, 645x729px) Image search: [Google]
troglodyt.png
81KB, 645x729px
>create github and bunch of local repos
>want to have these on my other computers as well
>check everything in to my subversion server

anyone else really smart here?
>>
>>61570863
Oh okay. So let me get this straight so I make sure i'm not confusing myself.

>2 (being 10 in binary) << 2
>this moves it to the left two times
>becomes 1000 which is binary for 8

Am I getting this right?
>>
>>61569013
>rustbabby cant handle criticism
why am i not surprised?
>>
>>61570934
yes
>>
>>61570741
>>61570761
>>61570829
thank you
>>
>>61570934
Yes, but maybe you are just being lucky, do -1 to confirm
>>
Are there some good ressources about game structuring using OOP?
I made a quick java game using libgdx, but it's becoming quite a mess already:

│   Game.java
│
├───Actors
│ │ Character.java
│ │ Door.java
│ │ Floor.java
│ │ Hero.java
│ │ Room.java
│ │ Stairs.java
│ │
│ ├───Enemies
│ │ Boss.java
│ │ Enemy.java
│ │ Slime.java
│ │
│ └───Utils
│ ProgBar.java
│ ScrollingBG.java
│ ScrollingLabel.java
│
├───Items
│ Food.java
│ Gold.java
│ Item.java
│ Key.java
│ Potion.java
│ Usable.java
│
├───Screen
│ CreditsScreen.java
│ GameOver.java
│ IntroMenu.java
│ IntroScreen.java
│ LoadingScreen.java
│ MainScreen.java
│ OutroScreen.java
│ ScreenManager.java
│
└───View
Hud.java
Inventory.java


Any tips appreciated.
>>
>>61570983
Doesn't look that bad to me desu.
>>
https://forum.dlang.org/post/[email protected]
>>
>>61571063
Why are you posting a link so some dead 90s forum?
>>
>>61571063
>Compile times are quite slow (about 1 minute to get a 3kB binary). Some discussion about that is taking place on the GDC forum [4].
>-O2 and -O3 give me a broken binary, but -O0, -O1, and -Os work well.
>>
>>61571087
>Turned out to be a problem in my code, not with the compiler. All optimiziation options work well.
>>
>>61571063
>Everything is in D (inline assembly is D).
>Compile times are quite slow (about 1 minute to get a 3kB binary)
>-O2 and -O3 give me a broken binary
And I assume it has no GC so the standard library and most of the 3rd party libraries are unavailable? Nice job debunking the language, m8.
>>
Is Erlang and Elixir the shit or a shite?
>>
>>61570942
Thanks, that cleared alot of confusion up.
>>
>>61571043
Well the thing bugging me is about how Room.java, for example handles everything, like generating items locations, checking collisions, ...

I have something like
 public void update() {
stage.act();

for (Enemy enemy : enemies) {
checkMapBounds(enemy);
if (player.getBounds().overlaps(enemy.getBounds())) {
enemy.hit(player);
}
}
for (Item i : items) {
if (player.getBounds().overlaps(i.getBounds())) {
player.pickUp(i);
}
}
}

So single responsibility principle isn't fulfilled here right?

Should I make a collision manager or relocate some parts on the code in other classes?
>>
>>61571063
Wew, m8: https://github.com/helena-project/tock
>>
>>61570937
Can you read? I don't use Rust.
It's not even a valid criticism, it's just plain retardation.
>>
>>61571410
dumb rust poster.
>>>/mlp/
>>
File: happy.jpg (41KB, 394x353px) Image search: [Google]
happy.jpg
41KB, 394x353px
Why is happiness programming in Ruby?
>>
Guys, is it possible to print a geometric figure in C ? Like, without relying on ASCII characters, and preferably without any library.
>>
>>61571639
Programming in Ruby is awful
>>
>>61571703
Then what programming language isn't awful?
>>
>>61571723
English
>>
>>61569247
What else would you recommend for fast back-end computation?
>>
>>61571729
>what programming language isn't awful
Your lack of reading comprehension suggests that English is pretty awful anyway.
>>
>>61571745
Rust, C++14, Java/Kotlin/Scala, in this order.
>go
>fast
Well, it's faster than Python, that's for sure.
>>
>>61571749
English is an amazing programming language
>>
>>61571769
Maybe he meant fast as in fast to write, not fast to execute in which case I'd argue neither Rust nor C++ are fit for that given the alternatives, I can't say much about the latter languages you mention though.
>>
File: inline_perform_until_code.jpg (341KB, 1118x747px) Image search: [Google]
inline_perform_until_code.jpg
341KB, 1118x747px
>>61571774
Hi, Grace.
>>
>>61571687
>and preferably without any library
That's going to rely on murky operating system specific details if you're talking about drawing something to the screen you can actually see.
Otherwise there are some very rudimentary image formats you could spit out which are very easy to generate.

Really though, using a library for this sort of thing is a better idea.
>>
>>61571812
Well, he said "fast computation", not "rapid development".
>>
>>61571195
Cant' you move that logic to the Enemy and Item class?
>>
>>61569701
Heartbleed was caused by something like that. If you do it you better know what you're doing.
>>
>find database online with private keys
>Page 1 out of 904625697166532776746648320380374280100293470930272690489102837043110636675

hows this possible?
>>
>>61572169
Is that literally enumerating all of the numbers between 0 and 2^256 or something?
>>
>>61572275
its a website with all the bitcoin private keys, so probably
>>
 
echo off
title Message
color 0a
cls
echo[
echo Hello friend . . .
echo[
echo[
echo[
pause

From 1 to 10, how l33t am I?
>>
>>61572305
whats this garbage?
>>
>>61572310
Karlie Kloss's latest project
>>
>>61572333
sauce?
>>
I'm having a real hard time understanding what "static" means and entails in Java. I understand that static method or variable belongs to a class and isn't instantiated by a constructor, but I can't wrap my head around how and when to use it; for example, does a subclass inherit it?
>>
>>61572472
Static members aren't inherited so they can't be overriden. They don't belong to any object.
>>
I've given up on Rust. The official book is crap and the documentation is crap. Rust Essentials is from 2015 so it's dated.
I guess I'll pick up FP languages again. They're a fun time sink. I'm thinking on either picking up Clojure or Haskell. Clojure feels more practical (and I secretly like Lisps), but Haskell is technically a better language. Any suggestions?
>>
>>61572552
>Babby is too retarded to learn a real language
Yes, compared to trash like Clojure, Lisp, and Haskell, Rust is a real language in my book.
FPtards confirmed retarded.
>>
>>61572472
Easiest way I can think of static is to think of it as completely separate from any instance of a class. I always use static when I intend on having variables that will always stay the same no matter how many objects of a class I instantiate, if any, and for methods that need to always produce the same output given the same input. Non-static methods could, on the other hand, produce different output given the same input since they are going to be dealing with each particular instance of a class and its own attributes.
>>
>>61572552
Elixir

>Elixir is a dynamic, functional language designed for building scalable and maintainable applications

https://github.com/elixir-lang/elixir
>>
>>61572578
>dynamic
Straight into the trash
>>
>>61569649
Sort of.
Most of the time where you have dynamic memory requirements you should have a growing estimate rather than allocating on the heap as you need.
Completely counter to the GC approach.
People who do GC generally don't understand that if they have memory concerns they will have to deal with memory management either way. It's just indirect in the case of GC.

I don't deem it worth it to manage a GC over calling your allocate once or twice.
>>
>>61572585
?

whats the problem
>>
>>61572552
>2015
>outdated
How?
>>
>>61572578
I've looked into Elixir, but I never had the chance to try it out myself. I know Discord uses it.
Is it any better than a Lisp?
>>
>>61572472
static members have static storage. They are not part of any class instance.
There is no need to complicate them any further, and it should become completely obvious how to use them and why you can't do certain things with them.
>>
>>61572603
>Is it any better than a Lisp?
i have no idea

i don't even program
>>
>>61572552
> I've given up on Rust. The official book is crap and the documentation is crap.
What exactly do you have problems with?
> Rust Essentials is from 2015 so it's dated.
If it's post-1.0 (i.e. May 2015) it's not dated.
>>
>>61572593
Dynamic.
That's the problem.

If it's not static, it's trash.
>>
>>61572542
Thanks. Just for clarification, does that mean in something such as "class ClassName extends SuperClass", you can't reference the static method via "SuperClass.method()" or "SuperClass.field" without importing the class?
>>
>>61572472
It's wiser to view it like static methods and variables are simply namespaced by the class identifier.
They don't really belong to the class in the way you'd normally view it.
>>
>>61572626
languages don't have to be like you, a static person that's afraid of being dynamic

prolly why you're a virgin
>>
>>61572618
>What exactly do you have problems with?
I like to learn a language by reading a book. The Rust Book is the worst programming book I've ever read.
>If it's post-1.0 (i.e. May 2015) it's not dated.
I disagree, a lot of important macro thingies have recently been stabilized.
>>
>>61572617
/dpt/ in a nutshell
>>
>>61572652
That doesn't make any sense.

Dynamic languages are trash. This is fact.
>>
>>61572669
but they can do a variaty of things static laanguages can't

probably why python, js, are the most used
>>
File: infinite shit.png (688KB, 1279x716px) Image search: [Google]
infinite shit.png
688KB, 1279x716px
How the fuck does this create an infinite loop?

Is that even possible with foreach loops?
>>
>>61572669
Dynamic languages are the most flexible, but they lack type safety obviously. I don't really care about the latter for my toy projects though.
>>
>>61572627
You can do that way, but you shouldn't. Modifying SuperClass.field modifies ClassName.field.
>>
>>61572691
I guess technically you could create an infinite loop with a custom container that intentionally defines fucked up begin() and end() methods.
>>
>>61572691
I have no idea what m_debufs is but if the iterators it returns on .begin() and .end() are fucked then it may well loop for ever.
>>
>>61572691
Not in that case, but you could theoretically add elements to the list you are iterating through inside of the foreach that would cause it to go into an infinite loop, if I'm not mistaken.
>>
>>61572661
> The Rust Book is the worst programming book I've ever read.
What exactly do you have problems understanding?
> a lot of important macro thingies have recently been stabilized.
So? You don't have to know them to use the language efficiently. After you learn 1.0 you can just read release notes one by one to learn what's new. I mean, C++17 has been voted on recently, this doesn't mean every C++ book out there is suddenly useless.
>>
>>61572733
>What exactly do you have problems understanding?
I want to learn idiomatic Rust and I refuse to learn from trial-by-error.
>So? You don't have to know them to use the language efficiently. After you learn 1.0 you can just read release notes one by one to learn what's new. I mean, C++17 has been voted on recently, this doesn't mean every C++ book out there is suddenly useless.
Every book pre C++11 is useless.
>>
>>61572717
Like so:
struct
{
int *begin() {
return &member;
}

int *end() {
return begin() - 1;
}

int member = 0;
} container;

int main(int, const char **)
{
for (const auto &v: container) {
// inf loop
}

return 0;
}
>>
>>61572691
>for (const auto& debuf : m_debufs)
Is the const actually necessary? if it was just auto&, would the const be automatically added if *this was const? or would it copy debuf?
>>
>>61572769
If the element it gets a reference to is not const, then const is added. If it is const, then nothing changes.
>>
>>61572769
>>61572801
As someone who's still trying to wrap their head around modern C++, what's the point of const being all over the place?
>>
>>61572801
No, I mean if it was rewritten like this:
for (auto &debuf : m_debufs)

and the element it is getting a reference to was const, would auto deduce a const reference?
>>
>>61572757
> I want to learn idiomatic Rust and I refuse to learn from trial-by-error.
So read the book? I mean, I don't know what's your problem with it, but as long as you understand the topics it presents there's no reason to just disregard it. I've read the first edition and it taught me the language just fine. Overwise just read the standard library code, it's very clear and well-documented, or read https://rustbyexample.com/ .
>Every book pre C++11 is useless.
So if neither C++14 nor C++17 made C++11 books obsolete, why do you think a couple of new language features make a 2015 book on Rust obsolete?
>>
>>61572827
Yes, it would.
You can't initialize a non-const reference even if you avoid auto. Unless you use const_cast of course.

>>61572822
It just describes your intent better. If you know you only want to get and not set, you can say that. It tells the reader what you're doing and it tells the compiler what you're doing so it can spit errors at you.
>>
>>61572822
Allows you to enforce guarantees about constness.
Gives the compiler opportunities to optimize.
Better self documenting code.
And you can bind rvalues to const lvalue references.
>>
>>61572827
No.
#include <cstdio>
#include <type_traits>

template <typename T>
void check_const(const T &, std::true_type)
{
std::printf("Variable is const.\n");
}

template <typename T>
void check_const(const T &, std::false_type)
{
std::printf("Variable is non-const.\n");
}

template <typename T>
void check_const(const T &t)
{
check_const(t, std::is_const<T>());
}

int main(int, const char **)
{
const int a = 1;
int b = 2;

auto &x = a;
auto &y = b;

check_const(x);
check_const(y);

return 0;
}
>>
>>61572873
>So read the book? I mean, I don't know what's your problem with it, but as long as you understand the topics it presents there's no reason to just disregard it. I've read the first edition and it taught me the language just fine. Overwise just read the standard library code, it's very clear and well-documented, or read https://rustbyexample.com/ .
This is blatant fanboyism.
The book is in bad shape. Who the hell teaches by compile errors? Look at the comments section for instance, it's a complete joke: https://doc.rust-lang.org/book/second-edition/ch03-04-comments.html
>So if neither C++14 nor C++17 made C++11 books obsolete, why do you think a couple of new language features make a 2015 book on Rust obsolete?
C++14 and C++17 are small but useful improvements over C++11. The #derive thing in Rust has gotten a serious overhaul. I like to know how to use that properly.
>>
>>61572961
>The book is in bad shape.
So read the first edition? It's still perfectly good and everything in it works just fine.
>Look at the comments section for instance
What else do you expect to find in a section about comments?
>C++14 and C++17 are small but useful improvements over C++11. The #derive thing in Rust has gotten a serious overhaul.
Either you don't know what C++17 changes or you have no idea how Rust has changed in the last 2 years. In either case, you're talking out of your ass.
>I like to know how to use that properly.
No, you don't, unless you're a Srede or Disel developer. And if you really do, you can always learn it after you learn the language. Programming languages change all the time, and if you refuse to read on anything except the bleeding edge the only language I can recommend is Common Lisp, since it hasn't changed in the last 25 years, mostly because it's dead.
>>
>>61572949
This code is wrong, and also not modern enough.

Fixed:
#include <iostream>
#include <type_traits>

template <typename T>
void check_const(T&) {
if constexpr (std::is_const_v<T>) {
std::cout << "Is const\n";
}
else {
std::cout << "Not const\n";
}
}

int main(int, const char **) {
const int a = 1;
int b = 2;

auto &x = a;
auto &y = b;

check_const(x);
check_const(y);
}


The problem was in your last check_const function. Because you accepted a const T& parameter, then passing in a const int would deduce T to be just int.
You can easily test the constness without the template magic, anyway. Just try to assign something to y, it'll fail to compile.
Although for some reason in my example, when I change the parameter to a T&&, it reports it as not const, not sure why.
>>
>>61572949
Dumb nigger.
#include <cstdio>
#include <type_traits>

template <typename T>
void check_const(const T &, std::true_type)
{
std::printf("Variable is const.\n");
}

template <typename T>
void check_const(const T &, std::false_type)
{
std::printf("Variable is non-const.\n");
}

template <typename T>
void check_const(const T &t)
{
check_const(t, std::is_const<T>());
}

int main(int, const char **)
{
const int a = 1;
int b = 2;

check_const(a);
check_const(b);

return 0;
}

Your code is fucked.
>>
>>61573099
>and also not modern enough.
Don't have access to GCC7 on this machine.

>The problem was in your last check_const function. Because you accepted a const T& parameter, then passing in a const int would deduce T to be just int.
Ah, you're absolutely right.
>>
>>61573082
>So read the first edition? It's still perfectly good and everything in it works just fine.
The first edition is even worse.
>What else do you expect to find in a section about comments?
Ditch the section and embed it somewhere else.
>Either you don't know what C++17 changes or you have no idea how Rust has changed in the last 2 years. In either case, you're talking out of your ass.
Great argument.
>No, you don't, unless you're a Srede or Disel developer. And if you really do, you can always learn it after you learn the language. Programming languages change all the time, and if you refuse to read on anything except the bleeding edge the only language I can recommend is Common Lisp, since it hasn't changed in the last 25 years, mostly because it's dead.
So you say that Rust is unstable?
>>
>>61573111
Read the thread, nigger.
>>
>>61573149
> The first edition is even worse.
I see.
> Ditch the section and embed it somewhere else.
Otherwise, the book is literally unreadable, I see.
> Great argument.
Well, all you have to do is to compare changes in C++14/17 with changes to the language since Rust 1.0.
> So you say that Rust is unstable?
I understand you were baiting from the start, but this is just too much.
>>
>>61573162
Nah he's right due to what >>61573099 said my code will tell you that neither variable is const so it's incorrect even before we get to the auto deduction, the corrected version would be without const in front of T like the other anon said.

https://ideone.com/RK4rdd

Which, with the correction and auto in mind, will actually do prove myself wrong because the answer was yes:
https://ideone.com/VXYQ8a
>>
What are the general guidelines for releasing an app on the app store? Like, my app has all the basic functionality but that's It, no extra features. I plan to add them later but there are like 20 people on my team that need the app and I don't want to/can't manually install it for each.

Is it ok to submit now or should I add more stuff or what?
>>
>>61573254
Gee I wonder, it's almost as if the stores where your publish didn't have any official guidelines that you could read.
>>
>>61572691
for i in 0 ... { }
>>
File: consider.jpg (29KB, 600x600px) Image search: [Google]
consider.jpg
29KB, 600x600px
new thread
>>61573303
>>
>>61567131
C is special because the Lispers like it and Lispers control what is taught nowadays. These languages declined in popularity when Lisp features and lambda calculus became the "fundamental" computer science.

In other words, they needed C to implement their FP and Lisps, but PL/I, Fortran, and Algol 68 had different principles and different ideas about what is fundamental, so teaching them would be harmful to the spread of Lisp and FP.

>>61567203
>it's the most notable and influential.
No, C is not influential. It is the most influenced. Every feature in C, C++, and Java came from somewhere else.
>>
>>61574575
>Lispers control what is taught nowadays.
lmao, lisp is a dead meme
Thread posts: 349
Thread images: 27


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