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

File: 1504347908639.jpg (205KB, 1520x1080px) Image search: [Google]
1504347908639.jpg
205KB, 1520x1080px
What are you working on, /g/?

Old thread: >>62452398
>>
>>
File: happy.png (598KB, 1095x1080px) Image search: [Google]
happy.png
598KB, 1095x1080px
>>62458004
Let's all love lain.
>>
>>62458044
Looks sane to me senpai.
>>
File: 1502619436425.png (3MB, 1845x1845px) Image search: [Google]
1502619436425.png
3MB, 1845x1845px
>>62458062
haven't seen a pass user in a while
>>
why do we you like lain so much? is it just because she's a cute girl and does computer things? the show has barely anything to do with programming
>>
>>62458072
That's because a lot of them hide it because they will get called attention whores or giving money to the jewish gook.
>>
>>62458087
It does have a lot to do with programming! She programs in LISP!
>>
>>62458087
This lainfags and NGE fags are the most pretentious bunch of weebs imaginable
>>
>>62458044
They should have kept protected in private inheritance, this way protected inheritance would be unnecessary at all.
>>
File: HMGatSm.jpg (129KB, 1366x768px) Image search: [Google]
HMGatSm.jpg
129KB, 1366x768px
>>62458087
>the show has barely anything to do with programming
>>
>>62458120
omg a screenshot
>>
>>62458087
It's an escapism anime that's heavy on existentialist atmosphere that revolves around a cute girl delving deeper and deeper into computers and death.

It's no wonder why /g/ loves it or why it spawned its own chan.
>>
Which is better for unit testing, Cmocka or Check?
>>
File: 14453526565790.jpg (7KB, 250x241px) Image search: [Google]
14453526565790.jpg
7KB, 250x241px
>strcom
>if strings are equal returns 0
>>
>>62458184
*strcmp
>>
>>62458184
>his language doesn't have bool
>>
>>62458184
I don't mind that. The real problem is how useless the negative and positive returns are.
>>
>>62458196
>strcmp returns bool
>>
>>62458184
>he can't compare strings with ==
wew
>>
>>62458196
>his language has bool
>>
trying to fix a disaster of a custom CMS written in .NET/JS. it's such a fucking mess. last week one of the junior devs wrote something that unintentionally substituted order number with the WIDTH OF THE THUMBNAIL. this somehow wasn't caught by code review, and we don't have any QA, and was released to ~300 clients. we hotfixed in a few hours but the fact that it happened at all is so typical of this organisation. i died.
>>
>>62458221
>strcmp doesn't return a bool
>>
>>62458184
>His strings are null-terminated
>>
>>62458237
>His language doesn't have strings
>>
>>62458242
>written in .NET/JS
I can tell
>>
>>62458259
>his language has strings
Hi webdev
>>
>>62458044
The only thing that's wrong with this is that public inheritance is not the default.
>>
>>62458267
>His language doesn't have strings and yet he uses %s
>>
Can you make a string comparison function that constructively uses a sentinel? I can't think of a way.
>>
>>62458184
>>62458196
>>62458221
>>62458228
>>62458237
>>62458250
>>62458258
>>62458259
>>62458267
>>62458271
>>62458274
>His language can't even split ranges
>>
>>62458242
your database is shitty probably
>>
>>62458290
but mine can, i can even chunk them if you want.
>>
>>62458263
>>62458296
I fucking know. we also have no db admin and no server admin. he just expects all devs to pull triple duty. some of our older clients regularly do db lookups that take >3 seconds to return ~5000 rows and none of us are qualified to fix it, but tech lead refuses to hire anyone specifically for it. it's a joke.
>>
>>62458242
Wow. That sounds awful. Look for another job. This place can clearly not give you a reference worth a damn.
>>
>>62458301
Shut up, D fag. Go replace your GC with unique_ptr first
>>
>>62458317
handed my notice in last week. the CEO is so picky to hire anyone new that they offered me a raise and a massive bonus to stay on for longer, so I took it. makes no sense because desu I'm not even THAT good, but whatever. I just laugh about it now.
>>
https://stackoverflow.blog/2017/09/14/python-growing-quickly/

what the shit
>>
>>62458274
kek
>>
>>62458331
Well that's good at least. Glad you're looking out for yourself. Too many people just stick around in bad situations for no reason.
>>
>>62458339
>stackoverflow
Didn't read, what's the tldr?
>>
>>62458347
there's definitely no reason to stick around in a place like that where I live (unless you get an offer like I did). tech jobs are booming here right now, I'd have no problem finding something else. do feel bad for anyone in a situation where they'd feel too anxious about not being able to find something new to leave a shit job though.
>>
>>62458339
>I am data """""""""""""""scientist"""""""""""""""
>>
>>62458304
desu first what comes to my mind is that you got no relations, just connect tables and enjoy
>>
>>62458217
You're're retarded.

char *names[] = {"Stalin", "Mao", "Hitler", "M00t". "OP"};
qsort(names, sizeof(names)/sizeof(names[0]), sizeof(names[0]), (int(*)(const void*, const void*))&strcmp);
>>
>>62458424
honestly I have no idea, I'm not qualified in db admin whatsoever. I can write lookups but that's about it. every single one of us keeps telling the tech lead to hire an admin, and he refuses. it's going to be like this something really disastrous happens or they force one of us to learn how to database.
>>
>>62458457
#define -1 1
>>
>>62458278
Nigga use English. The only definition of sentinel that I know of wouldn't make any sense for a strcmp function. Or am I being baited by a bot...

>>62458476
define You (exit(1))
>>
>>62458497
Goddammit, fucking phoneposting is the worst.
>>
>>62458184
It works the way it does because it tells you not only if two strings are equal, but also their alphabetical order.
>>
>>62458278
>Can you make a string comparison function that constructively uses a sentinel? I can't think of a way.
All the C string functions "constructively use a sentiment" to determine when the string ends... C strings are null-terminated.
>>
>>62458540
sentinel*
>>
>>62458463
>it's going to be like this something really disastrous happens or they force one of us to learn how to database.
the 2nd one, probably he is gonna make you all learn it. Why would he pay extra person for that
>>
File: gui.png (77KB, 522x516px) Image search: [Google]
gui.png
77KB, 522x516px
What would be the best way to create this gui in java?
>>
File: 1475452964956.png (59KB, 1127x686px) Image search: [Google]
1475452964956.png
59KB, 1127x686px
How do I learn to type without looking at the keyboard?
>>
>>62458641
play an MMO.
It's how i learned, desu.
>>
>>62458560
it's completely normal for an organisation of our size to have a dedicated database admin. I really don't know what his thinking is or why he refuses.
>>
>>62458339
->data scientist and machine learning people sometimes use python
->python is growing evenly across all industries
=>therefore data science and ai used in every field
Wew, so this is the power of data """scinetists"""
Also
>implying so tags have any connection to the actual industry
>>
>>62458653
MMOs are dead
>>
>>62458606
>java
>xp
>lorry
I can smell the curry through the screen
>>
>>62458702
Not really, you just gotta look beyond theme park shit.
>>
>>62458641
Practice
I used klavaro
>>
>>62458743
>xp
I took that image out of my project file
>>
>>62458791
You should delete the entire thing if you think that GUI is acceptable in the current year, rajeesh.
>>
I don't see why I shouldn't use protected instead of private members, with public inheritances.
- I don't have to make access functions to read the base classes
- Being protected, functions outside the classes can't read/write on the members
>>
>>62458806
I don't decide what the college wants me to do.
>>
>>62458815
why are you learning sepples, rustlet?
>>
>>62458844
Qt Quick 2 application
>>
>>62458815
>>62458856
Also, do the private members get inherited at all? They aren't accessible anyways.
>>
>>62458815
Do that if that's what you want.
>>
>>62458815
>I don't see why I shouldn't use protected instead of private members
Same reason you shouldn't use public instead of private members: whoever inherits your class doesn't necessarily know all of its internal invariants, so you can't give them access to all of the inner state and expect them to just do the right thing and not violate them.
>>
>>62458917
If I'm okay with the deriv classes being able to read (not write) the members of base, wouldn't I be okay with just creating a const protected member?

Oh wait I can't construct deriv classes in that case due to the some members being constant.

Sticky situation if you ask me.
>>
mmmh
>>
I want a program that notifies me when there's a new post on a subreddit. The API allows me to do that but requires OAuth signing. Luckily, there's also an RSS feed available. So I'll be using that. As a bonus, I can make the program work for any news website that provides RSS feeds.
My goal is to create a program that checks each RSS feed for new entries and prints it to stdout. I also want to be able to save the state of the program to disk. This way I don't get notified of previous articles. However, I'm not really sure on the design of the program. Using SQLite sounds like overkill. So I'm debating on some plain text format or simply serialize the state. The former requires more boiler plate, but makes for easier debugging. The latter just works, but is a binary representation of the program state.
>>
>>62459041
go back there
>>
>>62459041
reddit XD
>>
>>62458969
Maybe you should reconsider if you even need inheritance at all.
>>
>>62459041
I want an up that notifies me when I get a (you) on 4chan
>>
>>62459055
>>62459057
I only use it as a news aggregator. The community is cancerous.
>>
>>62459123
Why do you need a notification then?
>>
>>62459143
because interesting stuff might get posted to subreddits?
>>
>>62459143
To see if there's a new article I might be interested in to read.
>>
>>62458606
bumping this
>>
>>62459155
>>62459160

then just go to the page and scroll through it looking for interesting headlines? it'll take a few seconds per page
>>
File: 1503384415422.png (361KB, 473x675px) Image search: [Google]
1503384415422.png
361KB, 473x675px
What is reddit?
>>
>>62459167
I wouldn't want to keep 15+ tabs of reddit open at all times
>>
>>62459182
not open, just browse when you want an update
>>
>>62459167
I don't want multiple tabs open and refresh them manually. I can automate that. The only thing left for me is to see if the new article is interesting enough for me to read.
>>
>>62459202
No, I'm just saying go to the fucking page and read when you want an update
>>
>>62459167
I want to be the first to post memes and reap karma though
>>
>>62459214
Of course I could do that. This is just a simple toy program to keep me busy this weekend.
>>
>>62459186
I grok this

>>62459202
can't for the life of me grok this past

>>62459214
yeah I grok
>>
> C++

Is there a Linux IDE that has debugging integrated as good as Microsoft VS?
>>
>>62459275
no a program should do one thing and do it well
>>
>>62459275
I don't think so
>>
>>62459283
IDEs should do all things well
>>
>>62459275
Eclipse CDT, Qt creator etc.
Shouldn't you be using a debugger in a separate terminal window?

Also, see
https://github.com/facebook/infer
>>
>>62459275
tried netbeans/cdt already?
not quite as good but seems ok

there is also clion, not free though
>>
>>62459295
>Shouldn't you be using a debugger in a separate terminal window?
No? Debugging and setting breakpoints in your IDE is basic shit otherwise why use an IDE.
>>
An RPG and Photo Editing Application, I'd give the idea of the Application but uhhh someone might steal
>>
>>62459303
Not yet, but tried Code::blocks and some other shit that seems too primitive in comparison.
>>
>>62459309
Use Qt creator then
>>
>xe has to debug xir code
>>
>>62459319
What if Photo Editing RPG xd
>>
>>62458815
>I don't see why I shouldn't use protected instead of private members, with public inheritances
the "why you shouldn't" case is when some user implementing your base class could break its functionality by directly modifying a given protected data member. if this is not the case, then doing as you describe is perfectly fine

>>62458875
yes. they're still a part of the object's mutable state. they may not be directly accessible, but they can still potentially be mutated through methods which *are* accessible

>>62458969
>Oh wait I can't construct deriv classes in that case due to the some members being constant
not sure what you mean here. you can have constant members in a base class as long as they are initialized in the initialization list of a constructor and a derived class calls such a base constructor

>>62459275
qt creator. great editor in general. i use it even on windows. legitimately prefer it over visual studio
>>
>>62459394
What I want is
- Let the base class be able to manipulate the member when it wants
- Let the deriv class read the member when it wants, without having to create access functions

What structure am I looking at?
>>
>>62459439
class Base
{
private:
int nigger;
protected:
const int &nigger_ref;
}

Close enough.
>>
where could one learn cmake?
also, should I learn ninja instead?
>>
>>62459455
ayy
It's whacky, but does the job
>>
>>62459457
Sooner or later you will have to learn CMake anyways
>>
>>62459329
>>62459394
>qt creator. great editor in general. i use it even on windows. legitimately prefer it over visual studio

Can you make it work for non-Qt projects? I created a plain C++/Cmake project to test it and now it can't find standard headers like iostream.
>>
>>62459439
you're talking about one value with two different mutability rules. there's no way to achieve this without an accessor function. there are languages like C# that have properties, which could simplify this scenario, but those are just syntactic sugar for accessor functions. that's about the best you're gonna get even in theory
>>
>>62459471
this is what I was thinking as well, but is there a non-shit guide somewhere?
>>
>>62459485
yea, definitely. You can make plain C/C++ projects with CMake
>>
>>62459457
>also, should I learn ninja instead?
no, ninja can replace make but not cmake

cmake can work with either afaik but I never used ninja
>>
>>62459439
>>62459488
oh, i guess technically
>>62459455
this works
>>
>>62459488
Stop shilling C#
>>
>>62459464
probably gonna be less efficient than an accessor function though, I don't know how references compile down but it'll probably have indirection overhead
>>
>>62459490
I don't know myself.
C/C++ not having a standard build system is a major pain in the ass
>>
>>62459457
>>62459490
>>62459523
this is by far the best resource on it i've seen to date:
https://www.youtube.com/watch?v=bsXLMQ6WgIk

>>62459485
>Can you make it work for non-Qt projects?
absolutely, in fact i use it in exclusively this context
>I created a plain C++/Cmake project to test it and now it can't find standard headers like iostream
make sure it's configured correctly for your build environment. i use it with MSYS/gcc/gdb but i know it's capable of working with msvc

>>62459507
i'm not shilling C#, simply stating a feature it supports which was relevant in context
>>
>>62458004
Im jumping in learning some SFML, what's /g/ opinion about that library?
>>
>his language can't even do this
(defun iterate-compile-for (form)
(destructuring-bind (_ binding-name (func-name &args)) form
(apply (geti *ns* func-name) (cons binding-name args))))
(defun iterate-compile-while (form)
(let (data (object null))
(set! (. data cond) (second form))
data))
(defun iterate-compile-do (form)
(let (data (object null))
(set! (. data body) (cdr form))
data))
(defun iterate-compile-collecting (form)
(let (data (object null)
accum-name (gensym))
(set! (. data bind) (list accum-name '()))
(set! (. data body) `((set! ~accum-name (cons ~(second form) ~accum-name))))
(set! (. data finally) `((reverse ~accum-name)))
data))
(defun collect-field (field objs)
(filter (lambda (x) (not= x undefined))
(map (getter field) objs)))
(defmacro iterate (&forms)
(let* (res-name (gensym)
all (map (lambda (form)
(case (car form)
let (iterate-compile-let form)
for (iterate-compile-for form)
while (iterate-compile-while form)
do (iterate-compile-do form)
collecting (iterate-compile-collecting form)
finally (iterate-compile-finally res-name form)
default (error "Unknown iterate form")))
forms)
body-actions (apply concat (collect-field 'body all))
final-actions (apply concat (map (lambda (v)
(push `(set! ~res-name ~(last v)) (butlast 1 v)))
(collect-field 'finally all))))
`(let* ~(concat (list res-name undefined)
(apply concat (collect-field 'bind all)))
(loop ()
(if ~(cons 'and (collect-field 'cond all))
(progn
~@(apply concat (collect-field 'pre all))
~@(butlast 1 body-actions)
(set! ~res-name ~(last body-actions))
~@(apply concat (collect-field 'post all))
(recur))
(progn
~@(if (null? final-actions) (list res-name) final-actions)))))))
>>
struct Foo
{
int foo;
};

class Bar
{
private:
int bar;
protected:
const int &bar_ref = bar;
};

int main()
{
std::cout << sizeof(Foo) << std::endl;
std::cout << sizeof(Bar) << std::endl;
}

4
16

what the fuck
>>
>>62459588
Oh wait, I forgot about padding.
>>
>>62459565
>https://www.youtube.com/watch?v=bsXLMQ6WgIk
thaks dud, I'll watch that
>>
What's the Python equivalent to the BASIC TAB function?
>>
IBM just open sourced their JDK
>>
>>62459580
>his language is so shit he has to write his own highly inefficient iteration primitives
Wake up, grandpa, it's 2017, everyone has switched to lazy iterators for this shit, even C++ is getting ranges in 3 years.
>>
>>62459730
What does that mean?
>>
>>62459597
Aren't references implemented in pointers?
>>
>>62459743
I assumed they were (even though I hoped that this could be optimized away in this case).
What surprised me mainly was the sheer size of the struct, but I forgot there was 4 bytes padding between the 4 byte int and the 8 byte pointer.
>>
File: string.png (7KB, 467x102px) Image search: [Google]
string.png
7KB, 467x102px
Why is this not working? I'm doing everything like in the book
int main()
{
char word[MAX];
int n;

scanf("%s", word);

if (strcmp(word[0], word[1]) == 0)
n = 0;
else if (strcmp(word[0], word[1]) < 0)
n = -1;
else
n = 1;
printf("%d", n);
}
>>
>>62459777
>He is still comparing strings
>>
>>62459739
Haskell-style lazy iteration primitives: https://github.com/ericniebler/range-v3 , allows you to use all that juicy map/filter/group/zip stuff.
>>
File: 1505518638088.jpg (9KB, 239x249px) Image search: [Google]
1505518638088.jpg
9KB, 239x249px
>>62459730
>3 years.
>>
>>62459814
You can use it as a lib right now.
>>
>>62459777
strcmp compares a sequence of characters
If you entered "abcd", strcmp would compare "abcd" to "bcd". Just compare the actual characters directly.
if (word[0] == word[1]) { n = 0; }
That would be true if you entered "aa".
>>
Yet another combinatoric algo for my library.

function powerset(l)
local out = {}
local function helper(l_i, out_i)
if l_i > #l then
coroutine.yield(out)
else
-- element not in set
out[out_i] = nil
helper(l_i+1, out_i)
-- element in set
out[out_i] = l[l_i]
helper(l_i+1, out_i+1)
end
end
return coroutine.wrap(helper, 1, 1)
end
>>
>>62459836
which lib?
>>
Does std::boost have ranges?
>>
How realistic of a goal is it to be a game dev?
Every year I hear that a lot of people go in to CS with hopes of becoming game dev, how many of them actually make it?
>>
File: 1496998730043.jpg (33KB, 493x386px) Image search: [Google]
1496998730043.jpg
33KB, 493x386px
>>62459730
>"iteration primitives" that expand to exactly the same thing as hand-optimized iteration are highly inefficient
Are you mentally retarded? Also, good luck waiting X years to receive whatever scraps the C++ committee (or whoever calls the shots for what features make it into whatever meme language you use) has decided to gift you in its infinite kindness and wisdom. And don't forget to kiss their ass afterwards for finally providing you with something I can hack up in 5 minutes, programlet.
>>
>>62459866
https://github.com/ericniebler/range-v3
>>
>>62459808
>allows you to use all that juicy map/filter/group/zip stuff
you can do that stuff without them. i think the functionality lazy iteration adds is more to do with stuff like comprehensions and infinite ranges
>>
File: lisp_is_kill.png (4KB, 892x25px) Image search: [Google]
lisp_is_kill.png
4KB, 892x25px
>>62459897
> expand to exactly the same thing as hand-optimized
But it's still lisp, so it's highly inefficient by definition.
>lisper shitting on C++ committee
Oh wow.
>>
>>62459929
It's also about memory efficiency. Who the fuck wants to evaluate the permutations of the list 1 through 16 at once? It's not necessarily infinite, but it is too large for current or near-future systems.
>>
>>62460003
>highly inefficient by definition.
No, that's actually every non-trivial C++ program ever written. Go tell this efficiency meme to someone who will believe a sepples monkey.

>implying i write in CL
>implying CL users have to wait for a committee to implement whatever they need
>implying CL suffers from the same pathetic dearth of features that sepples has suffered from since day one
>>
How come I cannot pass a lambda for a C function pointer in a library call? I want to set GLFW callbacks using lambdas.

Like so:
        glfwSetWindowSizeCallback(window, [this] (GLFWwindow *, int width, int height) {
onResizeEvent(width, height);
});


But it says it cannot convert the lambda to a fp even though the signatures match, what gives?
>>
>>62460079
A lambda that captures anything (including this) can't be passed as a function pointer.
>>
>>62460106
So if I want the callback to call a function on a struct then I've no way to do it without resorting to a global object or a singleton? That's shitty.
>>
>>62460003
Also, you very much missed the point of that loop example: it can be easily extended to produce the equivalent of hand-optimized iteration code for whatever arbitrary data structure the user can come up with using simple functions. This is inherently impossible and will always be impossible in sepples and most other languages.
>>
>>62460121
Aye. Lambdas are seriously gimped outside of templates. If only C++ used a traits-like polymorphism model instead.
>>
>>62460010
right. i mainly just wanted to point out that functions like map/filter/group/zip already do have pretty trivial and generic implementations in C++, and are by no means dependent on lazy iteration in themselves

>>62460121
>I've no way to do it without resorting to a global object or a singleton
not quite. you can use a non-capturing lambda and then access state through a user data pointer in the struct. GLFW offers glfwSetWindowUserPointer and glfwGetWindowUserPointer for this purpose
>>
>>62460128
> it can be easily extended to produce the equivalent of hand-optimized iteration code for whatever arbitrary data structure the user can come up with using simple functions
It can only be `easily extended` only if you keep rewriting the macro over and over for each new data structure, this is like the opposite of abstraction, this means the macro isn't truly generic.

>This is inherently impossible and will always be impossible in sepples and most other languages.
In C++ if you implement the iterator concept (i.e. operator* and operator++), you get all the algorithms in the STL working with your data structure. In more modern languages, all you need to do is to implement the Iterator/Enumerator trait/interface to get loops and all the fancy methods like map/filter/zip/fold/etc for free. Modern compilers optimize all the function calls out, producing thigh loops. As a result in Rust/C#/C++/D, I can use any third-party data structure with the standard foreach loop out of the box.
>>
>>62460175
Is there any particular reason why lambdas with captures cannot be converted to a function pointer?

>>62460218
>GLFW offers glfwSetWindowUserPointer and glfwGetWindowUserPointer for this purpose
Hey, thanks, that did the trick.
>>
>>62460079
>});
>>
fuck opengl though
>>
>>62460315
Because the variables they capture are part of the lambda.
A lambda expression is an implementation defined type, that is essentially a struct containing a function pointer and the capture variables.
>>
What's a good book for learning how computers work to make me a better programmer?
>>
>>62460315
> Is there any particular reason why lambdas with captures cannot be converted to a function pointer?
It's because it's not clear where they are supposed to keep the captured values and who will free them after they are not longer needed. You need to guarantee the function pointer is valid at any time, and you can't do it for anything except static functions.
>>
What the hell is this supposed to do?
do /* skips rest of line after number */
scanf("%c", &one_char);
while (one_char != '\n');
>>
>>62460315
>Is there any particular reason why lambdas with captures cannot be converted to a function pointer?
because if they capture something, then they have individual state, and thus can no longer can be fully represented as a pointer to a function alone. lambdas are simply objects with overloaded () operators, and if they capture, the things captured are just data members/references in the object. you can even declare new mutable state in a lamdba declaration:

auto foo = [i = 0]() mutable
{
std::cout << i++ << std::endl;
};


this prints a higher every time foo() is called
>>
>>62460442
it reads until the one_char is newline and exits the loop
>>
>>62460442
It's a less compact way to grab input until the next line. I'm assuming you want to skip the rest of the input after the number just in case some retard started putting shit after the number you were supposed to input.

More compactly
while (getchar() != '\n') ;
>>
>>62460313
>It can only be `easily extended` only if you keep rewriting the macro over and over
Nope. You don't have to touch the macro at all. Why spew stupid claims about code you don't understand?

>b-b-but muh iterator interfaces
They're not equivalent and not an adequate replacement. For starters, they can only be used to iterate through a data structure in one predefined way. If you have multiple ways to do it, you have to use actual iterators, at which point the code produced is not equivalent to hand-optimized iteration.
>>
>>62458323
https://dlang.org/phobos/std_typecons.html#Unique
Now what
>>
>>62460552
> You don't have to touch the macro at all
What do you mean by "easily extended" then?
> For starters, they can only be used to iterate through a data structure in one predefined way
No, it's not, see reverse iterators for example.
>>
>>62460614
>What do you mean by "easily extended" then?
Can be easily made to work with new structures the original macro was not aware of or designed for. The usefulness of the macro can be extended without modifying it.

>see reverse iterators for example.
Did you read the post at all? Specifically:
>If you have multiple ways to do it, you have to use actual iterators, at which point the code produced is not equivalent to hand-optimized iteration.
Reverse iterators are exactly the example I had in mind when I wrote that.
>>
How do I compile a dynamic library to use with other programs.
I have a program written in C++ with multiple paths, classes, files, functions, structs, etc. Can I turn this into a lib. Every tutorial on libs only uses 1 file. I have many folders of files. My idea is just to remove the main function, and turn that into a lib. But when I tried it doesnt work. I also wouldnt know how to access the file later in the lib.
Im using VS.
>>
How do I condense these two functions into one?

template <typename K, typename V>
inline V get_default(const std::map<K, V> &map, K key, V default_val)
{
const typename std::map<K, V>::const_iterator itr = map.find();

if (itr == map.cend())
return default_val;
else
return *itr;
}

template <typename K, typename V>
inline V get_default(const std::unordered_map<K, V> &map, K key, V default_val)
{
const typename std::unordered_map<K, V>::const_iterator itr = map.find();

if (itr == map.cend())
return default_val;
else
return *itr;
}
>>
File: 1496690244379.jpg (43KB, 390x470px) Image search: [Google]
1496690244379.jpg
43KB, 390x470px
>>62460686
>template <typename K, typename V>
>inline V get_default(const std::unordered_map<K, V> &map, K key, V default_val)
>const typename std::unordered_map<K, V>::const_iterator itr

>this is an actual programming language that people use and take seriously
>>
>>62460706
The only thing that's wrong with this is the iterator typename and that will disappear with auto.
>>
>>62460706

brainlet
>>
>>62460664
>Can be easily made to work with new structures the original macro was not aware of or designed for
How exactly?
>you have to use actual iterators, at which point the code produced is not equivalent to hand-optimized iteration
This is false: https://godbolt.org/g/xVMSQu you can see, the compiler has even unrolled the loop.
>>
>>62460728
>this is what sepples users actually believe
>this is what sepples users think they can convince programmers of
>>
>>62460686
C++ supporst HKT:
template <template <typename K, typename V> M, ...>
>>
What sort of projects could I work on to practice plain C?
>>
>>62458606
javafx
>>
>>62460756
>How exactly
Using simple functions.

>it's true for one specific toy example, therefore it's always true
Nope.
>>
Why the fuck doesn't github support direct messages, I just want to ask the author one simple question, I don't want to create an issue for it.
>>
>>62460791
write a client/server thingy
>>
>>62460824
> Using simple functions.
Doing what exactly?
> it's true for one specific toy example, therefore it's always true
It's almost always true, this is why Rust is so close to C in almost all benchmarks. And it's certainly better than whatever hacks the CL compiler uses to compile a dynamically typed language into machine code.
>>
>>62460686
I got you, senpai.

#include <type_traits>
#include <map>
#include <unordered_map>

template <class>
struct is_map;

template <class... Tn>
struct is_map<std::map<Tn...>> : std::true_type {};

template <class... Tn>
struct is_map<std::unordered_map<Tn...>> : std::true_type {};

template <class M, class K, class V, class = std::enable_if_t<is_map<M>, void>>
V get_default(M const& map, K key, V value)
{
auto it = map.find();
if (it == map.cend())
return value;
else
return *it;
}


This should do the trick if I got the syntax right.
>>
I wont do it anyway but how far could I get if I studied 8 hours a day for 6 months?
>>
>>62460983
About 1440 hours far.
>>
>>62460995

is that a lot?
>>
>>62460983
pretty far
>>
Rust or C++?
>>
>>62460909
>It's almost always true
First of all, my original statement is true regardless of your theories about the compiler's ability to optimize it all away. Iterators do involve jumping through so additional hoops compared to manual iteration. As for your claim that those additional hoops will always be eliminated by the compiler, good luck proving that. It's very easy to produce code that looks like it "should" be optimized and then doesn't.

>it's certainly better
If you consider unreadable, unmaintainable, bug-ridden, non-scalable, inflexible, unnecessarily verbose heaps of code to be "better" then the opposite, then sure, it's better. Enjoy being a primitive sepples monkey.
>>
>>62461016
than the opposite*
>>
>>62461016
> unreadable, unmaintainable, bug-ridden, non-scalable, inflexible, unnecessarily verbose heaps of code
> writes he unironically after posting >>62459580
>>
>>62460909
>Doing what exactly?
Generating the necessary operations to iterate through the data structure in the desired way.
>>
Have a database systems midsemester test in two days. Have a pretty heavy stats/math background, know how to do a bit of shit in Python, know how to do a bit of shit in R.

But this database shit is so fucking vague
>oh it's really open to interpretation
>there's many right answers
>it's all down to what the client wants
>if you think something should be changed or do something strange write your assumptions down so I know
>the only way you're going to learn is by doing
>it's a department policy that we don't give exact answers so you have to go out and find the answer yourself

I get that you don't want to spoon feed your students but fuck. Some of us aren't computing majors who thrive in this weird elitist little club; I just want to learn how to fucking implement databases NOT be initiated into some fucking cult. The only way to get good marks is sit in the smelly computer labs all week and beg the tutors for their help.

This shit better fucking pay off
>>
My C assignment says that all standard-header files, type declarations, function prototypes etc should be in custom header file.

What do they even mean by standard header file in custom header file?
>>
>>62461035
And how would it be different from iterators? Besides, of course, the fact that CL code can't be type-checked at compile time and thus inherently less safe.
>>
>>62461031
Other than the fact that all the newlines got mangled, that code looks better than the average sepples monkey functions while accomplishing much more.
>>
>>62458004
What can I compile Microsoft VS? It looks like C, C++, C#, VB, and ASM. Is there anything else?
>>
>>62461058
All your .c files include a single .h file, and that .h file defines all the stuff you need and includes all the standard library headers.
>>
>>62460930
wouldn't you want the default case to inherit std::false_type?
might also want an is_map_v helper variable template for contexts where is_map<T>{} or is_map<T>::value could otherwise be required
>>
>>62461071
Ok so my main source file would only have to include
 #include "header.h"

and nothing else?
>>
>>62461089
Possibly, it's been too long since I last played with SFINAE.
>>
>>62461102
Yeah. That's what it seems like.
>>
>>62461120
Alright thanks
>>
File: 1504953336683.png (260KB, 483x368px) Image search: [Google]
1504953336683.png
260KB, 483x368px
>>62461058
>header file of header files
>>
>>62461065
>And how would it be different from iterators
It's like asking how a chair is different from an orange. I've already explained to you that it expands into code that looks the same as manual iteration, so there's no need to hope that the optimizer is smart enough to do the right thing (and it often isn't when it comes to less trivial stuff than your example).

>CL code can't be type-checked at compile time and thus inherently less safe
This is not relevant to the discussion. You can cry about how CL is "inherently less safe" all you want, but the fact remains that sepples monkeycoding is far more bug-prone than lisp programming, and when you do mess things up, you don't get a nice recoverable exception and the option to interactively fix and re-run the relevant section of the code. You get silent heap corruption and a segfault in a completely different place from the source of the mistake.
>>
File: download (1).jpg (7KB, 225x225px) Image search: [Google]
download (1).jpg
7KB, 225x225px
I challenge you to write fizzbuzz in holy Ocaml superior language

ProTip: you can't
>>
>>62461067
F#
>>
>>62461172
>no native multithreading support
>no unsigned type
>types are boxed
It's shit
>>
>>62461172
Pattern-match on a tuple of counter mod 3 and counter mod 5. Comfy.
>>
>>62461065
>CL code can't be type-checked at compile time
You can write your own Haskell-tier optional type system and type-check at compile time. People have done just that. You're a clown.
>>
>>62461172
I challenge you to write a multi threaded program in OCaml.

Pro tip: you can't.
>>
>>62461229
kek
>>
Anyone here uses Dev C++?
When you press " or (, for example, it writes "" and () for you. But when you press " or ) again it writes """ and ()). CodeBlocks jumps over characters it wrote for you if you type them.
There has to be an option to turn on the same in Dev C++ right?
>>
>>62461158
You still haven't explained how are you going to "expand" the marcro with functions, in such a way that it would be "the same as manual iteration". Again, how are these functions you're going to expand the macro with is different from Iterator::next() other languages expand their iteration facilities with?
>sepples monkeycoding is far more bug-prone than lisp programming
[citation needed]
We don't hear about bugs in CL code because there is no CL code left in production.
>>62461225
Go ahead, type-check me this:
(loop (print (eval (read))))
>>
>>62461280
>You still haven't explained how are you going to "expand" the marcro with functions
Literally just read the code.

>trying to compare generating optimized iteration code directly with writing iterators and hoping the compiler will be smart enough to do the right thing
How many times are you going to repeat this error?

>[citation needed]
Citation needed on literally every single one of your claims. However, my description of what happens in sepples-tier languages vs. what happens in decent lisp implementations when you fuck up is uncontroversial and can be confirmed by anyone who's ever programmed in them.
>>
>>62461280
>b-b-but you can't type-check arbitrary evals
What exactly do you think that proves, brainlet?
>>
>>62461335
> Literally just read the code.
There's nothing about expanding for other data structures there. If you mean adding more `iterate-compile-*` functions, this is exactly what I said - you have to change the code of the macro every time.
> How many times are you going to repeat this error?
Until you realize it's not the 80s anymore and compilers are pretty smart, or until you show that the difference is even visible in the inherently slow language.
> who's ever programmed in them
I've programmed in CL tho.
>>62461369
That any language which has `eval` in it can't be statically type-checked? Specifically, any language in which `eval` executes in the current computational context.
>>
>>62461469
>There's nothing about expanding for other data structures there.
Try actually reading and understanding the code.

>Until you realize it's not the 80s anymore and compilers are pretty smart
You're the one making the claim that the compilers are smart enough to optimize away the overhead in every case. Good luck proving it.

>I've programmed in CL tho.
Then you know about conditions and restarts, and if you've programmed in C or C++, you also know about arbitrary heap corruption and segfaults.

>That any language which has `eval` in it can't be statically type-checked?
(defun foo (x y) (+ x y))
(decltype foo (Number Number) Number)

(defun crap ()
(foo (eval) (eval))) ; "Error: expected Number, got Any


Yeah, okay, brainlet.
>>
File: 1501958812871.png (314KB, 500x684px) Image search: [Google]
1501958812871.png
314KB, 500x684px
I want to write a small onscreen graphic program for windows in c++, is directx the library to go with for that?
>>
>>62461716
>directx
Do you hate fun?
>>
>>62461716
>using DX directly to render some simple graphics
Just use one of the many graphics libraries available. Many of them use DirectDraw or something like that behind the scenes anyway.
>>
File: 1000000000000000hoursinpaint.png (5KB, 354x407px) Image search: [Google]
1000000000000000hoursinpaint.png
5KB, 354x407px
So for part of a problem I'm working on I need to obtain an in-order representation of a tree using successive numbers starting at 1. Say I have an unlabeled tree structure (pic related and variable 'b' in 'main' below) and I want to assign numbers 1 through the numbers of nodes into it so it's a proper BST. Then I want to retrieve the in-order serialization of that BST. For pic related an the example the outcome would be [8, 7, 2, 1, 6, 4, 3, 5, 9].

Is there an easier way to accomplish this besides what I've already done?

class binary_tree:

def __init__(self, left=None, right=None, n=None):
self.n = n
self.left = left
self.right = right


def assign_to_binary_tree(tr):
def helper(t, i):
if t.left:
i = helper(t.left, i)
t.n = i
i += 1
if t.right:
i = helper(t.right, i)
return i
helper(tr, 1)
return tr


def serialize_binary_tree(tr):
def helper(t, o):
o.append(t.n)
if t.left:
o = helper(t.left, o)
if t.right:
o = helper(t.right, o)
return o
return helper(tr, [])


def main():
b = binary_tree(
binary_tree(
binary_tree(
binary_tree(
None,
None
),
binary_tree(
binary_tree(
binary_tree(
None,
None
),
binary_tree(
None,
None
)
),
None
),
),
None
),
binary_tree(
None,
None
)
)
c = assign_to_binary_tree(b)
d = serialize_binary_tree(c)
print(d)

if __name__ == '__main__':
main()
>>
>>62461229
Ocaml doesn't need muhlti threadingeru
>>
File: brainlet.png (93KB, 750x802px) Image search: [Google]
brainlet.png
93KB, 750x802px
>>62461529
>Try actually reading and understanding the code.
I understand it well enough to see no way to expand it cost-free without modifying the macro.
>Good luck proving it.
I'm the only one who actually posted some assembly so far.
>arbitrary heap corruption and segfaults.
It's not arbitrary when you fuck up.
>conditions and restarts
Good for debugging, too costly for production.
>Yeah, okay, brainlet.
See picrel, but this isn't what I meant, I mean executing arbitrary code in the current context, like
(defun foo (x y) (+ x y))
(decltype foo (Number Number) Number) ;whatever the correct code is

(eval "(defun foo (x y) (cons (car x) (car y))) ")
(eval "(decltype foo (List List) List)")

(foo 1 2) ; ????

Before you start screeching, this is valid lisp code.
>>
>>62461763
Any you would recommend that work with 3d models?
>>
>>62461765
None of what you just said makes any sense and you don't seem to know the difference between preorder and inorder traversal.
>>
>>62461855
the absolute state of ocaml
>>
>>62461879
>I understand it well enough to see no way to expand it cost-free without modifying the macro.
Your opinions are irrelevant. I wrote it and I know exactly what it does and how it does it. You're arguing purely based on ignorance.

>I'm the only one who actually posted some assembly so far.
For one toy example. Still waiting for you to prove your claim that the optimizer will always do the right thing in more complex situations (a claim that I know to be false, so I know this proof will never arrive).

>Good for debugging, too costly for production.
Another monkeyshit claim with no evidence or logic to back it up. Dismissed.

>actually trying to run the code snippet
Are you retarded? It was just an example illustrating one way in which your retarded non-issue can be resolved.

>(foo 1 2)
>Error: expected List, got Number
What is your example supposed to prove? And again, you are arguing based on ignorance against objective and verifiable reality. It can and has been done. Can you try being less subhuman and offer anything besides denialism, brainletism and logical fallacies?
>>
>>62462170
>I wrote it and I know exactly what it does and how it does it.
>How?
>Just trust me, it werks, I won't say how tho, it just does, if you don't understand immediately you're just a retard.
Gee, I wonder why Lispers are universally despised.
>the optimizer will always do the right
This is now that I claimed tho, it will be right in enough case for it not being an issue, which you can see by looking at the benchmarks. The same benchmarks you can see CL struggling behind 5x times slower despite all the crazy hacks and non-idiomatic code lispers could come up with.
>It was just an example illustrating one way in which your retarded non-issue can be resolved.
If it can be done, why do you post non-working code? You even wrote an error in quotes as if it's from the compiler. You should really just stop making lisper look even worse than you are.
>Error: expected List, got Number
You can't be this dumb, the compiler can't know at the compile time what shit you'll put into eval during the run-time. This is basically why static type-checking is impossible in Lips.
>>
>>62460369
Tanenbaum's Operating Systems?
>>
>>62461716
>>62461935
openFrameworks might be a good fit for your use case. it's good for relatively simple 2D/3D multimedia applications and rapid prototyping and such. learning DirectX or OpenGL requires a nontrivial time investment and would probably be overkill if you don't need the level of fine-grained control they provide
>>
>>62462371
>spoon-feed me how this macro works while i argue with you every step of the way
For what? It's a lost easier to just point out that you're arguing based on ignorance.

>it will be right in enough case for it not being an issue
So now you're reducing it into the purely subjective claim: "it works well enough to satisfy me".

>muh micro-benchmark performance
That not a valid argument, and it can never be one.

>If it can be done, why do you post non-working code?
Because I thought you have enough brain-cells to understand the point without me having to tell you to install a bunch of shit: eval can be declared to return a result of type 'Any' (which is incompatible with any of the more specific type), completely sidestepping your complaints.

>This is basically why static type-checking is impossible in Lips.
I don't even need to get into why your argument is moronic (not that you'd have the mental capacity to understand why you're wrong anyway). Look up typed Clojure and typed Racket for recent examples of how macros can be utilized to implement static type checking in a dynamically-typed language with eval. You are just another subhuman monkey arguing with objective reality.

Any further denialism from you on this issue is equivalent to stating that those two examples don't exist (when anyone can google them and see that they do).
>>
>>62462605
> Look up typed Clojure
Clojure is dynamically typed.
> and typed Racket
https://docs.racket-lang.org/ts-guide/caveats.html#%28part._.Macros_and_compile-time_computation%29
>Typed Racket will type-check all expressions at the run-time phase of the given module and will prevent errors that would occur at run-time. However, expressions at compile-time—including computations that occur inside macros—are not checked.
> Concretely, this means that expressions inside, for example, a begin-for-syntax block are not checked.
Just like I fucking said, I have no idea why you keep digging.
>>
>>62462741
So we've reached the point where you deny direct evidence... scum like your parents just shouldn't have the right to reproduce. You have been proven wrong. I gave you two examples of static type checking using macros in dynamically-typed languages with eval. It's not up for any sort of debate.
>>
File: static_typing_in_lisp.jpg (44KB, 600x450px) Image search: [Google]
static_typing_in_lisp.jpg
44KB, 600x450px
>>62462828
Sure, you can """optionally""" check ""some"" code, this is not even close to comprehensive static type-checking Haskell-style, which I was talking about from the start, it's more like a shitty cargo cult. Type-checking only some code means your code isn't really type-checked, it's basically meaningless, you might as well write unit-test.
>>
File: tumblr_ovdhouoziJ1wqifv4o1_540.png (239KB, 540x467px) Image search: [Google]
tumblr_ovdhouoziJ1wqifv4o1_540.png
239KB, 540x467px
>>62462442
Great, thank you!
>>
>>62462878
>denying direct evidence
Simply subhuman.
>>
ARE YOU FUCKING SERIOUS WITH THIS?
ALL THOSE REDUNDANT WRITINGS
>>
I can login to linkedin headerless, boys

am I a real programmer now
>>
>>62462998
Welcome to the C linkage model. Cry.
>>
>>62463038
But that's sepples.
>>
>>62463045
They both use the same linkage model, with the detail that C++ also mangles names.
>>
why is haskell so popular among SJWs and hipsters, but they hate C passionately?
>>
File: 70a2a2d03e69ae6684c63699a5771af1.png (609KB, 1000x1000px) Image search: [Google]
70a2a2d03e69ae6684c63699a5771af1.png
609KB, 1000x1000px
Does anyone have a link to a good pdf copy of headfirst into java? I can only find shitty scans. Also is there any better /g/ book for learning java or is this the definitive one?
>>
How do I do void pointer arithmetic in C? Cast to intptr, do my arithmetic, then cast back to void*? Or should I use char* despite it not having anything to do with characters, just because it's 1 byte?
>>
>>62463092
Use char* yes. Although you should question why you're using void* arithmetic.
>>
>>62463085
except that wouldn't be such a clusterfuck in C, and using a header file for cat.cpp isn't needed since it's so small
>>
>>62463105
That's not required in C++ either
>>
>>62463088
I like both.
>>62463091
libgen.io
>>62463103
I have a blob of memory, I need to read X bytes from an offset of Y. They're not characters, just binary data, so using char* feels unclean somehow.
>>
>>62463128
char* was the original generic pointer before void* was added (and I believe it still has special rules wrt strict aliasing), so it's perfectly reasonable.
>>
>>62463120
I know, but making it an object oriented clusterfuck sure is if you want to write sepples "the modern way".
>>
File: 7438338.png (189KB, 770x337px) Image search: [Google]
7438338.png
189KB, 770x337px
>>62463128
>site can't be reached
is it down just now?
>>
>>62458004
Website for business has login for employees to access their work schedule how would one translate this into a phone app? Is this a difficult task?
>>
>>62463168
It's hosted on some russian guy's basement server and a reverse proxy half the world over, in addition to being written in PHP. Just wait a few minutes.
>>
>>62463092
>Cast to intptr, do my arithmetic, then cast back to void*?
Only use intptr if it is an pointer to an int.

>Or should I use char* despite it not having anything to do with characters, just because it's 1 byte?
The char storage type represents the smallest addressable unit, not necessarily characters.

>>62463128
Pointer arithmetics on void is undefined behaviour though. Mostly because void* can point to non-data addresses as well (for example function pointers), which may be stored in different type of memory with other addressing requirements on more exotic architectures.
>>
>>62458004
>What are you working on, /g/?
Userspace NVMe driver using sysfs and reading out the process' pagemap.
>>
>>62463194
No, an intptr is just an int that's guaranteed to be large enough for pointers. I know void pointer pointer arithmetics are undefined, but intptr arithmetic isn't.
>>
>>62463192
>russian guy's basement server
As usually, they have no respect to copyright.
>>
>>62463238
The project's core goal is in direct violation of copyright, it doesn't have to do anything with russians more than that they can do it without worrying about police.
>>
>>62463269
Your picture contradicts your post.
>>
>>62463258
Are you braking any laws by downloading that shit?
>>
File: 1499555342618.gif (855KB, 500x281px) Image search: [Google]
1499555342618.gif
855KB, 500x281px
>>62463269
>[Deleted]
>>
>>62463168
libgen blocks some us and uk ip addresses iirc
>>
>>62458641
Typing of the Dead
>>
>>62460686
Why are you not passing a value to find here?
>>
I don't understand how const references work in C++.
Why can I create a const int r = &n if n is a double or float?
Why can I also create a const reference to a literal?
I don't get it.
>>
>>62461958
It does, you're just an idiot. I did misspeak with the ordering of the traversals, it happens. I'm a mute irl; I'm not so good at words.

>>62461765
>>62461958
Inputs:
Unlabeled binary tree (nodes have no associated value but the structure is defined)

Outputs:
Preorder traversal of the tree yielding a list of values containing 1..n

First I add labels to the tree so it forms a proper BST (meaning it's ordered left-min and not some other random assignment). I use the values 1..n for the labels.

If explaining from the reverse direction would help: I need the output list to be ordered such that if I build a BST (without rotations) from that list by inserting each successive value into a partially constructed tree it will result in a BST with the same structure as the input binary tree.

My question is: Is there any easier or faster way to accomplish this? Perhaps this can be done with a single traversal?
>>
>>62463414
>const int r = &n i
That's not a reference.
>>
@62463428
>It does, you're just an idiot. I did misspeak with the ordering of the traversals, it happens. I'm a mute irl; I'm not so good at words.
Fuck you lol, at least I can speak and explain myself clearly. Does being a mute also make you a retard?

I won't even give you an (You).
>>
>>62463464
Fuck I meant const int &r = n;
My bad.
>>
I'm hangry
>>
What shall I use: ReasonML, Purescript or Idris?

ReasonML is relatively mature, backed by FB and can be used as a better javascript, i.e. both functional and imperative approach will work. Also, no need to care about purity, effects etc.
Cons: no type classes and no way to enforce purity. Also, has small ugly parts like `[@@bs.module]`. (And a funny thing: BS compiler does perform purity check)

Purescript already has some pretty usable ecosystem, advanced features like type classes and row polymorphism, simple&clean FFI, fine-grained Effects.
Cons: no corporate backing, fine-grained effects did bite my ass once already, no imperative programming possible, still 0.X.Y version.

Idris is really advances, has both IO and fine-grained Effects, dependent types, type classes, pretty simple FFI. Labeled effects seem to be really good, I can imagine writing almost imperative-looking code using them, much better than haskellesque atrocities. Already passed version 1.0.
Cons: no corporate backing, no ecosystem(even no package manager), not used by any serious company as far as I know(unlike both ReasonML and Purescript that already have some real uses).
>>
>>62463536
For what?
>>
>>62463489
You'll need to look up the difference between lvalue and rvalue to fully make sense of it.
lvalue is a named value, like a declared variable.
rvalue is an unnamed temporary, like the result of an expression 2 * n.
const references can bind to rvalues, but not non-const references.
In the case of something like this -
double d;
int const &ref = d;

d is being implicitly converted to an integer and a reference to the temporary is being initialized. If you change d afterwards, ref won't observe that change.
>>
>>62463551
For writing ultra-reliable backend stuff so that I have no need to rewrite it later.
>>
>>62463569
>ultra-reliable
>picks meme languages
C# or Java
>>
>>62463552
>implicitly converted
But what if the double or float variable has a floating point value? Is it truncated when the temporary is created, and the reference points to the new value? What is the point of creating a temporary, wouldn't it be better to have the compiler return a type error?
>>
>>62463679
Meh, I didn't say I want to be productive. But I want to make it rock-solid without writing unit-tests. I'm using C# at work and we still have good old NPEs sometimes.
>>
>>62463699
>But what if the double or float variable has a floating point value? Is it truncated when the temporary is created, and the reference points to the new value?
Correct. It's the same thing as would happen if you wrote this.
double d = 10.5;
int i = d;

Or otherwise used d in a context where an implicit conversion takes place like on a function call.
>What is the point of creating a temporary, wouldn't it be better to have the compiler return a type error?
I agree that it would be better, but that's how the language is specced.
>>
What's the best place to learn python for free?
>>
Anyway to pull a variable and data out of an if statement?

I'm asking the user, multiple times, if they know an answer to a question. If they do, they type "yes" and then enter the integer answer to the question. After the user is asked all of the questions, I need to be able to add all of the integer answers together. How could I do this with an if else
>>
File: 1464315477104.jpg (41KB, 551x720px) Image search: [Google]
1464315477104.jpg
41KB, 551x720px
In C++, while constructing a class, is it possible to call a function?
For example:
#include <iostream>
#include <string>
class Fruit {
protected:
std::string name, color;

public:
Fruit(std::string givenName, std::string givenColor)
: name{givenName}, color{givenColor} {}
};

class Apple {
protected:
std::string type;

public:
std::string promptType() {
std::cout << "Enter the type of apple: ";
std::string result;
std::cin >> result;
return result;
}
Apple(std::string givenName, std::string givenColor)
: type{promptType()}, Fruit{givenName, givenColor} {} {
std::cout << "A " << type << " apple created.\n";
}
};


Class(int x):
>>
>>62463726
What is your definition of rock solid?
My definition of a rock solid language is one that is actually being used by relevant companies.
>>
>>62463790
disregard the Class(int x)
>>
>>62463790

class Nigger
{
public:
Nigger() { my_function(); };
}

I don't get it.
>>
>>62463730
I see.
Is there a particular reason why it's possible to point to a variable with a different type than its reference only when the reference is a const?
>>
>>62463744
Pls respond
>>
>>62463790

First of all, stop passing strings by value, dumbass.
Second off, if you are unsure of whether something is legal, try and compile it.
>>
>>62463807
That's not what I meant. It has to do things with class inheritance; see I'm calling promptType() in the middle of base class creation/initialization
>>
gl_Position

What kind of fucking nigger though that after _ the starting word should beging with capital letter?
People behind opengl specs should be fucking killed
>>
>>62463837
It doesn't hence I'm asking if there is any way to make it possible
>>
>>62463800
Not the language should be solid. The stuff that I write should.
The definition is obvious: a program should never fail due to intrinsic code-related reasons, like NPE, array out of bounds etc. C# does not prevent these problems. Languages with sound type systems do.
>>
>>62463790
yes, the constructor can call functions (in reality the constructor is also just a function)
>>
>>62463837
fyi, passing by value is OK now, the compilers optimize it away
>>
>>62463817
Const references can bind to rvalues and non-const references cannot.
const int &x = 10; // ok
int &y = 10; // compile error

The result of the implicit conversion is a rvalue (unnamed temporary), which is the reason that the const reference can bind to it.
>>
>>62463857

Read the compiler error. What does it tell you? C'mon man, you spent over a decade in public schooling to be able to read and comprehend the English language. Your compiler will tell you, in English, what is wrong with your program. If it's incomprehensible, you're not using Clang, try again.
>>
>>62463838
So what?
>>
>>62463872

Rust then, fuck.
>>
>>62463150
this isn't true at all. there's a massive difference between "the modern way" and "the enterprise way" (in fact, they're effectively mutually exclusive; most large software companies sit on huge legacy codebases strictly limited to C++98/03 across the board). C++ has never required that you use OOP, and the related features are among the oldest parts of C++. it's always been possible (dare i say "preferable") to write effective C++ without the use of class hierarchies and runtime virtualization, and this has only become easier, more robust, and more concise with the additions in newer standards, which are largely inspired by functional/generic/data-oriented paradigms
>>
>>62463872
Idris and your other meme languages fail just as hard. Good code is written by good programmers. The language you choose is irrelevant. Consider this:
head []
>>
>>62463940
this
C++'s idea of class inheritance was broken from the start, you want to avoid it if possible.
>>
>>62463956
>Consider this:
This one: https://pursuit.purescript.org/packages/purescript-arrays/4.1.1/docs/Data.Array#v:head
or this one: https://www.idris-lang.org/docs/current/prelude_doc/docs/Prelude.List.html#Prelude.List.head
I guess you confused my "meme languages" with Haskell, which really has some soundness problems. But PS/Idris are not Haskell. Surprise, surprise.
>>
>>62463834
chodecademy supplemented with a good textbook is alright

https://shodan.me/books/Programming/Python/

idk which are the best and I hear a lot of them are shit

pick one at random and read the amazon reviews or something
>>
>>62463940
I agree with most of your post, but

>in fact, they're effectively mutually exclusive; most large software companies sit on huge legacy codebases strictly limited to C++98/03 across the board

is not my experience at all. I've worked in several years, and most of the C++ devs pushed hard for writing idiomatic C++11/14 code for new code and leaving legacy code as is.
>>
>>62464013
There are plenty of reasons to use head, esp. if you know already that a result will be produced.
Otherwise you have to write much more complicated and slower code to prove to the compiler what you might already know.

Your post earlier about effects and such was daft too.
>>
>>62463359
the other way around
>>
>>62464013
How can Idris determine whether the passed list is empty or not?
I assume you have to provide some kind of proof to the function, but how does it actually look in the language?
>>
>>62463780
You can access variables inside, just do something like summedanswers = summedanswers+int(currentanswer)
Don't know which language so can't give mroe details
>>
>>62463909
Ok. Thanks
>>
>>62463843
a line of garbage code a day keeps the pajeet away
>>
>>62464013
You're better off using Haskell for your rock solid backend. At least Haskell is used in production by a handful of companies. PureScript and Idris never left the developers basement. Expect major issues with the compiler and the standard library.
>>
>>62464037
>There are plenty of reasons to use head, esp. if you know already that a result will be produced.
Yeah, and there are plenty of reasons to dereference null pointers.
>Otherwise you have to write much more complicated and slower code to prove to the compiler what you might already know.
That's why I'm looking at Idris. You don't need to check for emptiness if you prove it once. You don't need to sacrifice speed if type system is good enough.

>Your post earlier about effects and such was daft too.
Elaborate.

>>62464064
Look here: https://github.com/idris-lang/Idris-dev/blob/master/libs/prelude/Prelude/List.idr#L63

>>62464117
PS is also used by several companies. I have also tried to use it once, the result was OK, but indeed, newer version introduced breaking changes. I can live with it, but not sure that PS is the best option.
And no, I don't want to touch Haskell. I know that people use it. But I also know that many Haskellers like `undefined`. And laziness is not for me.
>>
Who the hell thought -> was a good addition to C? It adds nothing but complexity,
(*structptr).member
is perfectly readable.
>>
>>62464215
it's simpler to write and really doesn't add that much complexity
>>
>>62464215
dereference should have been a postfix operator prove me wrong
>>
>>62464152
If you know a pointer is not null you wouldn't care about dereferencing it.

>you don't need to check if you prove it once
You obviously didn't read what I said, which is that the proof makes it much worse to write and has negative performance implications.

All of your nonsense is betrayed by the fact you said that purity was a hassle.
If you think that then you aren't ready for Idris.

You obviously aren't really interested in anything but not being seen as a Haskell guy.
Effects are worse than monad transformers when it comes to actually running them, and even worse they can be done in Haskell anyway through the likes of mtl ((MonadState s m, MonadReader r m, ...) => ...). Monad transformers aren't all commutative too, so you end up with differences anyway. Effect systems add too much fluff to a type system, though obviously you have stuff like dependent types that can alleviate that, but to suggest that an Idris style effect system is less of a pain than Haskell is utter nonsense.
>>
>>62464152
>PS is also used by several companies. I have also tried to use it once, the result was OK, but indeed, newer version introduced breaking changes. I can live with it, but not sure that PS is the best option.
I'm sure it is used by several companies. I suppose Idris is also used by some companies for whatever reason. Speaking about Idris: I heard that the compile times are terrible. Not Rust bad, but bad bad.
>And no, I don't want to touch Haskell. I know that people use it. But I also know that many Haskellers like `undefined`. And laziness is not for me.
Haskell has strict mode too.
Why don't you just go with Haskell and call it a day? There's even a middle ground: F#, Scala, OCaml. Just don't pick those toy languages for real work.
>>
>>62464239
It looks fucking disgusting and it's unsemantic, "structptr to member" is complete nonsense, compare it to "member of (dereference structptr)"
>>62464244
"pointer dereference"
"dereference pointer"
one is more readable than the other
and you can imagine it in your head like dereferemce(pointer) or *(pointer), you can't do that with postfix
also, (structptr*).member isn't more rerable
>>
how long would it take for someone proficient in c/++, java, python, etc to learn VB

i applied for a job that requires "proficiency" in VB and i dont know anything about VB but it looks pretty easy
>>
>>62464244
int i = *ptr;


dereference ptr and store it into a i

int i = ptr*;


take ptr, dereference it and store the result in i

first option: one connective (and) in the sentence
second option: one connective (and) and a comma

first one has less complexity, thus is easier to understand, thus is preferable

>status: btfo
>>
>>62464326
Drink some bottles of vodka to kill off brain cells and you're proficient in VB.
>>
>>62464325
>also, (structptr*).member isn't more rerable
It is because now you don't need parens.
>>
Can anyone link good ruby/ ruby on rails books?
>>
>>62464244
pointers should have used ^ instead of *
prove me wrong
>>
>>62464368
can't
>>
>>62464352
One of them is unsemantic. Or are you saying that char*жmalloc(12) is more readable than (char*)malloc(12) because you don't need paranthesis?
>>
>>62464368
You'd end up typing stuff like int î half the time
>>
>>62464328
int i = [n]arr;

Take the nth element of arr and store it in i.
int i = arr[n];
Take arr, take the nth element of it and store the result in i

your reasoning has no logic, nobody reads this way
>>
>>62464034
i'm glad to hear that; it's up to devs to put the pressure on their employers. but it definitely depends on the company, and all too many are stuck in the past. i know people at a few large companies in the area where they enforce strict guidelines requiring the use of way outdated standards, even despite constant outcry from their devs. it surprised me in a couple cases where the companies in question certainly weren't some old dinosaurs, but places staffed by young devs working on pretty cutting-edge, large-scale projects. but they were building on top of stable codebases from older projects built on older standards, and the companies had decided for whatever reason to stick to the same standards, even though more modern code would be able to interoperate with the legacy code if they allowed it
>>
>>62464498
Clearly they do, otherwise why would Ken and Brian choose *ptr over ptr*? They didn't make mistakes.
>>
>>62464690
C declaration syntax was a mistake.
>>
>>62464707
C was made by Brian and Ken. Brian and Ken are perfect programming gods whose every action and decision was perfect. C declaration syntax is beautiful, perfect and impossible to improve upon. You are a retarded faggot cunt if you disagree, because Ken and Brian are perfect and you're trash compared to them (we all are).
>>
In java:
Deque<char> z = new Deque<char>();


Gives:
Deque.java:112: error: unexpected type
Deque<char> z = new Deque<char>();
^
required: reference
found: char
Deque.java:112: error: unexpected type
Deque<char> z = new Deque<char>();
^
required: reference
found: char
2 errors


Where it's defined as:
public class Deque<Item> implements Iterable<Item>
{ // some shit
public Deque()
{ // construct an empty deque
n = 0;
first = null;
last = null;
}
// some other shit
}
What am I doing wrong?
>>
>>62464764
Java doesn't let you use primitive types as type arguments. You must use the boxed equivalent, Character.
>>
>>62464764
Read the Java Language Specification for the Standard Edition version 1.8. It will answer all your questions.
>>
>>62464784
>>62464789
Thanks, lads.
>>
>>62464797
Read the Java Language Specification for the Standard Edition version 1.8. Getting spoonfed is a bad habit.
>>
>>62464764
We wuz value types.
Soon...
>>
NEW THREAD!!

>>62465093
>>62465093
Thread posts: 339
Thread images: 27


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.