[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: 351
Thread images: 42

File: DPT.png (389KB, 934x1000px) Image search: [Google]
DPT.png
389KB, 934x1000px
Old thread: >>56971303

What are you working on /g/?
>>
deez nuts

HAH

GOTEEM
>>
>>56976481
Help, I recently graduated from a theoretical CS school and can't answer this programming interview question: "write a method that converts a floating type number to a rounded string with 2 decimal digits".

Here's my attempt that isn't working right.
    public string ShortenFloatString(float valueToShorten)
{
string xString;
string xString2 = "";

xString = valueToShorten.ToString();

if (xString.IndexOf('.') > -1)
xString2 = xString.Substring(xString.IndexOf('.'));

if (xString2.Length > 3)
xString2 = xString2.Substring(0, 3);

if (xString.IndexOf('.') > -1)
xString = xString.Substring(0, xString.IndexOf('.'));

if(xString2.Length > 2)
{
if(xString2[2] == '9')
{
int num = int.Parse(xString2[1].ToString());
if (num <= 9)
{
num++;
xString2 = "." + num.ToString();
}
else
{
num = 0;
xString2 = "." + num.ToString();

int firstNum = int.Parse(xString);
firstNum++;
xString = firstNum.ToString();
}
}
}
return (xString + xString2);
}


I have to email back the correct response soon.
>>
>>56976525
multiply it by 100 and convert it to an int
>>
>>56976525
return String.format("%.2f", valueToShorten);
>>
>>56976525
>>56976553
Don't waste your time on this guy he's extremely rude and entitled.
>>
>>56976562

As I said already, I'm pretty sure they want an implementation for ftoa, and not a one-liner that relies on String.format.
>>
>>56976563
How rude.
>>
>>56976572
in Python this is just
import solution
>>
>>56976525
Yeah, nah. You can fuck off from your attitude in the last thread.
>>
>>56976525
multiply by 100 and cast it to an int.

you CS people are fucking retarded
>>
>>56976525
>ShortenFloatString(1.999f) gives "1.10"
>ShortenFloatString(1.091f) gives "1.1"
>ShortenFloatString(1.089f) gives "1.08"

They won't notice, just submit it.
>>
>>56976572
import math
def convertToString (value):
roundedval = round(value, 2)
stringval = str(roundedval)
splitval = stringval.split('.')
string1 = splitval[0]
string2 = splitval[1]
print string1, " ", string2
convertToString(25.34123451345123)


what is ftoa?
>>
>>56976593
>>56976553
Casting a float to an int doesn't round it, it floors it you retards.
>>
>>56976643
the numbers after the . go away right
>>
>first time actually using a bash script to actually do something

Wew, feels great, worked on my first try too which is awesome. Just taking a folder of pictures and making blurred versions of each picture in another folder. Going to have my startpage background cycle with my desktop wallpaper, except blurred.
>>
>>56976634

Look it up.
>>
>>56976634
float to array doo
>>
>>56976643
Flooring is a form of rounding
>>
How do I take a string var in node.js and pipe it into a subprocess?
>>
>>56976643
>>56976666
Plus you can just add 0.5 and then multiply it by 100
>>
>>56976681
Print to string, check third digit after decimal to determine if you have to add 1 to second one, then simply trim that string.
>>
>>56976634
doesn't have a decimal point
>>
>>56976691
What are you on about? Add 0.5 and floor and you've got rounding to the nearest integer. You can also take away 0.5 and ceiling
>>
>>56976691
>>56976697
For instance

1.00 -> 1.50 -> 1
1.25 -> 1.75 -> 1
1.50 -> 2.00 -> 2
1.75 -> 2.25 -> 2
2.00 -> 2.50 -> 2
2.25 -> 2.75 -> 2
2.50 -> 3.00 -> 3
>>
>>56976694
just add a . in the space
i honestly dont get why the question asker is doing this in such a convoluted way? is t a part of the challenge that you cant use the builtin math functions?
>>
>>56976697
>>56976703
That's good. I guess I got carried away with that string manipulation.
>>
>>56976031
Wow I didn't get a single answer to my question, not even a suggestion that wasn't just
>fuck video games
>>
>>56976782
>>>hey guys where can i get some bleach to drink?
>>don't do it
>wtf why will nobody actually answer my question, not even a suggestion that isn't just >fuck bleach
>>
>>56976782
You didn't even mention what country you were from.
>>
>>56976800
burgerland, obviously
>>
>>56976808
Explains why you're such a fucking idiot
>>
>>56976782
make your own game, if your not learning brain surgery you dont need school.

stop acting like a whiny bitch.
>>
>>56976881
he's really into vidya, of course he's gonna be a whiny bitch
>>
>>56976794
>>56976800
>>56976808
>>56976811
>>56976881
>>56976888
>all onios
+1
>>
>>56976970
What?
>>
>>56976525
function otherGuysProblem(num){
num = num.toString().split(".");
if (num[1].length > 3){
num[1] = num[1].slice(0,2) +
(Math.round(Number(num[1].slice(2,4)) / 10));
}
return num.join(".");
}

Anyone could've done this
>>
>>56976794
You can get some bleach at your local grocery store.
Now answer his question

Or better yet, he should google it and not rely on people from 4han
>>
>>56977028
only rounds the last digit.
>>
>>56976553
I like this line of of thinking. You can just
String(Math.round(num * 100) / 100)
>>
>>56977073
What the hell would you expect it to do. Give me an example
>>
File: 1472327697330.jpg (54KB, 500x375px) Image search: [Google]
1472327697330.jpg
54KB, 500x375px
>>56976481
I need a fucking OpenSSL mage.
What's the difference between
SSL_get_verify_result()
and
X509_verify_cert()
?
Docs say the former "returns the result of the verification of the X509 certificate presented by the peer, if any."
And the latter "attempts to discover and validate a certificate chain based on parameters in ctx."

Are there two different kinds of verification?
Does the first function just get check if the second one succeeded?
I can't organize this API in my brain, it's just a collection of functions that seem superfluous or even contradictory in purpose, and many are deprecated or are lower-level alternatives to other functions.
What does the process of certificate verification look like using OpenSSL and C?
What is my flow?

I have this:
https://ghostbin.com/paste/vpukk
As you can see I have no idea what I'm doing.
>>
>>56977073
>2 decimal digits
if (num[1].length > 2){
num[1] = num[1].charAt(0) +
(Math.round(Number(num[1].slice(1,3)) / 10));
}

Replace the if statement with this.
>>
>>56977089
Oh, I assume you just used this.

I'm pissed I didn't come up with that to begin with, That looks nice doesn't it
>>
>>56977138
Speaking of OpenSSL how the fuck do I install it on windows.
>>
>>56976525
Could anyone tell me what's the benefit of knowing something like this? I am not really into CS/CE. I just like to try "programming" for ""fun"". I understand already they try to weed out the bad ones from the good ones, but I meant the actual question or "problem". Aren't most of them already done and provided freely online from other people?
>>
>>56977186
>Aren't most of them already done and provided freely online from other people?

Stop thinking like this, right now.
You're never going to get anywhere if you just copy paste solutions from pajeets on stack overflow.
>>
>>56977198
Thinking? I am just merely asking out of curiosity.
Would be great if you could explain the idea with putting out this kind of challenge(the one the poster mentioned about).
>>
>>56977138
i *think* the first one uses an ssl pointer and verifies the certificate used to open the connection. The second one is used to verify a certificate chain from the provided context

But i'm just guessing from examples here: https://www.ibm.com/developerworks/library/l-openssl/ and the docs. I've never actually used this myself and I've not done C in ~12 years sooo large grain of salt there.
>>
>>56977186
I'm the guy that gave the answer:
>>56977089

I don't know the benefit. I've been learning to code for a few months and I've realized I like making algos a lot better than making things.

From what I've heard from web developers, it doesn't have anything to do with the job. It may come up here and there and that's about it.

With other forms of programming, I'm hoping it's different. Mind you this is something people can do in a matter of minutes.
I'm curious what kind of work revolves around this kind of thing, where algorithms are more created in months etc.

But yeah, I think for 99% of programming you'll never need it.
>>
>>56977186
The point is for you to prove you have problem solving skills. Surely you know basic string manipulation and numeric calculation syntax in at least one programming language (these questions are give to CS grads remember), but can you combine the knowledge of those things into a solution to a specific problem? Or can you only follow directions and copy-paste from stack overflow? Most employers need independent problem solvers, otherwise you are just going to be pestering your co-workers for anything non-trivial and end up being a net cost on the team.
>>
>>56977267
These questions are given to everyone.
>>
>>56977262
>>56977267
Thanks, these are the kind of answers I like to read and get an understanding from.
>>
>>56977212

These aren't about solving a problem that hasn't been solved. Usually they are about seeing a candidate do this in real time (I don't get "mail in" coding interviews) and then throwing a few curve balls at them to see if they can adapt it. even if they memorized the solution to the base problem they need some aptitude to be able to adapt. As they do well you push them more and more to see how much is actual knowledge and experience and how much is reading interview books and copy-pasta from SO.

Anyone worth their salt going for a development job should understand the basics well enough to solve simple toy problems in a reasonable amount of time in the language they know best.

If you don't care about the jobs, then solving these might not be fun for you. Many people use them as tests of skill or challenges to see how well they can solve the problem. e.g. can I do it in less lines of code, can i make i run faster, etc. Others use them to practice knowing there are solutions they can draw from to learn where they get stuck or to validate their thinking.

*shrug* lots of reasons to know how to do this, but it's certainly not a requirement for anyone who just does this for fun and doesn't really care how things work. If you do start diving in to how the languages work then these tend to become fairly easy to pick up and solve.
>>
>>56977281
99% of programming job openings are going to require a CS degree or equivalent knowledge.
>>
Just opened an account here and playing with some data. https://www.quantopian.com/ Really interested in programming some algo with machine learning in the future.
anyone worked with this stuff before? Tips?
>>
>>56977298
Yeah, I have bootcamps in mind. Hack Reactor actually recommends you learn Js with codewars challenges, reading as little as possible
>>
>>56977426
Js syntax***
>>
Is this possible in any language?
unction add(n) {...}



add(1); //=> 1

add(1)(1); //=>2

add(1)(2)(1); //=>4


The only way I can think of to do it is to add a constructor to numbers, or to return some kind of thing that's a number in every context except for when it's invoked like a function.
>>
>>56977467
This is possible in Haskell:

add 1
add 1 1
add 1 2 1
-- same as (((add 1) 2) 3)
-- or in another language add(1)(2)(3)
>>
>>56977487
*1 2 1
>>
>>56977487

What is the type signature of the function add here? Because it would seem as though in Anon's example, it returns both an integer and a function, and not a product type of the two...
>>
>>56977467
That would require some weird type where it's a value, but you could call it as a function.
If I'm not mistaken, C++ is that retarded.
>>
>>56977467
This is FP 101, lisp-based languages will let you do things like
(+ 1)
(+ 1 1)
(+ 1 2 1)

Most imperative languages will let you do equivalent things by passing in arrays or an arbitrary number of parameters.
>>
>>56977512
>it returns both an integer and a function
Exactly, that's how it works in Haskell
You use some type class magic and then the typechecker can figure out which you need

Basically it ends up having a type
a -> r

and r is either the sum or another a -> r
>>
>>56977524

So it's a sum type? Like a union?

Although if you think about it, it would have to be a product type. Because it has to store both the integer returned and the function, depending on how the result will be used later...
>>
>>56977556
No, it's a polymorphic type that is either
r
or
a -> r
>>
>>56977487
Hey, what you implemented is not the same as what was pictured.

What you implemented in haskell is a variadic function which can handle multiple args.

That's possible in almost every language.

What's pictured here is:

add(1); //=> 1

add(1)(1); //=>2

add(1)(2)(1); //=>4

Return type of add(1) looks like a number, and yet that number has an overridden () function.
>>
>>56977563
That was one of the answers I was thinking could make this possible; a kind of data type that would act like a number in all situations except for when it's invoked with parenthesis.
>>
>>56977138
SSL_get_verify_result probably ends up calling X509_verify_cert; it's specifically a specialization for "I have this ssl connection, check to see if X509 certificate the server presented verifies against my collection of CA certs."

You'd use X509_verify_cert in a situation where you may not necessarily have an ssl connection set up and just want to verify that a cert can be validated against a set of CA certs. This is pretty reasonable since there's no reason you can't use an X509 cert to check the signature of an arbitrary piece of data not associated with an ssl connection.
>>
>>56977467
C++

 
int function(vector<int> vector);

function(vector<int>(1,2,1));


Can also use ellipses.
>>
>>56977556
>>56977563
Oh, when I say "either" I don't mean like a sum type, I mean that it's kind of like a template or a generic with a restriction kind of like type traits or interfaces


>>56977570
It is what you wanted though.
Haskell functions only accept 1 argument.
It quite literally gives you back something that is either a number (result) or a function
>>
>>56977588
x=add(1); // =>1
y=x(1); // =>2
z=y(2); // =>4

This is what I believe he wanted and your haskell add function does not allow that.
>>
>>56977601
It does allow that
>>
>>56977514
Yeah I was thinking C++ could let me overload operator().

Was actually going to hop into C++ and start fucking around with that.

Only problem I can't think of, on how to solve, is to make the 'class' or whatever behave like a number in all other situations

>>56977516
I know a little but of lisp and + 1, + 1 1, + 1 1 is same as add(1), add(1, 1), add(1, 1, 1) - variadic arguments.
Not same as add(1)(1)(1), where the returned data type acts a number in all situations save for invoking ()
>>
>>56977607
Show us the implementation.
>>
>>56977615
Working on it
>>
>>56977563

If it only could return r or a -> r, then one could not do add 1 2 1. The add 1 call would return an a -> r, not an a -> a -> r. What is described could be used at least once more, and presumably, used indefinitely.
>>
>>56977628
No, because r (the return type) could be another function
>>
>>56977609
You can overload the cast operator so that your object gets implicitly converted to an int when an int is required.
>>
>>56977632
Rather than converting something to an int, what would make this doable would be to convert it to a function when required
>>
File: polyvariadic function.png (32KB, 821x482px) Image search: [Google]
polyvariadic function.png
32KB, 821x482px
ok, but you get problems if you use stuff like x/y/z multiple times as arguments (in z I use x once)
>>
>>56977678
and the type is
forall r. SumT r => r

so basically, any r that has an instance for SumT - which includes
Integer
Integral -> Any SumT (and SumT could be another Integral -> ...)
>>
>>56977630

Oh. Derp. I thought r was representing the integer return value.
>>
>>56977704
The point is that r _could_ be an integer return value, or it could be another function - which in turn count return an integer, or another function, etc etc
>>
>>56977711
and when I say could
it's entirely up to the person calling it
it is both until specified otherwise
>>
>>56977678
Whoops, never mind about the problems, I was just an idiot and the code I first tested had z include itself.

If it could short-circuit that might be interesting though.
>>
File: image.png (144KB, 1297x1030px) Image search: [Google]
image.png
144KB, 1297x1030px
/dpt/-chan, daisuki~

>>56977570
Observe the power of python and object orientation (pic)

>>56976712
>>56976634
Pic (bottom right)

>>56976481
Thank you for using an anime image.
>>
oh and a really good example of a polyvariadic function in Haskell is a printf implementation
>>
>>56977779
Python classes return their arguments??
>>
Okay, question guys, I have to take a course on coursera or edx for a subject in my school.
It doesn't matter which one it is, because I don't have to present the content of it, just the syllabus, the looks, basically the teachers are going to be grading our presentation.

Anyway, which would be a good course to take, to teach me more about computer security? I don't know that much about coding, so I was thinking I'd either go with a course about C# or SQL, but I don't really know.
>>
>>56977779
what happens if you do

add(1)(1) + add(1)(2)
>>
>>56977779
wait if there are no explicit types in python then the 'int' in the parameter list is simply a variable, no? how is 'int' returned?
>>
I'm sorry for ever saying that Microsofts C compiler is decent. I take it back.

Microsofts C compiler is nonexistent.
>>
>>56977874
Microsoft don't even exist
>>
Is making a browser plugin hard?
>>
>>56977880
add-on*
>>
>>56977829
>>56977857
everything is an object in python, even procedures and integers.

object(...)
is syntax sugar for
object.__call__(...)
thus every object that has the __call__ method is callable.

for example

def foo(n)
return n + n

foo(1)


is actually

foo = function("return n + n")

foo.__call__(1)


>>56977855
>> 5

https://ideone.com/iJaJkq
>>
>>56977467
>>56977570
I took a go at this using C++ (by the way, I'm not a sepplesfag) and I don't think I've ever been more disgusted at myself.
#include <iostream>

template<typename T>
class shit {
T val;

public:
shit(T v): val(v) { }

operator T() const {
return val;
}

shit& operator()(const shit &rhs) {
this->val += rhs.val;
return *this;
}
};

int main()
{
shit<int> add(int);
std::cout << add(10)(20)(30)(40) << std::endl;
}

shit<int> add(int v)
{
return v;
}

People actually defend this language.
>>
>>56977904
so then does

add(1)

does the '1' go into the 'self' parameter, or the 'n' parameter?
>>
>>56977779
its a proof of concept (like thats even necessary) I wasn't thinking about validation and stuff
>>
>>56977924
I can tell what everything does except for

operator T() const {
return val;
}

What's operator T() const?

I think T is the template type right? So is that similar to saying some like 'int()' ?

Is that a/the type-casting operator?
>>
>>56977957
const on member functions means "this functions does not modify the state of the object"
>>
>>56977967

that aside what does 'operator T()' mean?
what is 'T()' ?

If the template type is in.. like shit<int>

Is that like saying 'operator int()' ?
>>
File: epik.jpg (19KB, 158x157px) Image search: [Google]
epik.jpg
19KB, 158x157px
>mfw when using
(syntax-rules)
and
(ir-macro-transformer)
side-by-side

I-is this it lads?
Is this what unlimited power feels like?
How can languages that aren't Scheme even compete?
>>
>>56977830
pls respond, what's the most common knowledge a person working as a security administrator has to posses?
>>
starting to make sense...
class classname(inherit):
.....

Ok so inherit, if it's int, is actually a special key word...

I tried
>>> int(3)
and got 3

so int is a kind of class in Python that can take a number and return it.

so

class add(int):

does this mean that because add inherits from int, it can do the same thing as:

int(2) // 2
>>
File: shitgetserious.png (298KB, 2271x2380px) Image search: [Google]
shitgetserious.png
298KB, 2271x2380px
>>56977927
>tfw [code ] is nestable.

oh, sorry.

the self/this argument is explicit in python but a method object which bind an instance to a class procedure is made to avoid passing the said argument every time you call a method.

for example,
class Foo:
def bar (self):
print(self)

ins = Foo()



here, ins.bar is not the same as Foo.bar but a method object created during the instantiation that bind Foo.bar to ins

something like

procedure insBar():
return Foo.bar(ins)

ins.bar = insBar
>>
If you want to feel unlimited power, try abusing method_missing and instance_eval in Ruby... along with the ability to arbitrarily add and remove methods from the base classes.
>>
>>56977874

Thank you for finally realizing that. Now use MinGW or Clang with MSYS2 or Clang with Microsoft Codegen for compiling C on Windows.
>>
File: frame-0046.jpg (247KB, 1440x900px) Image search: [Google]
frame-0046.jpg
247KB, 1440x900px
Playing with Processing and making cute wallpapers.
>>
>>56977467
(define-syntax add
(syntax-rules () ((_ (n) ... ) (+ n ...))))


(add (1) (2) (1)) -> 4
>>
>>56978062
is this possible in multiple versions of lisp?
>>
>>56978050
wait so you're saying that in the class (Foo) definition we have to put self as an explicit parameter.

but when we instantiate Foo, we can call Foo's methods and self will be implicitly passed as a 'hidden' 1st argument, which will land in our 'self' which we explicitly defined when we defined Foo?
>>
>>56978105
>but when we instantiate Foo, we can call Foo's methods and self will be implicitly passed as a 'hidden' 1st argument, which will land in our 'self' which we explicitly defined when we defined Foo?

Meant:
but when we instantiate Foo, we can call (THE INSTANCE VARIABLE)'s methods and self will be implicitly passed as a 'hidden' 1st argument, which will land in our 'self' which we explicitly defined when we defined Foo?
>>
>>56978080
it's scheme, not list
but as far as I know, syntax-rules and ellipsis are part of the standard and should be supported by every implementation
>>
>>56978116
They're standard but they're not supported by all implementations. I believe most of the major ones do though.
>>
This is how we break the rules in Ruby:

class Integer
alias :call :+
end

def add n
n
end

add(5) # => 5
add(5).(7) # => 12
add(5).(7).(2) # => 14
add(5)(7) # => syntax error, but it would be like this with any callable object.
>>
>>56978042
int(1) is actually nothing more than calling the constructor of the class int. everything is an object, even types which are instance of the the class `type`.

therefore,
class add(int):
...


makes `add` a type which has the same behavior as the type int.

>>56978105
>>56978115
yes, that makes high order programming much easier since a method is bound to its specific instance.

if foo.bar(...) were just syntax sugar for Foo.bar(foo, ...), then you couldn't pass foo.bar without also passing the instance.

for example with this system, you can do

https://ideone.com/jHiLoK
>>
I'm trying to print out a 2 dimensional array of my datatype but I get this compiler error.
Error subscripted value is neither array nor pointer nor vector.
void printField(cell field)
{
for(int i = 0;i<rows;i++)
{
printf("%c", field[i][i].current);

}
}
Here is my datatype declaration.
typedef struct{
char current;
char next;
} cell;
>>
So, do you guys contribute to any FOSS projects?
>>
Can anybody explain pointers to me? I don't get them, at all. I mean, I get the whole "when you order from Amazon you don't uproot your home and go to them to pickup your delivery, you send them your post code and have it delivered to you" part, but I can't get my head around translating it to programming since it's all hapenning within the same processor.

And also, what's up with pointers to pointers?

I'm starting to wonder whether it would be better to pickup asm basics to see if they give me any insight into those fucking pointers. They are supposed to be a very basic concept and I'm stuck on these fucks for like 2 years now.
>>
>>56978361
>And also, what's up with pointers to pointers?
What's so complicated?
>>
Thanks for reminding me that "mediocre" means "better than >99% of the ""programmers""" these days.
>>
>>56978382
>falling for the "most programmers are shit" memes
>>
File: koreans_during_la_riot.jpg (127KB, 1200x861px) Image search: [Google]
koreans_during_la_riot.jpg
127KB, 1200x861px
>>56978346
i contributed to the official /dpt/ c library for some time.
>>
>>56978405
link?
>>
>>56978402
>pointers
>2 fucking YEARS

And don't get me started on webdevs.
>>
>>56978425
he's a /dpt/ programmer tho
>>
>>56978336
field doesn't appear to be an array, pointer, or vector. It's just a single value. You can't index into a single value.
>>
>>56978336
Also, do you mean to print the full array, or just the main diagonal? Because your code is set up to print the main diagonal (every time you index into field, you're using the same x and y).
>>
>>56978361
Things are stored in memory. The computer knows where things are stored in memory by their address. Pointers hold the address.


int thisIsAnInt;

thisIsAnInt= 5; //we have assigned the integer value 5 to the memory where thisIsAnInt is stored

int *thisIsAPointerToAnInt;

thisIsAPointerToAnInt= &thisIsAnInt; //the & gives us the memory address of a variable. we have assigned the address of thisIsAnInt to the memory where thisIsAPointerToAnInt is stored. Note that thisIsAPointerToAnInt is not a memory address, it is a variable that holds a memory address, as such it needs it's own memory address to store that address.

int **thisIsAPointerToAPointerToAnInt;

thisIsAPointerToAPointerToAnInt= &thisIsAPointerToAnInt; //we have assigned the address of thisIsAPointerToAnInt to the memory where thisIsAPointerToAPointerToAnInt is stored. As pointers are not memory addresses, but merely variables that hold memory address and need their own memory addresses, this pointer to pointer will not hold the same address as the pointer it points to, it will hold the address of the pointer itself.

int thisIsAnotherInt= thisIsAPointerToAnInt; //this won't work because we are trying to assign the memory address the pointer points to a non-pointer. Instead we must dereference.

thisIsAnotherInt= *thisIsAPointerToAnInt; //this will work. The dereference operator looks into the memory address held by the pointer to retrieve the value.

thisIsAnotherInt= *thisIsAPointerToAPointerToAnInt; //this won't work. Although we've dereferenced our pointer, the value it points to is another memory address so we must double dereference.

thisIsAnotherInt= **thisIsAPointerToAPointerToAnInt;

int *thisIsAnotherPointerToAnInt= *thisIsAPointerToAPointerToAnInt; //here we've dereferenced the 'pointer to a pointer to an int' to retrieve the 'pointer to int' and assigned the memory address it holds(as opposed to it's own memory address) to another pointer to int.
>>
>>56978361
well you know how an array works right?

just envision all of your memory written to a single linear array

a pointer is just a number of the index where that data begins

so if you have some data
F A G G O T
stored at indices
1488 1489 1500 1501 1502 1503
in the midst of all the other memory, a pointer would just be the number 1488, where the data begins, rather than the literal values
F A G G O T


in C, referencing an array index with
array[n]
is just syntactic sugar for the pointer (memory address number) where the array begins + n
>>
Bored.

(define (make-goal n src dst)
(lambda (stack)
(if (> n 1)
(let ((aux (- 6 (+ src dst)))
(m (- n 1)))
(append (list (make-goal m src aux)
(make-goal 1 src dst)
(make-goal m aux dst))
stack))
(begin (display "move disk from peg ")
(display (number->string src))
(display " to peg ")
(display (number->string dst))
(newline)
stack))))

(define (hanoi n)
(letrec ((loop (lambda (stack)
(if (null? stack)
'done
(loop ((car stack) (cdr stack)))))))
(loop ((make-goal n 1 3) '()))))
>>
>>56978653
>thisIsAPointerToAPointerToAnInt
Fucking coding conventions

Every time
>>
Found a ML facial identification model and coding a lookalike program with a precomputed feature database in C++.Because I'm stupid,I coded my own simple way to store the features.

Now for some reason I can't read the whole file - both .eof() and .tellg()<length (length computed by .seekg() an verified with 'du -b database') hang up and return -1 for some reason,i'm guessing at the same place.Any ideas?
>>
>>56976481
Learning SDL. Is it worth it? I just want to try making some basic games and practice my c.
>>
>>56977467
variadic functions are ew. better to pass a list as an argument if you need to
>>
>>56978666

Interesting choice of example numbers there, /pol/.
>>
>>56978732
>can't do basic file IO in C++
>somehow thinks he is able to do the other part
>>
>>56978653
 
*int thisIsAnIntToAPointer; //this holds a memory address in the form of an integer. to assign it, we must cast a memory address to it.

int thisIsAnInt=5;
thisIsAnIntToAPointer=static_cast<int>(&thisIsAnInt); //seems like it's just an int, but if we dereference it, it will give us the memory address.

int *thisIsAPointerToAnInt= *thisIsAnIntToAPointer;
int **thisIsAPointerToAPointerToAnInt= &*thisIsAPointerToAnInt;
*int *thisIsAPointerToAnIntToAPointer= &thisIsAnIntToAPointer;
>>
>>56978848
That's the only part that doesn't work tho.
>>
File: 7884933.jpg (197KB, 953x797px) Image search: [Google]
7884933.jpg
197KB, 953x797px
I'm gonna teach myself how to program, what should I know? I'm thinking I'll start in java.
what's the best tutorials? best skirts for programming? etc
>>
File: blackdress.jpg (136KB, 1000x1666px) Image search: [Google]
blackdress.jpg
136KB, 1000x1666px
>>56978940
you get the best skirts at zalando.
dont forget to buy a pair of programmig socks too/
>>
>>56979018
I have rainbow stockings, those will do. what about tutorials/books/etc?
>>
File: 1474373650932.png (164KB, 413x352px) Image search: [Google]
1474373650932.png
164KB, 413x352px
>>56979018
>>56979031
Funny meme, mate XD
>>
>>56979034
it is, I enjoy it a lot.
>>
>>56979031
usually the in the op...
here u can download some books:
https://github.com/vhf/free-programming-books/blob/master/free-programming-books.md
>>
>>56979044
there's quite a lot there, do you know what's suitable for a beginner?
>>
File: serveimage-80.jpg (358KB, 2028x1522px) Image search: [Google]
serveimage-80.jpg
358KB, 2028x1522px
>>56978940
>>56979018
>>56979031
hello :D
>>
>calculating max_height of binary tree with 9000 shuffled values
This supposed to take.. a while? Need to do it for 800 separate fucking trees

Using the standard recursive method, can I optimize this somehow?
>>
>>56979096
Cache the values while building the tree, but requires more ram
>>
>>56979169
no clue how to do this
>>
>>56976481
>What are you working on /g/?
A C compiler to output any syntax of assembly I tell it, or just a raw binary. No ELF or any bullshit like that. https://github.com/Penot1/CASM
>>
>>56979277
>no elf
Why do you hate Christmas?
>>
>Java arrays cannot contain more than 2 billion elements
What did they mean by this?
>>
>>56979307
India's Manifest Destiny
>>
>>56979277
There's nothing wrong with writing a compiler for fun, but most C compilers can spit out assembly, and what do you have against ELF? Do you want your compiler to not be useful or something?

>>56979307
For some dumb reason, java uses signed 32-bit ints for array lengths, so they're limited to 2^31 - 1 elements, which is pretty fucking stupid.
>>
>Sometimes you simply want to copy elements from one existing array to another
>existing array. The System.arraycopy() method is designed to do this efficiently,
>and you can assume that Java VM implementations perform this method using
>high-speed block copy operations on the underlying hardware.

I can't handle how Java people talk. It's like they take pride in their own ignorance.
>>
>>56979328
>>56979301
The no ELF is because I'm making it for my operating system which doesn't have an ELF loader. I might add an option to have it link against ELF libraries and output an ELF executable but I dunno.
>>
Computer sciences are very feminine. Honestly, it gives me a boner when I see a guy programming in public because it's like wearing lipstick and a skirt. I only come to this board for all the cute boys who worship gnu/linux and writes code.
>>
>>56979374
Why do you keep posting this?
>>
>>56979391
Because that's what I feel.
>>
>>56979374
>>56979396
Nobody cares about your degenerate opinion, mate.
Maybe you should go back to tumblr, where you can be with like-minded scum.
>>
>>56979396
You could at least write something new every time you feel, and not post the same stale pasta.
>>
>>56979405
don't be rude.
>>
>>56979437
it's literally been posted twice, it's the theoretically freshest pasta possible.
>>
>>56976481
How hard would it be to make a simple 3D environment where you can walk and jump in C? Which libraries I would need?
>>
>>56979328
>For some dumb reason, java uses signed 32-bit ints for array lengths, so they're limited to 2^31 - 1 elements, which is pretty fucking stupid.

hotspot predates x64 for by several years
>>
>>56976525
dont bother, you're hopeless, you'll never make it
>>
>>56979455
That's one time too many.
>>
What is the perfect feet smell for programming
>>
Ok /dpt/, let's make an opensource distrusted alternative to Google Assistant that doubles as a search engine and we call it Lain
>>
>>56979626
I'll make the logo
>>
File: 14783672843874.png (174KB, 400x400px) Image search: [Google]
14783672843874.png
174KB, 400x400px
>>56979631
>>
so, in my program I am memory mapping a file. I have a char pointer to said memory mapped file. I also have a function to read a line from the char pointer.
char* readline(char* file, int line)
{
int l = 0;
char* temp = (char*)malloc(2048);
for(int i = 0;;i++)
{
temp[i] = file[i];
if(file[i] == '\n')
{
l++;
}
if(l == line || i == 2048)
{
return temp;
}
}

}

it basically reads until it finds the newline character and it also stops when an overflow is about to happen.
did i do good or do i deserve compsci_grad.png?
>>
I've been thinking about memmove in the presence of memory mapped in multiple places.

Let's say you have char *a, *b; which point to different addresses such that the pages [a, a + 4096) and [b, b + 4096) don't overlap. Now let's assume that those two pages refer to the same memory.

The common memmove implementation will now check if a < b or a > b and then copy byte by byte in the right direction. Naturally this is wrong because the pages overlap.

What part of the C standard forbids using memmove with such overlapping pages?
>>
>>56979625
fresh and mild
>>
>>56979670
i already found a goof myself
i should just include the || i == 2048 in the for loop
for(int i = 0;i<2048;i++)
>>
>>56979525
Fairly easily, if you already know vector/matrix mathematics. If not, it's going to be harder.

You also need some way to create data for your environment. You could try loading Quake maps, the BSP format is very well documented. And then you can use already existing Quake mapping tools to make levels. You just read the BSP structure and use the PVS to determine what's visible. Easy money. In the late 90's and early 2000's, making a Quake 1/2 level viewer was practically a rite of passage for aspiring 3D programmers.

Rendering is the hardest part. The easiest way is to just use OpenGL. It takes a few hundred lines to set up modern a OpenGL environment with shaders and buffers (add a few hundred more if you're under Windows and need to load OpenGL extensions because Windows isn't going to do that for you). Then you just determine what's visible based on camera position and view direction, update the buffers and issue a few drawcalls and that's it.

If you don't want OpenGL, you better already know how to project, clip and render texture mapped 3D polygons in software. You know assembly, right? Without assembly it's going to be too slow if you need more than a few hundred polygons.

For creating a window and reading keyboard/mouse, you have glfw and SDL2. Both are C libraries and will only take a 20-30 lines to set up. Enjoy!
>>
>>56979556
Languages like C and C++ use typedefs like size_t to get around these sorts of silly issues.
I don't know why Java didn't do something similar, or just use a largest possible integer type.
>>
class intSet(object):
def __init__(self):
self.vals = []
def insert(self, e):
if not e in self.vals:
self.vals.append(e)
def member(self, e):
return e in self.vals
def remove(self, e):
try:
self.vals.remove(e)
except:
raise ValueError(str(e) + ' not found')
def __str__(self):
self.vals.sort()
result = ''
for e in self.vals:
result = result + str(e) + ','
return '{' + result[:-1] + '}'
>>
>>56979709
Thank you for the comprehensive answer, but I am not looking to make my own 3D engine, that would be too much for me. What I want is a simple 3D library where I wouldn't have to touch OpenGL. Something like Irrlicht, but for C.
>>
>>56976525
so did you get the job?
>>
>>56979684
Memory mapping isn't a concept in the C standard, so it doesn't have any requirements about it.
Even then, memmove works fine if the address space overlap. It moves them "as if" copied to a temporary buffer first. You're probably thinking of memcpy.
With memcpy, it seems like it would just be undefined behaviour. You're copying between objects that overlap. I don't think there is a requirement that the objects have to be at the same place in memory to be overlapping.
>>
>>56979862
>You're probably thinking of memcpy.
No, I'm thinking of memmove. The typical memmove implementation looks like this:

if (dst < src) copy_downwards; else copy_upwards;
>>
>>56979781
Unfortunately most 3D engines and environments tend to be written in C++.

But take a look at Corange (https://github.com/orangeduck/Corange). Maybe it suits your needs.

Wikipedia has a list of game engines (https://en.wikipedia.org/wiki/List_of_game_engines), sort it by language and see if something interesting pops up.
>>
>>56979894
I don't know then. This seems like an incredibly obscure and esoteric situation that you should probably bring up on some POSIX/glibc/GCC/whatever mailing list, not 4chan.
>>
>>56979781
https://github.com/septag/darkhammer

I think that at least one of the python bindings for irrilicht had c wrapper which you could use.

Writing C wrapper for c++ game engines is one approach.
You could try with engine in some other language that talks easily to C like pascal, haskel, ocaml but it would likely require you to write some kind of wrapping code.
>>
>>56976525
lol
>>
File: recording-43.gif (364KB, 400x280px) Image search: [Google]
recording-43.gif
364KB, 400x280px
>>56979781
Not the guy that replied you but for character movement you need a physics simulator to detect collision. Using plain OpenGL is retarded unless you want to learn about 3D concepts, you should go with Ogre3D/Irrlitch.

I made this with C++ and Ogre3D and bullet, that is as close as you can get without using direct OpenGL or a defecation like Unity.

There aren't any pure C engines that are mature enough for proper usage.
>>
>>56976481
>float values aren't actually accurate
What the fuck? I thought I was on a computer?
>>
>>56980217
>I thought I could store every possible number in 32 bits
what did he mean by this?
>>
>>56980162
I'd wrap your engine
>>
>>56980235
I'm a 64-bit mainframe with blast processing, Pajeet

ALL THIS POWER
>>
>>56979525
This guy seems to do it, not sure what libraries he uses
http://jonathanwhiting.com/writing/blog/games_in_c/
>>
Is _Bool an integer and subject to integer operations?
>>
>>56980359
False
Thats a bool
>>
>>56980370
I tried this
/* bool.c -- a test for boolean integer qualities */
#include <stdio.h>

int main(void)
{
_Bool boolean;
boolean++;

printf("Boolean now equals: %d\n", boolean);

return 0;
}


and it printed

Boolean now equals: 81
>>
>>56980359
_Bool is integer type that can hold values from 0, 1
>>
>>56980370
Its an int if you are using < C99. According to stdbool.h:

typedef int _Bool;


>>56980392
You have to initialize it first to something like this _Bool boolean = 123123; and then compile it using > C99. It comes with a built-in datatype called _Bool and that shouldn't work.
>>
>>56978060
pretty
>>
>impying programming is fun
>>
>>56980470
It is for high IQ people
>>
You should not use Sepples because

1.templates are easily replaced by macros and _Generic (which selects arguments by compile-time type(without any float/int promotions!)
2.function overload is replaced by above as well.
3.Classes are essentially structs with function pointers.
GCC supports constructors(attribute constructor) and destructors(attribute cleanup) in plain C
http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc
http://echorand.me/site/notes/articles/c_cleanup/cleanup_attribute_c.html
4.constexpr can be rewritten as expression macros ({macro;return var;}) which will be optimized via constant propogation(but unlike constexpr can be runtime dependent).
5.GCC has new apply function for plain C
https://gcc.gnu.org/onlinedocs/gcc/Constructing-Calls.html#Constructing-Calls
6.Thread-safe atomics built-ins in Plain C
https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html#g_t_005f_005fatomic-Builtins
>>
File: moot.jpg (85KB, 1024x512px) Image search: [Google]
moot.jpg
85KB, 1024x512px
>>56980470
Who Are You Quoting?
>>
>>56977467
if you require a final () to get the value (i.e. the result is () -> Int), you can do
function add(n) {
return (x) => !x ? n : add(n + x);
}
// add(1)(2)(3)() === 6
>>
File: 1475580940102.png (20KB, 506x606px) Image search: [Google]
1475580940102.png
20KB, 506x606px
>tfw to intelligent to program in python
>>
>>56980520
>It is for high IQ people
>>
do you guys make a "TODO list" before writing any code?
>>
>tfw too busy having a well paying job and succesful life to use C/ C++
>>
i'm following this tutorial
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
where do i put the php files db_config.php and db_connect.php?
>>
>>56976511
Ben?
>>
File: autism.png (15KB, 105x137px) Image search: [Google]
autism.png
15KB, 105x137px
>>56980610
yes anon :)
>>
>>56980608
I know that feel
>>
File: ika_what.gif (1MB, 500x282px) Image search: [Google]
ika_what.gif
1MB, 500x282px
>mfw trying to understand how Iterative closest point calculations work
>>
>>56980613
i try to solve any problems before i start coding, and start coding only when i have an idea in my head of a solution that should work. i create TODO's as i go along. ie if i use a function that i'm counting on future-me to implement, i type //TODO make function so and so
>>
>>56980651
if it makes you feel better
>>
>>56980681
If what makes me feel better?
>>
>>56980593
#include <iostream>

struct add {
int i;

add(int v) : i{v} { }

add operator()(int v) {
return { i + v };
};
};

std::ostream &operator<<(std::ostream &os, add const &a) {
return os << a.i;
}

int main() {
std::cout << add(1)(2)(3) << "\n";
}
>>
File: dad_of_the_year.webm (2MB, 1335x720px) Image search: [Google]
dad_of_the_year.webm
2MB, 1335x720px
>>56980702
>>56980684
Late (>>56977924)

>>56980613
Yes, i maintain a todo of what should be done next but nobody should start to undertake a large project. You start with a small trivial project, and you should never expect it to get large. If you do, you'll just overdesign and generally think it is more important than it likely is at that stage. Or worse, you might be scared away by the sheer size of the work you envision. So start small, and think about the details. Don't think about some big picture and fancy design. If it doesn't solve some fairly immediate need, it's almost certainly over-designed. And don't expect people to jump in and help you. That's not how these things work. You need to get something half-way useful first, and then others will say "hey, that almost works for me", and they'll get involved in the project.

>>56979525
https://github.com/fogleman/Craft

>>56978410
Previous experiences have taught me that you should never share code on /dpt/. There are truly evil and negative people outta here.
>>
>>56980681
it makes him feel better being smarter than you indeed
>>
>>56980608
>>56980661
We ALL know that feel
>>
File: 1.png (1KB, 972x431px) Image search: [Google]
1.png
1KB, 972x431px
When you see a job posting telling that you will receive $ 80 K / year, how much of that goes into taxes?
>>
>>56980777
remember to vote
>>
>>56980777
None if you live in a libertarian paradise.
>>
>>56980702
any language can do that
>>
>>56980789
i'm not even American, just wondering about the job salary there
>>
>>56980777
120%
>>
>>56980796
Do it in C.
>>
>>56980804
No.
>>
do it to chorong
>>
>declaring a method synchronized makes the method thread safe
what did the author of the java book mean by this?
>>
>>56980830
mutual exclusion
>>
>>56980830
what did you mean by this?
>>
>>56980845
>mutual exclusion makes things automatically thread safe
what did you mean by this?
>>
>>56980851
>>56980870

>what did you mean by this
What did they mean by this?
>>
>>56980870
>he doesn't know what deadlocks are

what did you mean by this?
>>
>>56980943
>they didn't teach him the difference between livelocks and deadlocks
what did common core mean by this?
>>
>The volatile modifier says that the value of a field must
>always be read from and flushed to main memory, and that it may not be
>cached by a thread (in a register or CPU cache).

>or CPU cache
what did the java book mean by this?
>>
>>56979626
Looks promising
>>
>>56980777
About 28%-40% depending upon the state and your deductions.
>>
Does anyone here experienced with cmake?

I cannot seem get cmake to link the library without being too specific.

I have a library I have installed myself, so I am sure that everything about that is the problem.

It is located in /usr/local/lib, but I want cmake to be able to find it automatically.

eg. my libary is /usr/local/lib/libapp_x86.a

This works
find_library(
APP_LIBRARY CONFIG REQUIRED
NAMES app_x64
PATH_SUFFIXES lib
NO_DEFAULT_PATH
PATHS /usr/local/lib
)


How do I make it find it where I am less specific?
>>
>>56980990
The CPU cache is a special piece of high speed ram that is part of the CPU. When the CPU needs to access a piece of memory, it will copy it to the CPU cache first, then do a few operations, then copy it back to the main ram when done.
>>
#define add(n) n + add
#define add 0

nothin personnel niggos :^)
>>
>>56981023
what does that have to do with volatile?
>>
>>56981051
like the book says, volatile means anything written to the cache must immediately be copied back to main ram. It prevents issues when writing to memory from multiple threads.
>>
i'm following this tutorial
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
but it's written for WAMP and not LAMP. i created a folder android_connect in var/www and created the php test file, but when i go to http://localhost/android_connect/test.php it says not found on this server. what am i doing wrong?

i asked in /wdg/ and it's dead
>>
>>56981085
I don't think you know how the cache actually works and neither does the author of this book. No wonder my quips don't have the desired effects.
>>
>>56981046
add(5)(4) * 3
>>
>>56980990
>not cached in CPU cache
How the fuck are they going to make that work?
Sounds slow as fuck if they can. Storing in CPU cache shouldn't even matter in architectures where caches are write-back and there is cross-core cache access lines for shared data (like x86).
>>
>>56981046
is this c ?

#include <stdio.h>

#define add(n) n + add
#define add 0

int main(void)
{
int n = add(5)(6)(7);
printf("%d\n", n);
}


prog.c:4:0: warning: "add" redefined
#define add 0
^
prog.c:3:0: note: this is the location of the previous definition
#define add(n) n + add
^
prog.c: In function 'main':
prog.c:4:13: error: called object is not a function or function pointer
#define add 0
^
prog.c:8:10: note: in expansion of macro 'add'
int n = add(5)(6)(7);
>>
God damn this Java book is really Pajeet tier.
>>
>>56980392
>initialized variable
>>
>>56981120
>implying it's same cpu.

java threading model date from an era where parallel multi threading were done mainly on multi processors motherboard.
>>
>>56981114
Why do you think that?
>>
>>56981005
thanks for the first serious answer
>>
>>56981210
Because the cache is coherent. There is no point writing anything back to main memory because only one cpu at the time can have write access to a location in the cache.
>>
File: frame-0020.jpg (249KB, 1440x900px) Image search: [Google]
frame-0020.jpg
249KB, 1440x900px
>>56980456
You like that, huh?
>>
>>56981241
how to make this?
>>
>>56981259
paint
>>
>>56981241
yea man, but is that all you can do is triangles?
>>
>>56981279
No. i can do your mom too
>>
>>56981297

B T F O

T

F

O
>>
File: ss (2016-10-02 at 03.03.36).png (163KB, 798x798px) Image search: [Google]
ss (2016-10-02 at 03.03.36).png
163KB, 798x798px
>>56981279
I prefer shapes that tile and triangles are the simplest. Squares are not as interesting and hexagons are slightly more difficult, but they're doable in like five minutes.

Then there are more complicated things like the Penrose tiling (pic related), which would be extremely cool, but I'm not sure how to generate it such that it's both efficient and easily maintainable and modifiable.
>>
>>56981336
ooh that looks really good. Do you just start from the center for the triangles or do you just go from the top left to the right then down
>>
>>56981336
The more interesting question is how many different colors do you need to color it so that no two adjacent fields have the same color.
>>
>>56980811
thanks for saving me the time. how much would you accept to do my daily shitposting for me? I can set up a contract and transfer my trip code
>>
>>56981383
I go by lines from top to bottom and randomise the colours depending on the point's distance from the center.

>>56981399
4
>>
>>56981415
>4
proofs?
>>
>>56981415
can you make the triangles flash?
>>
>>56981399
at least five
>>
>>56981232
huh? But that's the whole reason volatile needs to flush the cache on every write. So that other CPU's can immediately see the change in main memory. Unless I'm missing something.
>>
File: 1462238903818.jpg (78KB, 449x600px) Image search: [Google]
1462238903818.jpg
78KB, 449x600px
>>56980520
>>56980556
>Falling for it
>>
>>56981441
Read http://www.morganclaypool.com/doi/abs/10.2200/S00346ED1V01Y201104CAC016
>>
>>56981415
>4

no, there are shapes that touch four different other shapes, no way 4 colors fit there
>>
>>56981449
Looks interesting, but I'm not all that interested in how the cache works to read a big article like that.
>>
File: triangles.webm (848KB, 999x801px) Image search: [Google]
triangles.webm
848KB, 999x801px
>>56981426
https://www.microsoft.com/en-us/download/details.aspx?id=52574

>>56981429
That's actually what I'm doing. The colours change in each frame, I take a screenshot and pick which ones I like.

>>56981436
The proof for this is a bit simpler than the 4 case.

>>56981450
You're right. It depends on how you define adjacency.
>>
>>56981471
>coq
that's homosexual
>>
>>56981471
>It depends on how you define adjacency.
y
>>
>>56981488
The usual definition, roughly speaking, is that two faces (shapes) are adjacent if they touch with at least one edge, not vertex.
>>
class Test {
static int i;

static {
System.out.println("In Test: " + Main.i);
i = 1;
}
}

class Main {
static int i;

static {
System.out.println("In Main: " + Test.i);
i = 1;
}

public static void main(String[] args) { }
}

Fucking java I can't even right now.
>>
>>56981501
correct, also the definition when dealing with map coloring

i was just being unusual for some reason
>>
>>56981203
Does NUMA not allow cache access across nodes?
>>
Is there any c++ specialist here?
I am trying to check for the null character in an array of strings. But it always gives me seg error.

//something like this
string a[3]; int b=0;
a[0]="Just"; a[1]="fuck my"; a[2]="shit up";

while(a[0][b]!=NULL){
cout<<a[0][b]<<endl;
}


I use the getline function for the string initialization btw. I need to check this array shit char by char and it always gives me seg error when i try to compare chars with null for some fucking reason.
>>
>>56981656
i forgot the "++b;" line but you get the while loop deal
>>
>>56981656
>I use the getline function for the string initialization btw.
Nani?
>>
File: cool.jpg (30KB, 942x467px) Image search: [Google]
cool.jpg
30KB, 942x467px
>>56976481
So I'm in a FB group for my Operating Systems class and someone posted >pic related.
I thought it was pretty funny but I realized I actually would have coded the left side. I felt kind of shitty and amateurish about it afterward.

My question for you guys is if you guys can share any tips for increasing productivity in less lines of code or more preferably lead me towards some reference materials. I searched YouTube for "programming tricks/shortcuts" and it hasn't been very fruitful. A lot of it is bullshit cmd stuff
>>
>>56981690
>le ebin reimplementing for loops as while loops maymay
better yet, do this
//something like this
string a[3]; int b=0;
a[0]="Just"; a[1]="fuck my"; a[2]="shit up";

loop:
if(a[0][b]!=NULL) goto done;
cout<<a[0][b]<<endl;
++b;
goto loop;
done:
>>
>>56981750
Read more. Write more.
>>
File: cs grad meme switch .png (1MB, 3300x1237px) Image search: [Google]
cs grad meme switch .png
1MB, 3300x1237px
>>56981750
>>
>>56981750
>I felt kind of shitty and amateurish about it afterward.
now you'll never write code like that again. Experience makes you better.

There's shitloads of well paid programmers who don't even try to learn new shit. If you try to improve all the time you'll get pretty good eventually.
>>
>>56981715
ahem.. i am trying to put lines of a text file into a string array.
>>56981758
why does the while loop sperg in my code? Bit of curious
>>
File: frame-0021.png (205KB, 4000x2500px) Image search: [Google]
frame-0021.png
205KB, 4000x2500px
>>56981750
Read SICP. Not even memeing. It's great for improving your problem-solving-in-a-programmatic-way thinking if you can write some code in your favourite language, but are not yet confident in making solid design decisions etc.

>>56981279
We hexagons now.
>>
>>56981656
Must be the way you're inputting a.

After that, you can just iterate through a[0] using foreach loops.
>>
File: obj.png (14KB, 1668x165px) Image search: [Google]
obj.png
14KB, 1668x165px
I'll try this again today...

Have an API endpoint that returns on object like shown in the Stuff Class. How do I iterate through this object to get the values returned? Can't modify the real endpoint.

    public class Stuff
{
public string Id;
public string Bullshit;

public object ReturnObject()
{
// Real function pulls data from database. Data goes into a datatable
DataTable dt = new DataTable();
dt.Clear();
dt.Columns.Add("Id");
dt.Columns.Add("Bullshit");
object[] o = { "1", "Status1" };
dt.Rows.Add(o);

var retObj = from a in dt.AsEnumerable()
select new
{
Id = a.Field<string>("Id"),
Bullshit = a.Field<string>("Bullshit")
};
return retObj;
}

}

public class Program
{
public static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Hello, world!");
Stuff s = new Stuff();
object a = s.ReturnObject();

Console.WriteLine("{0}", a.GetType());
Console.ReadLine();

}
}
>>
File: le wewwing kinsey.png (129KB, 201x331px) Image search: [Google]
le wewwing kinsey.png
129KB, 201x331px
>>56981750
check = (>)

` , : ^ )
>>
File: frame-0036.png (202KB, 4000x2500px) Image search: [Google]
frame-0036.png
202KB, 4000x2500px
>>56981857
Cuter colours if you're into that.
>>
File: thisspeakstome.png (128KB, 2000x1125px) Image search: [Google]
thisspeakstome.png
128KB, 2000x1125px
what's the best language if you're a pretty princess?
>>
>>56981887
what do you mean? Does your code not work?
>>
>>56981926
python or ruby or some gay shit like that.
>>
>>56981887
How do I use the object returned? I can't seem to iterate over it, I can't seem to cast it to anything. I need to use the results of ReturnObject() but can't access anything.
>>
quicksort([]) ->
[];
quicksort([Pivot|Rest]) ->
{Smaller,Larger} = partition(Pivot, Rest,[],[]),
quicksort(Smaller) ++ [Pivot] ++ quicksort(Larger).

partition(_,[],Smaller,Larger) ->
{Smaller,Larger};
partition(Pivot, [H|T], Smaller, Larger) ->
if H =< Pivot ->
partition(Pivot, T, [H|Smaller], Larger);
H > Pivot ->
partition(Pivot, T, Smaller, [H|Larger])
end.


daily reminder that erlang is beautiful
>>
>>56981926
C+=
>>
File: le c++ trap code.png (89KB, 813x925px) Image search: [Google]
le c++ trap code.png
89KB, 813x925px
>>56981926
C and Scheme
>>
File: mde shig.png (92KB, 213x252px) Image search: [Google]
mde shig.png
92KB, 213x252px
>>56981975
>that
>quicksort
enjoy your O(n^2) time
>>
>>56981926
>>
>>56981975
>can't share pointers to data

>daily reminder that erlang is slow
fix'd
>>
File: sussman shig.jpg (71KB, 500x375px) Image search: [Google]
sussman shig.jpg
71KB, 500x375px
>>56982035
>only c and lisp get shit done
>but the way they do triggers faggots
>>
>>56982035
I lost it at that last one
>>
>>56981656
There's a waterfall of problems here.
NULL is depreciated, and should be replaced with nullptr.
But that's not what you want here anyway. You're looking for the null terminator which is '\0'.
But std::string doesn't use null terminators.

You can use a simple for each loop instead.

 
std::string a[3];
for(std::string &str : a)
{
for(char &ch : str)
{
std::cout<<ch<<std::endl;
}
}
>>
File: dr pavel im cia.png (30KB, 124x155px) Image search: [Google]
dr pavel im cia.png
30KB, 124x155px
>>56982035
>>
>>56982124

You don't get to bring friends.
>>
>>56982114
>depreciated
:^?
>>
>>56982144
Uhh.. they're not my friends
>>
>>56982144
>>56982155
Don't worry, no trademark for them.
>>
>>56982168
And why would i want a trademark?
>>
>>56982173
They were trying to import your library. The Masketta Main.
>>
>>56982191
Maine?
>>
File: maine cia.jpg (25KB, 418x328px) Image search: [Google]
maine cia.jpg
25KB, 418x328px
>>56982200
Get them on make, I'll include them in!
>>
>>56982114
Oh alright, i'll try this then. I am still a bit new to the cpp namespaces/classes. I just thought i could walk around the issue just like in c.
>>
tfw im a retard at programming but i liked my data structures and algorithms classes
>>
>>56979405
fucking triggered
>>
i f*cking love memes
>>
>>56982114
>
char &ch

>
>>
File: 1474363000057.png (211KB, 2672x1984px) Image search: [Google]
1474363000057.png
211KB, 2672x1984px
>>56979405
Go back to pol and join the rest of your flock of retarded shitlords in rolling around in the mud.
>>
>>56982431
What?
>>
>tfw designing UI and it all looks like shit
>>
>>56982459
For what purpose.
>>
File: wew butthurt.png (446KB, 551x669px) Image search: [Google]
wew butthurt.png
446KB, 551x669px
>>56982447
>shitlords
>that butthurt image
hello tumblr
>>
>>56981758
>1968+48
>le ebin goto in high level code meme
>>
>>56982447
>If you don't think programming is feminine and makes you get boners when you look at guys, you must be some kind of /pol/ white supremacist
parody is real now
>>
>>56982492
That's what you get for working at Apple.
>>
File: 1474364043026.gif (87KB, 1231x930px) Image search: [Google]
1474364043026.gif
87KB, 1231x930px
>>56982508
> MUH degeneracy
> MUH tumblr boogeyman
Yeah right, that definately doesn't belong on /pol, like, AT ALL. Sure thing,
>>
>>56982502
You call for its address instead of its value.
So you create a pointer instead of a temp memory on a for loop.
>>
>>56977987
Learn to write CPS syntax-rules and you'll be able to do even more with pure R5RS!
(define-syntax anaphoric
(syntax-rules (it)
((_ k var (a . d))
(anaphoric (ana-rec k var d) var a))
((_ (k ...) var it)
(k ... var))
((_ (k ...) var x)
(k ... x))))

(define-syntax ana-rec
(syntax-rules ()
((_ k var d a)
(anaphoric (ana-rec2 k a) var d))))

(define-syntax ana-rec2
(syntax-rules ()
((_ (k ...) a d)
(k ... (a . d)))))

(define-syntax aif
(syntax-rules ()
((_ pred then otherwise)
(anaphoric (finish-ana-if x pred otherwise) x then))))

(define-syntax finish-ana-if
(syntax-rules ()
((_ x pred otherwise then)
(let ((x pred))
(if x then otherwise)))))

(aif (memq 'x '(x y z)) (cdr it) 'nope) ;==> (y z)
>>
>>56982544
>So you create a pointer instead of a temp memory on a for loop.
Nani?
>>
>>56982502
In this specific example I guess there's no real reason, but it just makes sense to have access to the actual element and not just a copy so I see no reason why not.
>>
>>56982567
It's inefficient.
>>
make it a gook thread
>>
>>56982544
That's C++ you mongrel and that would be a reference, completely different thing.
>>
>>56982548
But if you're not autistically obsessed with muh hygiene like a Hascuck is with muh purity, you can just express it as
(defmacro aif (pred then else)
`(let ((it ,pred))
(if it ,then ,else)))
>>
>One of the great strengths of the Java platform is the standard library that it ships. It
>provides a great deal of useful functionality—and in particular robust implementa‐
>tions of common data structures.
Is this true or is the author trying to meme me again?
>>
>>56982604
A pointer underlies a reference.
>>
new thread

>>56982609
>>56982609
>>56982609
>>
>>56982606
The point was
>with pure R5RS
though.
>>
>>56981750
>having a check function at all
>not just using
(x>y)
as an expression
Spotted the Java programmer
>>
File: 1357186670445.jpg (79KB, 441x403px) Image search: [Google]
1357186670445.jpg
79KB, 441x403px
>>56982528
>burzum shirt
kek
>>
>>56982584
it is less memory consuming tho
>>56982604
no
>>
>>56981767
Well sir, I thought it was clear that I was looking for resources to read.
>>
>>56982650
It's moreso just an example of code vs superior code.
>>56981857
thanks, will look into it
Thread posts: 351
Thread images: 42


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