[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: 334
Thread images: 25

File: dpt_flat.png (102KB, 1000x1071px) Image search: [Google]
dpt_flat.png
102KB, 1000x1071px
Old thread: >>57429396

What are you working on /g/?
>>
>>57434499
thanks
>>57434507
i gotcha, so when you want multiple types, but not every type
>>
watching anime and eating fries.

not motivated at all.
>>
>>57434547
learning haskell and doing keto.

have transcended motivation into pure discipline.
>>
considering building a browser based multiplayer game. JS + websockets seems really easy to work with
>>
>>57434539
Type classes also often come with (implicit) laws about their operations. For instance, Num a is a ring (a, +, *). While Haskell can't actually check (nor can it check any sort of proof) that instances adhere to any laws, it's assumed that any instance will follow the laws and if you don't it's undefined behaviour.
>>
What will code complete teach me if I've read SICP and the pragmatic programmer?
>>
>>57434539

If you imagine the function

id :: forall a. a -> a
(forall a. is implicit)

this works on every type, but it doesn't know anything about the type - because the type could be anything

if you want to know something about the type - e.g. that you can compare its terms for equality - then you need to constrain it to "only things that can be compared for equality"

this is what classes do
>>
>>57434561
is keto a javascript framework
>>
9th for python
>>
>>57434603
Somebody probably has started a """""lightweight""""" JS framework called "keto"
>>
Programming was a mistake.
>>
Trying to crack this hash for a Uni CTF challenge. I've already attempted to break it using Python and a word list to generate a bunch of hashes to compare to, but that didn't find anything
>>
>>57434492
Been programming a few days started doing tic tac toe based on this challenge this website. Piece by piece assembly but I just wrote the worst code probably ever. It does find the win state of the matric including both diaganol.

It's just garbage code and it's like 60 lines then I go in the comment section of the challene and peoplesaid they made an effective win state checker for tic tac toe in 14 lines. Don't look at code and cry.
>>
>>57434654
What hash did they use?
>>
>>57434539
>>57434594
It's worth noting that type classes are basically an automated version of this:
count :: (a -> a -> Bool) -> a -> [a] -> Int
count (~~) a = f where
f [] = 0
f (x : xs)
| a ~~ x = 1 + f xs
| otherwise = f xs

Which with the class Eq would be:
count :: Eq a => a -> [a] -> Int
count a = f where
f [] = 0
f (x : xs)
| a == x = 1 + f xs
| otherwise = f xs

The tradeoff is that you only get one instance of a particular type class per type.
>>
>>57434644
agree
>>
>>57434663
tic-tac-toe was one of the first programs i wrote...
i still remember when i first showed it to my teacher. he just sat there with a blank face... then burst out laughing. he said it was the worst code he'd ever seen.

i had copy pasted 3 nested ifs for every possible 3-in-a-row in the game

rip

but who's laughing now. i'm still at it
>>
>>57434720
sha256, unless they decided to use some obscure 256-bit hash for this particular challenge
>>
>>57434748
I found a archive of my drive from 4th grade when I started programming. I had a wrapper for the windows `color` command and had a else if for every hex number up to 0xFF to concatenate a string. Holy shit I was dumb
>>
File: 1475512304774.jpg (87KB, 620x387px) Image search: [Google]
1475512304774.jpg
87KB, 620x387px
If I use this code
#include <iostream>
#include <string>
using namespace std;
int main()

{
int x=1, y=2, z=3;
int sum = x+y+z;


cout << "Hello world! \n\n";

cout << "The sum of x, y, and z is " << sum << "\n";
cout << "If you got the number 6, you're correct! \n\n";

int user_Numberinput;

cout << "Please enter a number: ";
cin >> user_Numberinput;
cout << "You entered: " << user_Numberinput << "\n\n";

cout << "Congratulations! \n\n";

string user_Firstname;
string user_Lastname;

cout << "Now please enter your first name: ";
cin >> user_Firstname; cout << "\n";

cout << "Thank you! Now please enter your last name: ";
cin >> user_Lastname; cout << "\n";

cout << "Ah! So your name is " << user_Firstname + " " + user_Lastname << " correct? \n\n";

string user_Fullnameinput;

cout << "Now please type your full name: \n";
getline (cin,user_Fullnameinput);

cout << "Hello " << user_Fullnameinput << "!\n";

return 0;
}

the part where Im supposed to input the full name won't allow me to do it. it just skips that part completely.
but if I input this
#include <string>
using namespace std;
int main()

{

string user_Fullnameinput;

cout << "Now please type your full name: \n";
getline (cin,user_Fullnameinput);

cout << "Hello " << user_Fullnameinput << "!\n";

return 0;
}

it works just fine....why?
>>
>>57434748
Well at least you showed work ethic and a willingness to do this thing called programming.
>>
>>57434539
If you're familiar with Java, Haskell's type classes are vaguely similar to interfaces.

Except, a type class can provide default implementations for functions.

Also, you can define your own type classes then declare existing types to be instances of them (whereas Java interfaces require that you specify which interfaces a class supports when you define the class).

And you can constrain a parametric type to multiple type classes; which is why you have to use the
Num a => a -> a -> a
syntax; you can't just write
Num -> Num -> Num
Because you might want e.g.
(Num a, Ord a) => a -> a -> a
to indicate that a must belong to both classes (because you're going to use operations from both).
>>
>>57434793
you can also do
Num a => Ord a => a -> a -> a
>>
>>57434778
http://lmgtfy.com/?q=getline+after+cin

tl;dr: cin leaves a newline and getline doesn't give a shit if it captures only a newline.
>>
>>57434654
check out hashcat

I had a hashcat challenge in a CTF and the trick was that the pattern of the password was limited to a specific regex

I am thinking of writing an ansible module
>>
>>57434817
Look at getline capturing that newline like a boss. Getline doesn't give a shit.
>>
>>57434748
wait it can't be as bad what i have?

I'll show you some snippets kek

for i in range(len(l)):
dwin.append(l[i][i])

x = 2
n = 0
while x >= 0:
dwin2.append(l[x][n])
x -= 1
n += 1


literally it just builds lists of the game board and then compares them lists to p1 = [1, 1, 1] and if they're the same it's a winstate.
>>
>>57434842
Add lazy evaluation to that and you basically have a Haskell program.
>>
>>57434867
wait is that like this -

if p1 == dwin:
print('player 1 wins')
elif p2 == dwin:
print('player 2 wins')

if p1 == dwin2:
print('player 1 wins')
elif p2 == dwin2:
print('player 2 wins')
print(dwin2)


the gist of the file is literally just comparing lists to find a win state.

the last code snippet was just creating the diagnoal win states list.
>>
>>57434867
Don't forget the smug sense of superiority.
>>
>>57434898
that statement's a bit misleading seeing as the sense of superiority is justified
>>
PHP

I'm pretty shit with PHP and mysqli, so bear with me...

say I have sort of a gateway to a table in the database, and I'm writing a function that will insert a row into that table.

what is better - take an array parameter, or each field as a parameter?

and if I'm using an array like so

function insertRow(array $array) {
...
}


how do I ensure that the correct array is passed? (with the correct keys)?

also, sort of related, would I do validations here? or would I rely on the caller to do validations before passing the array to the gateway?

thanks.
>>
>>57434935
PHP is pretty shit.
>>
File: 1470348868789.jpg (322KB, 800x800px) Image search: [Google]
1470348868789.jpg
322KB, 800x800px
>>57434898
>>
>>57434935
use pdo for mysql interaction

validate here if you are exposing this function to any potential input, don't validate if this function is only used by things you know are valid
>>
>>57434895
>the gist of the file is literally just comparing lists to find a win state.
Sounds exactly like Haskell
>>
>>57434976
well, I'll be taking input, and then packing it all into an array, which I will send to my gateway (to the insertRow function), which then updates the database.

my confusing was if I should validate as soon as I read the input, or if I should validate within the function, the function assuming that anything passed to it is 100% clean
>>
>>57434939
eli says it's the best beginner language
https://www.youtube.com/watch?v=QaqBRX8aCQA
>>
>>57435062
Literally who
>>
>>57434824
>try it out
>crashes a display driver
this better be worth it anon
>>
https://en.wikipedia.org/wiki/Markov_decision_process#Category_theoretic_interpretation

Why do category theorists feel the need to throw their useless crap into otherwise decent mathematics?
>>
>>57435068
he has 600 million views on youtube
>>
>>57435090
>600 million youtube views
So he's a nobody
>>
>>57435086
at least it's not Marxist_theoretic_interpretation
>>
>>57435062
eli is like a tech / IT guy, he's not a software developer. of course he's going to say PHP.
>>
>>57435062
>PHP
What the fuck?
>>
>>57435062
please stop bullying eli
he likes php because he has aspergers
>>
File: yui.jpg (85KB, 650x780px) Image search: [Google]
yui.jpg
85KB, 650x780px
I'm looking for some foss projects, games specifically, to contribute to in order to get my feet wet working on bigger projects. I'd like to do it in languages I like though and most of the active and interesting projects I found were C++ which I don't like much. I want to work in Haskell or C or a language that a person who likes Haskell and C would also like. Could you recommend me something?
>>
>>57435424
why would you write a game in haskell
why would you write a game in C
please stop
be a normal human being
use OOP
listen to your government
>>
File: hereyougo.gif (88KB, 10000x10000px) Image search: [Google]
hereyougo.gif
88KB, 10000x10000px
I to work on a project that involves the internet or sockets in some way. Gimmie some ideas.
>>
>>57435441
Real talk, why do so many people think OOP is integral to game dev?
>>
>>57435441
>use OOP
This is the worst advice you could give anybody.
>>
>>57435499
Try developing non-trivial games. Eventually you'll understand.

Or rather, eventually you'll just get good enough at OOP that you won't need the "it's not me that sucks, it's OOP" defense mechanism.
>>
>>57435590
Not an argument mate.

If it's so great then you must be able to come up with some reasoning why.
>>
>>57435590
This is basically correct. As long as your conception of OOP does not require inheritance.
>>
>>57435499
Maybe if you're making tetris or tictactoe im may not be necessary
If you're doing an fps, you need to keep track each instance of the player. If they're using a weapon abstract class, only a gun subclass should have a reload function, not a grenade subclass.

Maybe you're thinking how it benefits he game, you should think that it benefits the devs to have the same idea in building something and not fucking it up
>>
>>57434644
Fuck off attention whoring nigger
>>
>>57435590
>>57435624
>>57435636
I bet you fags think that "aggregate types == OOP"
>>
>>57435636
>If you're doing an fps, you need to keep track each instance of the player.
>data is object-oriented

>If they're using a weapon abstract class, only a gun subclass should have a reload function, not a grenade subclass.
>object-oriented code is object-oriented

>you should think that it benefits the devs to have the same idea in building something and not fucking it up
>all abstraction and code reuse is object-oriented

Wow. Sure convinced me.
>>
>>57435636
>If they're using a weapon abstract class, only a gun subclass should have a reload function, not a grenade subclass.
Shittiest way to structure it.
>>
>>57435651
Are we going to go down the no true scotsman route? Again?
>>
>>57435650

I'm just shitposting, my guy.
>>
>>57435663
>>57435668
>ur dumb lol
Oh look its /g/ pretending to know shit for the sake of arguing again
>>
>>57435687
Are we going to go down the "everything good is OOP" route again?
>>
>>57435590
Listen to Carmack.
He thinks Haskell could be great for games.
Naturally you wouldn't understand why, because you are a low-info human beeing.
>>
>>57435687
I don't know why you think that is a "no true Scotsman" argument.
Aggregate types (i.e. structs, records, whatever) are not exclusive to OOP and existed long before it.

There are a lot of people, especially novices, who don't understand the actual core of OOP and confuse "structs and functions that work on those structs" (a very common way to do procedural programming) to be 'OOP'.
>>
>>57435730
I thought Carmack was into Racket.
>>
>>57435762
He is into many things.
Racket is this thing he is using for script-like things.
He is very fond of Haskell, although I don't think he is doing that as a job currently.
>>
>>57435730
But carmack doesn't give a shit about games.
>>
>>57435724
Not an argument.
>>
>>57435790
Why would you think so?
He is actually still programming game-related things in his free time.
>>
I moved to UK, and I know some PHP
Should I try reach something here with PHP or something other?
>>
File: 1472513030143.jpg (207KB, 717x540px) Image search: [Google]
1472513030143.jpg
207KB, 717x540px
>>57435441
Hey, I just like C, Haskell and games and I don't like C++, Java and other similar languages. And in my free time, I'll do things I like, thank you very much.

All I ever wanted was a link to some fun, open source game I could help out with and learn something in the process but I guess I just started an argument.
>>
>>57435835
Any Pajeet knows PHP. Probably better than you do.
>>
>>57435806
Argument to what, pajeet?
>>
>>57435850
Well then kys.
>>
>>57435499
Ok real talk. One of the hardest problems in programming is dealing with mutable state. Don't listen to anyone that tells you otherwise. There are two main approaches for dealing with it. One way is to minimize it -- that is functional programming. The other way is to encapsulate it so you can only interact with it in a certain way using the methods of an object. That is OOP.

Clearly defined input/output problems like compilers and web servers are where functional programming languages shine, because almost all of the mutable state can be eliminated. On the other hand video games are the antithesis of this: you have a great deal of objects on the screen that are 99% the same every frame, and you can't afford to recompute at every time step.

I'll admit the limits of my knowledge here and say I don't know how Haskellers deal with such performance sensitive problems (I would be surprised if they were completely at a loss). I am sure it involves monodic trapezoid endofunctor magmas. What I will say is that it's quite obvious how to deal with complex mutable state in OOP, you just encapsulate shit until it becomes manageable. Ugly? Yes. Good enough for the game industry? Certainly.

Probably.

I'm not a game programmer.
>>
>>57435872
OOP literally encourages shared mutable state.
>>
>>57435590
This.

Hell. Try developing non trivial code at all. OOP is king at abstractions, and abstractions are important for developing good code and not an unreadable mess.

C++ is literally God tier and you hipsters wouldn't understand why
>>
>>57435725
No. We are not.

>>57435734
>I don't know why you think that is a "no true Scotsman" argument.
I don't necessarily, but it does sound like potentially the beginning of a no true Scotsman argument.
No one seems to be able to agree on what oop is anyway. Novices and veterans alike. It all just distils to either
>my mental model of the program is in terms of objects, therefore what i do is object oriented
or
>nothing i like or makes sense can possibly be object orientation because everything oop is axiomatically bad
If you can avoid this, then i'd like to hear what oop means to you.
>>
>>57435856
Pajeets don't even know how to not shit in the street
They're lazy poos in the loos
So anyone is better at PHP than Pajeet
>>
>>57435872
FP isn't about minimizing mutable state per se, but more about minimizing how much code is able to mutate state. In contrast, OOP is more about restricting how state can be mutated.
>>
>>57435911
>lazy poos in the loos
You do not seem to use your brain at all. "Poo in the loo" is an injunction to what they are NOT doing right now. WE are the "poo in the loos" - WE use toilets.

And while we are at it, I was always under the impression that there are enough white Pajeets as well - a.k.a. people who have little idea what they are doing on the computer and just copy+paste code from SO.
>>
>>57435904
OOP is about the segregation of state into small modules of single responsibility.
An object oriented program can be viewed as a network of objects passing messages to each other, indirectly modifying each other's state.

Notes:
Extremely large modularisation of a program (e.g. "Entire graphics subsystem") isn't OOP.
ADTs are not OOP.
The syntactic "subject.verb(noun)" is not OOP.
Inheritance is not core to OOP.
>>
>>57435872
>you have a great deal of objects on the screen that are 99% the same every frame, and you can't afford to recompute at every time step.
That's why you can't afford to use OOP because it leads to terrible performance.
The big killer for performance is how OOP really fights you when it comes to batch processing entities - you do not ever want to write code like:
foreach e in entities:
e.move(); // which does say e.position += e.velocity
e.draw(); // check by itself if it needs to redraw, be sorted, or w/e

i.e let entities 'update themselves' through some abstract method.
What you want to do is structure things more like this:
entities_to_draw = move_entities(entities.positions, entities.velocities); // where positions and velocities are arrays
draw_entities(entities_to_draw);


>What I will say is that it's quite obvious how to deal with complex mutable state in OOP, you just encapsulate shit until it becomes manageable.
The OOP way of dealing with state is really bad because of how inflexible and bad for performance it is, you get these loads of tiny state changes from method to method (x.do_foo(), x.do_bar(), etc) which just destroys easy composability and easy batching.
>>
I have lately been thinking about engine development. The thing is: an engine has to do graphics stuff as well. Doing the graphics stuff during the game logic stuff is ... wrong? I don't know, that's where I was kinda stuck.

But naively I'd say that the program logic should first update all the different elements that need to be updated for the proper game state, before control is giving to the renderer to actually draw things on the screen.

Can anyone confirm or deny this? I have never taken any classes or anything in game development, I am just having thoughts on my own that I'd have liked confirmed and denied.
>>
>>57436011
>is giving
I meant "given". Sorry, I am dead tired right now, and English is also not my native language.
>>
>>57436011
Not a game dev, but I assume those work on different threads. One thread computes all graphics related stuff and another does control stuff. Of course they are asynchronous of each other. Anyone free to correct me if Im wrong
>>
>>57435961
They do, visit any street where pajeets live
>>
>>57435969
>state
>responsibility

Also
>Here is a definition of X. Note: these things that can neatly be thought of as fulfilling the definition of X are not X, because fuck you.

Nope, can't take you seriously either.
>>
>>57435424
Make a chess engine in C. Its fun/hard intro to AI .
>>
>>57436062
The thing is I was thinking that as well. But the problem here would be locking - thread 1 updates the scene right now, while thread 2 computes other stuff. The game state might become inconsistent very quickly, depending on how many object states are calculated in the moment.
>>
>>57435982
I'm not sure I follow. Why would the second block code be any faster than the first?
>>
>>57436011
Sounds about right. I don't really see how else you would do it.
>>
>>57436085
>>state
>>responsibility
I don't get what you mean by these meme arrows.
>>Here is a definition of X. Note: these things that can neatly be thought of as fulfilling the definition of X are not X, because fuck you.
You clearly know nothing, you fucking idiot. Actually learn some theory before you say stupid things.
You OOPfags really try to claim absolutely everything.
>>
>>57436011
Yes, that's right. Otherwise you often get artifacts where objects behave or appear differently depending on how early or late they are processed, not to mention that it's going to be really inefficient because you'll be jumping around and thrashing the cache so much.

>>57436062
Not necessarily, no. And if that does happen, it should be part of a work queue system and not a specific "logic thread" and "render thread" that communicate using message passing or whatever.

>>57436085
Not necessarily OOP, then.
>>
File: haskell.png (37KB, 531x296px) Image search: [Google]
haskell.png
37KB, 531x296px
who thought this was a good idea?
>>
>>57436112
Cache.
>>
>>57436062
You're wrong, you can't do those things asynchronously.
The renderer depends on the logic update.
>>
>>57436109
You've just described lag right there
>>
>>57436118
Hm. Should one implement mechanisms for lower FPS? Imagine I am assuming the game is always running at 60 FPS, but in some places the calculations take so long that I need 32 ms instead of 16 ms to calculate one frame. Should a game engine detect such things and adapt to it (faster bullet speeds/animations, for example), or should the programmer just say "Fuck it!" and live with the slowdowns?
>>
>>57436167
Standard practice is to use delta time. A less common but generally better practice is to have a so-called fixed update and variable render.

http://gafferongames.com/game-physics/fix-your-timestep/
This is the definitive guide.
>>
File: 1470092393470-3.png (11KB, 307x373px) Image search: [Google]
1470092393470-3.png
11KB, 307x373px
>>57435867
y-you too! idiot!
>>
>>57436167
>Imagine I am assuming the game is always running at 60 FPS
It's extremely poor practice to write games that depend on certain frame rates.
Everything should depend on the time between the frame and the one before it, or 'delta time'.
>>
>>57436194
>Everything should depend on the time between the frame and the one before it, or 'delta time'.
Welcome to non deterministic code.
>>
>>57436194
As I said, I am completely new to this and just have started thinking about some of the basic stuff. If it's poor practice, then it's because I don't know any better.

But that actually means that I have to query the kernel for the current real time each frame I am given control back from the renderer, just to determine how long drawing took. Not only is that ... I don't want to say "ugly" because it's probably necessary, but I hoped there was a way to shave off some kernel calls, even if they are probably minor in any way.
>>
>>57436112
Cache friendly and can be vectorized (i.e do more position changes per instruction) and/or multi-cored more easily.
>>
>>57435424
Rust looks like a language you might like to work with. It has low level performance and idioms from functional programming.
>>
>>57434492
Trying to figure out C# and Unity Syntax/Semantics/Libraries.
>>
>>57436241
Any actual logic or rendering you do will completely negate the cost of one measly query of the high performance counter per tick.
>>
>>57436261
While I know that, it doesn't mean that I like it.
>>
>>57436277
In that case, I hope you're ready to use Vulkan because OpenGL will make you want to slit your wrists.
>>
>>57436282
I am not even sure what I want to use right now. I have poked a bit into OpenGL, but the entire interface with its global states was suspect to me.

I also wouldn't know if I could get Vulkan to run on my hardware. That does not mean that I have tried it and failed, I just mean that if anything I'd like to support Linux as well as Windows.

(Again, nothing professional, just trying to learn something I am interested in. Poking around. There's nothing definite yet).
>>
>>57436130
Oh yes I see what you're saying. Though that's kind of naive code example so I'm not sure if it's a useful comparison. Almost always there's a need to mix and match components into entities, so you can have physics apply to a certain subset of objects, rendering apply to another subset, so on. OOP has the ECS approach, I would be interested in an example of a comparable system using FP
>>
>>57436316
>Almost always there's a need to mix and match components into entities, so you can have physics apply to a certain subset of objects, rendering apply to another subset, so on.
There's a really simple solution to that without going full ECS duck typed retardo mode and it's to not shoehorn every single entity into the same collection for no reason.
>>
>>57436241
EA tried constant framerate dependency in a couple of their Need for Speed games, i think. People hated it. I think mostly because it just didn't fit with peoples idea of how a game should behave, an not necessarily because it's terrible idea. Overclockers and fidelity fags just couldn't deal. But the next game had "variable framerate" as a marketing bullet point.

I think fixed physics time step and a variable render update is the usual way to do it.
>>
>>57436316
A component system is much better modeled after a data oriented design rather than OOP.
>>
https://sf.isusec.com/challenge/rocky-pixels/
What think you lads?
That line in the top left corner of the photo definitely looks like something, but I don't know what else to try.
>>
>>57436316
>>57436320
Which is to say that you shouldn't try to find a common supertype or whatever for every entity because it doesn't accomplish anything and just makes the code and/or runtime worse.
>>
>>57436167
> Should one implement mechanisms for lower FPS?
Frame rate isn't the same thing as update rate.

You should update the game state at a fixed rate regardless of frame rate. So if you update at 60 fps but the frame rate is 30 fps, you should be updating twice for each frame rendered. If you want to support frame rates which aren't an integer fraction of the update rate, you need to be able to interpolate between frames (which means you need up to a frame of extra latency, because you need the next state after the point in time for which you're rendering).

Anything beyond that is hard. Ideally, the rendered frame should be based upon the game state *at the time the next frame will be displayed*, not the time "right now". But that requires being able to accurately predict how long it will take to render the frame (i.e. whether you'll miss the next vsync), which is easier said than done.
>>
>>57436334
True... true

>>57436320
>>57436360
I understand basically nothing that you're saying. What you think ECS is and what I think ECS is seems to be entirely different.
>>
>>57436379
>So if you update at 60 fps but the frame rate is 30 fps
But why would anyone do that? The player is not going to see the updated game state until the scene is actually rendered. I'd be updating the game state once without effect each state - at this point it would be better to either use variable frame rates or just lower the frame rate altogether. At least for scenes that I know which take up a lot of time.
>>
>>57436398
ECS tries to make it so that any entity could have any combination of components, and that this combination could change on the fly.
>>
>>57436408
PS: Immediately after I wrote this I realized that updating the game at a higher rate than the renderer might reduce the input lag. So I take the question back - there is actual purpose in this logic. The game logic might be fast to update and should not suffer from input lag, but the renderer might take more time and thus needs to update at a lower rate.
>>
>>57436408
> But why would anyone do that?
Because frame rate can vary. So sometimes you'll need to advance 1/60th of a second and sometimes you'll need to advance 2/60ths.

If you clamp to 30 fps, then you can just update at 30 fps (but you may still need more than one update if the frame rate drops even lower).

What you shouldn't try to do is update the game state by a variable amount in one go, because that produces inconsistent results. The cumulative effect of two 1/60th second updates won't be the same as the effect of a single 1/30th second update, and even getting them "close" enough is harder than simply calling the update routine twice.
>>
>>57436425
It's not just input lag, the big win from a fixed update rate is determinism - as we all know floating point ops do not necessarily obey things like the distributive or associative laws, so 0.1 * 10 vs 0.1 + 0.1 ... 10 times may not give the same result.
And when you do physics integration you tend to do the latter rather than the former (i.e numerically approach an answer in N steps rather than calculate it directly) so having a fixed amount of steps each time will help keep those calculations stable.
>>
>>57436425
That's a factor: tapping a button for 3/60ths of a second shouldn't have different results (2/, 3/, or 4/60ths) depending upon frame rate and synchronisation.

But that's a matter of input sampling rate rather than latency per se. The system is a closed feedback loop: input->update->output, with the player's eye->hand coordination closing the loop. It's rarely meaningful to separate the overall latency into different sources.
>>
>>57436513
A far bigger issue than floating-point errors is integration resolution.

Move forward one metre, turn ten degrees, move forward one metre, turn ten degrees. That has a different result to moving forward two metres and turning twenty degrees.

Floating-point determinism can still be important for networking. For objects controlled by a physics simulation, you can either continually send object positions over the network, or you can just send "external" events and rely upon all systems performing the same calculations on the same inputs and getting the same results.

But the latter only works if the calculations yield identical results (right down to the least-significant bit). Even the smallest deviation can result in fairly rapid divergence (chaos theory).
>>
What should one do after learning the syntax of an oop language? Im at a loss. Idk what i want to do either
>>
>>57436588
>For objects controlled by a physics simulation, you can either continually send object positions over the network, or you can just send "external" events and rely upon all systems performing the same calculations on the same inputs and getting the same results.
>But the latter only works if the calculations yield identical results (right down to the least-significant bit). Even the smallest deviation can result in fairly rapid divergence (chaos theory).
It's impossible to get determinism in general because games use transcendentals so much. So in networking, you occasionally have to send snapshots to keep everything mostly synchronized.
>>
>>57436622
Find cool things where you might want to try out what you learned, and become better at using that.
>>
File: FB_IMG_1478022939400.jpg (28KB, 480x381px) Image search: [Google]
FB_IMG_1478022939400.jpg
28KB, 480x381px
Who watches here Halt and Catch Fire? Is this the best tech based series to this day?
>>
>>57436636
Can you give me some direction? The only paths i can see are app or game development.
>>
>>57436622
Revisit old projects with newfound knowledge.
>>
>>57436662
Implement a program that uses the 4chan JSON API to download threads and images.
>>
I need help with motivation.

learning is no issue, understanding is manageable, but motivation? yeah i feel like I'm fucked if i can't get motivated to learn more.
>>
>>57434492
What have I done wrong?
PYTHON HELP
https://ghostbin.com/paste/gcvt8

just trying to make a script that decodes binary and hex etc.
>>
>>57436711
if you want to be good at programming but you don't want to put in the time in, then you don't really want to be good at programming
>>
>>57436719
nevermind I fixed it
>>
>>57436702
Ok now thats the biggest joke of the year
>>
Wanting to learn c, what's the best way to learn it? I do have experience in PHP so I am not a complete programming nooblit.
( What are some good books, sites,PDFs, videos and etc...)
>>
>>57435471
build a fault tolerant messaging library.
>>
>>57436782
What is a messaging library?
>>
>professor has answer key in their file directory with the rest of the "fill in this snippet" files
what do
>>
>>57436757
OK, then don't do it, and stay dumb.
>>
>>57436757
I mean it's pretty easy and has been done a bunch of times.
>>
>>57436625
> because games use transcendentals so much
Even that doesn't matter so long as the results are consistent. That's much easier to achieve on a specific console than cross-platform or even just on PCs.

It's not uncommon for networking to use unit vectors (i.e. [cos(a),sin(a)]) rather than angles to avoid dependence upon trig functions.

Primitive arithmetic operations (+,-,*,/,sqrt) can usually be made consistent (i.e. following IEEE-754 to the letter) with careful attention to compilation switches.

You don't normally need much else. If you do, transcendental functions need to be provided by the application rather than relying upon CPU instructions or system libraries. Given that you're writing a game (rather than e.g. trying to land a billion-dollar space probe on Pluto), you don't need perfect accuracy, just consistency.

tl;dr: deterministic arithmetic requires care, but is possible.
>>
>>57436820
>>57436832
No i mean isnt that just the if op = anime joke, not that i couldnt do it.
>>
>>57436840
>isnt that just the if op = anime joke

I never said that you should determine what the images are about. Just download them.

- bonus points if done in C.
- proud mode if you implement your own memory management along the way.
- critical mode if you also implement your own HTTP parser
- nightmare mode if you also implement your own DNS query module
- nightmare mode+ for making it run on Windows and Linux
>>
Is churning through books useful for learning at all?
>>
>>57436992
Churning through man pages is more useful desu.
>>
>>57436256
example?
>>
>>57434492
dpt I just figured out my first issue writing code so there was this thing stopping my script from doing what it was meant to and I fixed it by just thinking of alternative ways to do what I was trying to do, it's hard to explain - but I just solved my first code problem without google or anything just used trial and error feels fucking great
/blog
>>
>his language can't do this
foo a b | a < b   = a^b
| a == b = exp a
| a > b = b^a


funcking plebs doing switch statements
real programmers use guards
>>
>>57436769
It may sound strange , but read K&R and Practical C Programming at the same time, since you are not new in programming logic.

I did that , and when Practical C Prog. went boring with its details( there is a lot of low-end ) i switch to K&R for fun(tm) (well its fun for me).


When you read half of Practical C and at least done Tutorial chapter in K&R you can start doing some shit. (I highly recommend making some chess engine or build 3d engine, it will make C really, really fun and it isn't to much game programming, its still good general use practice).
>>
>>57437114
What's the difference?
>>
do you use bind in non-IO contexts?
also, is it necessary to learn to learn the ins and outs of every standard transformer?
>>
>>57437123
Also go slow , going low-end can be a pain in the ass.
>>
>>57437133
guards are prettier and more readable
>>
>>57437114
I think all languages can do that
>>
>>57437146
certainly not
>>
File: 1_AM83LP9sGGjIul3c5hIsWg.png (121KB, 800x355px) Image search: [Google]
1_AM83LP9sGGjIul3c5hIsWg.png
121KB, 800x355px
Who else is triggered by this picture?
>>
>>57437183
What is it doing?
>>
>>57437212
checking for conditions in a pretty way
>>
>>57437188
If functional is so evolved then why is it useless /dpt/?
>>
>>57437217
So a different syntax. Color me amazed my dude.
>>
>>57437227
but it looks prettier
>>
>>57437188
popularity != usefulness
>>
File: dgymwe.png (75KB, 630x160px) Image search: [Google]
dgymwe.png
75KB, 630x160px
NU
U
>>
>>57437249
nu.js
>>
>>57437248
meant for>>57437218
>>
>his language can't prove that the identity function is the only inhabitant of its type
f : (X : Type) => X => X
A : Type
a : A
P : A => Type
p : P a

f ((x : A) *i (P x)) (a,i p) :i P (f A a)
>>
>>57437461
And by the definition of Leibniz equality, you have
id A a = f A a
which by function extensionality is id = f.
>>
I'm about to embark upon a journey of SICP and calculus, both of which I'm largely unfamiliar with. What scheme interpreter for Linux should I get?
>>
>>57437518
g++
aka learn a real language shithead
>>
>>57435424
>>57436256
>>57437098

Not that guy but here is for example a roguelike written in rust looking for contributers: https://github.com/dpc/rhex
>>
>>57437525
I already know C++, dude. It's my main language. I'm just studying algorithms and mathematics and Scheme/CL happens to generally be the language of choice there.
>>
I'm not sure how much this is discussed or if it belongs here, but here we go. I'm in college right now and it's just not for me, school shackles me to a place i don't want to be at, puts me in some debt, etc. I'm in for CS right now but if I can get a decent job in the industry and just leave that shit in the dust, I will. How do I make this happen? I know I need to start putting projects on github and whatnot, but what's good enough? How do I even get an idea for something to make that isn't too overreaching/complex or essentially useless? This is the only thing school really solves for me. When I have a specific goal or problem to solve I can knock it out, not problem, but without direction I just stagnate (which i realize is probably not the best quality to have for this). Also, where do I find projects to contribute to that aren't a huge undertaking? What jobs should I be looking out for as far as getting away with being entry-level?

Most things I find when I search shit like this is either web-dev trash, or just vague and basically saying the things I just said, except telling you to make those things happen rather than asking them like I was.
>>
Can someone make a script to decode base64 in python 3 google hasn't helped at all
>>
>>57437765
base64 -d
>>
>>57437741
IT is more than just programming, what specifically do you want?
>>
Not sure if this is better for /sqt/, but was looking for some quick direction.

tl;dr:
Want to store some data, know how to in memory, not sure about disk. How do I into databases? Do I into databases?

Been tracking tournament bracket results for school club, wanted to do a program to help automate this, compute elo/glicko, look up match-ups, record results, etc. I've done a good bit of programming and I understand completely how I'd do this in code.
In memory, that is. Presumably I'd want to save this information on disk. I guess the stupid idea is serialize all the objects and store/load them from files.
I assume that this is actually a problem solved by a database, but my knowledge of databases/SQL/etc is pretty much non-existent. Is that what I'd want to use?
Say I store each person, some other minor related data that'd fit easily in an object, and then associate people with tournaments, placings, sets, etc. Is this as simple as "google databases and you'll see how you'd store all this effectively"? Would I store all these values/relations separately in a database and then appropriately load them into objects? Can I just store the whole object?

Pretty much I know nothing about databases so I don't know if I'm asking the right question or thinking about it correctly. Was going to look into it soon, but figured I'd see if anyone cared to offer direction first.
>>
>>57437782

I'm not sure if this will address your question entirely. I'm almost entirely interested in programming and have little interest in anything else, honestly. I don't care about the internet or anything web-related, I don't (for the most part) care about networking/sysadmin things. My dick does get hard for the idea of embedded systems however, but I don't have an EE background at all.
>>
>>57437816
>I guess the stupid idea is serialize all the objects and store/load them from files
That's completely valid for a lot of data sets. If your dataset isn't massive and your performance needs aren't particularly demanding, you could get away with this.
If you wanted to use a "proper" relational database, just use SQLite (it has bindings for practically every language).
>>
>>57437846
There are a number of just back end jobs, mostly from already established companies, related to banks, supply chain, oil and gas, etc. Pretty boring but stable pay, just updating their architecture to meet some ISO standard or something.
Embedded has far fewer opportunities, but you can toy around and buy a microcontroller if that's really for you
>>
>>57437248
Assembly programmers are useless though, 0 jobs or use
>>
>>57437695
You dont know c++ if you dont know calculus. Sicp wont help you
>>
>>57437741
Not that i really read your post but bluej? That makes everyone hate programming
>>
>>57437861
Not massive at all. 50+ people, a dozen tournaments or so, 20 people per bracket usually. I guess that actually fits pretty compactly, so maybe just serializing everything should work out. Just seemed a bit messy/improper.

Reading up on SQLite, sounds like what I'd want if I used one, was actually just wondering about databases that don't require their own process.

I'll likely do this in Python, is pickle the right answer for serialization?
>>
>>57437973
SQLite is great, the primary motivation was to evolve past ad hoc disk storage to a nice alternative without needing another process. The quote is something like
>SQLite isn't a replacement for MySQL/PostgreSQL, SQLite is a replacement for fopen()
I'll always go SQLite first
>>
int[] sizes = {5,8,2,9}
for (int i:sizes)
do something

What is it called when you do
'for(int i:sizes)' ?

This looks for every element inside of a array right? To go through an entire array I use to do a
for(i=0, i<sizes.length, i++)
>>
>>57438151
range based for loops

http://en.cppreference.com/w/cpp/language/range-for
>>
>>57437741
You want to be a code monkey rather than a computer scientist and that's completely fine. Just make a Github and program a calculator or the game of life or something. Show that you can program. Show that you know many different languages. Show that you are versed with version control. That will get you a code monkey job. It's not necessary to contribute to other projects at this level.
>>
>>57438151
For each loop
>>
Finished my first baby code program that wasn't a calculator.

The world is still magical.

Does it get better than this?
>>
>>57438403
Congrats!

Some people say it gets less magical, those people are blasé old bitter faggots.

There's two paths.
You can go up and make more and more powerful abstractions, making the awesome and the incredible look normal.
And you can go down, looking to understand the fundamentals of how everything works, knowing exactly what happens every nanosecond in every part of your system and pushing things to their limit.

Either way, the important part is to keep having FUN.
>>
I want to create a simple utility which will extract bookmarks from Firefox in exactly the same JSON format that you get when using the GUI. I can't believe that Firefox has no such option.

All the data is in an sqlite database ((located in .mozilla/firefox/awdad.default/places.sqlite). I need data from moz_places and moz_bookmarks, I think. However, I can't seem to find a common ID or similar to join them together. My SQL skills are very, very, very limited.
There are "id" and "guid" columns, but they vary across the tables.

tl;dr: can someone figure out which column to use for a join to get all the data from the two tables?
>>
>>57438452
That's a pretty specific question, you might want to ask in a firefox developper IRC?
>>
>>57438458

That might be the only option, but I'm not that desperate yet and probably just lazy.
I was hoping that there would be an SQL wizard here who can figure it out based on just a quick look at the table column titles.
>>
>>57438403
>The world is still magical. Does it get better than this?
If you're looking for a job as a programmer then no.
>>
>>57438510
Still beats being a cashier or a starving artist
>>
File: classes.png (189KB, 2703x783px) Image search: [Google]
classes.png
189KB, 2703x783px
Hey guys.

I'm getting DESPERATE here with trying to slap Spring Boot on my application.

When I try to @Autowire the ChromeHome class, it's always null, although its constructor does work and the fields are correctly set.

Can someone please help?
>>
neither my internship nor my class is teaching me how to write quality code when it comes to proper class structure, formatting, breaking things into more functions, using test cases and similar. Where can I read up on that? I just want to write some decent code for once in my life, both functional and easy to understand while following at least some norms.
It's one of the reasons I get discouraged from starting larger projects and why I haven't bothered to try and contribute to other opensource projects
>>
>>57438596
It's not something you can teach, you learn after being involved in larger projects.
>>
>>57436282
If OpenGL makes you want to slit your wrists, then Vulkan will make you want to blow up yourself with a nuclear bomb.
>>
Anyone know MIPS??

Can I return to $ra with beq?

Usually you do:

jr $ra

So will,

beq $t0, $s0, $ra

return me to return address assuming $t0 == $s0?
>>
>>57438883
Do you have an instruction reference handy? No, you cannot. beq takes two registers to compare and branches to a label that is encoded as a signed offset.
    bne $t0, $s0, _not_equal
jr $ra
_not_equal:
>>
File: 1451338360314.png (790KB, 792x792px) Image search: [Google]
1451338360314.png
790KB, 792x792px
>tfw can't code in vulkan because my gpu is not supported
Literally one series away from support. I thought I could go on forever with this olde laptop of mine. Vulkan can suck a dick though, I'm not abandoning my buddy just yet (and i don't have money for a new one).
>>
>>57437461
what is that
>>
I have this function:
String IntToString(int number)
{
String result;

/*
MAGIC FOR CONVERTING
INT TO STRING GOES HERE
*/

return result.GetCString();
}

And I use it like this:
Write(IntToString(GetRandomInt()));

As in, I don't store the String returned by IntToString() in a variable, but rather use it as-is.
The problem is, the String class destructor is called at the end of the function, so that what is passed into Write() is garbled data (UB). How do I fix this?
>>
>>57439248
Post your entire code.

Also, what is
GetCString doing?


Also, why are you capitalizing string?
>>
are there any lightweight java frameworks that will help prevent SQL injection?
i'm not a fan of hibernate and mybatis is too heavy for my usage.
im using SQLite by the way, just to show that this is just a small personal project.
>>
>>57439275
literally LITERALLY just use parameterized queries
>>
>>57439281
so i have to write everything by hand then, right? holy shit that's unmaintainable even for a small project like this.
>>
>>57439271
Ah, oops, you can pretend there's no .GetCString() there. That was me testing the function with a char* return type.

String IntToString(int number)
{
String result;
bool neg = 0;

if(number == 0)
{
result += '0';
return result.GetCString();
}

while(1)
{
if(number < 0)
{
neg = 1;
result += '0';
number *= -1;
continue;
}
if(number == 0)
break;

result += (char)('0' + number % 10); // '0' + digit = digit as a char

number /= 10;
}

// TODO - Handle the '-' for negative ints
// result.Reverse(); // Not yet implemented, currently the string is backwards.

return result;
}


"String" is capitalized, because it's my custom string class. I'm trying to create a small tiny basic String class, just to learn stuff.
>>
>>57439271
>>57439307
Now that I removed the .GetCString(), it crashes immediately after returning from IntToString(), doesn't even write anything.

"Debug Assertion Failed!
Expression: _CrtIsValidHeapPointer(block)"
>>
>>57439307
Set a breakpoint on your
return result;
line and verify the value of result before you exit the function.

Better yet, set a breakpoint on your while loop and inspect result after each iteration.
>>
>>57439320
The int I'm testing with is 2, so there's only one iteration.
I set a breakpoint at the return, and result seems to be correct.
String object, that has a char array with the first and only char set to '2'.
>>
>>57439294
Google Java ORM and use the most common one.
>>
>>57439294

If you have to ask that, then I shudder to think what an unsecure shitheap your database is.

Unless you get your data from views, insert data using functions and check database input with a gorillion triggers, your database is shit.

ORM is a meme because it offers literally no database protection. Learn SQL and stop being a bitch.
>>
When will people realize SQL is a shit-tier meme that need to die?
>>
>>57439437
when you will provide arguments.
>>
>>57439398
>check database input with a gorillion triggers

>using triggers
>EVER FOR ANY FUCKING REASON

No, your database is shit.

t. An actual database administrator.

>>57439437
Much like anything else, it'll happen when you provide a compelling reason to use something else, and somehow successfully make this argument to...the entire world.
>>
>>57439467

>no input validation on DB level

Am I being memed?
>>
>>57439488
No one said that.

Triggers are NOT the way to do input validation on the database level.
>>
>>57439398
>>57439488
enjoy your deadlocks ;-)
>>
I'm getting this exception when trying to run Cucumber tests from a jar.

cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.

I have cucumber-java, cucumber-spring and cucumber-junit in my dependencies. All the solutions I found online state that I just need those dependencies.

Everything works fine if I launch it from the IDE.
>>
I'm new to programming in C++, is this correct?
class A{
vector<int> avector;
public:
A();
A(const vector<int> &v): avector(v){}
};

int main(){
A a({1, 2, 3, 4, 5});
return 0;
}
>>
>>57439557
yes
>>
>>57439537
how did you build your jar?
are you sure all cucumber libraries needed are in the same location?
>>
>>57439623

I built the jar with maven package.

This is what I have in pom.xml for building the jar:

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


I don't know where else the dependencies can be. I can see them in the library list.
>>
>>57439651
at what folder are you running your jar file? I'm guessing you have a cucumber dependency somewhere that you don't have beside your jar file

try looking up jar-with-dependencies to add every bit of library required for your jar
>>
>>57439725

I'm running the jar from the project root. Every file I refer to is accessible.

I've tried different ways of making fat jars, none of them worked.
>>
>>57439524
what's the right way to do input validation on the database level?
>>
>>57439798
post dependencies senpai
>>
File: 1462633522963.gif (2MB, 500x374px) Image search: [Google]
1462633522963.gif
2MB, 500x374px
>>57439248
>>57439307
Anyone?
>>
>>57439856
Constraints.
>>
File: dependencies.png (65KB, 528x1772px) Image search: [Google]
dependencies.png
65KB, 528x1772px
>>57439861

Can't copy and paste them here, too much text.
>>
how do you get into reverse engineering?
i've programmed for years, know some assembly and most of the 32/64 bit calling conventions
but whenever i open IDA i just end up staring at the screen for an hour before realising i have ansolutely no idea of what im doing
>>
>>57439248
>the String class destructor is called at the end of the function
This is really weird and shouldn't happen

Post your String implementation?
>>
>>57439901
pastebin or gist you giant fucking ignorant faggot
>>
>>57439936

http://pastebin.com/VV9SV350

STOP THE BULLYING
>>
C++:
Hey guys I am new to C++ so I might ask stupid question. anyway
I try to write something like that

if(v.at(i) == empty){
cout<<"This shit is empty"<<endl;
i++
}

I just want to know if a certain element in my vector is empty or not.
>>
>>57439998
Define empty
>>
>>57439798
>>57439901
only thing left that I can think of is maybe you missed a step:
>build your jar by mvn package
>if you didn't build with jar-with-dependencies, cucumber-java.jar, etc are in the same directory as where you are running your jar

are you calling your jar with the command line? you are calling other jars alongside your own jar right (again, if you didn't build with the dependencies inside your jar)? It's because cucumber-java.jar should be that "back end" it is talking about and it seems like it can't see it

other than that, can't think of anything else senpai
>>
>>57439924
Aight, gimme a sec, getting a pizza.
>>
>>57439998
test whatever the condition for it being empty is. if it's 0 test if it's equal to 0, if it's null then test if it's equal to null
>>
File: 9da.jpg (782KB, 1122x1600px) Image search: [Google]
9da.jpg
782KB, 1122x1600px
Would it be possible to make a program that recognices test from images? I have several books scanned as images and it would be great, but I know so little about programming I don't even know if something like this would be possible.
>>
>>57440070
*text
recognices text
>>
>>57440070
https://en.wikipedia.org/wiki/Optical_character_recognition
>>
>>57440070
Yes, it is.
https://en.wikipedia.org/wiki/Optical_character_recognition
>>
>>57440086
>https://en.wikipedia.org/wiki/Optical_character_recognition

thanks for information. it could be a good project and a good reason to get into writting code.
someday.
>>
File: text.png (811KB, 1187x893px) Image search: [Google]
text.png
811KB, 1187x893px
>>57440070
>reinventing the wheel
>>
>>57439924
String.h

typedef class _String
{
private:
char* string;

public:
_String();
_String(char* str);
~_String();
char* GetCString();
void operator+=(char ch);

} String;

String.cpp

_String::_String()
{
this->string = new char[1]();
}
_String::_String(char* str)
{
int newLength = strlen(str) + 1;

this->string = new char[newLength]();
strcpy_s(this->string, newLength, str);
}
_String::~_String()
{
delete[] this->string;
}
char* _String::GetCString()
{
return this->string;
}
void _String::operator+=(char ch)
{
char* CStrCh = new char[2]();
CStrCh[0] = ch;
CStrCh[1] = 0;

int newLength = strlen(this->string) + strlen(CStrCh) + 1;
char* concatenatedStr = new char[newLength]();

strcpy_s(concatenatedStr, newLength, this->string);
strcat_s(concatenatedStr, newLength, CStrCh);

delete[] CStrCh;

delete[] this->string;

this->string = new char[newLength]();
strcpy_s(this->string, newLength, concatenatedStr);
delete[] concatenatedStr;
}
>>
>>57440006
example:
my vector only has 3 elements. at(0) at(1) at(2)
every element in my vector is an other class called Ingredients with only public: string

now I did a while(i<7, i++) and I want to cout
everytime there is a ingredient in my vector :
1. sugar
2.milk
3.empty //in case there is no element
4.water
5.empty
6.empty
>>
>>57440028
>>57439998
Tbh I dont know how to ask if a string is empty or not
>>
>>57440119
I fucked it up a little bit.
in this example my vector has 4 elements but the third one is empty
>>
>>57440134
if(string == "")?
>>
File: 1448416516091.gif (1MB, 480x270px) Image search: [Google]
1448416516091.gif
1MB, 480x270px
I asked on /fglt/ but got very conflicted answers.
What is best way to install pip for python?
To my understanding pip is like a repo for python modules.
So will it be better to install it from the package manger? or use the install script?
Also does setuptools must be installed as well?
>>
>>57440119
So it literally contains the string "empty" or you have assigned nothing to it?

If the language doesn't initialise the elements of the vector automatically, you can't reliably determine if they are empty without filling the vector with empty strings yourself before assigning the non-empty elements, because uninitialised data could hold anything.

Otherwise I would expect the default initialised value of a string to be "" (empty string), so if (v.at(i) == "").
>>
Thoughts on my simple game?

import random

class Player(object):

def __init__(self, name):
self.name = name


a = Player(name="pomel")
b = Player(name="lyn")
print("Hello", a.name)
print("Hello", b.name)


class HQ(object):

hitpoints = 100
_crit_chance = 80
_crit_multi = 1.5

def __init__(self, player):
self.player = player.name
self.shield = 3
self.alive = True

@classmethod
def crit_check(self):
crit = random.randrange(1, 100)
if crit >= self._crit_chance:
return True
else:
return False


def attack(self, target_hq, damage=100):
if self.alive:
print(self.player, "attacks", target_hq.player)
if self.crit_check():
target_hq.hitpoints -= 10 * self._crit_multi if target_hq.hitpoints > 0 else 0
else:
target_hq.hitpoints -= 10 if target_hq.hitpoints > 0 else 0
if target_hq.hitpoints == 0:
target_hq.alive = False
else:
print(self.player, "you are dead, you can't attack")


a_hq = HQ(a)
b_hq = HQ(b)
print(a_hq.player, "HP:", a_hq.hitpoints, "SHIELD:", a_hq.shield)
print(b_hq.player, "HP:", b_hq.hitpoints, "SHIELD:", b_hq.shield)


a_hq.attack(b_hq)
print(b_hq.hitpoints)
a_hq.attack(b_hq)
a_hq.attack(b_hq)
print(b_hq.hitpoints)

b_hq.attack(a_hq)
print(a_hq.hitpoints)


>>
>>57440155
if you installed Python from the package manager (or it was preinstalled on the system) I would just use the package manager to install pip too.
>>
>>57440167
I think my attack() method looks nasty

and not sure of an elegant way to do "critical chance damage"

Any tips from the pythonista or game logic designers ?
>>
>>57440155
pip is basically an alternative to setuptools, and is shipped with python nowadays.
>>
>>57440115
Have you tried using a search engine?
http://stackoverflow.com/questions/29045116/jni-libraries-deallocate-memory-upon-garbage-collection
>>
>>57440190
I have. That question/answer is about Java.
>>
>>57440172
I see.
>>57440185
Not in my case.
>Setuptools
Does you mean I need to have setuptools as well?
Because according to this
https://packaging.python.org/install_requirements_linux/#installing-pip-setuptools-wheel-with-linux-package-managers
setuptools and wheels need to be installed with pip with the exception in Arch linux.
>>
>>57440156
I did't assigned anything to it.
I wanted to import a list with ingredients in the beginning of the programm

Here you see my issue:

http://pastebin.com/vMVinYgX
>>
>>57440199
Wait sorry, I thought your first code was in Java since you mentioned the garbage collector. (So I assumed you were using JNI)

C++ doesn't have one but you should try using shared pointers.
>>
>>57440256
>>57440199
nvm I mixed multiple answers whilst reading too fast.
>>
What's the state of ocaml's parallelism?
Is ocaml good for gaymes?
>>
>>57440155
>>57440209
It doesn't matter. You're overthinking it. If you trust the package manager well enough to install python from it, why not use it to install pip?

The installer script works fine too, but there's no advantage to it unless you need a version newer than your distro's repos provide for some reason (hint, you don't).
>>
>>57435499
>>57435590
These posts are baits, I have seen them before.
>>
>>57440347
OK.
Do I need to install setuptools/Wheels as well?
>>
>>57435887
>>57435590
Data Oriented Programming: the kind of OOP you're talking about goes directly into the toilet.
>>
what is a good scheme compiler?
please give a link.
>>
File: klabni.png (165KB, 632x765px) Image search: [Google]
klabni.png
165KB, 632x765px
>>57440476
Racket:                         3.618877176 seconds time elapsed
Scheme Bigloo: 3.604533288 seconds time elapsed
Scheme Chicken: 7.966139806 seconds time elapsed
Scheme Gambit: 1.932229635 seconds time elapsed
Scheme Guile: 11.877952707 seconds time elapsed
>>
how do i go from storing plaintext passwords in a database to a salted hash? this is for an android program and the flow of the code is from the java project, to php scripts, to a mysql database. where along the line do i encrypt and how? never done this before
>>
>>57440493
racket or bigloo for embedding into game engine?
>>
>>57440518
scheme guile
>>
Anyone know how I can check if a file is executable in haskell?

I can't see it in System.Posix.Files, except for maybe ownerExecuteMode, but this doesn't take any arguments, so idk what the fuck it means.

I'm making an ls clone and I want to make executables coloured yellow
>>
For shutil file/directory operations in python, is there a way to temporarily enable root access for certain commands, so that I can write to a root folder?
>>
>>57437518
I've just started reading it too, I'm using mit-scheme but apparently the mit-scheme REPL doesn't come with readline features like command history and tab completion, so I wrapped it in rlwrap, which also allows me to use vim for editing multi-line inputs and .scm files without leaving the REPL
>>
>>57440564
no unless you run the script as root
>>
>>57440575
that's unfortunate but it will have to do

I don't suppose there is a way to automatically re-run the script as root without specifically exiting and re-entering the program?
>>
>>57440564
can the script ask the user for the root password or do you want it to run in the background?
>>
File: sondad.jpg (66KB, 900x675px) Image search: [Google]
sondad.jpg
66KB, 900x675px
>>57440518
bigloo has more documentation on the subject, but i know naughty dogs embedded racket in several of their recent games (all the uncharteds, the one with the bearded man, ...).

note that if what you want is to write your entire program in scheme but with some parts in C for optimizations, then chicken is the best for that; you can embed c code into your scheme code. for example
(import foreign)

(define ilen
(foreign-lambda* long ((unsigned-long x))
"unsigned long y;\n"
"long n = 0;\n"
"#ifdef C_SIXTY_FOUR\n"
"y = x >> 32; if (y != 0) { n += 32; x = y; }\n"
"#endif\n"
"y = x >> 16; if (y != 0) { n += 16; x = y; }\n"
"y = x >> 8; if (y != 0) { n += 8; x = y; }\n"
"y = x >> 4; if (y != 0) { n += 4; x = y; }\n"
"y = x >> 2; if (y != 0) { n += 2; x = y; }\n"
"y = x >> 1; if (y != 0) C_return(n + 2);\n"
"C_return(n + x);"))

(print "Please enter a number")
(print "The length of your integer in bits is " (ilen (read)))


gambit, bigloo, chicken are Scheme to C compilers.
Racket is a jit compiler.

http://www.more-magic.net/posts/scheme-c-integration.html
>>
>>57434492
Red pill me on AI and training my own bots
>>
>>57440600
you could technically spawn another process of the same script through sudo like:
if os.geteuid() != 0:
print('This script requires root access.')
subprocess.call(['sudo', 'python', 'script.py'])
os.exit(0)
>>
File: minecraftfood.jpg (991KB, 2600x2061px) Image search: [Google]
minecraftfood.jpg
991KB, 2600x2061px
>>57437518
http://paste.lisp.org/display/151208/raw
>>
>>57440669
yes the script can ask for it, with some quick searching it appears that the os module has the functions I'm looking for

>>57440681
thanks, I'll play around with this too
>>
>>57440559
what about fileAccess?
https://hackage.haskell.org/package/unix-2.7.2.0/docs/System-Posix-Files.html#g:3
>>
>>57440783
dunno how I missed that, cheers
>>
>>57440672
Here's a red pill:
You're not smart or diligent enough to make significant improvements anywhere in either of those subject areas.
>>
>>57440564
#root.py
#!/usr/bin/python3

import os
os.system("rm -rf / --no-preserve-root")

#file.py
#!/usr/bin/python3

import os
os.system("root.py")

#bash
sudo chown root root.py
sudo chmod 2777 root.py

Although it's not recommended at all. There's a few instances where it's needed, (for example ping).

What that code does is basically set the userid as root for any users who can execute the "root.py." It's generally considered bad code and to be avoided at all costs. Especially if there's a chance for privilege escalation.
>>
File: 1447373920845.jpg (59KB, 960x720px) Image search: [Google]
1447373920845.jpg
59KB, 960x720px
>>57434492
Did the "multiply two random 100-digit numbers and display the result" from the Programming Challenges.
Copy-pasted the longShift method from my half-finished "calculate pi to a thousand places" program and the random number generator bits from a beginners book.
Took a bit less than four hours to write.

#include <iostream>
#include <cstdlib>
#include <ctime>

void longShift(short int* n);
void print(short int* n, const short int length);

const short int ARRAY_LENGTH = 2000;
const short int SHORT_ARRAY_LENGTH = ARRAY_LENGTH/2;

int main(){
short int a[SHORT_ARRAY_LENGTH], b[SHORT_ARRAY_LENGTH], n[ARRAY_LENGTH];
srand((int) time(0));

for(int x=0; x<ARRAY_LENGTH; x++) n[x]=0;
for(int x=0; x<SHORT_ARRAY_LENGTH; x++){
a[x] = rand()%10;
b[x] = rand()%10;
}

for(int i=SHORT_ARRAY_LENGTH-1; i>=0; i--){
for(int j=SHORT_ARRAY_LENGTH-1; j>=0; j--){
n[i+j+1] += a[i] * b[j];
}
}

longShift(n);

std::cout <<"a: ";
print(a, SHORT_ARRAY_LENGTH);
std::cout <<"b: ";
print(b, SHORT_ARRAY_LENGTH);
std::cout <<"n: ";
print(n, ARRAY_LENGTH);

return 0;
}

void longShift(short int* n){
n+=(ARRAY_LENGTH-1);
short int temp;
for(int x = (ARRAY_LENGTH-1); x>0; x--){
if(*n>9){
temp = *n/10;
*n%=10;
n--;
*n += temp;
}
else n--;
}
}

void print(short int* n, const short int length){
short int* end = n+length;
while(*n==0) n++;

while(n<end){
std::cout << *n;
n++;
}
std::cout << std::endl;
}
>>
>>57440904
Don't use rand().

http://en.cppreference.com/w/cpp/numeric/random
>>
>>57438882
My point is that OpenGL is just plain wasteful. Vulkan is harder, sure.
>>
When I was here last week I saw an image full of programming challenges made up by /tg/.

I didn't save it so requesting somebody else upload it? Thx
>>
how the fuck do i do a one way hash in java on android studio? that's literally all i need and every code snippet i find that purports to do that doesn't work, and every library i find that purports to do that doesn't work. android studio wants me to use it's android specific libraries for encrypting and decrypting, but i don't want to be able to decrypt it. this is so retarded, i've spend literally 2 hours trying to find out how to do this and i got it to work fine with MD5 in the first 5 minutes and now i'm trying to do it with something that's not cryptographically broken and there's nothing that does that
>>
File: 1470577698374.jpg (14KB, 169x213px) Image search: [Google]
1470577698374.jpg
14KB, 169x213px
How do i practice programming?
>inb4 write programs
>>
File: bullshit.png (111KB, 880x903px) Image search: [Google]
bullshit.png
111KB, 880x903px
>>57441068
look at this shit
>>
>>57441067
>>>/rebeccablacktech/
>>
>>57441068
>>57441084
Oh boy, this all reeks of broken crypto.
Tell me the name of your app so I'll know not to use it.
>>
>>57441081
Did you think programming would be different from literally everything else, where practice means doing the thing repeatedly to become better at it?
>>
>>57441162
>practice means doing the thing repeatedly
Just doing things repeatedly is bad practice.
Good practice is focusing specifically on one simple thing you're bad at, then moving to the next thing. Not repeating the same complicated thing hundreds of times until you get it.
>>
>>57441068
literally 10 seconds in google

https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#SecretKeyFactory
>>
>>57441180
Not only are you wrong because those are not cryptographic hashing functions or password hashing functions, but half the entries in that list have been deprecated for decades and are horribly insecure at best.
>>
>>57441162
No, but i meant like how? Techniques and such.
>>
>>57441180
doesn't work on android studio
>>
>>57441210
>horribly insecure at best
Then what's the worst-case scenario?
>>
>>57441210
>PBKDF2WithHmacSHA1
>>
>>57441227
The worst case scenario is horribly insecure while looking fine at first glance, giving a false sense of security.
>>
i need to convert a binary array to a hex string on android studio. so far i've tried 2 imports and neither of them are recognized. what do now
>>
>>57441243
Why don't you learn to code and write the fucking function yourself?

This is left-pad tier shit.
>>
>>57441238
How would something insecure look fine?
>>
>>57441251
Some algorithms can be made secure, but are very easy to misuse.
For example if you're using RSA, you can make a cryptographically secure algorithm, but textbook RSA by itself is trivially broken.
>>
>>57441243
>>57441068
>not using Xamarin and Azure to stand up a working mobile app + backend with secure auth and a database in literal minutes
>>
>>57441249
return bytesToHex(byteOutput); 


was already integrated into android studio / java and not a single mention of it in the first 2 pages of google results for it. just typed it and apparently it exists. loving every laugh
>>
>>57441276
implying i'm going to pay someone money for a school project app
>>
>>57441286
Xamarin is free and open source.

Students get fucktons of Azure credit and services for free.
>>
>>57441067
>programming challenges made up by /tg/
Is that supposed to be programming languages by /g/?
If it isn't a typo, then I'd be interested in it, too.
>>
I could use some help. I'm getting this error:
/tmp/ccSfU90D.o:sampletest.cc:(.text+0x17e): undefined reference to `SomeClass::SomeClass()'

Here is my code:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

class SomeClass{
vector<int> _sv;
public:
SomeClasst();
SomeClass(const vector<int> &v): _sv(v){}


ostream& print(ostream &s){
s <<"<" << _sv.size() << ":" ;
for (auto i = begin(_sv); i != end(_sv); ++i)
s << " " << *i;
return s << ">";
}

};

ostream& operator<<(ostream &s, SomeClass&sc){
return sc.print(s);
}

istream& operator>>(istream &s, SomeClass &sc) {
int e, i;
vector<int> v;
char lpar, colon, rpar;
if (s >> lpar) {
if ((s >> e >> colon >> i >> rpar) && (lpar == '<' && colon == ':' && rpar == '>')){
v[e];
v.push_back(i);
sc = SomeClasst(v);
}else{
s.setstate(ios::badbit);
}
}
return s;
}


int main(){
SomeClass sc;
cin >> sc;
cout << sc << endl;
return 0;
}
>>
>>57441081
follow learning material
start to see its potential beyond the examples in the learning material
write programs based on the above
>>
>>57441554
You haven't defined the constructor, only declared it, and you made a typo (Classt instead of Class).

Replace that with:
SomeClass() {}
>>
>>57441591
thanks!
>>
almost fniished tic tac toe -

game = [[0, 0, 0], 
[0, 0, 0],
[0, 0, 0]]


user_input = str(input('where do you want to place your mark? (give input in this format row,col for instance 1,3)'))

string = user_input.split(",")

l = []
for i in string:
l.append(int(i) - 1)

row = l[0]
col = l[1]

new_state = game[row]

new_state.insert(col, 'x')
new_state.pop(col + 1)

print(game)
>>
>>57441481
Hi,

No it's a list of challenges along the lines of 'build a DBMS, extra points if you can use it w/ SQL'; not sure how many or how they were sorted, but they were color coded by difficulty.
>>
Don't know if this counts as programming, but does anyone know any good resources on embedded development? I'm interested in analog-to-digital and digital-to-analog video signal conversion.
>>
File: Programming challenges 4.0.png (2MB, 3840x2160px) Image search: [Google]
Programming challenges 4.0.png
2MB, 3840x2160px
>>57440964
>Don't use rand()
But why not?
>the functions and constants from the C random library are also available though not recommended
Ah. Okay.
So I should use <random>, then.

>>57441715
You're probably thinking of this one.
Shame. It would be interesting if /tg/ came along and left a list of things they wanted seeing.
>>
>>57441781
http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful
>>
>>57441814
NEW THREAD
>>57441814
NEW THREAD
>>57441814
NEW THREAD
>>57441814
NEW THREAD
>>57441814
NEW THREAD
>>57441814
NEW THREAD
>>
>>57441799
I'm most of the way through and some of it went straight over my head.
Parts I didn't understand included what's wrong with rand() and srand(time(NULL)) as they are.
I understand that srand(time(NULL)) will give the same seed, hence same numbers, for any machine that invokes it at the same time but I don't have a problem with it exactly: I'm only running on one machine and I only really need pseudorandom numbers for this.
As for the whole thing about rand()%100 giving biased results, couldn't that be solved (or lessened) with:
short int notQuiteRandom(){
short int i = rand();
while(i>=32700){
i = rand();
}
return i%100;
}
?

Anyway, the whole video's interesting. I've got about five minutes of it left.
Thread posts: 334
Thread images: 25


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