[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: 356
Thread images: 36

File: timetocode.webm (2MB, 1152x648px) Image search: [Google]
timetocode.webm
2MB, 1152x648px
This is /dpt/, the best subreddit of /g/

In this thread:
r/programming
r/compsci
r/ReverseEngineering
r/softwaredevelopment

/!\ ** Read this before asking questions ** /!\

http://mattgemmell.com/what-have-you-tried/
http://www.catb.org/~esr/faqs/smart-questions.html

*** D I S C O R D ***

https://discord.gg/kFegv

What are you working on ?
>>
God Save The Queen
>>
In java, making a File instance never creates a file in the disk, however, if I make a RandomAccessFile instance and the file I'm using for the constructor doesn't exist, then a new file always gets created. How can I test if a RAF exists without creating a new file on disk?
>>
third for Objective-C
>>
where can I find a fully working clean version of the latest ida pro?
>>
God Save The Queen

In java, making a File instance never creates a file in the disk, however, if I make a RandomAccessFile instance and the file I'm using for the constructor doesn't exist, then a new file always gets created. How can I test if a RAF exists without creating a new file on disk?

third for Objective-C

where can I find a fully working clean version of the latest ida pro?
>>
God Save The Queen

In java, making a File instance never creates a file in the disk, however, if I make a RandomAccessFile instance and the file I'm using for the constructor doesn't exist, then a new file always gets created. How can I test if a RAF exists without creating a new file on disk?

third for Objective-C

where can I find a fully working clean version of the latest ida pro?

God Save The Queen

In java, making a File instance never creates a file in the disk, however, if I make a RandomAccessFile instance and the file I'm using for the constructor doesn't exist, then a new file always gets created. How can I test if a RAF exists without creating a new file on disk?

third for Objective-C

where can I find a fully working clean version of the latest ida pro?
>>
>>57099273
only the 6.8 version has been leaked.
>>
hellp
>>
   $array["a"] = "Foo";
$array["b"] = "";
$array["c"] = "Baz";
$array["d"] = "Wom";
print end($array);
while($val = prev($array)) {
print $val;
}

>You may think that will iterate over an array in reverse, printing out values as it goes; however, the value at key b is empty, which will cause both prev() and next( ) to think that the end of the array has been reached. So, when they hit b, they will return false, prematurely ending the while loop.

>PHP
>Even once
>>
God Save The Queen

>>57099351
this is a pretty bad Markov chain
>>
>>57099157
>constructors with 25 optional arguments
C++ fags
>>
>>57099355
Ok, thanks. Could you provide a link if possible?
>>
>>57099448
that's what designated initialisers are
>>
>>57099466
no, it's illegal, sorry. you may also consider Hopper, Binary.ninja, or x64dgb (windows only)
>>
>>57099545
lol, fair enough. Just wanted to save myself searching through dodgy sites.
>>
>>57099534
X f(nullptr, nullptr, nullptr, nullptr, nullptr, g, nullptr, nullptr, nullptr, h);

X f = { .a = g, .b = h };

hmm
>>
>>57099174
https://docs.oracle.com/javase/tutorial/essential/io/check.html

check if it exists like any other file
>>
>>57099610
f doesn't have any optional parameters
>>
>>57099641
What would you know about what f has.
>>
>>57099651
f is my son
>>
Any good resources on OpenGL for 2D?
>>
>>57099742
What are you trying to make?
>>
>>57099772
Nothing specific, just wanna get the basic gist of projection/textures/shaders. I've only ever used abstractions like SDL and SFML but I'd like to find out how does this stuff work on the inside.
>>
>>57098751
She makes c++ sound easy.
>>
>>57099797
I think you just have to set a special projection matrix, that will remove all perspective, and point the camera at the XY plane, then put all your shapes on the XY plane etc. Not too complicated.
>>
https://twitter.com/dhh/status/787547255259758592

this'll be fun
>>
>>57099822

It can be.
>>
>>57099860
>programming
>>
>>57099860

DHH is a major faggot and I'm ashamed that I have to use his shitty web framework for my senior project.
>>
File: faggot.png (48KB, 568x240px) Image search: [Google]
faggot.png
48KB, 568x240px
>>57099932
>https://twitter.com/dhh/status/787547255259758592

what a faggot
>>
>>57099880
Apparently, if you teach it right.
>>
>>57099990
very nearly checked
>>
>>57000000
checked
>>
>>57099132
>*** D I S C O R D ***

how dead or alive??
>>
>>57100163

There's a bunch of disgusting tripfags in there.
>>
>>57100179

any useful/meaningful discussion?
>>
Is there anyway to convert a pointer to a virtual base to a derived?
 
class base{};
class derived : public virtual base{};

base *A = new derived;

derived *B = static_cast<derived*>(A);


How do I make this work?
>>
>>57100279
dynamic_cast instead of static_cast
>>
>>57100202

Occasionally.
>>
>>57100305
Nether work.
>>
>>57100332

is it worth it to get on??
>>
>>57100350
shouldn't it be
new derived()
? What code did you actually compile and run and what did you get as a result?
>>
What language has the best standard string library? I'm writing one for my own language and want a good idea lf what to aspire towards.
>>
>>57100350
>>57100406
nope
class base{
virtual void method() { }
};
class derived : public virtual base{};

int main() {
base *A = new derived;

derived *B = dynamic_cast<derived*>(A);
}

ftfy. it has to have a vtable. http://en.cppreference.com/w/cpp/language/object#Polymorphic_objects
>>
>>57100483
I don't think you need virtual there:

class derived : public virtual base{};


can be just

class derived : public base{};
>>
>>57100483
Thank you, friend.
>>
>>57100365
No, chinese botnet.
>>
>>57100554
I used that as the simplest example of my problem. I was actually experimenting with multiple inheritance with variadic templates when I ran into though.
>>
>>57100554
> what is virtual inheritance
notice if you remove the virtual there, you can change the whole thing to
class base{
};
class derived : public base{};

int main() {
base *A = new derived;

derived *B = static_cast<derived*>(A);
}
>>
File: ss (2016-10-16 at 06.02.33).png (102KB, 572x707px) Image search: [Google]
ss (2016-10-16 at 06.02.33).png
102KB, 572x707px
Friendly reminded that you can parse regular languages in logarithmic time.
>>
>>57100706
Any widespread programming languages that are also regular? Is xml regular? I know this shit is nice for syntax highlighting, but does it play well into the existing ecosystem?
>>
Could you guys give me some advice what application should i create on UWP, which contains the advantages or features of it? I need for my home assignment for my college course, where I'm learning to develop for UWP devices.
>>
>>57100754
>Is xml regular?

Oh no, you didn't.
>>
>>57100706

Was there a problem before where somebody wanted to parse regular languages but darn it's polynomial time?
>>
I'm new to programming. It makes me feel like an idiot. Right now I'm back at the university for a degree in compsci and the stuff we're doing isn't too difficult but I have just immense amounts of anxiety built up around it. When I had little tastes of programming before it was C# and kind of pretty but my class is for C++ and it's just so ugly to me... I'm working a part time job in IT for the state so I'm not totally fucked but I'm depressed because I really thought I would like learning to program more. Is it worth sticking with it? Obviously the pay is high for programming, but is it just miserable working one of those jobs or do you reach a point where you know what you're doing and it's easier to tackle issues and solve problems?

It may be more due to my mental issues but I'm finding it to be monotonous and less liberating than I thought it might be -- though maybe enough practice will allow me to reach that point. Just looking for advice and opinions.
>>
>languages that can't nest expressions arbitrarily
why
>>
Is JavaScript a difficult language to learn?
>>
>>57100906
Even web developpers can learn it.
>>
>>57100816
programming is miserable, it's only worth it for the pay/the result
>>
>>57100940
t. code monkey with no passion
>>
File: wtf.jpg (16KB, 238x397px) Image search: [Google]
wtf.jpg
16KB, 238x397px
>>57100906
>>57100929
nobody can learn it
>>
Made a rocchio classifier that I currently test.
May take a while.
>>
I want to do something like
int a, b;
auto fn = [static x = a, const y = b](){
//do something with x and y
}

but c++ won't let me use qualifiers in the capture list. Help!
>>
>>57100955
That pic actually mostly makes sense.
The JS WTF talk had much much worse
>>
>>57100967
You can't.
But since lambdas are just syntactic sugar for functors, you can still make an actual class with an operator() and a constructor.
>>
>>57100754
>Any widespread programming languages that are also regular?
No. Regular languages are those you can express by standard regular expressions (no PCRE extensions). Look up 'Chomsky hierarchy'.

>>57100804
Yes.
>>
File: 1464823306282.png (5KB, 270x175px) Image search: [Google]
1464823306282.png
5KB, 270x175px
>>57100968
>>
>>57101000
Now that's what I'm talking about! PHP-tier garbage design.
C++ looks well-designed next to that.
>>
>>57100906

it's easy in the sense that it doesn't make you think about memory or data types

it's hard in the sense that it has convoluted OOP features. As someone who thinks in C I think it's a terrible monstrosity of a language. Maybe you just have to be a braindead webdev to understand it.
>>
File: 1467640398135.png (36KB, 473x328px) Image search: [Google]
1467640398135.png
36KB, 473x328px
>>57101009
>>
File: this-guy.gif (4MB, 411x227px) Image search: [Google]
this-guy.gif
4MB, 411x227px
>>57100816
>less liberating than I thought it might be
>>
>>57100816
learn Haskell
>>
>>57101000
First one's bullshit, i is 2 after that.
Second one makes i "11".
What's wrong with fourth and fifth?
Eight is reasonable.
Everything else is just wtf
>>
>>57099132

Can I use the library "GLU" with C?

I really don't want to learn c++...
>>
File: what.jpg (9KB, 667x69px) Image search: [Google]
what.jpg
9KB, 667x69px
>>57101047
this is the last one
>>
>>57100983
Annoying and cumbersome.
>>
File: 1472143176499.jpg (53KB, 564x428px) Image search: [Google]
1472143176499.jpg
53KB, 564x428px
>>57101014
Never understood the desire of language designers to just keep going long after the code makes no logical sense at all. What should string minus an integer even mean? No one knows. So they just pull something out of their ass and that's what the language does then.

>what writing php feels like
>>
>>57100948
t. newfag

you enjoy programming because you still have plenty of new things to learn, once you know your shit the programming in itself isn't fun, only seeing the resulting program
>>
>>57101064
>==
>>
>>57101014
>>57101000
how do i never use this language? isn't it necessary to run scripts in html?
>>
File: talks.png (5KB, 132x100px) Image search: [Google]
talks.png
5KB, 132x100px
haskell sucks
>>
>>57099132
>want to learn javafx
>all the tutorials are made by poos in loos

fuck.
>>
>>57101095
yes? can i help you
>>
>>57101100
go sucks too
>>
>>57101076
You can capture an effectively const variable by not marking the lambda mutable, capturing statically on the other hand makes little sense. What were you trying to do?
>>
>yesterday morning
>bored af and feeling depressed since haven't done any legitimate (home)work in a week
>algorithm analysis group assignment due next week involving the Johnson-Trotter algorithm
>"fuck it, I like the ingenuity behind it so let's code it"
>on first try
>iterate function shits itself when finding max mobile element for n >= 4
>get depressed and say fuck it
>come back 24 hours later
>gut the shit out of the algorithm, modularizing the searching and maximum subroutines at the expense of using a shit ton of "pointer arrays"
>it works on first try for n=4
>too lazy to map out the 120+ permutations for n >= 5 and check the work
>on fence about actually using it for project or just letting my partner rip the code off some university hub like usual
Still feel pretty accomplished tbqh
>>
In c++ if I include a header (like for example GLFW which is supposed to load GL functions + other garbage) how do I use the imported functions?

In C if I include GLFW I can then just call glGenVertexArrays() or any other GL functions, but in C++ including GLFW and then attempting to call a GL function doesn't work.

Do I have to include it as an extern or something? doesn't seem right.
>>
File: 1397402072868.png (208KB, 400x400px) Image search: [Google]
1397402072868.png
208KB, 400x400px
>>57101134
>algorithm analysis group
>coding
What kind of shitty school do you go to?
>>
File: false.png (1KB, 389x41px) Image search: [Google]
false.png
1KB, 389x41px
>>57101111
>>
>>57101134
what do you have against Steinhaus
>>
>>57100816
>I wanted a degree in CS
>They required me to use a difficult language and actually learn how things work
>I haven't even taken an actual computer science class, only introductory programming courses
>it's too hard
>boo hoo
>>
>>57101094
>t. newfag
Would it blow your mind if I told you I'm not?

I think that you're bitter or burnt out and you forgot how to learn.
The time where the likes of Poincaré could pretend they know everything is long over.

You just know too little to realize how little you know. Read a book.
>>
>>57097621
>>57095193

Bump.
Can someone please tell me what's wrong with my loop?
>>
>>57101168
what's your point?

what is your defense for == returning true in the example i gave?

you obviously believe it is reasonable or you wouldn't be defending it

can't back out now faggot
>>
>>57101173
*tips fedora*
>>
>>57101160
No, you just include the header and use it. I happen to have actually used C++ with GLFW yesterday and it worked just fine.
>>
>>57101183
>>>/reddlt/
>>
>>57101168
you used the identity operator, not the comparison operator
>>57101111
nice quads
>>
>>57101195
most programming tasks involve a lot of "manual labor", code monkey tasks if you will, typing a lot of code and debugging errors, it's not fun, almost all programmers drink a shit ton of coffee just to be able to push themselves through it
>>
>>57101219
thanks
>>
>>57101162
>What kind of shitty school do you go to?
State university in my hometown since I dropped out of the prestigious school I went to years ago. We actually don't do that much coding, one project every 2-3 weeks
>>
>>57101219
>you used the identity operator, not the comparison operator

Yes, that's correct.
>>
>>57101187

How do I go about getting this to work in C++? is it even possible or am I doing something stupid?

https://github.com/colinstein/minimalopengl/blob/master/test.c

What I did was just copy and paste it into a C++ header. When I call the main function of this (I renamed it and changed the args of course) in my main.cpp, it doesn't recognize any gl functions. I think it would work otherwise though
>>
>>57101169
I inherited it from my book. I didn't even know Steinhaus was involved until doing some googling
>>
>>57100594
link expired. I'd like to see for myself.
>>
>>57101118
I want to to send a couple of variable that will have persistent values over all the calls to the lambda, for some error checking the function needs to do. One of them is going to be used as a reference value, so should be constant.
>>
>>57101262
post exact code and error message
>>
>>57101226
>most programming tasks involve a lot of "manual labor", code monkey tasks if you will, typing a lot of code and debugging errors, it's not fun, almost all programmers drink a shit ton of coffee just to be able to push themselves through it
Don't think your own problems apply to everyone else.
Good code is code that does not have useless boilerplate, that does not need to be debugged often, and that is simply easy to read.

You describe your code as if written by the stereotype of the average Java programmer, if so then yeah sucks to be you. But you only have yourself to blame.

Some people are still having fun after all this time, I'm still having fun. The problem is with you.
>>
>>57099132
>not linking to previous thread
>anime webm
>subreddits

kys
>>
>>57101291
t. haskell NEET who hasn't made a single useful application
>>
>>57101303
>kys
Kill yourself
>>
>>57101262
This is because that file does not include GLEW.
Add #include <GL/glew.h> before including GLFW and it will build fine.
>>
>>57101289

it's long but only because a lot of that code was copy and pasted from the repo

also it mentions an external C header. This is just my object file reader I made in C. Don't pay attention to that, I already verified that it works and it shouldn't effect anything else.

http://pastebin.com/hvbbY0Du
>>
File: snap038.png (25KB, 883x400px) Image search: [Google]
snap038.png
25KB, 883x400px
>>57101308
If that helps you sleep at night, you can always lie to yourself or insult the languages I use, as if that makes you superior to me as a person.

I write in C++, C, Python, C#, Java, Bash, and I know a bunch more than I rarely use, but no Haskell.
>>
>>57101366
you're clearly just a hobbyist
>>
>>57101316

ok, that fixes all but one error. I'm getting

/home/nate/code::blocks workspace/obj_reader_cpp/main.cpp|19|error: ‘renderer’ has not been declared|


but renderer is a header file, not an object or anything.

I'm lost because In C i know you would just be able to call functions from a header as if you had copy and pasted them.
>>
How effective is working a shitton of problems on kattis, Project Euler, r/dailyprogrammer, etc for learning and developing skills in general?
>>
>>57101380
Did I hit close to home when I said average Java developer?

I have a job that I love, but I'm also a hobbyist yes.
We can even compare dick sizes if you want, my github has lots of stars.
>>
>>57101396
Not really, you'll be good at solving puzzles, but that's not very valuable experience when working on serious projects.
>>
>>57101390
it's render not renderer
>>
>>57101396

they are good for your technical skills.

but a lot of programming is also organisational skill, which these projects wont help.

dont rely only on them
>>
>>57101406
>Did I hit close to home
>keeps replying to defend programming being """"fun""""
nice projecting
>>
>>57101347
glGenVertexArrays isn't a function glfw3.h will ever provide since it's not a glfw function. Proof http://www.glfw.org/docs/latest/glfw3_8h_source.html You're doing it right with including glfw tho AFAICT, so keep up and find where glGenVertexArrays and all the functions that don't begin with 'glfw' live. Can't help you with that tho sorry.
>>
>>57101419

the file is actually called renderer
>>
daily tip: coding ins't the same as programming
>>
>What are you working on ?

I haven't done any programming today, but I've tidied my room.
>>
I want to make my room more suitable for programming.

I have a desk, a cm 2 1440p monitors
>>
>>57101431
>>keeps replying to defend programming being """"fun""""
Yeah, because that's my point of view and that's what we're arguing about.
Maybe you live in a little echo chamber and you're not used to people replying to you, but that's how arguing generally works.

>nice projecting
You're using that word wrong.

It's not very useful talking to you, you know.
>>
>>57101473
>It's not very useful talking to you, you know.
it's apparently """"fun"""" though
>>
>>57101483
Yes, yes it is.
What is even your point.
>>
>>57101491
>being a contrarian edgelord participating in meaningless "arguments" with strangers on the internet is fun
kys
>>
In C++ in a virtual method, is this the same in the child and in the parent?
>>
>>57100816
I think you are suffering from a bad encounter with the education system, not with programming.
>>
File: getHelp.png (49KB, 300x93px) Image search: [Google]
getHelp.png
49KB, 300x93px
>>57101514
>>being a contrarian edgelord
Because I disagree with you?
Top kek. You literally can't handle people having different opinions.

Do you need your little safe space where no one will argue with you?

>participating in meaningless "arguments" with strangers on the internet is fun
Where exactly do you think you are?
>>
>>57101546
here's your (You)

and i suggest focusing more on your programming if it's so fun
>>
File: 1371671791622.png (105KB, 500x550px) Image search: [Google]
1371671791622.png
105KB, 500x550px
>>57101567
>here's your (You)
I know you won't ever admit to being wrong, and that's why it's fun seeing you dig your own hole.

>and i suggest focusing more on your programming if it's so fun
Oh don't worry about me, I can multitask.
>>
File: main.png (277KB, 966x1694px) Image search: [Google]
main.png
277KB, 966x1694px
Are there Erlang programmers in this thread?
Started learning Erlang this yearsteday, I made a small chat server. I was wondering if someone could look at my code and see if there is anything awfully wrong with my code.
http://pastebin.com/4ybY3msU
>>
>>57101519
Your question doesn't make a lot of sense, what do you mean?
>>
int a;
auto fn = [x=a](){
x++; //error; expression must be a modifiable lvalue
}

wtf? x is not an lvalue?
>>
>>57101632
Guys, I found the haskeller!
>>
I feel like an ass. Does anyone here know what 2^n + 2^(n-1) + 2^(n-2) + ... + 2^1 is equivalent to? I feel like I've learned this before and I'm just blanking on it.
Trying to analyze T(n) = T(n-1) + 2^n running time
>>
>>57101639
It's an lvalue, but it's not modifyable.
The lambda needs to be marked mutable if you want to do that.
>>
>>57101647
Isn't it 2^(n+1)-1?
If you look at it like a bitset, it seems easier.
>>
>>57101619
>andalso

holy kek
>>
>>57101665
Yeah, it felt kinda weird to use that. Is there another way to do that?
>>
>>57101607
>I know you won't ever admit to being wrong, and that's why it's fun seeing you dig your own hole.
i'm not wrong, i simply gave my opinion as advice to the anon who asked

>Oh don't worry about me, I can multitask.
me too, but clearly programming is not all that fun if you think wasting time on this meaningless argument is also fun when you could be getting more involved with your programming instead
>>
What do you do to keep the fun in programming
>>
>>57101663
>mfw
based anon
It's actually 2^(n+1) - 2, but you led me to the answer
>>
>>57101684
Have a wank after each new class you create
>>
>>57101684
to think programming is fun past the learning phase you'd have to be the sort of sperg who thinks it's fun to argue about trivialities on 4chan
>>
>>57101684
Keep on learning new things. If you start stagnating you'll start to want to kill yourself.
>>
>>57101671
Maybe:
is_valid_name(Name) ->
case {string:len(Name) > 2, string:chr(Name, $ ) == 0} of
{true, true} -> true
{_, _} -> false
end.

But that's a bit more verbose.
>>
>>57101656
I thought lvalues were modifiable by definition.

But i guess this solves my problem.
Problem solved and experience gained. Nice.
>>
>>57101722
can you not do &&
>>
File: happyAsian.gif (1MB, 209x180px) Image search: [Google]
happyAsian.gif
1MB, 209x180px
>>57101672
>i'm not wrong, i simply gave my opinion as advice to the anon who asked
That part is fine, it's you acting like a child that I find entertaining.

Let me quote your posts again:
>t. haskell NEET who hasn't made a single useful application
>you're clearly just a hobbyist
>nice projecting
>kys
This is what you wrote. Half of it is wrong, the other half is pure shitposting.

>me too, but clearly programming is not all that fun if you think wasting time on this meaningless argument is also fun when you could be getting more involved with your programming instead
As I just said, multitasking. Just because I enjoy programming doesn't mean I can't enjoy posting on 4chann.

>>57101685
Oh yep, you're right. And no problem.
>>
>>57101753
(You)
>>
File: 29zfZY6I.jpg (12KB, 512x512px) Image search: [Google]
29zfZY6I.jpg
12KB, 512x512px
should a programmer have a twitter?
>>
>>57101725
I wish it were that simple.
For reference here's what lvalue/rvalue/xvalue/prvalue/glvalue actually means: http://en.cppreference.com/w/cpp/language/value_category

>>57101761
^__^
>>
>>57101770
that's what i use /dpt/ for.
>>
>>57101770
if you have a life you have a twitter account

prove me wrong
>you cant
>>
>>57101770
just have a 4chan gold account
>>
>>57101751
Erlang doesn't have &&. It has and (which doesn't work with expressions) and andalso, which works with expressions.

>>57101722
Yeah and I don't know, pattern matching here doesn't make much more sense.
>>
>>57101656
>>57101786
Oh, and thanks!
>>
File: 1472027258212.png (30KB, 440x177px) Image search: [Google]
1472027258212.png
30KB, 440x177px
>>57101789
>tfw having a life means having a twitter account but having a twitter account doesn't mean having a life
>>
>>57101809
frogposters don't deserve to live, except as a mean to an end of the end of death
>>
File: 1438781024656.jpg (68KB, 640x585px) Image search: [Google]
1438781024656.jpg
68KB, 640x585px
>>57101809
>>
>>57101817
i just like that picture
i don't really have any other frogs on my computer
>>
File: oksana_neveselaya.jpg (67KB, 480x480px) Image search: [Google]
oksana_neveselaya.jpg
67KB, 480x480px
Hey deepeetee, I have a question.

Take languages where method lookup is done by searching associative tables with strings as keys at runtime, such as Python, Lua, or Javascript. Why don't people use arbitrary object as keys for methods? (Or do they?) The idea behind my question is that, while strings are fine for objects whose class you know in advance, in generic code that would simplify stuff by making name collisions a non-problem. It's possible to choose the same method name as some unrelated interface/protocol --- and then when a class wants to implement both, they conflict --- but it's not if you have to explicitly create a dedicated unique object.

Lua proof of concept
-- OK so I just decided lua's length operator sucks so I'm making my own.
len = {}
setmetatable(len, len)
function len:__call(other)
return getmetatable(other)[self](other)
end

implementor = {}
setmetatable(implementor, implementor)
implementor[len] = function(self)
return -42
end

print(len(implementor)) -- prints '-42'

-- I even get to copy the method in an intuitive way!
size = len
print(size(implementor))
-- And of course, if another module has a len, it'll always be unambiguous which one it is.


Notes:
I noticed it won't necessarily play well with the established syntax of JS and Python, but they could certainly be extended.

Python doesn't allow for non-string keys on classes, brb writing a PEP about it.
>>
>>57101831
ok
but if you see any frogposters, make sure you shoot them in the head
>>
>tfw engineer friend that only uses coding for running statistics in his advisor's lab is better at programming than you are despite your years of practice
>>
>>57101881
Gotta keep on practicing.
>>
>>57101881
keep dreaming
>>
in Haskell (and all FP I guess) how would one insert into a tree when variables are immutable? e.g. in C you'd create a node structure, figure out where to insert it then change the pointers to acommodate. If you can't change variables in Haskell what do you do?
>>
>>57101944
You'd probably represent your tree with lists of lists of lists.
>>
>>57101944
you create an entirely new tree with the one node changed.
>>
>>57101944
see >>57101982
since it's immutable you can reuse the old tree too, you only need a few nodes to be different
>>
>>57101991
Would the complexity of insertions not go up if you have to do that?
>>
>>57102007
Yes and no. The compiler can actually compile to code that just mutates the tree.
>>
>>57102007
depends what you're doing
>>
>>57102018
WHAT
IS
THE
FUCKING
POINT
THEN

fuck haskell
>>
>>57102041
>WHAT
>IS
>THE
>FUCKING
>POINT
>THEN
The whole fucking point is you are doing everything more declaratively and safely. Mutation is only a problem when the programmer is doing it, because the programmer tends to make mistakes. The compiler can make code that mutates that will never do something unintended.
>>
>>57102041
what's the point of using for loops when they just compile to goto
>>
Hello /g/...
Does anyone have a PDF copy of "The Pragmatic Programmer"? Can't find it on bookzz...
>>
>>57102068
>the programmer makes mistakes
>but the person who programmed the compiler can't make mistakes

top jej
>>
>>57102148
>but the person who programmed the compiler can't make mistakes
Of course they can, but in a decent compiler it's pretty fucking rare.
>>
>>57102144
Come on, first result

google.com?q=The+Pragmatic+Programmer+pdf
>>
>>57102144
i see a ton of copies on libgen
>>
i need help connecting to my university's network to submit my assignments and stuff. all the instructions they have are for people using windows. now that i'm on linux, nomachine doesn't work for me, so i'm trying to ssh

http://www.cs.ecu.edu/~rws/systems/login.html

there's no instructions on how to ssh into it. can someone help??
>>
>>57102185
The command is:

ssh [email protected]


Replace yourlogin by your user name, then enter your password when prompted.
>>
File: last.png (14KB, 998x324px) Image search: [Google]
last.png
14KB, 998x324px
Working on my terminal emulator, just finished making soft scrolling regions work properly, it was a pain in the ass.

Now trying to figure out why cursor save/restore isn't working properly.
>>
>>57102169
dunno why he decided to jump in and derail but anyway I'm reading that laziness solves the problem in Learn you a... book but it doesn't even begin to explain why.
>>
>>57102199
it just stalls out
>>
>>57102231
Okay so apparently the command is actually:

ssh [email protected] -p 2200


If that doesn't work either, then I don't know. Ask your school.
>>
>>57102248
arigatou
>>
Hopefully come to the right place... maybe someone can help me out:
How long would it take for me to learn to make a simple game for android? By simple I mean a memory game where text(images) and sounds are associated with each other by selecting them.
No experience of programming...
Can provide more details about the game
>>
>>57102200
Nice, wishing you lucy bro
>>
>>57102317
About 5 years and a team of 30 asian engineers.
>>
>>57102317
It depends how you go about it, maybe a couple weeks, maybe a couple months.
>>
>>57102317
Depends on how much you apply yourself. If you want something that isn't a terrible buggy mess, I'd say you'll have to at least spend six months programming daily.
>>
>>57102317
Should take less than an hour.
>>
>>57101087
PHP would be much better if it had type safety.
>>
>>57102382
Hack does that.
>>
>>57101174
You shoving everything into one line.
For fucks sake.
>>
LoadData = [&file, remaining = tmpChunkHeader.chunkSize](UINT32 size, BYTE* data)mutable
{
if (!file.good()) return 2;

if (size <= remaining)
{
file.read((char*)data, size);
remaining -= size;
}
else if (0 < remaining)
{
file.read((char*)data, remaining);
memset((char*)data+remaining, data[remaining-1], size-remaining);
remaining = 0;
}
else
{
return 2;
}
return 0;
};


Rate my code, /dpt/.
>>
>>57099418
>iterate over an array in reverse
that's not an array you stupid fucking webfag
>>
>>57102402
Hack is not PHP though.

Is hack actually any good?
>>
>>57102420
>UINT32
>BYTE
>return 2 on error instead of negative number
What are you doing?
>>
>>57102420
What the hell is this language?
>>
>>57102508
C++
>>
>>57102470
Windows programming.

I'm actually a little worried about porting this to Linux later.
>>
>>57102516
Fair enough.
>>
File: 1476604289203.jpg (133KB, 500x700px) Image search: [Google]
1476604289203.jpg
133KB, 500x700px
There is a thread on /a/ discussing C as programming language for building games.

So what's wrong with it? and how does C# and C++ compare to it?
>>
>>57102556
it's not high level enough
and doesnt really lend itself to abstraction
>>
>>57102556
C is generally too low-level and barebones for gaymemes develpoment.
>>
>>57102556
You can build a game in C, but that's like building a web app in ASM.
You might as well use the best tools for the job.

C# is fine, but since it's GC'd you'll have to deal with unpredictable latency and that's just hell when you're on a strict millisecond budget per frame.

C++ allows you to build powerful abstractions while staying as close to the metal as you want. It's called the zero-overhead principle.
>>
>>57102470
>return non zero on error
As it should be.
>>
>>57102556
C# and C++ both provide a lot of useful abstraction that speeds up the developement process and convenience features that do not force you to ugly unhygienic macro or compiler extension hacks to achieve something.

It's alright for clones of simple old games though.

Also fuck off back to /a/.
>>
>>57102612
>C++ allows you to build powerful abstractions while staying as close to the metal as you want.
This is the best description of sepples i've ever heard.
>>
>>57102614
There's a very simple convention.
For a function named after an action e.g. do_something() you should return -1 or another negative error code on error, and 0 on success.
For a predicate like is_thing() you return 1 on success and 0 on error.
>>
do any of you fucks have the invite to the discord?
I wanna ask really meaningful questions :^)
>>
>>57102671
it's in the first post faggot
>>
>>57102671
you don't need an invite. i didn;t anyways
>>
File: 1470038049426.gif (3MB, 200x150px) Image search: [Google]
1470038049426.gif
3MB, 200x150px
Alright DPT.
I know Java.
I want to work in a company that does J2EE.
Does anyone know how to learn J2EE?
At least the basics and principles and whatnot.
There is an open internship at this place which wants people who know Java and being knowledgeable in J2EE is a plus.
I'm also very insecure about my coding skills and don't know what to expect. This will be my first programming job.
>>
File: 1476596775678.jpg (154KB, 1280x720px) Image search: [Google]
1476596775678.jpg
154KB, 1280x720px
>>57102576
>>57102605
>>57102612
Thank you.
Which is easier to learn and be able to create very very basic game?
C, C# or C++
>>57102617
>Also fuck off back to /a/.
Is this /g/ being tsundere to /a/?
>>
>>57102717
It's hard to say. C is probably the hardest, I'd say it's a tie between C# and C++, but probably many people will find C# easier.

Another advantage of C# is you can start with Unity, which is a stupidly powerful game engine.
>>
>>57102705
I'm sorry, did you try the link?
Try to implements a few precautions before you end up being a complete fucking retard
>>
>>57102717
C# is probably the easiest but it's also made by an evil corporation so you're kinda trapping yourself in their ecosystem.
>>
>>57102711
>I want to use J2EE
>J2EE
Just burn yourself with gasoline. It would be less painful.
>>
>>57102717
Haskell
There's nothing wrong with /a/, /g/ is just full of faggots that don't realise the purpose of 4chan
>>
>>57102711
Are you comfortable with Java?

Just join the internship and learn as you go. I'll bet you'll learn everything in a few weeks and the job will be boring as fuck.
>>
>>57102717
>>57102731
Ignore this shitpost. C is easier and won't waste your brain.
>>
>>57102717

Of the three, C# by a long shot, if only because you can whip some dogshit in unity with minimal effort.

Even then, I always recommend that people learn C++.
>>
>>57102732
sucks for you. we don't want you here
>>
>>57102765
This reads like a very biased opinion.
In C you have to deal with pointers all the time, which is hard for a beginner.
In C# and modern C++ you can do everything you want with just the existing abstractions.
>>
>>57102771
>Implying everyone on 4chan is not a fucking faggut
>>
>>57101944
create a new universe where the tree has the inserted variable
>>
>>57102068
you're still doing the mutation, just that you have the mindset that you're creating a new immutable variable
>>
Where the hell can I find a simple tool that lets me visualize the synthesis of some verilog code?
>>
>>57102771

>Implying a single person represents the entire server
>Implying you're not an underage faggot thinking he actually means something for joining "muh sekrit club"

No seriously tell me you're baiting
>>
>>57102784
>bla bla bla abstractions
You still have to understand how your program works. OOP is hard, and useless.
>>
>>57102813
this discord is everything but "muh sekrit club" trust me, i'm just doing you a favor
>>
>>57102837
you've confused OOP for abstraction
>>
>>57102837
Yes, and for beginners it's easier to understand what they're actually writing when they don't have to deal with pointers and low level details.
That's why all the kids start out with Javascript.

OOP is not a panacea, but it's a very successful paradigm, if you can't see that, you're trolling.
>>
>>57102648
The return value 2 has a specific definition in the context. I could return a negative, but that just means the caller is going to convert it to a 2 anyway.
I guess i really should use an enum though. Then you wouldn't have complained about that.
>>
>>57102807
>you're still doing the mutation
no you aren't. You're creating a new value based on an old one.
>>
>>57102864
>I guess i really should use an enum though. Then you wouldn't have complained about that.
I think you definitely should make an enum in this case!
That's exactly what enums are for.
>>
>>57102868
if you're not using the old one then it's exactly equivalent to mutation, hence why the compiler could optimize it
>>
>>57102850
Don't worry friend - if it ends up being too cancerous we'll just burn it down
>>
>>57102837
>OOP is hard
t. retard
>and useless
t. sour grapes
>>
>>57102897
>if you're not using the old one then it's exactly equivalent to mutation
no it's not, because you are not prone to any of the problems associated with shared mutable state. Nothing can have access to the value and have it change in value unexpectedly because some other code changed the value somewhere that didn't seem likely are clearly possible when reading the code. That's the whole point. Optimising the the code so it's mutates at run time changes nothing about how the code behaves.
>>
>>57102925
he's half right
OOP isn't hard
>>
>>57102863
>kids
>...
>javascript
Poor wasted humans. Pointers are truly simple to understand. Why would you add unnecessary layers of complexity to hide such simple mechanisms.

>>57102925
I'm glad I don't have to answer your shitpost.
>y--yes
>>
>>57099001
>>
>>57102966
>Poor wasted humans. Pointers are truly simple to understand. Why would you add unnecessary layers of complexity to hide such simple mechanisms.
They were for me, the concept is simple, but many beginners have a trouble with pointers. Let them have javascript if that's what they're good at.
>>
>>57102216
Laziness by default probably creates more problems than it solves.
>>
>>57102966
>Pointers are truly simple to understand.
simple to understand, hard to use without fucking yourself unless you're very careful.
>>
if I master C++ how will my skills transfer to C#?
are any fundamentals different, or just faster dev speeds?
>>
File: watt.gif (2MB, 250x187px) Image search: [Google]
watt.gif
2MB, 250x187px
>>57101014
>>57101000
>>57100955
>>
template<typename ... types>
class entity : public types...
{public: virtual ~entity(){};};

class graphical : public virtual entity<>
{
public:
virtual void f()
{
std::cout<<"I am graphical.\n";
}
};

class physical : public virtual entity<>
{
public:
virtual void f()
{
std::cout<<"I am physical.\n";
}
};

class thing : public entity<graphical, physical>
{
void f()
{
std::cout<<"I am thing\n";
}
};

int main()
{
std::vector<entity<>*> A;
A.push_back(new entity<physical>);
A.push_back(new entity<graphical>);
A.push_back(new entity<physical, graphical>);
A.push_back(new thing);

for(entity<>* B : A)
{
if(physical *C = dynamic_cast<physical*>(B))
C->f();
if(graphical *C = dynamic_cast<graphical*>(B))
C->f();
}

return 0;
}


Inheritance is fun.
>>
>>57103089
If you master C++ learning C# will be the job of a weekend.
>>
> when a printf statement makes your program work
>>
>>57103109
>
virtual ~entity(){};

If you define it with {} then you don't need the semicolon.
But really you don't need to define it at all. Or if you want to be explicit use
= default;
>>
best way to learn assembly?

best way to learn C++ past structs/the basic stuff?

is SICP actually worth going through?
>>
>>57103138
>best way to learn assembly?
Download nasm, do a hello world. Then do more complex shit.

Or the other way around, take a program and disassemble it. Do crackmes and cracks for shareware.

I did both personally.

>best way to learn C++ past structs/the basic stuff?
Actually use it for real projects and challenge yourself to learn things you don't know.

>is SICP actually worth going through?
It's a neat book, the first several chapters are interesting if you're never done functional programming before, but it's not the panacea.
Most people who recommend SICP haven't read SICP.
>>
>>57103089
if you master C++, you don't need filthy C#
>>
I bought a book on C but it doesn't mention how to make classes. How do I make classes?
>>
>>57103212
>
>>
>>57103212
apt purge gcc
apt install g++
>>
>>57103212
>C
>classes
>>
>>57103136
Matey no destructor definition means a non-virtual destructor, which means the correct subclass destructor might not be called when needed.
>>
>>57103223
>apt
>>
>>57103212
this

wtf is wrong with them
>>
>>57103212
Use C with classes, or some weirdoid framework by Microsoft®
>>
>>57103230
Really? Pretty sure as long as you declare it virtual you're good. It's a destructor, so the compiler will generate one for you either way (and it'll be virtual since you said so).
>>
>>57103136
>If you define it with {} then you don't need the semicolon

Thank you, not sure why I even did that.

>But really you don't need to define it at all. Or if you want to be explicit use

I will change it to that, but I defined it because otherwise the class would have no vtable as >>57100483 showed me and a virtual destructor seemed the most obvious thing.
>>
>>57103253
>Pretty sure as long as you declare it virtual you're good.

Then clarify this statement:
>But really you don't need to define it at all.
>>
What are you working on?
>>
>>57103272
>>57103263
Okay there's a confusion between declaration and definition it seems.

This is a declaration (but NOT a definition):
virtual ~entity();


This is also a declaration AND a definition
virtual ~entity(){/*Your code here*/}


If you only declare a destructor, the compiler will generate a definition (the actual code) for you.
If you don't even declare it, now you're in trouble.
>>
hi /g/, I'm looking for some resources on KWin scripting but I haven't really found anything proper besides the wiki tutorial, does anyone have any good resources?
>>
File: 1472429171510.jpg (131KB, 1080x1196px) Image search: [Google]
1472429171510.jpg
131KB, 1080x1196px
So how the heck do you program stuff in C without classes? I understand that object orientedness usually doesn't work for abstract concepts, but if you are creating something that mimics real world physical objects then classes are super useful. For example if you wanted to make a video game, enemies all naturally group together, weapons all natural group together etc. I can't wrap my head around how C would work for a project of that nature.
>>
>>57103322
programming
>>
I've started programming in Erlang recently, and I'd like to know what is the proper way of writing functional programs. Every time I have to do something that would traditionally be accomplished by a loop, I have to use recursion, which is fine, but declaring another function just to do the looping is ugly, I'd prefer it to be inside the body of the original function. Should I use funs instead?
>>
>>57103322
A lot of C programmer essentially end up reinventing C with classes.

You have a struct Foo, and then free functions Foo_do_something() that are totally not class members I swear.
>>
>>57103322
C has "OOP" through structs.

struct Weapon {
unsigned damage;
unsigned magazine_size;
unsigned rounds;
};

struct Weapon *weapon_create()
{
return malloc(sizeof(Weapon));
}

void weapon_destroy(Weapon *weapon)
{
free(weapon);
weapon = NULL;
}

void weapon_can_shoot(const Weapon *weapon)
{
return weapon->rounds > 0;
}
>>
>>57103322
Honestly, look up the doom source code.

The game's entirely in C and some inline assembly and there's a lot going on in it.

You can write code that simulates classes kinda
>>
>>57103322
>I can't wrap my head around how C would work for a project of that nature.
because you spend all of your time talking about programming instead of just programming
>>
>>57103344
The poor man's C++.
>>
>>57103326
> declaring another function just to do the looping is ugly, I'd prefer it to be inside the body of the original function.
It's not ugly, it's nice and clean. But yeah, you could use funs if you wanted to.
>>
>>57103322
You are a dumb shit.
A class is nothing more than a struct with dedicated functions.
Why don't you think for a second before asking shit in here.
Google it next time.

This kind of shit is why I hate /dpt/,
it's just full of complete beginners who are too lazy to actually learn shit.
It should be renamed to programming beginner general or something.
>>
>>57103294

>>57103109 won't compile without a definition.
>>
>>57103366
NO BULLY!!!!
>>
How are you supposed to return an array of unknown size (at compile time atleast) in C?
>>
>>57103370
Eh you're right, the definition is actually needed here or the vtable will be empty.
My bad.
>>
>>57103322
an object is basically data + methods

what they do in C is use structs + functions as if they were objects. it's almost just a matter of syntax.
>>
>>57103326
loop f begin step end = -- todo
>>
>>57103326
You just call the same function again with a termination condition.

defmodule Test do
def fib(n) do
case {n} do
{0} -> 0
{1} -> 1
{_} -> fib(n - 1) + fib(n - 2)
end
end
end
>>
>>57103394
pointer+size.
>>
File: whatever.png (47KB, 800x837px) Image search: [Google]
whatever.png
47KB, 800x837px
>>57103294
agreed on declared vs defined.

The thing is, nor declaring neither defining a destructor gets one generated for you (albeit a non-virtual one because you didn't specify it had to be virtual by hypothesis) but declaring without giving even a dummy or default definition gets you a nice linking error. (see pic) Probable explanation: this allows forward-declarations.
>>
>>57103344
>
weapon = NULL;

Absolutely useless considering the variable will get purged off the stack one line later.

It could work like this, but nobody does that just to set a pointer to NULL.
void weapon_destroy(Weapon** weapon)
{
free(*weapon);
*weapon = NULL;
}
>>
>>57103411
Yep, I fucked up. My bad.
>>
In the market for another monitor for programming, currently using a 2515H. Any other recommendations?
>>
File: delegates.jpg (136KB, 1280x720px) Image search: [Google]
delegates.jpg
136KB, 1280x720px
How do I make it so that this program preserves whitespace?
// converts all lowercase letters in a string to uppercase letters
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main (int argc, char* argv[])
{
if (argc > 6)
{
puts("too many words nigger");
return 1488;
}

for (int i = 1; i < argc; i++)
{
char* c = argv[i];
for (int j = 0; j < strlen(c); j++)
{
if (isalpha(c[j]) && islower(c[j]))
c[j] = toupper(c[j]);
}
printf("%s", c);
}

printf("\n");

return 0;
}
>>
>>57103419
Use C++!

template<typename T>
void stupidfree(T *& ptr) {
std::free(ptr);
ptr = nullptr;
}

No need to thank me, inferior Cman
>>
>>57103443
Holy shit, ignore this. I figured it out.
>>
>>57103450
Use modern C++!
template<class T>
void smartfree(unique_ptr<T>) {
// RAII.
}
>>
File: 1434026258595.jpg (29KB, 436x436px) Image search: [Google]
1434026258595.jpg
29KB, 436x436px
>>57103378
Sorry, I don't want to be a meanie,
but I'm kind of fed up with this...
People just keep treating this thread like a homework question thread,
and keep asking questions for which answers can be find on stack-overflow in seconds.
>>
>>57103419
>It could work like this, but nobody does that just to set a pointer to NULL.

But if you don't do that then if you check the pointer to see if it's NULL it will pass the check and you'll have an use-after-free when you dereference it.
>>
>>57103443
>How do I make it so that this program preserves whitespace?
I guess you mean that
./program a   b
typed into a shell results into A B rather than A B.

short answer: call it with
./program "A    B"


long answer: it's the shell that's doing the splitting up into words. Your program can't influence that, but the quotes can prevent that.
>>
>>57103473
I have a hard question for you if you want.

What's the fastest way to wakeup a Linux thread or process if you want to measure the context switch overhead?
There's futexes, blocking pipes, signals, can you do better?
>>
>>57103473
>visits thread every day
>complains about thread within thread for attention

So you'd rather have a dead thread than one with a few beginners? Nearly every post is a reply to a question that you could "just google". Why don't you make your own TRUE PROGRAMMER thread and just sit in it? Would that make you happy?
>>
>>57103488
OH MAN fuck this god damn shit, 4chan itself destroyed my [codes] ffs, doing exactly what I was trying to describe. Well kudos for reasoning it out >>57103463, and bye
>>
NEW THREAD!

>>57103514
>>
>>57103505
This tbqh.
I answered lots of questions in DPT threads, and sometime it's a bit annoying when the answer is literally the first result on Google, but everyone has to start somewhere, and helping people is a better use of my time than being smug.
>>
>>57102556
Only use c if you want to makes games for the dreamcast
>>
>>57103473
so instead of people with varying amounts of experience you want only seasoned shitposters and dunning-kruger haskell newfags
>>
>>57103405
I hope this message is bait.
>>
>>57103402
I think that's some haskell specific shit, I'm using Erlang.

>>57103362
>>57103405
I don't think I was clear enough. I was talking about writing something like a program that reads in a line and then counts the word. You have your recursive function that reads in the lines, and then you have to actually count the words in each line with another recursive function that you call within your original function, but this approach leads to you declaring a bunch of functions that aren't really reusable, so I wanted to know if there's something I miss, e.g. people using funs (anonymous functions) for these purposes instead of creating "actual" functions.
>>
>>57103556
What do you mean?
>>
>>57103572
What is he trying to say?
>>
>>57103570
No it's not, write a recursive function to do traditional for loops
>>
>>57103505
>>57103538
No need to exaggerate.
There is quite a lot of middle-ground between hardcore-programmer-discussion, and cs-first-weeker q/a.
And checking google before asking things here should be natural, as finding solutions by yourself is a huge part of this whole field
I'd be ok with the thread being a bit slower, and the expected quality of discussion being a little higher, since at this point there is rarely any discussion or anything.
Since this is not anything I can enforce I don't browse this thread too much recently, and I guess that is also the case for a lot of other more experienced programmers on /g/.
>>
>>57103408

tried that, got undefined behavior

Google says you have to malloc and free it yourself
>>
>>57103632
Well, yeah. I'm guessing you tried to return a stack-allocated array.
That's not gonna work. You can't return a stack-alocated anything, because they die when you return.
>>
>>57103643

If I return a pointer that was malloced in a C header to a C++ file where it gets freed, does that fuck it up?
>>
>>57103705
It will work fine, but it doesn't get freed automatically, you have to call free in the C++ file.
>>
I'm making a roguelike in php and I'm slowly losing my mind
//check movement
switch($player->state) {
//player is in battle
case 'battle' :
if (isset($_POST['battle'])) {
switch($_POST['battle']) {
case 'attack' :
if ($player->attack <= $enemy->defense) {
$enemy->setHP($enemy->hp - 1);
} else {
$enemy->setHp($enemy->hp + $enemy->defense - $player->attack);
}
if ($enemy->attack <= $player->defense) {
$player->setHP($player->hp - 1);
} else {
$player->setHp($player->hp + $player->defense - $enemy->attack);
}
if ($enemy->hp <= 0) {
$player->setExp($player->exp + $enemy->exp);
$player->setGold($player->gold + $enemy->gold);
unset($enemy);
unset($_SESSION['enemy']);
$player->setState('normal');
}
break;

case 'run' :
break;
}
}
break;


in other news, why does 4chan use such low character counts
>>
>>57103746
>in other news, why does 4chan use such low character counts
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>>
>>57103746
>I'm making a roguelike in php
why.jpg

>in other news, why does 4chan use such low character counts
use tabs for indentation you turbo nigger
>>
>>57103746
>I'm making a roguelike in php and I'm slowly losing my mind
textbook definition of 'asked for it'
>>
>>57103751
I could compact my code

>>57103770
I do you turbotard

>>57103784
It's not so bad, I can output directly into the CSS and use CSS for a ghetto sprite sheet, it's pretty nice.

.tile {
float: left;
width: 16px;
height: 16px;
}
/*GRASS*/
.grass {
width: 16px;
height: 16px;
margin: 0;
padding: 0;
background-image: url("../images/sprite_grass.png");
background-repeat: no-repeat;
}

.grass1 {
background-position: 0 0;
}

.grass2 {
background-position: -16px 0;
}

.grass3 {
background-position: -16px -16px;
}

.grass4 {
background-position: 0 -16px;
}

/*HOUSE*/
.house {
width: 16px;
height: 16px;
margin: 0;
padding: 0;
background-image: url("../images/sprite_house.png");
background-repeat: no-repeat;
}

.houseNWcorner {
background-position: 0 0;
}

.houseNwall {
background-position: -16px 0;
}

.houseNEcorner {
background-position: -32px 0;
}

>>
>>57103831
>>57103746
Here's my chat logger, it can parse messages and display them in the 'HUD'
        public static function logMsg($message) {
if(!array_key_exists('logs', $_SESSION)) {
$_SESSION['logs'] = array();
}
if (array_key_exists('logs', $_SESSION) && count($_SESSION['logs']) === 20) {
for($i=0; $i<10; $i++) {
unset($_SESSION['logs'][$i]);
}
$_SESSION['logs'] = array_values($_SESSION['logs']);
}
$_SESSION['logs'][] = $message;
}

public static function getMsg($type) {
switch ($type) {
case 'move' :
$message = array(
'You head :direction: and find nothing.',
'After going countless footsteps :direction:, you find nothing.'
);
break;

case 'blocked' :
$message = array(
'There seems to be something blocking your path :direction:.'
);
break;
}
return $message[rand(0, count($message) - 1)];
}

public static function cleanMsg($message, array $params) {
if (array_key_exists('move', $params)) {
$message = str_replace(':direction:', '<span class="direction">'.$params['move'].'</span>', $message);
}
if (array_key_exists('enemy', $params)) {
$message = str_replace(':enemy:', '<span class="enemy">'.$params['enemy'].'</span>', $message);
}
if (array_key_exists('playerattack', $params)) {
$message = str_replace(':playerattack:', '<span class="playerattack">'.$params['playerattack'].'</span>', $message);
}
if (array_key_exists('enemyattack', $params)) {
$message = str_replace(':enemyattack:', '<span class="enemyattack">'.$params['enemyattack'].'</span>', $message);
}
return $message;
}
>>
>>57101834
Javascript is getting exactly this feature.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
>>
>>57103831
>It's not so bad, I can output directly into the CSS and use CSS for a ghetto sprite sheet, it's pretty nice.
or you could use qml and areal language
>>
new thread whence?
>>
>>57104357
1 hour ago.
Lrn2^F
>>
File: Screenshot_2.png (6KB, 616x79px) Image search: [Google]
Screenshot_2.png
6KB, 616x79px
I've been going through a c++ book and was wondering If this is hard to do for someone new to programming.
>>
>>57103488
That's not what I meant anon, the program would take "wew lad" as an argument and print "WEWLAD" rather than "WEW LAD".

It was a pretty trivial fix though, just changed line 21 from
printf("%s", c);
to
printf("%s ", c);
>>
>>57104362
>Lrn2^F
what did he mean by this?
>>
>>57104402
Learn to search.
>>
>>57104453 meant for >>57104448
>>
>>57104453
oh i read it as Lm instead of Lrn
>>
>>57104402
no, it isn't.
>>
File: recursivePepe.gif (2MB, 600x450px) Image search: [Google]
recursivePepe.gif
2MB, 600x450px
>>57104402
A bit, you'd have to into recursion which can be a bit daunting to wrap your head around.

https://en.wikipedia.org/wiki/Recursion

https://stackoverflow.com/questions/126756/examples-of-recursive-functions
>>
>>57104582
>3 parameters to be sorted
>recursion
no
>>
>>57104627
Did you even read the requirements he posted? I think it's pretty clear that the book is trying to get him to write babby's first recursive function.
>>
>>57104582
>>57104655
It just wants him to do some if-statements.
>>
File: 1383179903358.gif (236KB, 300x100px) Image search: [Google]
1383179903358.gif
236KB, 300x100px
>>57104402
Easy.
Here's an actually legit, working solution.
Best code I've ever writter.

std::vector<int> shitsort(int a, int b, int c) {
return{a<b?a<c?a:c:b<c?b:c,a<b?b<c?b:c<a?a:c:a<c?a:b<c?c:b,a>b?a>c?a:c:b>c?b:c};
}
>>
File: closeUpPepe.jpg (77KB, 653x590px) Image search: [Google]
closeUpPepe.jpg
77KB, 653x590px
>>57104666
>satan has downs syndrome
wew
>>
>>57104672
Let me just indent it nicely and it's perfect for the IOCCC

std::vector<int> 
shitsort(int a, int b, int c)
{
return
{
a<b?a<c?a:c:b<c?b:c,a
<b?b<c?b:c<a?a:c:a<c?
a:b<c?c:b,a>b?a>c?a:c
:b>c?b:c
} ;
}
>>
>>57104672
You were supposed to use 4 parameter as output parameter so you need reference or pointer.
>>
>>57099825
Orthographic projection, if you use GLM it has a function for that.

Probably a good idea to disable depth so you don't get crazy z fighting when things overlap.
>>
>>57104788
It's better to not disable depth, and use the z-value for sorting.
>>
File: worksOnMyMachine.png (441KB, 1600x1548px) Image search: [Google]
worksOnMyMachine.png
441KB, 1600x1548px
>>57104739
Fine, then I fixes it for you, now you have NO REASONS to complain.

void shitsort(int a, int b, int c, int list[3])
{
int*_=[=]
{
return
&extent<decltype(list)>::value
[list];}();(b-b)[_]=a<
b?a<c?a:c:b<c?b:c;(b/b
)[_++]=a<b?b<c?b:c<a?a
:c:a<c?a:b<c?c:b;*++_=
a>b?a>c?a:(c):b>c?b:c;
}
>>
>>57104933
>>57104933
OP here, this looks scary, gonna see if it works but will prob just try another problem. :P
>>
>>57105132
Please don't copy what I did, it's the worst solution possible!
But the function is actually pretty simple to do with a couple if statements.
Thread posts: 356
Thread images: 36


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