[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: 33

File: 1480956343871.jpg (675KB, 940x822px) Image search: [Google]
1480956343871.jpg
675KB, 940x822px
What are you working on, /g/?

Old thread: >>58032469
>>
>>58036933
>>
File: 1481908776342.jpg (25KB, 640x298px) Image search: [Google]
1481908776342.jpg
25KB, 640x298px
thanks for not using a fag image
>>
>>58036933
((or + -) 1 2 3)

; => 6


That's so fucking cool
>>
>>58036966
>weak typing
RRREEEEEE
>>
>>58036958
he cut his penis
>>
>>58036981
>he
shitty meme desu m80
>>
>>58036980
You think that's bad?
((and = 1 1) +) 1 2 3)

; => 6


I don't see what the issue with weak typing is, I wouldn't actually write a program that did this, but why have a constraint in your fucking syntax that limits the ways you can handle data, just have a uniform function set and let that eat the damn nails when it has to

strong typing only exists to keep someone who doesn't know what they're doing from shooting themselves in the foot
>>
>>58037017
I fucked up, should be ((and (= 1 1) +) 1 2 3)
>>
>>58037017
That way madness lies.

Any decent LISP* has strong typing.

*or decent language, for that matter
>>
>>58037017
>t. unemployable
>>
>>58037027
Okay, but in all honesty as a novice programmer what's the problem with weak typing?
>>
>>58037017
Strong typing is also better for documentation and optimization.

>strong typing only exists to keep someone who doesn't know what they're doing from shooting themselves in the foot
Use something untyped like assembly then, Master.
>>
>>58037017
for anything non-trivial you will want sanity checks to ensure correctness. with strong typing, all you have to do is specify the type and it saves you and everyone else a lot of extra effort.
>>
>>58037033
>in all honesty as a novice programmer what's the problem with weak typing?
This is: >>58037026

>why have a constraint in your fucking syntax
It has nothing to do with syntax.

>just have a uniform function set and let that eat the damn nails when it has to
I have no idea what this means. Do you?
>>
>>58037045
never said I knew what I was doing
>>
My manager wants us to start using Scala, how can I convince him that we should stick with Java?
>>
>>58037060
Also consider that even people who know what they're doing don't want to waste cognitive effort on something that the computer can do just fine. Machines should work, people should think.
>>
>>58037063
You don't. Scala is the better choice and there's a reason you're not the manager.
>>
>>58037059
Without that open that wouldn't have run, strong typing wouldn't have helped that
>>
>>58037069
I heard Scala is a terrible language.
>>
>>58037063
java is the tried and tested choice of the industry, it's by far more popular and more widely supported

>>58037069
scala is shit
>>
>>58036966
>or special form returns the first non-nil/#f argument
>>58037017
>and special form returns the last argument if everything before is non-nil/#f
>>
>>58037081
>>58037084
I didn't say Scala is good. I said it's better than Java.
>>
>>58037081
>>58037084
At least it's not Rust.
>>
>muh trivial OOP shit
Every fucking thread, don't disappoint me now /g/
>>
>>58037089
it's not better than java you insufferable autist. at best it's a matter of opinion.
>>
>>58037086
Those quotes are acurate, the or/and functions seem retarded even to my brain damaged ass, but I STILL don't see how strong typing would help
>>
>>58037074
Expecting implicit type coercion makes reasoning about types more complex and more error-prone.

What about the second and third points?
>>
Hey guys how do I average two ints?
>>
>>58037100
it is, actually but you're the only one going Gran Autismo here. Keep the reeeeing down to a minimum please.
Thanks.
>>
>>58037099
>muh smug FP shit
kys
>>
>>58037099
Hey this is trivial FUNCTIONAL shit you dweebo
>>58037104
Nothing was wrong with those last two, or I would have mentioned them
>>
>>58037112
you're pathetic dude, you're not special for programming in haskell/idris, any programmer could do it if they wanted to, but any actually competent programmer realizes how shit those languages are
>>
>>58037121
But the third point was a question...
>>
>>58037111
mul x, x
bnz $0
>>
>>58037122
Nice run-on sentence, Javesh.
>>
>>58037129
I get a compiler error do I need to do this on Windows maybe? I have a MacBook
>>
>>58037122
Why are they shit, then?
>>
>>58037122
I never said I use haskell. You sound insecure as fuck though.
>>
Still working on akari-bbs!

I added dynamic page titles, but it cuts off unicode characters halfway through.
How do I tell if I'm in the middle of a UTF-8 byte sequence?
>>
File: Dvorak_header_1.jpg (45KB, 730x400px) Image search: [Google]
Dvorak_header_1.jpg
45KB, 730x400px
I think we can all agree that using Dvorak makes you a better programmer.
>>
>>58037129
>bnz
ARM?
>>
>>58037168
I used Dvorak for a while. It was verrah nice.
>>
how to compute the average from an array?
example:
values from array: 1, 2, 3, 4, 5, 6 

output
3.5
>>
Hey /dpt/ long time listener first time caller
Is there anyone who knows C++ that can help me?

It's homework but I'm not understanding the tutorials enough to get it to work.

Essentially I'm using void functions to open a file and then I want to be able to read the file from the main.
I can elaborate if need be but I'm trying to do this without posting my code and then going "whats wrong with it?"

Please help
>>
Reminder that having the same input give the same output across the program is about as restrictive as you ever need to be. This admits side effects but they either must be modelled in the inputs (or outputs, like with IO in Haskell) or they must not be observable again from the program.

Rarely, you might need to model a bit more than that, like imposing time and space restrictions for hard real time software.
>>
>>58037111
pavgw xmm0, xmm1

You even get 8 results at once.
>>
>>58037219
What about random algorithms.
>>
>>58037208
POST MORE DETAILS

C'MON

YOU CAN DO THIS
>>
>>58037229
Pass around the state of the random generator somehow.
>>
>>58037208
Sounds like homework
>>
>>58037063
Tell him there are better meme JVM languages like Frege, Clojure and Kotlin
>>
>>58037264
>Frege
Immature

>Clojure
Garbage

>Kotlin
You might as well stick with Java
>>
>>58037208
Use stdio
>>
>>58037208
pass a reference to the function?
>>
>>58037241
Wouldn't that be bad for crypto?
>>
>>58037306
No?
>>
>>58037306
Why do you say that? If anything it's more secure because the state of the random generator isn't just in a static location, it's ephemeral wherever it goes.
>>
>>58037318
But, wouldn't that be bad for crypto?
>>
>>58037278
>You might as well stick with Java
this

what scala and kotlin are doing with java is like if you take a carefully engineered ferrari and then you give it a hellaflush and put a homemade exhaust on it. anyone who actually knows their shit realizes how ridiculous this is
>>
/dpt/ is amateur hour 24 hours a day
>>
>>58037325
Comedy gold.
>>
>>58037318
How do you know the rng state that gets passed in is safe?
>>
>>58037326
this

>>58037336
amateur detected
>>
>>58037323
No?
>>
>>58037337
What do you mean by safe?
>>
>>58037233
FUCK okay
The program I'm trying to make is supposed to be a menu program that reads a different file depending on what you choose (ie you have 5 choices, choose 1-5 to make choice) once the user makes the choice the program is supposed to clear screen (I'm using system("cls"); for this) and display a read file opened from a void function.
Problem is I set my void function to open the file like so:
void DisplayWinter()
{
inputFile.open("Winter-Summer.txt");
}

and I go back to the main to input text from the file before printing like so:
while (choice == 2)

DisplayWinter();
{
inputFile >> line;
cout << line << " ";
inputFile >> line;
cout << line << " ";
inputFile >> line;
cout << line << " ";
inputFile >> line;
cout << line << endl;
}
inputFile.close();

my console output just comes up like as if all I've done was just clear the screen.
If I'm still not making sense please let me know
>>
>>58037350
stdio
>>
>>58037179
Why'd you stop?

I'm on Dvorak now, it's the fucking best
>>
>>58037350
can you post the whole program?
>>
>>58037337
???????????????????????????????????????
>>
XML needs to DIAF
>>
>>58037366
I got a job involving much typing on many different computers I have no control over :(
>>
>>58037241
The client shouldn't know the rng state.
>>
>>58037364
No dice, still comes up blank

>>58037378
You asked for it
#include <iostream>
#include <conio.h>
#include<string>
#include<fstream>
#include<cstdlib>
using namespace std;
//**********************Function Prototypes******************************
//5 function prototypes (all void); one for each menu option
void DisplayFall();
void DisplayWinter();
void DisplaySummer();
void DisplaySpring();
void DisplayQuit();
//****************Program Setup (Declarations)***************************
string Heading = "buttfuck College";
string subHeading = "Computer Science Course Offering";
string line;
ifstream inputFile;
int choice;
char word[255];
//**********************************************************************

int main()
{
cout << Heading << endl;
cout << subHeading << endl;
cout << "Main Menu" << endl
<< "Select one:" << endl
<< "1. Fall Quarter" << endl
<< "2. Winter Quarter" << endl
<< "3. Spring Quarter" << endl
<< "4. Summer Quarter" << endl
<< "5. Quit" << endl;
cout << "Enter Choice (1-4) ===> ";
cin >> choice;
if (choice < 1 || 5 < choice)
{
cout << "ERROR. . . re-enter choice (1-5) ===> ";
cin >> choice;
}
while (choice != 5) //Processing Loop
{
while (choice == 1)
DisplayFall();
cout << endl;
while (choice == 2)

DisplayWinter();
{
inputFile >> line;
cout << line << " ";
inputFile >> line;
cout << line << " ";
inputFile >> line;
cout << line << " ";
inputFile >> line;
cout << line << endl;
}
inputFile.close();
while (choice == 3)
DisplaySpring();
cout << endl;
while (choice == 4)
DisplaySummer();
cout << endl;
}
if (choice = 5)
cout << "The program will now terminate." << endl;
return 0;
}
void DisplayWinter()
{
inputFile.open("Winter-Summer.txt");
}


It's obviously incomplete but I want to work out my problem before putting the rest together.
Thank you all, seriously
>>
>>58037241
What if the program requires true random number generation?
>>
hey, you lads like asp.net?
>>
>>58037441
i'm pretty sure i will use it when the time comes
>>
>>58037436
>comment banners
>>
>>58037446
if it were up to me I wouldn't use them. Instructor's orders
>>
>>58037423
Just because you're passing it around doesn't mean it's open. It could also just be a capability to access a pointer to static memory. It could even be a handle to send a RCP to some server to do it.
>>
>>58037423
what do you mean by client? in a client-server scenario, the state would be stored on the server of course
>>
>>58037457

Kill him. It's your right as an American citizen.
>>
File: eclipsetennis.png (244KB, 1603x928px) Image search: [Google]
eclipsetennis.png
244KB, 1603x928px
How do I fix?
>>
>>58037440
Then you use a linear marker type modelling the world for the input, or equivalently something like IO in Haskell. While this doesn't actually change the operation of the program, it acts as a hint to the compiler so that optimization doesn't fuck it up. The more you put in types, the easier it is to optimize.
>>
File: sublimetennis.png (213KB, 1920x1080px) Image search: [Google]
sublimetennis.png
213KB, 1920x1080px
>>58037486

It compiles just fine with javac on the terminal but not in Eclipse.
>>
>>58037497
>The more you put in types, the easier it is to optimize.
Holy fuck somebody on /g/ finally gets it.
>>
Typing, no side effects, etc is autistic and dumb.
Programming should be as free and flexible as natural language the computer should figure it all out by itself.
You spergs would probably try and write math proof all in formal logic (lol).
>>
>>58037457
don't use function prototypes
put the functions above the main function instead and you don't need a prototype

and don't use global variables
make them local and then pass them as arguments to whatever functions need them if necessary

now your code is better and you don't need comment banners
>>
>>58037522
kys
>>
>>58037522
>You spergs would probably try and write math proof all in formal logic (lol).

But.. formal logic systems are fun.
>>
>>58037187
for loop looping < array size, add every value into a holder variable then divide by array size?
>>
>>58037522
>the computer should figure it all out by itself
Well, computers can't (yet).
>>
>>58037350
pass the ifstream (inputfile) to the void function as a reference, so void DisplayWinter(ofstream&) for the prototype and calling it like DisplayWinter(inputfile) so whatever you do in void carries back to main?
>>
bow down
#include <iostream>
#include <algorithm>

template <typename T, std::size_t N>
constexpr std::size_t countof(const T(&)[N]) noexcept
{
return N;
}

template <class T>
std::size_t countof(const T& container)
{
return container.size();
}

template <class T, class Iterable>
T average(const Iterable& iterable)
{
return std::accumulate(
std::begin(iterable), std::end(iterable), T()
) / countof(iterable);
}

int main()
{
auto numbers = { 1, 2, 3, 4, 5, 6 };
std::cout << average<double>(numbers) << std::endl;
return 0;
}
>>
>>58037518
The way I see it, one of the goals of functional programming and powerful type systems is so that the compiler does more work for the programmer without having to think for itself (e.g. in optimizations). Computers are great at checking solutions that humans come up with, type-theoretically.
>>
>>58037486
Not a Java user but change your eclipse errors preferences. Maybe the current settings don't allow you to override standard library methods or some shit.
>>
>>58037533
Function prototypes are a must if you intend to have more than 1 compilation unit.
What do you think headers are for?
>>
>>58037578
obviously doesn't apply to this code snippet otherwise they'd already be in a header file
>>
>>58037518
>>58037574
Like, there are two ways a compiler can know a pointer is non-aliased so it can optimize accordingly. The programmer can assert that it is non-aliased, or the compiler can infer it. Obviously, the latter is generally undecidable and thus the compiler needs to be conservative. It also makes compilation take longer. While programmer assertion could be done with a simple annotation like "restrict" in C, if you use linear types or borrowing or whatever, the compiler can cheaply check that it is truly non-aliased. Win-win situation.
>>
Are there many programming jobs in Australia?
>>
>>58037571
You average function should accept iterators, not the container itself.
>>
>>58037653
There are if you fit the description. There's a lot of .NET jobs in the Brisbane area, Java too. For Sydney and Melbourne, there's jobs for everything.
>>
>>58037659
You just need something that has a Foldable instance
>>
>>58037671
Thanks!

Anything more on the FP side of things? I could do C# but I just don't find it as fun.
>>
>>58037486
which eclipse version is that? get eclipse neon if it's not neon
>>
>>58037522
kys
>>
>>58037704
it's rainbow.

should i try neon?
>>
>>58037715
t. autist
>>
>>58037722
yes
>>
guys i'm working on a kernel written in C and i could use some help.


if there's enough interest, i'll post my github with the repo
>>
>>58037734
t. non-programmer
>>
>>58037751
>kernel written in C
why? Can neither BSD or Linux work with what you are doing?
>>
>>58037187
you give up.

how can you ever succeed if you ask help for a question like this? you can't learn how to be intelligent
>>
Is programming being automated?
>>
>>58037751
Post repo, i wanna systems code.
>>
>>58037792
>>58037771
here's my github:

github.com/torvalds
>>
>tfw tic tac toe can't be done elegantly in "functional" languages
>>
File: coding is easy.jpg (692KB, 1200x1000px) Image search: [Google]
coding is easy.jpg
692KB, 1200x1000px
>>58037789
programming cant be automated
that's why wages are being driven down by flooding the market with women and gen z'ers who think premade drag and drop logic is any way comparable to a real language.
>>
I'm working on a decentralized TV system, and I'm feeding random data into the importer to see what could possibly go wrong.
>>
File: 1444233131169.png (611KB, 780x720px) Image search: [Google]
1444233131169.png
611KB, 780x720px
>>58037802
>programming cant be automated
>>
>>58037503
I would like to suggest you LibGDX.
JSwing is too old and it was not created for making games, while LibGDX was (not 100% sure).
>>
>>58037578
That's only true if you intend to use those functions outside of its compilation unit
>>
>>58037816
>(not 100% sure).
so shut the fuck up.

you only post things that you are 100% sure.
>>
>>58037827
Yes?
What point is there in having more than 1 compilation unit if you're not utilizing things declared in other files?
>>
>>58037841
Because not every single function needs to be used outside of the file it's declared in.
>>
>>58037802
Companies are going to learn the hard way that diversity is not a substitute for talent.
>>
>>58037789
no

>>58037813
programming being automated would mean that you basically have general artificial intelligence and it would affect so many other things than just programming
>>
>>58037571
C++ is so shit
>>
>>58037802
I really hate the idea of your pic. Bad example from your side. I think code.org was made to make programming more attractive to children and girls, and to make them start to understand programming problems. It's better to confront children with this than with C for example. There is low chance, little child would understand that.
>>
>>58037802
>canadian head
>French name
>doesn't speak French
wait i don't understand
>>
>>58037894
Dragging shit together is nothing like programming.
>>
>>58037940
dragging pre-written statements and choosing variables from drop-down lists is basically programming just with training wheels
>>
>>58037971
>assembling prewritten sentences is is just like writing a novel! whats the difference???
>>
whats there to program besides boring math equations and finding the biggest number in an array?
>>
>>58038077
Make a game.
>>
>>58037940
It's designed to help you understand the basic concepts in a way that children will understand. Of course you're not going to be shitting out professional grade C code suddenly because you can make a shitty game in that, but when you learn an actual language and you come across things like if statements and loops, you will already have a core understanding of those concepts and it makes learning the language as a whole easier.
>>
After I get home from work, make and eat dinner, wash up, and take care of the other household stuff, I can't concentrate enough to write any code. What should I do, /g/?
>>
>>58038102

>make dinner
>wash up
>other household stuff

what the fuck man? you need a bitch to do that shit for you.
>>
>>58038064
the syntax is predefined. you're working with a finite set of variables which your editor can suggest in the same way as the drop-down list. drag and drop stuff is babby tier but it's equivalent to writing code just that you can't fuck up the syntax
>>
>>58038115
Is it Turing complete?
>>
>>58038124
it doesn't need to be. in a "real" program you're also only doing a specific task and you're calling functions/methods like "set baskell scene" etc
>>
>>58038157
But you wrote those functions yourself.
If you can't implement your drag and drop language in the same language, it's not real programming.
>>
>>58038205
who gives a shit like holy shit how autistic can you be

it's basically a limited form of programming just with a lot of hand-holding

and even in "real" programs you don't see people implementing opengl emulators and shit they just use what's already there
>>
>>58038243
>how autistic can you be
Where do you think you are dot jaypeg.
>>
File: whatdoxml.png (15KB, 966x147px) Image search: [Google]
whatdoxml.png
15KB, 966x147px
My .xml is in this file location, but my game can't find it.

What am I doing wrong?
>>
>>58038412
that looks like a absolute path not a relative path

try removing the first /
>>
>>58038412
there's probably a file path constant that you can use to reference where your target xml is in relation to the code being executed

i dunno just a guess, what's your error look like?
>>
>>58038421
>>58038435

oh shit nvm, homeboy is right
>>
File: theerror.png (61KB, 1993x308px) Image search: [Google]
theerror.png
61KB, 1993x308px
>>58038421
>>58038435
Without the / it doesn't work
I've tried all sorts of file location paths, as well as moving the file to other locations, but nothing works.
>>
>>58037208

So you have a file opening function and you'd like to read it with another function?

You create the read function and have it call the file opener and if the file opening is a success you just read the data using an ifstream you created.
>>
>>58038470
you could try file:/assets/etc/etc since the seems to want a URL
the first / might not be needed for that if it works
>>
>>58037187
template <typename ResultType, typename ForwardIterator, typename LengthType=ResultType>
ResultType average (ForwardIterator first, ForwardIterator last)
{
ResultType sum = 0;
LengthType len = 0;
for (; first != last; len++)
sum += *(first++);
return sum / len;
}

int main (void)
{
std::vector<int> array { 1, 2, 3, 4, 5, 6, 7 };
std::cout << average<double>(array.begin(), array.end()) << std::endl;
return 0;
}
>>
>>58038470
>>58038497
the file:/ thing was my first instinct too but apparently it expects a URL and not the actual contents of an XML file

stack overflows tells me you should try to pass this to the parse function instead - full disclosure: java is gross as fuck and i've never written a line of it in my life

Document document = builder.parse(new InputSource(new StringReader(xml)));
>>
>>58038564
from the documentation for documentbuilder
>The method DocumentBuilder.parse(String) >take a URI and tries to open it. I you want to >directly give the content, you have to give it an >InputStream, for example a >ByteArrayInputStream.
>>
File: itwerks.png (17KB, 1064x182px) Image search: [Google]
itwerks.png
17KB, 1064x182px
>>58038564
>>58038577
It finally works, time to go to bed
Thanks for the help!
>>
>>58038618
np senpai, lrn2google next time also start learning iOS if you want to actually make money
>>
File: 20161217_163307.jpg (2MB, 2120x1668px) Image search: [Google]
20161217_163307.jpg
2MB, 2120x1668px
Am I ever going to make it?
>>
>>58038618
Java is horrifying.
>>
guys what's the name of when a file/code is exclusive to a company and you'll never see it anywhere else

i forgot the name they use for this type of code
>>
>>58038643
for fucks sake
I can't believe someone could even come up with that much filler
it must have taken teams of fluff specialists to develop that behemoth
>>
>>58038664
proprietary?
>>
>>58038670
thanks, i was almost dying trying to remember it
>>
>>58038665

Probably a bunch of shit about templates.
>>
File: last.png (7KB, 551x321px) Image search: [Google]
last.png
7KB, 551x321px
>>58035105
And I'm done, fuck the police.
>>
>>58037063
You don't. All ML derived languages are superior to thier ALGOL derived counterparts because programming with expressions is much comfier than programming with statements. Once you transcend into the realm of functional programming you will cease to be a pajeet and the heavens will open before your eyes. Your manager has your best interests at heart because he knows that java is bad for your brain, so quit being an insufferable little bitch and do what your told.
>>
File: last.png (415KB, 1918x841px) Image search: [Google]
last.png
415KB, 1918x841px
>>58038752
You can call me snake.
>>
File: 378378_1324992292_large.jpg (580KB, 1600x1226px) Image search: [Google]
378378_1324992292_large.jpg
580KB, 1600x1226px
What language is best for a botnet?

What language/framework to code the panel in?
>>
>>58038777
>lack of new-line

>>58038779
VB.net
PHP
>>
>>58038785
I didn't make the converter, I made the terminal emulator.
>>
File: browser.png (2MB, 1920x1080px) Image search: [Google]
browser.png
2MB, 1920x1080px
>>58038779
BASIC
>>
>>58038794
Did you ever release the source of the browser? If no, why?
>>
>>58038757
Scala isn't ML-derived. It's a Frankenstein's monster of a programming language.
>>
my dad works at 3M and says they need programmers who know "C machine" and asked if he should give them my name

i think he's talking about C, which i don't know, and i also have no experience. still a student. what should i do?
>>
>>58038821
You don't want to work at the sort of place that can't even get terminology correct.
>>
>>58038808
why would I do that? everyone knows closed source is better.
>>
>>58038752
>>58038777

Neat, pham.
>>
>>58038852
Just because people can't see the bugs in the source doesn't mean they're not there.
>>
>>58038831
my dad's a salesman. i assume the error in the game of telephone occured with him
>>
>>58038638
4chan was my choice after I spent 30 mins on google and yt

>>58038660
It is. I'm looking forward to learning C# after I've finished my current project. I hope it's at least a little nicer.
>>
guys what's a good paper on learning how pointers work? I get what they are in concept.
>>
>>58038912

>I get what they are in concept
There's not much to really get. It's a location in memory. If you're having trouble conceptually, just read this:

http://cslibrary.stanford.edu/102/PointersAndMemory.pdf
>>
>>58036933

Misato is better
>>
Why doesn't firefox do proper GC?
>>
>>58038943
it's really shit and old
>>
How do you learn VHDL/verilog?

I was gonna emulate a MC14500BDW, and I was gonna do it in C++ but I kinda want to try a hardware description language out
>>
>>58038912
It's a memory address.
you can do arithmetic on them and do lots of unsafe shit that scares the fuck out of web developers.
Combine it with the use of goto for maximum triggering.
>>
>>58038779
Do not post machiavelli around me.
>>
>>58038964
>goto

If you're not leveraging longjmp, you aren't even close to maximum triggering.
>>
Hey /dpt/, noob here.

I'm learning about C, and think I have a decent grasp on pointers. I have a question for you guys:

Which of the two following declaration styles should be used and why?

First:
int *p;


Second:

int* p;


The second makes more sense to me but it seems many people prefer the first one
>>
>>58039090
it's up to you really
but the answer is
int * p;
>>
File: last.png (59KB, 1258x883px) Image search: [Google]
last.png
59KB, 1258x883px
More sixel cuteness.
>>
>>58039100
Why is that?

I haven't seen a lot of production C code, but from my limited experience, I have never seen anyone use that. What's the benefit?
>>
>>58039090

The first is correct.
>>
>>58039107
it's a great middle-ground
>>
>>58039090
I do int *p because when you do a list declaration like this

int *i, *j, *k
You get three int pointers, but if you do
int* i, j, k
then you'd get one pointer and two ints, and if you wanted say two pointers and one int then it'd look all fucked up
int* i, j, *k
>>
>>58039090
the first one
if you want to know why, compile this and look at what it does

int* p, q;
>>
>>58039128
But why?
>>
>>58039135
>>58039136
I understand that it helps you prevent mistakes, but is there a deeper, semantic reason to prefer the first over the second?

The second one makes sense to me in that "declare a variable a, which is of type 'int*' ", but the first one doesn't quite convey the same thing
>>
>>58039134
pussy
>>
>>58039149
slut
>>
>>58039090

The difference between them is that the first one lets you declare more on one line

 int i, j, k, *ip, *jp, *kp; 


opposed to

 
int i, j, k;
int* ip, jp, kp;


only difference.

The answer to your question as to SHOULD be used is this : follow the style guide the codebase is using.
>>
>>58039135
>>58039136
>>58039128

Also, what if you want this:
int *const a;


Is this the correct asterisk position in this case?
>>
>>58039147
For me the first one says "this name is a pointer" which I feel is more correct semantically.
You know, like if you declare int *p then p is the pointer.
So I guess it depends on if you want semantic emphasis on the type or the indirection, with me it's on indirection.
It's also more consistent, since when you de-reference a pointer, you do *p, not *int.
>>
>>58039159
would you still say that if you it was a GNU style codebase?

>>58039163
no
int * const a;

btw that's a const-pointer to an int
not a pointer to a const-int if you were aiming for that
>>
>>58039147

Don't get fooled by "deep" semantics. At the end of the day you're using a program called a compiler to generate machine code that your computer will run.

The computer doesn't give a fuck. Code is for reading by people
>>
>>58039175
Yeah, a const pointer to an int is what I was aiming for.

I still don't understand why this example should have the asterisk by itself in the middle, but the previous one would have it attached to the identifier
>>
>>58039137

Because that's how Ritchie designed it.
>>
C++ anon back again with another question
I've been able to get my function to open and read my txt file, but now I'm having trouble making it so the whole text file isn't bundled together.
Below is the entirety of the code that I used to make my reader function work but unable to make it endl move to the next sentence:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

void DisplayWinter(ifstream&); // Function prototype

int main()
{
ifstream inputFile;

inputFile.open("Winter-Summer.txt");
if (inputFile.fail())
cout << "Error opening data file. \n";
else
{
DisplayWinter(inputFile);
inputFile.close();
}
return 0;

}
//DisplayWinter
// This function reads and displays its contents.
void DisplayWinter(ifstream &someFile)
{
string line;
while (someFile >> line)
cout << line << " ";
cout << endl;
}


Assume this is the text file I am trying to make print out accordingly:
-----------Winter (or Summer) Quarter-----------------Winter/Summer Schedule Menu
Co Sci 801 Introduction to Computers and their Uses Co Sci 830 Microsoft Office Application


How could I make that txt file endl according using the while loop?
Sorry if this question seems stupid
>>
>>58039193
back to /o/, jungle boi
>>
>>58039196
that came out weird as shit so I'll just input it here
txt file:

-----------Winter (or Summer) Quarter-----------------Winter/Summer Schedule Menu
Co Sci 801 Introduction to Computers and their Uses Co Sci 830 Microsoft Office Application
>>
>>58039192
the previous one should be in the middle too

>>58039196
http://en.cppreference.com/w/cpp/io/basic_istream/getline
>>
File: 1480380494994.jpg (43KB, 640x480px) Image search: [Google]
1480380494994.jpg
43KB, 640x480px
>>58039203
-----------Winter (or Summer) Quarter-----------------
Winter/Summer Schedule Menu
Co Sci 801 Introduction to Computers and their Uses
Co Sci 830 Microsoft Office Application
>>
File: 1407788907336.jpg (12KB, 251x242px) Image search: [Google]
1407788907336.jpg
12KB, 251x242px
>>58039215
>the previous one should be in the middle too

Okay you guys are pulling my chain now
>>
>>58039198

"no"
>>
>>58039196

the line

 someFile >> line 


isn't doing what you expect. There's probably an overload to read to the first line separator. As it is the compiler's interpreting that as "read the entire ifstream into line variable"
>>
>>58039196
>>58039215
actually the getline function seems very shitty for C++ so read the whole file in then find each \n

>>58039231
the frog is not allowed here
>>
>>58039241

actually I can see the error now.

 while (someFile >> line) cout << line << " " << endl;


You need more braces. This isn't python. The semicolon is interpreted as the end of the while statement. You can alternately use a code block delimited by {}
>>
>>58039246
>actually the getline function seems very shitty for C++ so read the whole file in then find each \n
std::getline() is just fine, what's wrong with it?
>>
>>58039241
How would you suggest I get the file read in >>58039221 format?

>>58039246
Should I just not bother with the while loop then?

I've been trying at this program 7 am and it's currently 11 pm
>>
>>58039293
So how should I use the braces? Assume the code I posted is the program in its entirety
At this point I'm hoping for a spoon feed as this is starting to make me suicidal
>>
>>58038665
C++ has a lot of autism if you want to go further down the rabbit hole
>>
>>58039298
u r right
I saw that the istream::getline needed a size parameter for the file and that is not very cppie but forgot about std::getline

>>58039322
stuff like if, while, do, else, and etc need {} around any statements/expressions that you want done in it

so
while(x)
y();
z();

only does y() while x

if you do
while(x) {
y();
z();
}

then it will be fine

with std::cout you can do multiple strings without using multiple expressions/statements split by semicolons

std::cout << line << std::endl;

someFile >> line
reads the whole file into line

so you could do someFile>>content

then you'd use std::getline(content, line) to grab lines out of content
>>
File: spaghetti.png (135KB, 2127x1667px) Image search: [Google]
spaghetti.png
135KB, 2127x1667px
>>58036933
How the hell do you guys comment/navigate through your spaghetti?

Decided to create a text field hierarchy using arraylists. Turned my code into spaghetti (goes on like this for awhile) and now I have no idea what does what anymore. But it works though....
>>
>>58039386
I'm not sure I follow
isnt this
string line;
while (inputFile.good())
{
getline(inputFile, line);
cout << line << endl;
}

already like
while(x) {
y();
z();
}

?
>>
>>58039410
Step 1: Don't do all that .get shit
Step 2: descriptiveName = Fields.get(i);

>>58039420
yes, it's exactly the same
whitespace doesn't matter much in C-like languages

either style of the starter bracket is fine though if that's what you're asking
>>
>>58039428
well my problem is that the txt file is being read as
-----------Winter (or Summer) Quarter-----------------Winter/Summer Schedule Menu
Co Sci 801 Introduction to Computers and their Uses Co Sci 830 Microsoft Office Application
in the console output when I want it read like
-----------Winter (or Summer) Quarter-----------------
Co Sci 801 Introduction to Computers and their Uses
Co Sci 830 Microsoft Office Application


I'm not sure if with a loop I can just find the end of the line and have it enl here and move to the next
But also it doesn't have to be a while loop at all but I simply dont know how
>>
>>58039454
if you're using a Windows OS then there could be problems with either endl used by C++ or the file newline sequence

Windows generally use the \r\n (carriage-return + line-feed/newline) for ending lines in text files and probably the CMD

I can't help too much but you could try replacing endl; with "\r\n" or "\n" and see if either works
>>
>>58038987
hello liberal
>>
What's the Hugh Mungus of programming?
>>
Found out a pretty neat trick in fasm for building up lists of macros at assembly time, then later execute them all recursively.
Gonna simplify building up the Forth symbol table significantly (before I had a bunch of manual definitions of names, symbols and the asm entry point, so I had 3 pieces to keep in sync)

// base case for recursion
macro FORTHNAMES { SNAME '--END-OF-NAMES--' }
macro FORTHSYMBS { dq -1, -1 }

macro FORTHENTRY name, xt, ct=0 {
macro FORTHNAMES \{ // redefine FORTHNAMES
FORTHNAMES // calls previous definition of FORTHNAMES
SNAME name
\}
macro FORTHSYMBS \{
FORTHSYMBS
dq xt, ct
\}
}

macro FORTHCODE name, xt {
FORTHENTRY name, xt
label xt
}

section '.text'

FORTCODE 'foo', 1
// asm code

FORTCODE 'bar', 2
// asm code

section '.data'
forth_names:
FORTNAMES // essentially traverses a linked lists of functions and executes them, generating the symbol table
forth_symbs:
FORTSYMBS


Hadn't really looked too much at the macro language in fasm (just basic refactoring of common repeated pieces of code), but it's seriously powerful.
>>
Just finished a semester of c++
Whats a really good language to learn that would be actually useful?
>>
>>58039979
What do you want to do?
>>
>>58039987
Network security
>>
>>58040009
c++
>>
File: 342.png (17KB, 900x900px) Image search: [Google]
342.png
17KB, 900x900px
Why would you ever need to return a function? I don't understand this meme.
>>
>>58040156

to action it in a given context
>>
How do I program in C in Windows without Cygwin/MinGW?
>>
>>58040188

visual c++ with only c libraries
>>
>>58040188
bash for win10 with gcc
>>
>>58040188
Visual Studio (the entire IDE), or winddk or standalone sdk+build tools.
PellesC.
Intel C Compiler.
>>
>>58040188
Pelles C :-)
>>
What does programming have to do with anime?
>>
>>58040286
usually nothing but this is 4chan home of anime
>>
>>58040156
It looks cooler.
fn = select_action();
fn()

vs
action = select_action();
switch(action) {
case DO_THING:
do_thing();
break;
case DO_OTHER_THING:
do_other_thing();
break;
case DO_YET_ANOTHER_THING:
do_yet_another_thing();
break;
...
default:
explode();
}
>>
>>58040156
A dynamic loader for example.
void (*foo)() = loadfunc(dynamiclib, "foo");
>>
~~~PROGRAMMER' S CHALLENGE~~~

verify through progmatic audio/video analysis that the filmer did in fact hit the mug 5208 times

https://www.youtube.com/watch?v=kp6JwRd7_2c
>>
File: niconiconii.jpg (150KB, 1252x1252px) Image search: [Google]
niconiconii.jpg
150KB, 1252x1252px
>tfw you're too stupid for c++
>>
Any embedded guys here?
>>
>>58040552
No, but I like to pretend I know a lot about embedded systems.
>>
>>58038518
int main(void)
{
std::array<int, 7> array {1, 2, 3, 4, 5, 6, 7};
double average = std::accumulate(array.begin(), array.end(), 0) / array.size() ;
}
>>
>>58039107
not anybody who's responded but it's the most consistent style with no "exceptions" to how you write it including when you are being const-correct.
int * ptr;
int * const ptr;
int const * ptr;
int const * const ptr;


this is opposed to int *ptr where sometimes the asterisk hugs the name but not if it's a const pointer
int *ptr;                    //hugging
int * const ptr; //not hugging
int const *ptr; //hugging
int const * const ptr; //not hugging
>>
>>58039979
if you think C++ isn't useful after a semester of it you should get your money back
>>
>>58040548

what?

how?
>>
>>58040637
what is the surprise?
most people are
didn't you take comp sci 101? like 3/4ths drop out
>>
>>58040585
c++ really is a horrible language.
>>
>>58040670
just because you're too stupid to understand it and use it correctly doesn't mean it's horrible
>>
>>58040684
Do you know ANY other programming language?
How can you look at idiomatic C++ code and not be disgusted?
>>
>>58040694
>>58040670
I blame haskell fags for this
c++ was near perfect before they started introducing these cancerous functional paradigm "features"
>>
>>58040611
int *const ptr;
int const *const ptr;

Is the correct way if you understand c declaration syntax, because *that* is the most consistent when you consider function pointers.
>>
>>58040694
He's just probably not autistic.

>>58040707
there's nothing about the code snippet that uses "functional paradigm 'features'"

>>58040711
except it isn't. nice try though.
>>
File: 1381228285622.jpg (27KB, 260x384px) Image search: [Google]
1381228285622.jpg
27KB, 260x384px
I'm convinced that all advocates of C++ are either have a severe mental illness, or are just baiting.
>>
>>58040724
>there's nothing about the code snippet that uses "functional paradigm 'features'"
shows how much you know about the subject
whatever, I'm going to bed
>>
>>58040752
for (; first != last; ++first) {
init = init + *first;
}
return init;


wow such functional paradigm
>>
>>58040763
>init = init +
>not init +=
lol noob
>>
>>58040724
>except it isn't.
Except it is.

What are you gonna do for function pointers?
int ( * fp)(int)

Disgusting.
>>
>>58040774
>c++ committee are noobs
lol noob

>>58040777
>what are you going to do, be consistent?
>the most consistent way to write something is to be inconsistent
go to bed. maybe you'll stop posting stupid shit after you've had some rest.
>>
How fast do you plow thought programming books /dpt/?
>>
File: data.png (1MB, 764x525px) Image search: [Google]
data.png
1MB, 764x525px
I have a program running on an embedded device that outputs 16-bit measurement data via serial port to the computer.
I'd like to make a program for converting the incoming 2*8-bit data values into 16-bit integers, add timestamps and then save the data as a file for easier analysis.
How should I get started with this?
>>
>>58040786
I don't read them. They're boring. I'd rather work on projects and look up a specific chapter when I hit a roadblock.
>>
>>58040744
The problem is, most of them just start out baiting, but they get so invested in the meme they go on to develop true mental illness.
>>
>>58040785
>the most consistent way to write something is to be inconsistent
int *ptr;
int *const ptr;
int const *const ptr;
int (*fp)(int) = 0;
int (*fp)(int *) = 0;
int (*fp)(int *const) = 0;
int *(*fp)(int) = 0;
int const *(*const fp)(int);

Is the most consistent.
>>
>>58040796
>responding to low quality bait
anon...
>>
>>58040785
>>c++ committee are noob

Well, if they want to create a new language that builds upon C before they actually understand C well enough to stop reinventing the wheel, then yeah, they are a bunch of noobs.
>>
>>58040611

Const-correctness is one of those memes that never goes away. I only wish that Carmack hadn't given it a huge popularity boost in the past few years.
>>
>>58040801
don't be retarded
int * ptr;
int * const ptr;
int const * const ptr;
int (* fp)(int) = 0;
int (* fp)(int *) = 0;
int (* fp)(int * const) = 0;
int * (* fp)(int) = 0;
int const * (* const fp)(int);


>>58040822
t. CS 101
>>
File: 555.jpg (34KB, 338x305px) Image search: [Google]
555.jpg
34KB, 338x305px
>>58040807
>Not using a script to quote yourself
>>
>>58040834
thanks for the insight from the top of Mt. Stupid
>>
File: 1481300302478.png (9KB, 404x399px) Image search: [Google]
1481300302478.png
9KB, 404x399px
>>58040848

I actually just woke up and am doing my pre-coffee shitposting ritual.
>>
>>58040835
Show us a single example where there is a valid reason to use explicit:
shit = shit + x


instead of the much more efficient, and more maintainable:
shit += x


Only instance I can think of is it you need to cast shit to a different type, but the original snippet in >>58040763 certainly doesn't need that.
>>
File: K28C6Jd.jpg (147KB, 640x628px) Image search: [Google]
K28C6Jd.jpg
147KB, 640x628px
>>58037168
Im using colemak with blank caps, its breddy gud. Doesn't makes you a better coder thou, just comfy af.
>>
>>58040860
same here LMAO
>>
>>58040188

Clang
Intel C Compiler
Tiny C Compiler

There's options.
>>
>>58040801
I do exactly the same. Do you use two sapces indentation too?

Do you refuse to align args because it's stupid?
example
myfunction (45, 32,
13, 78);
>>
Should I learn OCaml? Need some pros and cons. I know haskell already and OCaml isn't as useful as Haskell.
>>
File: 1480491340187.jpg (223KB, 550x550px) Image search: [Google]
1480491340187.jpg
223KB, 550x550px
>tfw no qt girl to teach me git

https://www.youtube.com/watch?v=JkIVaYaeBMk
>>
>>58041137
Yes. Slowly but surely OCaml is becoming the third millennium language.
>>
>>58041124
It only looks "stupid" if you never have nested calls.

myfunction(a, b, c,
another_func(d, e, f,
oh_shit_theres_more(g, h)));
>>
>>58041137
Modules are nice
>>
File: IMG_1998.jpg (43KB, 564x549px) Image search: [Google]
IMG_1998.jpg
43KB, 564x549px
Wasn't there a list of shit for neets like jobs and learning shit or is that some other daily thread? Anywho how much knowledge is required to get a job starting out? I know the barebones for several languages(c, c++, java), like for example c++, I know vectors, file streams, and templates but that's it. Should I know sorting techniques and shit using algorithms before I even attempt to find a job?
>>
>took about an hour to get boost to install and work
>just so i could use boost::filesystem::exists
>just found out std::filesystem exists
>>
>>58041346
just use boost::everything_else
>>
>>58041179

If you have something that looks like that, it might be worth using some temps.

x = oh_shit_theres_more(g, h);
y = another_func(d, e, f, x);

myfunction(a, b, c, y);
>>
>>58041179
myfunction(a, b, c,
another_func(d, e, f,
oh_shit_theres_more(g, h)));

is fucking retarded
myfunction(a, b, c,
another_func(d, e, f,
oh_shit_theres_more(g, h)));

is the proper way to indent nested calls.
>>
>>58041454
>the proper way
>[citation needed]

Using any number of fixed spaces to offset wrapped lines is pretty fucking dumb unless you also stick to a relatively large, fixed number of spaces per indentation level.
I guess if you want to be retarded anyway, you should be consistently retarded.

>>58041369
Usually that's a much better solution, I just tried to come up with an inherently ugly example to show the benefits of proper arg alignment
>>
>>58041515
>>[citation needed]
Myself.
>>
>>58041515
>I just tried to come up with an inherently ugly example to show the benefits of proper arg alignment

Fair enough.
>>
Do packed structs (for networks) fuck up the performance of stl containers?
>>
>>58040792
1. What is your order, LSB or MSB?
2. What kind of timestamp do you have?
>>
really basic pajeet question

let's say I have a nice simpel functional method

public Foo doFoo(){
Foo foo = new Foo();
foo.do();
return foo;
}


now I call them in a multi thread environment. will the threads interfere with each others local Foo? such methods should be 100% thread-safe right?
>>
>>58041940
>will the threads interfere with each others local Foo?
No.
>>
>>58041346
sudo apt install libboost-all-dev


So difficult.
>>
File: 7.jpg (107KB, 1920x1080px) Image search: [Google]
7.jpg
107KB, 1920x1080px
Why is /dpt/ so slow? Is everyone saving their posts for the next thread?
>>
>>58042245

I generally tend to do that towards the end of threads, personally. But to be honest, consider the time. In the US, it is between 5:35 and 8:35 AM.
>>
>>58042245
Are you in brit/pol/ right now?
It's all karen posters and no tripfags
>>
>>58042293
I'm always in Brit/pol/ desu.
>>
>>58040792
Pretty sure a bash script would do the trick, assuming the data is put into a plaintext file in the same format as your image.
>>
>>58042245
YES
>>
Please use a Karen image for the next thread.
>>
>>58037063

Let me tell you a story about a company adopting Scala. They had a "rockstar programmer" chief who where a scala god and ate monads for breakfast, the rest was more or less average Java devs which tried to slowly adapt the Scala syntax, but without a deeper understanding of functional programming.

It all went well one day the scala god decided to leave. He was leaving behind a lot of legacy code, and so it came that a lot of times when the semi gods had to change a feature, they discovered that scala god had used many super high level language features they didn't understand.

It ended up with companies doing complete rewrites of modules under sever time pressure, because it was faster and more reliable than decrypting the mysterious entities their former star programmer had produced.


Lessons learned:
- If you want a exotic language, make sure you hire enough programmers that have a decent skill level there.
- If you want a super complex and powerful language, invest some time to create a policy / guidelines for coding practice.
- If you want to enable your company to use a higher language, try it for some minor projects first. Don't lay all eggs in one basket, building wisdom takes it's time.
>>
File: problem.png (39KB, 905x499px) Image search: [Google]
problem.png
39KB, 905x499px
ive got a problem

im trying to make a java text area where when i press enter in the textbox it lets me write in new row or whatever. the problem is when i try to print the text it prints it out as if it were all in a single row.

i cant for the life of me figure out what to do. i would really appreciate some help here.

im using netbeans, btw.
>>
I'm not usually one to bitch about other people, but god damn.

I've worked on this school project for a while and we assigned one of us four programmers to create a UI system for us, or more specifically, extend what I had already gotten done. I thought it was clear what we wanted was a generic UI system capable of handling anything you'd throw at it.

Now I've been skipping through the code and instead of making a generic UI system, every element of the UI is practically aware of the program's state at all times, and instead of assigning specific properties to a given instance of a UI element, everything seems to be done within the elements' own functions instead. Like the drop menu creation function here for instance: its a 400 line function containing if-elses for every single drop menu in the program. Fucking fuck me.
>>
New thread:

>>58042656
>>58042656
>>58042656
>>
>>58038643
>SAMS
Stop right there anon. Go and get the Lippman C++ Primer instead.
>>
>>58039383
All of which is available in the C++ FQA, which should be enough to convince you to drop the language as soon as possible.
>>
>>58042636
kek

but it looks doable to refactor it
Thread posts: 317
Thread images: 33


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