[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: 317
Thread images: 31

File: daily programming thread2.webm (2MB, 600x338px) Image search: [Google]
daily programming thread2.webm
2MB, 600x338px
old thread: >>59576713

What are you working on, /g/?
>>
Stop posting this cringy fag webm.
It's not funny. It was never funny.
>>
Still better than many other alternatives.
>>
>>59580472
that strikes me as seeming a bit unsafe... is C for alpha male risk takers?
>>
The most practical programming language today is Idris.
>>
>>59580541
>the literally who version of Haskell
I hope these aren't the same people telling me D is dead
>>
>>59580496
Code being used in the industry for real world things.
D has games, systems,audio, Ebay's Data mining, etc.
And thats still with the GC.
Haskell and co. are still in academia for the most part.
>>
>>59580509
I like it
>>
>>59580541
You just acknowledged that Idris is a programming language, meaning it can't have the property of being "practical".
>>
am I wrong to think that C++ is the future of mankind?
>>
>>59580552
Remedy Entertainment is slowly introducing it as well
>>
>>59580565
You have no idea how wrong you are
>>
Go is the worst programming language. It's not the most unpleasant language to program in, or the least productive, but it was designed ignoring 30+ years of research, so the designers knew how to make a better language and they deliberately chose not to.
>>
>>59580567
Yeah, thats who I meant since the other is a no-name MMO
>>
>>59580552
>real world things
As opposed to fake world things?
>>59580551
D can't be "dead". It is plain garbage, though.
>>
>>59580580
Wrong
>>
>>59580517
with great powers come great responsibilities as they say
>>
>>59580576
>unironically cant local import or format how I want like Python
truly a mistake.
>>
If you're not using a pure language then you're not programming, you're just coding.
>>
>>59580576
Golang appeals to the lowest common denominator.

That was its design and purpose.

>>59580498
If I want to do functional Web Dev, what languages/stacks should I be looking at? Is it worth it over using C++?
>>
>>59580600
>you're not programming, you're just coding
:thinking:
>>
>>59580600
>with no I/O
you forgot to add this.
>>
>>59580600
>pure language

What did he mean by this? Binary is the only true, pure language.
>>
>>59580573
prove me wrong
>>
File: 1490484678175.png (435KB, 720x720px) Image search: [Google]
1490484678175.png
435KB, 720x720px
>>59580621
>Binary
Retard.
>>
>>59580621
Binary isn't a language.
>>
>>59580636
Should I have just said writing 1s and 0s???
>>
>>59580636
It actually is. I'm 100% certain that the set of all languages has something which accepts only 1 and 0, true and false, etc.
>>
>>59580650
"Machine code" is the correct thing to call it.
Binary is just a number base, or describing a 2-ary function.
>>
>>59580659
true and false isn't a language
>>
>a language so pure and expressive, you could do away with names completely

pretty neat concept 2bh
https://www.youtube.com/watch?v=buQNgW-voAg
>>
>>59580671
>imaginary
>>
>>59580509
anime website
>>
>>59580671
John De Goes is an absolute beast.
>>
>>59580692
Gotta start somewhere.
>>
>>59580668
They can be the alphabet of the language called Binary.
>>
>>59580671
>a language so pure it is literally useless

/dpt/ will like it.
>>
>>59580671
>>59580692
>>59580706
Who said this?
>>
>>59580706
The day haskell gets officially dethroned will be great.
>>
File: dpt95.png (345KB, 640x480px) Image search: [Google]
dpt95.png
345KB, 640x480px
R8
>>
>>59580721
ugly trash, much like your favorite """"language""""
>>
>>59580719
I think Idris might do that.

>>59580721
shit
>>
>>59580719
>>59580733
Dethroned for the language everyone jerks off but doesn't actually use?
Congrats I guess
>>
>>59580671
>so pure
How can something be more pure than something else?
>>
File: dpt.png (742KB, 1920x1080px) Image search: [Google]
dpt.png
742KB, 1920x1080px
>>59580721
this is better
>>
>>59580747
Remove the trashkell logo and it'll be better.
>>
>>59579896
OK, so let me ask you a question.

Someone hands you a box. A gift for you. You open the box and it is Swiss Army Knife. You encounter a rope, and you notice that the Swiss Army Knife can be used as a cutting instrument.

Where does it make sense to put the determination of what kind of object it is and what uses it has? Did the gift giver have to specifically access the "giveKnife" protocol of your interactions? Does the Gift interface have to hold place-holders for every possible action that could possibly performed by any kind of Gift? Where does the complexity really lie? Does the complexity lie in the concept of a gift, the concept of giving, or does it lie in the human?

Yes, these are satirical questions and if you don't get that, YOU are the punch line.
>>
FP = Fairly Perfect
OOP = Opposite Of Perfect
>>
File: dpt2.png (1MB, 2504x1409px) Image search: [Google]
dpt2.png
1MB, 2504x1409px
>>59580755
So this?
>>
>>59580770
PP = Perfectly Perfect
>>
>>59580770
fairly poop
>>
>>59580773
Perfect.
>>
>>59580763
It's obvious, you need a Giver class, and a GiverFactory to get instances of Giver from.
>>
Can someone help me realize what the meanings of the following are:

class B{
public:
int f, b;
B(int f, int b);
...
}'

class A {
public:
B b;
A();
};

A:A() {
B = new B(1,2); //returns point of B from heap?
//or
b = B(1,2); ///??????
//or (assuming it's like a struct and we already have the memory there, skip the constructor????)
b.f = 1;
b.b = 2;
}


which is correct and what the fuck does the middle one mean
>>
What is Idris going to be actually used for, what is its purpose?

And can someone please tell me what the concurrency model looks like, and how it compares to other languages?
>>
>>59580805
nothing useful
>>
>>59580777
Holy trips have spoken.
Functional programming is over.
God himself uses OOP.
>>
>>59580805
It's a general-purpose programming language. You can use it for games, webdev (the compiler can output PHP!), CRUD apps, theorem proving, ...

Apparently it has support for message passing built in, there may be libraries available for other concurrency models.
>>
>>59580822
Not necessarily. He just declared FP is fairly poop, that's all. He may prefer other paradigms.
>>
>>59580800
do your own homework poojeet
>>
>>59580800
Cool green text.
>>
>>59580857
I wish this was homework since I could just tell the TA to tell me, but it's not and i'm all by myself learning this fucking language.
>>
>>59580874
In that case, stop learning that defective shit.
>>
>>59580874
>paying $20k a year to learn programming language
AAAAAAAAAAAAAAAAAAAAAA
>>
File: 1484760958793.jpg (52KB, 611x393px) Image search: [Google]
1484760958793.jpg
52KB, 611x393px
>>59580822
>>59580844
which dubs do i trust???
>>
>>59580884
That's why you community college that kind of bullshit, assuming it's required.
>>
>>59580887
Believe my trips fag
FP = fairly poop
>>
>>59580887
Trust no one.
>>
File: 1479653806598.jpg (39KB, 255x676px) Image search: [Google]
1479653806598.jpg
39KB, 255x676px
>>59580498
Isn't struct packing/padding on the compiler's side, though?
>>
>>59580918
Not necessiraly.
>>
>>59580918
Jesus Christ I'm gonna fucking rape your face
>>
What's the name of that coding language, like hackshall or hashall or something.
>>
>>59580918
The programmer can control it.
>>
>>59580800
A::A() : B(1, 2) { }
>>
>>59580928
Lisp
>>
>>59580928
Highcall
>>
>gcc 7 when
>>
>>59580965
>not using clang
>>
>>59580944
>>59580950
It was Haskell. I should had added that it was completely autistic and irrelevant of a language.
>>
>>59580974
gcc is the only true compiler and you know it
>>
>>59580835
In all likelihood it will not be used for anything noteworthy at all.

What 'problem' does it solve that other languages are incapable of doing?
>>
>>59580980
D
>>
>>59581005
>What 'problem' does it solve that other languages are incapable of doing?
Having dependent types.
>>
File: 1490225604206.png (29KB, 209x250px) Image search: [Google]
1490225604206.png
29KB, 209x250px
>>59581009
>Python,Java and C+++ bastard baby
>>
>>59581038
I can't find anything different from C++, it looks like a C++ generally.
>>
>>59581038
>C+++ bastard baby
Technically its just a C/++ one because Walter finally got tired of C++.
>>
>>59581038
I use C++ sometimes but I hate it
>>
>>59581038
this image makes me uncomfortable please remove it thank you
>>
>>59581038
u wot
>Python
making me think senpai
>>
>>59581056
That's because it's symmetric
>>
struct gs_override
{
gs_override(selector new_gs) { set_gs(new_gs); }
~gs_override() { set_gs(old_gs); }

gs_override() = delete;
gs_override(const gs_override&) = delete;
gs_override(gs_override&&) = delete;
gs_override& operator=(const gs_override&) = delete;
gs_override& operator=(gs_override&&) = delete;

private:
void set_gs(auto s) { asm volatile("mov gs, %w0;" :: "rm" (s)); }
selector old_gs { get_gs() };
};

rate my raii thing
>>
>>59581074
What fucking language is this?
what value does delete convey?
Why isn't delete a function that accepts a struct gs_override pointer to delete?

C++ was a mistake
>>
File: sym face.jpg (94KB, 625x625px) Image search: [Google]
sym face.jpg
94KB, 625x625px
>>59581056
You actually have a level of autism anon!
>>
File: 1475558003203.gif (2MB, 400x224px) Image search: [Google]
1475558003203.gif
2MB, 400x224px
Is there a compiler for the simply typed lambda calculus? I need it to output machine code.
>>
>>59581087
>What fucking language is this?
C.
>>
>>59581148
>defiling your pure algorithms by running them on physical machines
baka hentai
>>
>>59581087

= delete in a prototype like this means "delete the default constructor/destructor of this signature, and if there would be any attempt to do something that would invoke this (i.e. copying an object), throw a compiler error."

In this instance, delete is neither a value nor an expression. It's just a keyword with a special meaning. In other instances, keyword delete maps to a memory de-allocation function.
>>
>>59581156
>private
I don't think C had that.
>>
>>59581148

Somewhere floating out on the Internet... probably. If you can't find what you're looking for though, now might be a good time to pick up some compiler theory and learn LLVM.
>>
>>59581164
seems to me like they should have thought of a much better way to represent this behaviour
>>
>>59581162
Sadly I'm not able to calculate what I need by hand, so I will have to make use of a machine.
>>
>>59581198
Implement them in an actual language then, it's probably simpler than making a lambda calculus compiler.
>>
>>59581196
I know the basics of LLVM and how to implement a simple imperative language. I have no idea how I would convert STLC to LLVM though.
What books would you recommend?
>>
>>59581156
>C
No it's not, idiot.
>>
>>59581214
>an actual language
Are you implying that lambda calculus is somehow not an "actual" language?
>it's probably simpler than making a lambda calculus compiler
I refuse to do such a thing. And I doubt there is a pleasant enough total language for me to do so.
>>
>>59581074

1. Implementation should not be in interface. This type isn't a template, and set_gs doesn't need an auto argument, since it is only called with a selector argument.

2. While struct and class only truly differ in terms of default access, structs are typically only used where there are no private elements.

>>59581215

Hrm... I don't know of any books that specifically cover lambda calculus into compile lambda calculus, although if you're looking for a good book on compilers in general, Crafting a Compiler and "The Dragon Book" (I can't be fucked to look up the actual name) are both well-respected books on the subject.

The process should be somewhat similar at least to writing a compiler for an imperative language.

scan for tokens
parse into abstract syntax tree
find some way to make sense of that abstract syntax tree as an imperative program
convert to llvm
>>
>>59581197

C++ was designed by committee, several times, with attempts at maintaining backwards compatibility at each time. A lot of things are not well throught-through.
>>
>>59580805
Proving hipsters are ready to wait hours to build simple programs if it allows them to use state of the art functional programming memes
>>
>>59581336
Can't blame them, they're trying to make a good language on a shit base.
>>
Write a templated constexpr function that takes a parameter array of type T and return it's size.
Can dpt solve this advanced C++ exercise?
>>
But what creates the factories? And the factory factories?
>>
>>59581496
const thing (T)
return T.sizeof
>>
>>59581548
Anon, you're drunk.
>>
>>59581496
constexpr size_t size<>() { return 0; }
constexpr size_t size<class T, class ...Ts> { return 1 + size(Ts...); }
>>
>>59581548
My dick
>>
>>59581570
sizeof...()
>>
what are some good web dev portfolio projects?
>>
>>59581595
zerodays on popular websites
>>
>>59581554
>>59581570
Fuck. I ruined the wording of the exercise.
It's meant to be written in a way that allows the compiler to deduce the size of the array.

template<typename T, unsigned N>
constexpr unsigned func(T(&arr)[N])
{
return N;
}
>>
>CS 440 Social, Legal and Ethical Issues in Computing
Jesus Fucking Christ. What kind of bullshit can I expect?
>>
I'm getting really weird behavior from this loop, it's part of a roguelike engine I'm working on, basically it prints the map, prompts the player for a letter representing which direction to move in, updates the map data structure to move the player to the new position, and then repeats. However, every time after the initial iteration, it prints the map twice, and I can't figure out why.

Here's the code of the loop in question:
    while(true) {
printmap();
c = getchar();
c = tolower(c);
if(c == 'l') moveplayer(LEFT);
if(c == 'r') moveplayer(RIGHT);
if(c == 'u') moveplayer(UP);
if(c == 'd') moveplayer(DOWN);
if(c == 'q') break;
};


I've tried different compilers, and I'm getting the same inexplicable result. I also know for a fact that none of the functions I call should be calling printmap() themselves; my entire program is a single source file, and the only occurances of "printmap" are the printmap function definition itself, and the call inside the loop. I also considered the possibility that somehow, there was something wrong with stdin and it was placing two copies of my input character in there, so it read it again the second time around without waiting for input - but if that's the case, it should be moving the player twice, and that's not happening. It's like there's an invisible second call to printmap() right after the first, but I've checked the code thoroughly and there doesn't seem to be anything to explain why that's happening.
>>
File: 20170101_133731.jpg (4MB, 4128x2322px) Image search: [Google]
20170101_133731.jpg
4MB, 4128x2322px
To my dearest /dpt/ I have a computer science degree and about a years experience at a start-up doing web development. I produced something from the ground up.

What's the secret to getting a job at a big company where I can finally learn to work with a team and actually learn what sensible product development and software engineering cycles are like?
>>
>>59581651
flush the inbuffer after the call to getchar
>>
>>59581635
>allows the compiler to deduce the size of the array.
But I already have deterministic memory arrays.
>>
>>59581657
Composing a resume and taking the time to apply and follow-up.
>>
>>59581485

Indeed. Arguably, Rust is what C++ is trying to be, if it didn't have to fall back on quasi-compatibility with C.
>>
>>59581651
pretty sure it is reading the carriage return or newline as another character so the loop is running again.

as in, type 1 character, hit enter to submit, getchar gets the first character, then the loop runs again and it pulls the newline or carriage return and prints again before waiting for the next input.
>>
>>59581694
That's true. It's just an exc to help with understanding templates.
I found it quite fun and interesting.
>>
>>59581704
>Rust is what C++ is trying to be,
uwot
C++ has never ever stressed or even cared about safety.

Backwards compatibility """killed""" C++, thats it.
>>
>>59581688
>>59581714
I finally got it to work by putting
    while((c = getchar()) != '\n' && c != EOF);
at the bottom of the loop. However, for some reason when I tried to create a function that did the same thing:
void flush_stdin(void)
{
char c;
while((c = getchar()) != '\n' && c != EOF);
}

And placed a call to the function at the bottom of the loop instead of the while((getchar blah) blah blah), then it started double-printing the map again. Any idea why that was happening? It's doing basically the same thing in either case, calling getchar() until the result is a newline or EOF.
>>
>>59581788
I suspect they mean it in the sense of being an applications language that gives you low-level control. C++ is all about ``abstractions" rather than ``safety", but both are intended to do basically the same thing, help the programmer write code that actually works and doesn't have undesired effects.
>>
>>59581932
I still think its a pretty shitty comparison.
Two completely different language goals.
>>
IN INFRARED IS HOW WE SAW
THE NIGHT THAT LIT UP SCARECROW PLOTS
THE THAT PINCHES CRIPPLED HOBBLED
FROLICKED FLAT ON ITS OWN FACE
>>
>>59581788
>C++ has never ever stressed or even cared about safety.

RAII, unique_ptr, shared_ptr, rvalues, move semantics, templates, std::optional, std::variant

Safety is a huge part of modern C++ and its future direction.
>>
>>59582013
>RAII
someday, some smart dude will come up with a better term and acronym to represent what this actually means
>>
>>59582037
I could have just said destructors but that's not as cryptic and exciting.
>>
best programming language to learn before I go to school for software engineering cause i'm too shitty with math to do EE or CE? I'm thinking C but it seems like it's getting a bit dated
>>
>>59581900
you need to make c an int because that comparison to EOF is meaningless if it's a char.
>>
File: 1440246538429.png (304KB, 722x768px) Image search: [Google]
1440246538429.png
304KB, 722x768px
a = False
if clause:
a = True

if not a:
x = i
else:
x = function(n)

or
a = lambda n: ""
if clause:
a = lambda n: function(n)

x = a(n) or i
>>
why does do in scheme suck so much

no wonder most schemers think it's an abortion
>>
>>59582090
Yeah that seemed to fix it. Weird that it worked when that while loop was inline though.
>>
>>59582100
x = clause ? function(n) : i
>>
>>59582100
Is this satire?
>>
>>59582164
I'd bet that the compiler did something to "optimize" when it was just a line in the tight loop, probably just moved everything to registers so if you have 32 or 64 bit registers, the comparison to EOF would work. But when you removed it to the function, it was probably writing to the 1byte memory location, then doing cmps from the register value for EOF and the 1byte value at the memory location which fails to do anything.
>>
>>59582236
>>59582164
A compiler would not perform that sort of optimisation, as it would change the semantics of the program.
I imagine the 'c' in that code snippet was just an int to begin with.
>>
>>59582258
lots of compilers move everything into registers without regard for size of the type, you can do this in gcc with O3. Changing the semantics of the program is literally what the compilers do when they optimize. Ignoring retards who want to access 1 byte at a time when you need more cycles to get just 1 byte makes sense...
>>
>>59582317
You seem to be confusing integer promotion with compiler optimisations.
That shit still happens with unoptimised code.
>>
>>59580498
Writing some data collection scripts for the reddit API. I'm trying to get data I could use to build a sub recommender as well as ego-centric subreddit visualizations. Yay school projects...
>>
i want to write a simple script (.bat?) for a friend

how can script use content from clipboard as input
>>
>>59582344
No idea, I could write it in bash though. You have that subsystem now windows, use it.
>>
>>59582344
have you considered using nodejs and electron instead?
>>
>>59582013
>RAII, unique_ptr, shared_ptr, rvalues, move semantics, templates, std::optional, std::variant
All for convenience, added benefit of safety was not intended.
>>
Can anyone explain me the entity--component--system paradigm? I'm planning on writing a 2D game library for C but the only game engine I've ever made was object oriented. Here's how I'm thinking about implementing this paradigm, does it seem right?
>Leave the system part of the paradigm entirely up to the engine
>Systems: quadtree of entity IDs for collision detection, circular priority queue of component IDs for rendering; separately ordered circular priority queue of component IDs for managing detected collisions, handling input, and carrying out per-tick operations; FIFO "master system" queue pushed to by all other systems to notify it that things should happen and popped from on its own time to make those things happen; maybe also a system for in-game message boxes (like for dialogue) idk
>Component: a struct featuring a bitfield with at least as many bits as there are simultaneous entities allowed; 1 for "yes the entity with this ID has this component," 0 for "no it does not"; struct also features component-specific arrays for entity state, as well as function pointer fields to indicate what to do when an entity that has the component faces a certain condition, or when a request from a system must be responded to
>Entity: just an int that serves as a key to array fields of components
And then I'd have the game state be an array of all the components, using the members of a user-supplied enum as keys to the components themselves (i.e. "component IDs"), with a macro for declaring this enum that would prepend engine-implemented component IDs that might be expected to be universal in all or most graphical computer games (e.g. movement logic, collision logic, rendering logic, etc).
>>
Working on my first real personal project, hoping to put something on a portfolio, maybe help get an internship.

It's an android app to track workouts. Allows user to input a workout, weight lifted, and how many reps, and select a date. Stores this in an SQLite database. User can then go to "review" and see the table of workouts, weight and reps. Buttons to sort the table by date, workout, or highest weight, buttons to clear the whole db, or delete specific workouts.

It's my first time working with android, java, SQLite and hell, first time working with databases in general, so it's been a complete learning experience. It doesn't look very pretty, but it's got all the functionality. I'm almost completely self-taught in this particular area, so I don't really have a finger on what's considered "internship" material. Would such an app be looked on favorably, or more of a "meh" thing?
>>
>>59582456
meh

make something that will actually get downloads, like a free game, or a flappy bird clone.
>>
How many times the copy constructor is called?
I counted 7 but its calling 6 times.
Can someone explain.
>This is high level C++ concepts. Beta cucks can ignore.
#include<iostream>
class Point{
public:
int x;
Point() = default;
Point(int l):x(l){}
Point(const Point& p);
}global(4);
Point::Point(const Point& p){
x = p.x;
std::cout<<"I am copy constructor\n";
}
Point foo(Point arg){
Point local = arg, *heap = new Point(global);
*heap = local;
Point pa[4] = {local, *heap};
return *heap;
}
int main(){
Point one(10);
Point mainPoint = foo(one);
return 0;
}

>>
>>59582203
>x = clause ? function(n) : i
Thanks, I never heard of ternary conditions until now. But Python has it a completely unlike other languages for some reason:
x = function(n) if clause else i

>>59582215
No. What's the problem?
>>
>>59582433
So you basically want to write GameMaker Studio in C?

Why not just use GameMaker Studio? The hard part's already done for you, you just have to make the game.
>>
>>59582507
Ternary ops are generally poopoo'd for readability reason, but they're nice for simple obvious things.
>>
>>59582433
Read Eric Gamma's Design Pattern
>>
>>59582417
What a mindless thing to presuppose. Half of those things have no other definite purpose other than augmenting memory safety in the language.

http://www.stroustrup.com/resource-model.pdf
>>
>>59582510
Too much bloat and proprietary bullcrap. My version will be free, open source, and will compile to a pure game with only the features needed, not a self-extracting archive containing a complete game engine and a tiny little sub-application for it to run. Also you'll be able to use it on any OS with nothing but a text editor, because it will literally be nothing but a library. These are all things I'm quite sore about GM Studio lacking, hence why I'm trying to do this.
>>
>>59582547
Thanks will do
>>
>>59582561

sounds neat. keep us posted
>>
File: dpt.jpg (164KB, 800x1000px) Image search: [Google]
dpt.jpg
164KB, 800x1000px
>>
>>59582592
No literally read that.
I work on a big software for my company. I don't understand how that whole softwar works. So many components in it. We have 4-5 devs working on different components.
We are provided with multitude of architectural documents but none helps.
After reading just the first 3 chapters of it it started making all sense.
Now I can explain why some components are libraries and some are remote process while some are just functional call.

Its just 478 pages. I am on 4rth chapter. Thinking of completing by March end but fuck my job.
>>
nombre Fibonacci : 
a est un nombre
début
questionne a sur "Entrez un nombre :"
affiche fibo(a)

fibo :
* n est un nombre
début
si n est < 2, retourne n
retourne fibo(n-1) + fibo(n-2)
>>
>>59582617
Point local = arg;

Is not this copy initialization?This has to be;
We are copying arg object values into local variable.
>>
>>59582354
how would it look for bash
>>
>>59580721
Looking at that I can hear the Windows XP close-down sound.

https://youtu.be/PBVR5tlsaG0
>>
>>59582730
Well I lied, it relies on the Xorg tools to pull the clipboard out. It doesn't directly translate to Windows.
>>
>>59582504
Figured it out myself by setting breakpoint in copy constructor.
*heap = local;

This doesn't call copy constructor. It probably call move constructor.
>>
>>59582840
>>59582504
Damn
*heap = local;

This is not move constructor. This is assignment operator overloaded member function.
>>
>>59582504
I counted 6. Two from passing/returning by value, 1 from initializing local with args value, 2 from Point array initialization, 1 from initializing heap with global. Also, I don't think I have ever seen anyone generate a global (as in syntactically, not the name you chose) class object with that syntax before, and only very rarely with structs.
>>
>>59582914
{global(4);

You mean this?
I just tried it and it compiled.
I was thiking that in struct we give variable names at the end of stuct to initialize few objects and I did here but also tried using one argument to use constructor taking single int.
I wonder if this is possible in C.
Does C have constructors?
How we initialize its member variables.
>>
How the fuck does a kernel mode C program even declare a variable

Like how does it know who to ask the memory for
>>
>>59583016
Do you mean the kernel it's self, i.e. OS code, or something else?
>>
>>59583016
They don'y usually ask for memory. In good kernels at least.
>>
Why is it called RAII and not RAID? When I declare a variable I expect it to acquire its resources then and there, not wait until I initialize it with a constructor call or initial value
>>
>>59583044
>They don'y usually ask for memory
rude
>>
>>59583016
The kernel needs to set up a stack, and the compiler takes care of it
As for malloc, that needs to get implemented
>>
if I use graph theory to make a sentient kernel modeled after a little puppy brain, and then I install a non-sentient userspace, is using the computer animal cruelty?

GNU/Doggix: the first ever OS to patently facilitate virtual torture
>>
>>59583079
>GN*
dropped.
>>
>>59583099
b--but he invented programming
>>
>>59583099
(cont from >>59583106 ) i think gnu is a pretty cool guys, eh invented programming and doesn't afraid of anything
>>
>>59583004
C doesn't have constructors, when you call malloc you are just given raw memory of the requested size (unlike C++ new which implicitly calls the objects constructor). Generally, typedef your struct, malloc when you want to make a new one, then call your initializer function.
>>
>>59583121
except closed source and proprietary software
>>
>>59583121
steve jobs invented programming.
>>
>>59580509
I think it's an awesome webm.
>>
>>59580576
Nice pasta.
>>
>>59583016
It is written directly in memory with appropriate CPU instructions. A common design decision is to implement a program as a machine with global symbols, a stack and a heap. The global symbols' position in memory are actually stored in the binary file. The stack uses frames and pointers computed at compile time to know where which variable is stored. As for the heap usually each process has a dedicated memory area which is recycled through the call to dynamic allocators at runtime by the OS (so you need to implement the functions) but for large malloc it might just do a full mmap in Unix like OS. You can check the osdev wiki for information regarding actual implementation.
>>
File: 1486367945687.jpg (102KB, 640x640px) Image search: [Google]
1486367945687.jpg
102KB, 640x640px
Should I learn Forth or Common Lisp?
>>
>>59583453
No.
>>
>>59583474
Let's assume the answer is "yes", which one of those would it be in that case?
>>
>>59583482
Forth then, I guess.
>>
>>59583482
>Let's assume the answer is "yes"
then the answer is yes
>>
Can somebody please explain what the fuck is going on here? My ev variable is set and it suddenly magically becomes NULL. What the fuck.
Breakpoint 2, server_accept (epoll_fd=0x7fffffffb0cc, ev=0x7fffffffb100, addr=0x7fffffffb110) at src/housekeeping.c:40
40 printf("%p\n", ev);
+(gdb) s
0x7fffffffb100
41 socklen_t length = sizeof(struct sockaddr_in);
+(gdb) s
42 int client_socket = accept(housekeeping_socket_fd, (struct sockaddr*) &addr, &length);
+(gdb) s
43 if (client_socket == -1) {
+(gdb) s
46 int current_flags = fcntl(client_socket, F_GETFD);
+(gdb) s
47 fcntl(client_socket, F_SETFD, current_flags | O_NONBLOCK);
+(gdb) s
48 ev->events = EPOLLIN;
+(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x000055555555556e in server_accept (epoll_fd=0x7fffffffb0cc, ev=0x0, addr=0x100007f46910002) at src/housekeeping.c:48
48 ev->events = EPOLLIN;

I don't even have threads or shared memory or whatever else would allow another program to suddenly change something in my program's memory.
>>
File: fragzeichengrab.jpg (93KB, 777x777px) Image search: [Google]
fragzeichengrab.jpg
93KB, 777x777px
I want to guarantee that a certain file will always be the first in a directory on Unix-like OSes, so I'm starting it off with a "!". Is this considered harmful? I can navigate to the file just fine as long as I escape the !, but does it risk fucking with scripts/other shells in ways I haven't considered?

What is an alternative to ensure a file shows up first? It seems like all the earlier characters in the ASCII set have shell implications.
>>
>>59583517
Have you tried using asan to check whether ev gets overwritten somewhere?
>>
>>59583546
I did some printf debugging and it seems that accept() is overwriting ev.
I'm beginning to think that it's a gcc bug since changing the variable's doesn't fix the problem.
>>
>>59583595
Well gcc is known to do insane shit. Try building with compcert/clang.
>>
File: byte_data_bitmap.png (56KB, 644x896px) Image search: [Google]
byte_data_bitmap.png
56KB, 644x896px
I'm trying to learn more about I/O in Java and how bits/bytes are interpreted as text, images, binaries, etc.

I made a simple 2x2 16-bit bitmap and output the byte data in Java using the read() method from InputStream.

The .bmp file is 64 bytes, and the program spit out 64 bytes of data when reading it. Each line is a byte value, and 16 bytes represent one pixel of the bit map file.

After this exercise, I'm wondering three things:

1. Why is it called a 16-bit image if it takes 16 bytes to represent a pixel?

2. Are these lines of bytes sequential? That is to say, do the first 16 bytes output represent the first pixel of data? And the second 16 lines represent the second pixel of data? And so on?

3. If the lines of bytes are sequential (the first 16 lines representing the first pixel), how do these 16 bytes end up representing the color "white" in the bitmap? I would have suspected a completely white pixel to be represented by 16 sequential 0's, but that's not what I received from my program.

Any insight is greatly appreciated!
>>
>>59583615
why the hell do you space your posts like that, plebbitor?
>>
>>59583608
Thanks for the idea. Hadn't thought about compiling with clang.
My variable is still overwritten though. This probably means that accept() overwriting an epoll_event pointer is an epoll "feature". I can't see anything about that in the manpages though.
>>
>>59583615
Read the specification of your file format, you'll realize there is metadata in files.
>>
>>59583615
you should use hexadecimal when working with bytes and shit, i don't remember how to print ints into hexidecimal in java though.

it's 16 bits because each pixel is represented by
16bits
so you have 1bit of padding/alpha
5bits of red
5bits of green
5bits of blue

white would be 0-11111-11111-11111
>>
File: BMPfileFormat.png (19KB, 640x1333px) Image search: [Google]
BMPfileFormat.png
19KB, 640x1333px
>>59583615
read the wiki on the bmp format, because a lot of the first bytes in the graphic are header information
>>
>>59583732
Thanks! That helps, but I guess I'm still confused by the bit-vs-byte nomenclature.

It's called 16-bit color depth since each pixel is represented by 16 bits of data. But my program here reads 16 bytes per pixel, as opposed to 16 bits. There's some gap in my understanding that I think is causing this to confuse me.

>>59583755
Ah, this is really helpful, thanks!
>>
>>59583791
yeah you're reading a bunch of bytes, but not all of them are actual pixel/color information. the pixels are still 16bits, but they're buried in the other byte data.

a lot of times what you would do is pull in some bytes and cast them as a struct for easily reading
>>
>>59582635

Seulement utilises l'anglais, s'il te plait.
>>
>>59583835
*Ne parle qu'anglais, s'il te plaît.
CÇPT
>>
>>59583828
Ahh, I see.

And the bytes I'm reading are going to vary depending on the file format (or "encoding"?) of the image file I'm reading, I suppose? Even if the pixel/color content of the image is the same, the actual byte data will vary depending on bit depth, file format, and such?
>>
So uh anons I got a job as a software developer.

The thing is I only have a PC at home and a Thinkpad X230 (SSD, 8GB RAM so it's not bad or anything). But I've been thinking of selling both of them and just getting some other powerful and reliable laptop (small too) and just carry it with me wherever and plug it into an external monitor at home/work.

Any recommendations? Should I even bother?
>>
>>59583863
yeah exactly.

Here's what you could do. Look at the file header, and it has File offset to pixelarray. Read in that data and use it to skip to the pixel colors. Then you can step through each pixel using the bitdepth.
>>
>>59583881
"bring your own device" set-ups kinda suck if they make you join the domain or whatever set-up they have.
>>
>>59583932
Thanks a bunch. I think I understand much better now
>>
File: asdasd.png (38KB, 1022x326px) Image search: [Google]
asdasd.png
38KB, 1022x326px
>>59580498
>What are you working on, /g/?
still project euler.
Finished problem 21 now. Takes quite a long time, because bruteforce, but I don't care.

   1 #!/usr/bin/python3                                                                                  
2
3 import math
4
5 def get_divisor_sum(n):
6 sum = 0
7 for i in range(1, int(n/2)+1):
8 if(n%i == 0):
9 sum += i
10 return sum
11
12 def has_amicable(a):
13 b = get_divisor_sum(a)
14 if( a != b and a == get_divisor_sum(b)):
15 return b
16 else:
17 return 0
18
19 res = 0
20 for i in range(1, 10000):
21 res += has_amicable(i)
22
23 print("sum: %d" %res)



real 0m3.237s
user 0m3.236s
sys 0m0.000s
>>
>>59583881
You won't be able to get both small and powerful. Keep the x230, it should be fine.
>>
>>59584118
>inb4 python haters
>>
File: next.png (40KB, 1033x274px) Image search: [Google]
next.png
40KB, 1033x274px
>>59584136
python is good for stuff like that though.
You can easily script that shit.

next problem is pic related. Seems not too hard. Not sure yet if I want to implement sorting myself
>>
>>59584164
I know it's good. I was getting 'in before' python haters start complaining.
You should go back.
>>
I forgot to add else statements to a 1000+ line project, am I gunna make it?
>>
>>59584233
XD
>>
>>59583860

>CÇPT
Quoi?
>>
>>59584259
Corrigé Ça Pour Toi, mon ami.
>>
>>59584256
I wasn't shitposting it was genuine
>>
>>59584265
BUT I WAS, LOL!
>>
File: game.png (12KB, 478x496px) Image search: [Google]
game.png
12KB, 478x496px
>>59584118
Just finished it. It registers moves through mouse clicks and has a simple and a better(or just more complicated really) ai to choose from as an opponent.
>>
>>59584118
read the section on loops in
http://www-rohan.sdsu.edu/~gawron/compling/course_core/python_intro/intro_lecture_files/fastpython.html
might help you with the performance
>>
>>59584118
why the fuck are you copying line numbers?
>>
>>59580565
If C++ is the future of mankind then our future doesn't look very bright at all.
>>
>>59580600
Let me guess, you also program with no I/O?
>>
>>59583453
You can learn both, though CL is more contemporary.
>>
>language is so great and rich
>never got full compiler back in time
>>
What wouldd be the prefered way of saving editable configuration for my simple CLI script? Using Json, Xml ?
>>
>>59584774
toml
>>
>>59582417
>*_ptr
>Convenience
They are no more convenient than raw pointers. They exist for safety reasons.
>>
>>59584794
>Be warned, this spec is still changing a lot. Until it's marked as 1.0, you should assume that it is unstable and act accordingly.

yeah no
>>
>>59580704

Sure, just not the language itself.
>>
>>59580580
>It is plain garbage, though.
pajeet detected
>>
How do neural systems decide what neurons to add and remove?
>>
>>59582417

In this case convenience means safety. If you do not need safety you can use usual pointers for errything.

dynamic_cast is a safe thing, there is unsafe static cast as well.
>>
>>59584505
because I copied it from vim
>>
>>59585039
make it yank to system clipboard buddie then it's just shift+v, highlight the lines you want and hit y to copy
>>
Anons anime title?
>>
>>59585069
wew lad. thanks.
>>
>>59585085
himegoto
>>
>>59585093
also if you don't have plugins already get nerdtree , auto-pairs and undotree
>>
>>59585157
what awful fucking taste you have
>>
What text editors do you guys use?
I'm new to programming, can't decide between Gedit and Sublime.
>>
>>59585299
Do take your time.
>>
>>59585299
Geany
>>
>>59585299
Learn to use Neovim or Emacs. This is how you'll get good.
>>
>>59585287
tell me why or name better
>>
>>59585299
gvim
>>
>>59585318
>emacs
Don't waste your time on learning Emacs' braindead keybinding, start with spacemacs instead.
>>
>>59585299
Personally, I use Sublime Text 3 for the majority of my work, but use Vim for quick edits in the terminal, or when editing over SSH.

That said, use whatever editor you are most comfortable with. What tool you use to edit your code with has no effect on the quality of that code, just on how productive you can be with it. Think of it like you're buying a handgun. One of the most important specs to take into consideration is how it fits to your hands. What works for one person, isn't always ideal for another.
>>
>>59585325
>Better
Not adding antifeatures is better. Undotree is... fine I guess, there's a bunch that are equal to that.
>>
>>59585359
>antifeatures
the fuck does this mean?
>>
>>59585362
Antifeatures means things that are the opposite of a feature. Adding something that you don't want, on purpose. Who would want auto inserting pairs?
>>
>>59585375
I do, saves me effort
>>
>>59585356
I use nano for my quick edits in the terminal. Anyway, thanks for your input.
>>
>>59585381
I've had to use shit that does it by default and 99% of the time it gets in the way.
>>
>>59580498
What animu is this
>>
>>59585325
>undotree
Lrn2 :earlier :later

>nerdtree
Lrn2 netrw, :e, :b and if you really don't like wasting time unite/denite

>>59585375
>Who would want auto inserting pairs?
It's actually useful, though the plugin he named is shit. I love tpopes' vim-endwise because I never remember if I have to put "end if" "endif" "fi" or whatever else is needed to close an if.

>>59585348
Nah, spacemacs is shit. It's slow as fuck. If I wasn't stuck on neovim I'd build a clean config with plain emacs+evil.
>>
>>59585398
>It's slow as fuck.
So is Emacs.
>>
File: 1483054230091.png (66KB, 425x258px) Image search: [Google]
1483054230091.png
66KB, 425x258px
>>59585299
What's the lightest text editor for programming?
>>
>>59585398
I was only not hating on undotree cause it's nice to see it in a convenient manner, yes the features exist globally.

>>59585417
vi
>>
>>59585417
Notepad
>>
>>59585410
Yeah Emacs is slow, but Spacemacs is orders of magnitude slower than Emacs.
While Emacs' slowness is tolerable, Spacemacs' isn't.

>>59585417
Ed. https://github.com/jhallen/joes-sandbox/tree/master/editor-perf
>>
>>59585417
That would be Ed. It is the standard editor.
>>
>>59580498
trapfag is this you?

https://www.youtube.com/watch?v=oJ1eZqenaDw
>>
>>59585417
Nano
>>
File: beavis computer.gif (337KB, 492x376px) Image search: [Google]
beavis computer.gif
337KB, 492x376px
I'm trying to learn how to do buffered I/O in Java.

I'm not certain if I'm doing this right. Does a BufferedInputStream need to use the read() method or the read(byte[]) method to correctly read buffered data?

It seems to work fine just using read() and doesn't work when using read(byte[]), so I'm a bit confused, since I thought you needed to read from the stream indicating a byte array for the buffer. But I guess that isn't necessary since I established the buffer size in the constructor?

Any insight is greatly appreciated!

package testing;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class tester {

public static void main() throws Exception {

int bufferSize = 8 * 1024;

InputStream input = new BufferedInputStream(new FileInputStream("input.png"),bufferSize);
OutputStream output = new BufferedOutputStream(new FileOutputStream("output.png"), bufferSize);

int data = input.read(); //read() returns the next byte of data from the input stream as an integer between 0 and 255. If no byte is available due to the end of the data stream being reached, it returns -1

while(data != -1){
output.write(data);
System.out.println(data);
data = input.read();
}

System.out.println("Done!");

input.close();
output.close();

}

}
>>
File: 1362541000428.png (14KB, 550x375px) Image search: [Google]
1362541000428.png
14KB, 550x375px
>yfw 'C'++ == 'D'
>>
File: .webm (123KB, 600x336px) Image search: [Google]
.webm
123KB, 600x336px
How to do nothing and find a job?

t.neet
>>
>>59585782
you mean ++'C' == 'D'
>>
>>59585782
>D-fags are that desperate
'C'++ isn't a valid expression. Assuming char C = 'C', C++ is still equal to 'C'. You have to do ++C to get 'D'.
>>
File: 73961539153.png (101KB, 411x387px) Image search: [Google]
73961539153.png
101KB, 411x387px
>>59585843
>>59585868
oh
>>
>>59585804

Mutually contradicting conditions there, Anon.
>>
>>59585804
maybe you meant
"how to get money without investing physical or metanl effort".
>>
>>59585804
Prostitute your boipussy.
>>
File: p22.png (43KB, 1126x349px) Image search: [Google]
p22.png
43KB, 1126x349px
problem 22 done.

#!/usr/bin/python3

import re

fname ="p022_names.txt"

with open(fname) as f:
content = f.readline();

names = re.findall('"([^"]*)"', content);

names.sort()
total = 0

for i in range(0, len(names)):
namescore = 0
for j in range(0, len(names[i])):
namescore += (ord(names[i][j])-64)
total += (namescore*(i+1))

print("total score: %d" % total)

>>
>>59586022
I just started Python and I've never seen "with ... as .."
why do you do it like that?
>>
>>59586041
dunno. I am really not good in python.
Seen it somewhere on stackoverflow, copied it and it works
>>
>>59586022
>for i in range(0, len(names)):
Actually, many modern languages support iterating through compound datatypes, so you cound just write:
for name_i in names:
>>
>>59586094
I know. Had it like that at first, but is there a way to get the index then? I needed the index to calculate the 'score'
>>
>>59586108
https://docs.python.org/3/library/functions.html#enumerate
>>
>>59586017

Even prostitution requires some amount of work. At minimum, Anon would have to seek out clients. If he wants to earn decent money, he'd also need to put in some effort into proper grooming. To get repeat customers, he'd also need to at least put on a good performance during the act. He would need to make himself "more worth it than a fleshlight." At the end of the day, unless you are desperate for cash, it's probably more worth it to work at McDonalds than to work as a prostitute.
>>
>>59586088
I googled it.
>>
can you guys recommend me some material to understand how classes work in java? i still don't understand the get()/set() part
>>
>>59586374
Whatcan you not unterstand?
You use get/set methods because you shouldn't access to inner variables of the object directly.
>>
>>59586395
Which was the operating theory of OOP in the 90s, nowadays nobody really thinks it's necessary.
>But anyone who writes this code could change our internal variables!
>but... don't do that
>okay
>>
How early did you guys get into programming? I'm 18 and I feel like I left it way too late
>>
>>59586403
Well, what can I read to learn modern OOP practices?
>>
>>59586421
I don't actually know, I mostly read stuff in the 90s. Just a matter of paradigm/idiomatic shift, I don't think there's any real "best" practices in that regard. Both/others are valid.
>>
>>59586412
it doesn't matter when you start, as long as you don't stop bb
>>
>>59586395
whats the difference between them?
>>
>>59582433
I don't think it's a good idea to compete so directly with other solutions.
ECS is pretty worthless anyway. It's a minor convenience for games it is appropriate for and it's too constrained for more interesting games.
Games that don't need it usually fall into it as a trap.

Invent something new.
>>
>>59586445
get() is getting something without being able to change that
set() is changing something inside the class
>>
>>59586445
Get = read from object
Set = write into object
>>
>>59586459
>>59586465
Which makes perfect sense if you decide to add your safety checking in those functions.
>>
How should I go about making a program to replace misspelled words?
>>
>>59586421
>modern OOP
Doesn't exist.
https://www.youtube.com/watch?v=RdE-d_EhzmA
This is a the closest I've found to a modern OOP.
And I'm not saying it's a good idea but it's certainly a better idea.
>>
>>59586468
Yes.
Isn't that implied?
>>
>>59586488
Well it might help someone understand the context better. They're not ALWAYS arbitrary functions to flip switches just placed somewhere else, sometimes they have a purpose.
>>
>>59586477
Write a Perl script
>>
File: 1482524515684.png (95KB, 1065x473px) Image search: [Google]
1482524515684.png
95KB, 1065x473px
>>59580498
Messing around with my very own OS (just another Unix-clone attempt)
Implemented fork() and some VFS stuff, now working on getting execve() to work.
(Pic: reading stuff from files from userspace application on initrd)
>>
>>59586498
>>59586488
Oh and for the record there's also the idea of abstracting the internals away while keeping a stable API into your "black box" of a class. The internals can change whenever you want as long as those functions remain in place. It's all sorts of useful as a paradigm.
>>
>>59585107
Thanks
>>
>>59586512
You've done better work on explaining.
>>
New thread:

>>59586527
>>59586527
>>59586527
>>
>>59586477
Try comparing the soundex of a misspelled word to the soundex of a correct word.
>>
>>59585299
Geany and emacs.
>>
>>59586412
18 isn't too late at all, in fact your brain probably hasn't even matured yet to the point where you're able to reach your full potential as a programmer. but it's good that you're getting started. i started at 20
>>
>>59586597
>>59586412
I did most of my learning when I was like 10-13 and now I'm functionally retarded. Learn as much as you can while you can guys.
>>
>>59580580
Kill yourself, pal
Thread posts: 317
Thread images: 31


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