[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: 372
Thread images: 35

File: 1481225269428.jpg (1MB, 3537x3335px) Image search: [Google]
1481225269428.jpg
1MB, 3537x3335px
What are you working on, /g/?

Old thread: >>59573335
>>
is this the right /dpt/?
>>
>>59576713
C# is literally the cutest language.
>>
>>59576774
Too bad it's Microsoft only.
>>
>>59576787
What do you mean?
>>
>>59576805
C# is .NET language, and .NET is severely limited to MS platforms.
>>
File: g_programming_bingo.png (318KB, 740x926px) Image search: [Google]
g_programming_bingo.png
318KB, 740x926px
One of these

>>59576787
>>59576805
Anyone who hasn't actually tried hosting/running Mono on Linux should not respond.
>>
>>59576831
You can target Mono or .NET Core, both of which are open-source and cross-platform.
>>
>>59576843
See >>59576840
>>
>>59576851
I've used both Mono and .NET Core, and I have worked on live applications that use Mono and a myriad of microservices on .NET Core currently deployed at a mid-sized company.
>>
>>59576840
>>59576843
>Mono
Some third-party implementation
>.NET Core
Not complete.

I wouldn't make anything .NET related if it's not on MS platform.
>>
>>59576840
I think you should have placed "Code actively used by others" in the center.
>>
>>59576843
>You can target Mono or .NET Core
Yes. In the same way you can target Wine when writing Windows executables.

If you write a program in C# on .NET and only later try to run it on Linux or anything else, you're going to have a bad time.
>>
>>59576895
>Some third-party implementation
This is true, but Microsoft pays Microsoft developers to contribute to this projects.

>Not complete.
I agree, but it has worked fine for what I have deployed. I've got 10+ microservices using .NET Core sitting on an Ubuntu VM.

I'm certainly looking forward to .NET Standard 2.0, and in the longer term, Mono and the .NET Framework eventually merging into a single FOSS codebase (this has been hinted at by devdiv).
>>
>>59576840
I love CODE too!! Lets code!
>>
File: 222.png (376KB, 740x926px) Image search: [Google]
222.png
376KB, 740x926px
>>59576840
I suck.
>>
File: 1490477704724.png (355KB, 740x926px) Image search: [Google]
1490477704724.png
355KB, 740x926px
>>59576840
>>
File: bingo.png (375KB, 740x926px) Image search: [Google]
bingo.png
375KB, 740x926px
>>59576840
I don't remember if I programmed 2D grapjics, maybe I did, but I decided to not check it
>>
>>59577018
Contribute to a FOSS project by searching any small time github repo for common misspellings like "recieve" :^)
>>
File: 1489807819329.jpg (18KB, 399x300px) Image search: [Google]
1489807819329.jpg
18KB, 399x300px
>>59576944
>I've got 10+ microservices using .NET Core sitting on an Ubuntu VM.
What microservices?

>and in the longer term, Mono and the .NET Framework eventually merging into a single FOSS codebase (this has been hinted at by devdiv).
I am deeply concerned, because I can't find why MS would do this. I don't understand profits of such move, if it's not good ol' EEE.
>>
>>59577058
I think writing a self-balancing data structure would be better.
>>
>>59576955
>>59576966
>>59577018
is writing a self balancing tree that hard ?
>>
>>59576955
>>59576966
>>59577018
How have your retards not made a RB tree?
>>
>>59577126
>>59577134
I just use std::map if I need one. I'm not a C toddler to reimplement every data structure by myself.
>>
File: nigga are you serious.jpg (639KB, 2250x2724px) Image search: [Google]
nigga are you serious.jpg
639KB, 2250x2724px
>>59577062
>What microservices?
All sorts of things. Some of them dig into Exchange mailboxes, determine various things, and injest/move the mail around to create service tickets, or notify admins if there's an issue with ticket flow. Other automation tasks to update counts on various licensed things based on API calls and information in internal databases. Some of them "talk" to each other, and one of them is a little ASP.NET frontend so you can log in and get some information without reading the logs.

>because I can't find why MS would do this
Where have you been for the last 5 years?

Microsoft is slowly open-sourcing all of their dev tools and making them much easier for people to use.

They've realized that Azure is their cash cow these days, combined with their persistent corporate licensing for on-prem things like Exchange, Active Directly, and SQL Server, while also having these things as cloud-hosted offerings.

Here's the "why": say I'm familiar with .NET, and know the ins and outs because the language and FOSS ecosystem is attractive. I need to deploy some servers/databases/data warehouses/lakes etc. into the cloud with all sort of ETLs and whatnot. If I know that Azure offers all of this with robust .NET SDKs, that's what I'm going to recommend to management.

In fact, all of this is making life easier for the developer, and if the developer is happy and can produce results, management will buy what the solutions architect recommends.
>>
File: dpt.jpg (164KB, 800x1000px) Image search: [Google]
dpt.jpg
164KB, 800x1000px
>>
>>59577186
Wew
>>
Functional friends i need your help.
First functional language (Idris)

>For example, to define a function which reverses a list, we can use an auxiliary function which accumulates the new, reversed list, and which does not need to be visible globally:
reverse : List a -> List a
reverse xs = revAcc [] xs where
revAcc : List a -> List a -> List a
revAcc acc [] = acc
revAcc acc (x :: xs) = revAcc (x :: acc) xs


feeling like a brainlet because after the prototype definition, im lost.
Could someone step through each line for me?
>>
>>59577134
MIT uses an AVL tree as an example of a self-balancing tree. Also as it was mentioned earlier, there're plethora of libraries with data structures and algorithms.
>>
>>59577186
>just use std::map if I need one
thanks c++14 retard
>>
>>59577223
acc = accumulator

revAcc acc xs
reverses xs onto acc (acc ++ reverse xs)
>>
>>59577236
They're both self balancing trees, so I don't know why you brought that up. Also you make them in the first year of college.
>>
>>59577189
Well, I'll look into .NET infrastructure for Linux. Thanks.
>>
>>59577223
>>59577271
to add:
= means =

revAcc acc [] = acc
when you apply the args acc and [] (an empty list) to revAcc, you get back acc

revAcc acc (x :: xs) = revAcc (x :: acc) xs
when you apply the args acc and (x :: xs) (a list which has a head x and a tail xs) you get back the result of a recursive call
revAcc (x :: acc) xs
>>
>>59577325
So how would I call this in main to see an example?
I think iss understand better that way.
>>
>>59577387
Use a REPL
you enter an expression and it prints the result


reverse [3,4,5,6,7]
or
reverse (3 :: 4 :: 5 :: 6 :: 7 :: [])
>>
OOP is shit.
>>
>>59577410
Ah, im a big dummy, i was over complicating it.
thanks mang
>>
>>59577413
we know
>>
File: OOPs.png (315KB, 1680x740px) Image search: [Google]
OOPs.png
315KB, 1680x740px
What does the "s" in OOPs stand for?
>>
>>59577465
shit
>>
>>59577413
c# would be great if it wouldn't be for JIT
>>
>>59577413
>>59577465
(You)
>>
File: 1422303568745.png (256KB, 600x600px) Image search: [Google]
1422303568745.png
256KB, 600x600px
>mfw C++ is like C(leverest) but better
>>
File: airstrikes.png (124KB, 922x795px) Image search: [Google]
airstrikes.png
124KB, 922x795px
Designing an esoteric programming language called Nasenbluten. Here's Hello World.
>>
Why didn't they call it ++C
>>
File: languages3.png (17KB, 522x384px) Image search: [Google]
languages3.png
17KB, 522x384px
>>
File: 2017-03-19-164406.jpg (333KB, 1280x960px) Image search: [Google]
2017-03-19-164406.jpg
333KB, 1280x960px
I'm making a cpu benchmark tool for linux and windows. The only problem is that my benchmark only uses cpu0 and I want it to utilize all of the cores, do you have any recommended libraries I should use?
>>
>gcc 7 when
>>
>>59577523
Looks like Ook
>>
>>59577524
it's called c++17 now.
think of it as (c + (+17))
>>
>>59577583
m8... don't ask about libraries without saying which language or framework you're using.
>>
File: robot.png (771KB, 852x956px) Image search: [Google]
robot.png
771KB, 852x956px
>>59577620
>coercion
What languages still allow this in 2017
>>
>>59577654
even asm doesn't allow this
>>
>>59577583
>not having language native parallelism
wew lad
>>
File: heaven technology.png (116KB, 522x384px) Image search: [Google]
heaven technology.png
116KB, 522x384px
>>59577553
Get on my level
>>
What's a good intro on machine learning?
>>
>>59577747
Go back to your mind palace. The adults are talking.
>>
>>59577747
Microsoft® Lisp 95
>>
File: 1490477704724.png (387KB, 740x926px) Image search: [Google]
1490477704724.png
387KB, 740x926px
>>59576840
A lot of what I've done has been numerics or physics/math/engineering related. Take with a grain of salt.
>>
>>59577747
Lisp a shit, literally a worse Scheme, it shouldn't even be possible to ruin Scheme but somehow they did it
>>
File: 786374567856.jpg (24KB, 235x235px) Image search: [Google]
786374567856.jpg
24KB, 235x235px
I'm trying to learn ASM is it worth it?
(my first language desu)
>>
>dynamically typed
>prefix notation because babies believe macros are only possible with homoiconicity
HAHAHA
>>
>>59577553
>bait.bmp
>>
>>59577808
God no
Pick anything else
>>
>>59577774
>it shouldn't even be possible to ruin Scheme but somehow they did it
Obviously Lisp came out first and Scheme tried to fix it a decade later
>>
>>59577808
Are you EE?
>>
>>59577808
>>59577830
YES, but once you have a basic comprehension immediately ditch.
>>
>>59577808
It's a useful learning exercise to better understand what exactly your code in languages like C, C++, Rust, etc. is going to compile into. I've found it very useful for reasoning about optimizations when programming in those languages. Other than that though: No. It's still used yes, but not by very many people and you're unlikely to ever encounter it.

I would recommend learning some higher level language and then going over it in vague terms to get an idea of what those languages are probably doing under the hood. The specifics of assembly are generally useless as they change from implementation to implementation.
>>
>>59577813
>thinking homoiconicity is only used because of macros
>>
>>59577864
Why is it used, then?
>>
File: fixed heaven.png (116KB, 522x384px) Image search: [Google]
fixed heaven.png
116KB, 522x384px
>>59577762
>>59577765
>>59577774
OH FUCK I DIDN"T NOTICE THERE WAS ALREADY LISP
have the other instead
>>
>>59577873
language masturbation
>>
>>59577844
>>59577854
>but once you have a basic comprehension immediately ditch.
sounds legit, what language do i learn after this?
i'm using this web
https://www.tutorialspoint.com/assembly_programming/
i don't know if it is a good resource i haven't coded anything yet i'm just reading all the basic stuff.

>>59577843
>Are you EE?
what's that?
>>
>>59577808
I guess it depends on what you mean learn. If you want to get a conceptual understanding of 'machine code' (i.e. us syntax that just represent bits within a word), then I recommend a paired down version created @ my university, LC3. There are a few books as well as a windows IDE (lol) for it out there, and it's what we learned before going to C/C++/Python ect. It's based around 2 byte words/simple ISA/simple architecture. It was very cool writing LC3 assembly code and being able to trace its execution by hand through the HW.
>>
I just learned that Swift had pattern matching. Suddenly my opinion of it is a lot higher.
>>
>>59577898
Electrical engineer.
If you are not one, I think you'd better learn any other algorithmic language to take a grasp on what's programming is.
If you don't want to, well, good luck.
>>
>>59577898
C#, Java, C++, Python, Javascript, any of them really. The skills are (fairly) transferable, it's just a question of what you want to do.

C#/Java for your standard desktop apps and enterprise development.

Javascript for web.

C++ for anything high performance, servers, embedded, games, etc.

Python is good to know no matter what you're doing, it's nice for making quick tests and pieces of duct tape to tie other software together, but is particularly popular in science.
>>
>>59577977
This is a reasonable post.
>>
>>59577874
Microsoft® Forth 95
>>
File: 1438816683135.png (95KB, 680x478px) Image search: [Google]
1438816683135.png
95KB, 680x478px
>tfw couldn't formally complete half of the exercises from that one guys post about job questions for homework
>>
>>59577977
>C++ for anything
This is a reasonable post.
>>
>>59577985
No. There's no mention of any functional language (JavaScript is dysfunctional).

>>59577991
That's fine, those questions were shit.
>>
>>59578006
>There's no mention of any functional language
I would imagine this is intentional.
>>
>>59578013
So it's intentionally not forward-looking?
>>
>>59577977
To add a bit more I forgot:

Java for Android.
Swift for iOS.
C# if you want to develop for both at the same time through Xamarin but beware, reviews of doing this range from "it's great" to "thanks Xamarin, now I have cancer". Also if you're commercial you need to pay for it. Kinda.

>>59577998
That's my personal opinion on the matter, I love C++ to bits and will attempt to solve almost every problem with it, but I wanted to keep it objective.

>>59578006
I wanted to focus on popular industry standard stuff, not academic curiosities. I also don't know much about functional languages, I've only ever done Haskell and I have fuck all idea what use cases to suggest for them.
>>
>>59578098
>Also if you're commercial you need to pay for it. Kinda.
?
>>
>>59578098
>I wanted to focus on popular industry standard stuff, not academic curiosities
Functional languages are hot in fintech right now.
>>
>>59578124
They've restructured their bloody licensing page again in a way that almost suggests it's no longer true, but it used to be the case that if you wanted your app to be closed source, you needed to pay for a Xamarin license, making paid apps on the free license difficult but presumably making in app purchases and advertising still viable.
You'd need to look into it though, they claim it's now part of the Visual Studio Community license, which didn't impose any requirements upon source openness before, so I'm not sure what the story is.

>>59578128
I was unaware.
>>
>>59577977
>C++
>embedded

I remember when embedded programming had limited stack depth, kb worth of memory and 8bit words.

Now it's writing shell script cron jobs for 1GHz ARM CPUs running GNU/Linux.
>>
>>59578210
that's why C is literally irrelevant now.
>>
>>59578203
>so I'm not sure what the story is
Then you should have said this in the first place.

You may have been thinking about the "Starter" edition of Xamarin, which no longer exists, due to Xamarin itself being FOSS, and the dev tools in VS included with VS.

The only potential issue you may run into is Visual Studio Community licensing, which is intended for those making less than $1,000,000 in revenue per year.
>>
>>59578245
Not really. The last embedded programming I did was actually in C because the platform had only had a C compiler ported to it (as C++ is a much much larger standard). I said C++ in my post because if you learn it properly you'll basically learn C along the way. There was a whole office of us all doing different things in C on this thing, it's alive and well in some places.

>>59578278
I thought I knew what the story was, until I actually went and checked for further clarification. I apologize for not doing due diligence in my research for posts on a mongolian dishwasher maintenance forum.
>>
File: checked.png (340KB, 740x926px) Image search: [Google]
checked.png
340KB, 740x926px
>>59576840
Gotta catch 'em all
>>
Can't imagine a rational reason to be against functional programming. It's just more principled procedural programming.
>>
>>59578498
Angry OOP salesmen don't like it, because it reveals their snake oil for what it is.
>>
>>59578498
>>59578504
Would probly break all the UML diagrams lol
>>
>>59578504
>Angry OOP salesmen don't like it,
I like functional programming when I can use it in a language that lets me do straight imperative, and also use OOP if I want to.
>>
>>59578504
>OOP salesmen
Name a single popular programming language that must be purchased to be used.
>>
>>59578534
matlab
>>
>>59578534
C#
>>
>>59576840
>Anyone who hasn't actually tried hosting/running Mono on Linux should not respond.
So did you ever try to run a c hashtag program in mono or are you just spewing shit?
>>
>>59578534
They don't make their money through the languages themselves, but their books.
>>
>>59578540
Popular != forced on engi/EE students
>>
>>59578534
They don't sell the language directly. They sell "training" and "support".
>>
>OOPs programming is actually being seriously discussed
just wow
>>
>>59576713
Recruitment task. Java Restful API for meetings planning.
>>
Learning Elixir right now
it's beautiful
>>
>>59578555
I did. It was similar to porting a Linux C program to Windows. It was easy as long as you didn't try to use any APIs whatsoever.
>>
Show me a sublime color scheme that bolds keywords, but leave all text black and on an off-white background.
>>
File: 149020586933.gif (328KB, 500x517px) Image search: [Google]
149020586933.gif
328KB, 500x517px
>>59578498
Can't imagine a rational reason to be against object-oriented programming. It's just procedural programming tied to certain data.
>>
File: 1461737108240.png (860KB, 841x720px) Image search: [Google]
1461737108240.png
860KB, 841x720px
>>59578603
>sublime
>>
>>59578607
Encapsulation makes code reuse harder and prevents cache optimization.
>>
>>59578607
OOP is flawed, and encourages stupid shit like shared mutable state.
>>
>>59578607
But data structures are the primary focus, not logic paradigm.
>>
>>59578603
tomorrow color scheme
>>59578613
>trying this hard to seem 1337 on a forum
>>
>>59578607
I took my first OOP class in 1999. People still believed that you could take that Customer class you wrote for one program and reuse it in another.

So naive.
>>
>>59578629
How is laughing at some literal cuck who uses a fucking proprietary text editor "trying hard to seem l33t"?
I think you must be new.
>>
>>59578643
>1999
>still
Wait, I thought 90s was the heyday of OOP.
>>
>>59578655
>literal cuck

>check post header
>4chan pass user
>>
>>59578655
>4chan pass
>trying this hard to look like an oldfag
your parents neglect is showing my man
>>
>>59578570
>They sell "training" and "support".
What is wrong with this?
>>
>>59578660
>>59578661
Thanks for the (You)s.
Just using the shitposting clover pretty much means guaranteed replies.
>>
>>59578685
>mom, dad, i got a reply on 4chan!
>are you proud of me now?
>>
>>59578685
>2012

Since December 21st? Why even try?

ERCOM Avenida
>>
>>59578607
Why did your retarded brain feel the need to make a reply? Are you implying that FP and POO are somehow opposites? Please don't visit this site if you are underage.
>>
>>59578685
You sound pretty proud of it, I'm sure being noticed is a big accomplishment for you anon. I'm happy for you
>>
File: 1474124287116.gif (2MB, 400x347px) Image search: [Google]
1474124287116.gif
2MB, 400x347px
>>59578714
Why are you so buttblasted?
>>
>>59578128

Why?
>>
>>59578747
Why are you avoiding my questions?
>>
I'm working on a chess game in JavaScript with hopefully in the future connected to an sql database with PHP

Anyone have experience making chess? Any tips?
>>
Why does every single gnu project still use mailing lists and usenet as their only means of communication?
>>
>>59578789
Why wouldn't they?
>>
>>59578791
We have imageboards nowadays.
>>
>>59577523
>>designing
>simply replacing ook with airstrikes
>>
>>59578629
Still has color and doesn't bold keywords. I guess I'll just make my own.
>>
>>59578791
>>59578789
As much as I loathe mailing lists, they are universal. There is not a single person who doesn't have access to email on the entire planet. They've been around forever and thus people have systems in place to handle them (if they're not newfags and do work)
>>
>>59578789
It was state of the art at the time of their inception and they're hesitant to change something that still works.

They were pretty slow to adopt SVN and more recently Git when they've been getting by for decades mailing each other gzipped tarballs.
>>
How do I get into FPGA programming?
>>
File: 1473738349823.jpg (11KB, 274x268px) Image search: [Google]
1473738349823.jpg
11KB, 274x268px
>>59578762
Because you seem to be upset now and completely incapable of emotion-less productive talk.
Go calm yourself, and maybe tomorrow you'll be able to speak to me properly and respectfully.
>>
>>59578828
I am God on this Earth. Answer me.
>>
File: 1374577775522.jpg (3KB, 125x126px) Image search: [Google]
1374577775522.jpg
3KB, 125x126px
>>59578828
>Stupid POOfag
>Tries to talk down on somebody else
>>
What language will help me get aids?
>>
>>59578901
Rust
>>59578868
>proving his point
gg
>>
>>59578901
php
>>
>>59578819
If you're knew to digital design, get a digital logic book that teaches combination and sequential logic design with some examples in hardware description languages as well as traditional gates. Look for something written for electrical engineering students in about their sophomore year.

If you already know how to design a finite state machine, then a book that focuses on a hardware description language will do. Then it's just a matter of learning to use the tool chain for the FPGAs you want to target.
>>
>>59578868
who said this?
>>
>>59578912
see >>59578931
>>
>>59578923
If you're new*
>>
File: shejudges.net.png (41KB, 149x157px) Image search: [Google]
shejudges.net.png
41KB, 149x157px
>>59576787
what is mono
>>
>>59579007
Tragically immature.
>>
>>59579036
you're talking about the picture right?
>>
>>59579049
Picture is probly mature enough for this board.
>>
Things could have been different
We didn't have to go with C
>>
>>59579147
C was the lowest common denominator for all the old systems.
>This code might run with minimal changes on any of your tens-of-thousands-of-dollars university machines!
>>
File: system limits.png (5KB, 550x136px) Image search: [Google]
system limits.png
5KB, 550x136px
>>
>>59579166
>auto x
That is shitposting too hard.
>>
>>59579181
Forget about the semantics, how do I raise my limits?
>>
>>59579198
Install 128-bit CPU
>>
>>59579198
You haven't got enough RAM to store it in memory
>>
>>59579198
implement your own integers
>>
>>59579223
>>59579279
>using hardware designed by others
>>
>>59579232
I have 8 GB. Should I get 16/32/64 to store my large int?
>>
>>59579305
>implying you can't have 128-bit CPU of your design
>>
>>59579166
>>59579198
Big integer library
Is this C++ or D?
>>
>>59579333
It's C89.
>>
>>59579333
C++
>>
>>59579318
**************551616 (you won't be able to see this until you fix your RAM issue) is *****744073 (hopefully you can see that one) gigabytes
>>
>>59579350
Yeah, find a good big integer library for C++ then
>>
>>59578819

>>59578923
here.

Found the new version of the text I had in my EE digital design class.

http://libgen.io/book/index.php?md5=7084609A715D3C56A468C66D66DD1019
>>
>tfw native big int
BigInt a = "9588669891916142";
BigInt b = "7452469135154800";
auto c = a * b;
writeln(c); // BigInt("71459266416693160362545788781600")
>>
>>59579559
What do you mean "native"?
>>
>>59579589
Built into the language / I dont have to download and use a 3rd party
>>
>>59579603
Which is it? Or do you mean either of these?
>>
If I have:

int array0[] = {/*numbers*/};
int array1[] = {/*numbers*/};
int array2[] = {/*numbers*/};
int array3[] = {/*numbers*/};
int array4[] = {/*numbers*/};

int n = /*number*/;


When I try to access data doing this:

array0[ array1[ array2[ array3[ array4[ n ] ] ] ] ]


What will happen in the actual compiled program? A bunch of jumps in the assembly code, redirecting me to the address of the data inside array0?
>>
>>59579559
>BigInt
>String
Jesus that's awful.
>>
Haskell or OCaml?
>>
>>59579616
Yeah I don't think it's native if it has to be constructed by a string. That anon is retarded.
>>
>>59578789
They are pretty useful. You can't have discussions through a VCS.
>>
>>59579610
They mean the same thing in this context.
>>59579616
I can still operate,assign and print them like literals.
Not like Ill ever use BIs anyway, just another neat feature i didnt know about before.
>>
>>59579612
array4[n]
the nth element of array4

array3[array4[n]]
the array4[n]'th element of array3
array2[array3[array4[n]]
the array3[array4[n]]'th element of array2

e.g.

int n
int m = array4[n]
int l = array3[m]
int k = array2[l]
int j = array1[k]
int i = array0[j] /// you are here

>>59579637
Haskell
>>
File: integer.png (4KB, 390x114px) Image search: [Google]
integer.png
4KB, 390x114px
>>59579648
>I can still operate,assign and print them like literals.
>Not like Ill ever use BIs anyway, just another neat feature i didnt know about before.
>>
>>59579648
But in other contexts, they do not.

For example, if a language has a standard library implementation of this, it's not really "built into the language", but it is easily utilized with packages already available to your project.
>>
Using Java and trying to use an arraylist
I have two classes Weapon and Gun, gun extends weapon
I have a private variable in Gun called velocity with a getter and setter method
I have both guns and weapons being added to my arraylist
Now how can I access the private velocity in Gun from the arraylist? So that I can add it to something else or whatever I want?

My arraylist is
 
private ArrayList<Weapon> inventory = new ArrayList<>();


Am I in the right direction by doing this?
 
Weapon addVelocity = inventory.get(index);


I just want to add the velocity to my setter method for range
setRange(range + ????);
>>
>>59579667
 auto x1 = 9_588_669_891_916_142;
>>
>>59579652
>Haskell
Why?
>>
>>59576713
rate my number concatenation function
double numConcat(double a, double b){
int tempA = a * 10;
int divCount = 0;

while(b > 10){
b = b / 10;
divCount++;
//printf("%f", b);
}

double tempRet = tempA + b;

return tempRet * pow(10, divCount);
}
>>
>>59579706
It's pure and it has type classes for ad hoc polymorphism
>>
File: 1428166758785.jpg (259KB, 1280x1810px) Image search: [Google]
1428166758785.jpg
259KB, 1280x1810px
>>59579612
See https://godbolt.org/g/IAQVIN

array0:
.long 5
.long 6
.long 7
.long 8
.long 83
.long 4
array1:
.long 43
.long 54
.long 3
.long 6
.long 6
array2:
.long 3
.long 6
.long 7
.long 3
.long 2
.long 7
array3:
.long 43
.long 6
.long 34
.long 3
.long 6
array4:
.long 234
.long 3
.long 4
.long 6
.long 3
n:
.long 6
test:
.zero 4
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L3
cmp DWORD PTR [rbp-8], 65535
jne .L3
mov eax, DWORD PTR n[rip]
cdqe
mov eax, DWORD PTR array4[0+rax*4]
cdqe
mov eax, DWORD PTR array3[0+rax*4]
cdqe
mov eax, DWORD PTR array2[0+rax*4]
cdqe
mov eax, DWORD PTR array1[0+rax*4]
cdqe
mov eax, DWORD PTR array0[0+rax*4]
mov DWORD PTR test[rip], eax
.L3:
nop
pop rbp
ret
_GLOBAL__sub_I_array0:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
>>
>>59576713
guys i need help , im not very smart , this is the question:
Write a function print_squares_to_number(number) that takes a single positive integer and prints a table of all integers and their squares from 1 up to and including number, with a single space in between.
The program should print the error message ERROR: number must be at least 1 when number is less than 1.
Output should be formatted as in the table below
For example:
Test Result
print_squares_to_number(5) 1 * 1 = 1
2 * 2 = 4
3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
print_squares_to_number(3) 1 * 1 = 1
2 * 2 = 4
3 * 3 = 9
print_squares_to_number(0) ERROR: number must be at least 1

this is what i have so far :

def square(x):
print( x + "*" + x + "=")
return(x**2)

def print_squares_to_number(x):
int(x)
if x < 1:
print("ERROR: number must be at least 1")
else:
return square

i have repeatedly run into errors can somebody please help
>>
>>59579739
its in python 3 , sorry
>>
>>59579694
if( inventory.get(index) instanceof Gun) {
Gun gun = (Gun)inventory.get(index);
gun.setRange( gun.getRange() + 1);
}


Get the idea? The type check isn't strictly speaking necessary but if you know beforehand that it's a gun then why do you need a more abstract list?
>>
>>59579757
>python
>>>/r/ibbit
>>
>>59579757
Put code tags.
>>
>>59579762
Honestly drew a blank and forgot I could just cast it as a Gun instead. Thanks anon.
>>
>>59579765
will probably go if i cant get help here
>>59579767
code tags?
>>
>>59579739
def lol(n):
import math
if(n <= 0):
print("Not so fast friend")
for i in range(1, n + 1):
print("{} + {} = {}".format(i, i, int(math.pow(i, 2))))

>>
What's the best name to name a function which returns a specific object by some attribute, or if that object doesn't exist, creates it and then returns it?

Something like get_foobar does not really fully describe the idea.
>>
>>59579821
thank you , i love you so much
>>
>>59579826
reserve?
>>
>>59579826
I'm sorry, but you must be confused, redditor.
Never ever recommend usage of objects or OOP here.
>>
>>59579826
get_thing_or_create_one_if_it_doesn_exist_yet_and_then_return_it()

honestly I think get_thing() is descriptive enough.
>>
>spoonfeeding cs kids
/dpt/ pls
>>
>>59579850
Lol....
Is this from xkcd?
>>
>>59579849
If it will make you sleep any better I'm just re-using pooled structs.
>>
how would you go around implementing a stack in C? i just know the java way
>>
>>59579878
no, your language is trash, redditor. leave. just fucking leave and spare yourself from further embarrassment.
>>
>>59579694
You don't. If you're going to use a shitty OOP language, you should at least try to write decent OOP. If you need to access fields of a derived class to do something, you do that something as part of an overridden virtual method.

This >>59579762 is absolutely disgusting.
>>
>>59579889
>allocate an array
>done
>>
>>59579896
>you should at least try to do something which is by definition impossible
Nice plan.
>>
>>59579889
What's the Java way of implementing stack?
>>
>>59579907
i make a class with an array, a pop, and a push method
>>
>>59579907
Qbits <stack>forwarding.protocolOut(obj o, E e, index i);
Debuff (q);
Buff (r);
>>
>>59579904
Decent is the wrong word. Proper? The L in SOLID describes what I mean, i.e. subclasses should actually be subtypes.
>>
>>59579849
>>59579890
anti-OOP is a reddit meme now

These days, we talk about the language we like and why we like it, rather than subscribing to dogmatic memes.
>>
>>59579968
no, OOP is trash, redditor. leave. just fucking leave and spare yourself from further embarrassment.
>>
>>59579982
How are you supposed to do any large or complicated program without it being OO?
>>
>>59579982
>OOP is trash
Back this up, and I'll consider it.
>>
File: Screenshot_2017-03-25-21-39-51.jpg (809KB, 1440x2560px) Image search: [Google]
Screenshot_2017-03-25-21-39-51.jpg
809KB, 1440x2560px
C++ question...
I'm reading through this, and I don't
understand the highlighted in red part.
How can const float* be given aname instance resource variable of type array?

Screenshot in picture
>>
@59579994
Is this a serious question?
>>59580008
It's in the name.
>>
>>59578583
>Learning Elixir right now
>it's beautiful

Same. Got the Programming Elixir 1.3 book right in front of me.
>>
>>59579917
the c way is making an array and pop and push functions
>>
>>59580018
Ah, so you don't have an argument.

Typical.
>>
>>59579994
How does OOP help?

>>59580008
It's the null hypothesis. Well, strictly speaking the null hypothesis would be that OOP is useless, but of course perfection is only reached when there is nothing left to remove. OOP is bad because inheritance is bad (even OOP cucks realize this) and encapsulation is bad for code reuse and cache optimization.
>>
>>59580017
>C++
>>>/p/lebbit
>>
>>59580029
>inheritance is bad
>even OOP cucks realize this
>encapsulation is bad for code reuse
>encapsulation is bad for cache optimization
>these things being true make the statement "OOP is trash" objectively true.

Alrighty, here's your five points.

Prove them all beyond a reasonable doubt.
>>
File: Screenshot_20170325-214636.png (181KB, 1440x2560px) Image search: [Google]
Screenshot_20170325-214636.png
181KB, 1440x2560px
>>59580036
>>
>>59579889
You just need an array and an index into that array.
>>
>>59579732
Very nice, thanks.
>>
https://www.tesla.com/sv_SE/careers/job/software-engineer-supplychainautomation-45810?redirect=no

Did an indeed.com job search for Rust jobs. A big portion of them are either FP hipster ocaml shops or job ads that list fifteen+ languages, but Tesla stood out.

They list four languages, the other three are part of their current active toolchain so they must have specifically chosen Rust as the fourth one.
>>
@59580051
The proof is trivial.
OOP := trash.
Q.E.D.
>>
>>59580075
I'd guess we're at least 2-3 years from rust jobs being a big thing. Some places might want that in advance or be trying nightly shit though.
>>
>>59579719
a = 12
b = 10
result = 130.000000

Good work. Good call making it accept doubles and return a double.
>>
>>59580075
>>59580103
Rust wasn't stable until mid 2015.

Rule of thumb is that it takes a language 5 years after its first stable release to get traction in the jobs market. If it doesn't have it by then, then it will never have it.
>>
>>59580051
>inheritance is bad
It's a limited form of composition that only removes the boilerplate required when composing encapsulated objects together. It's also a very bizarre way to induce subtyping because subtypes are supposed to be refined types, not extended types. Theoretically inheritance would be okay without methods but then there's no difference from encapsulation.

>even OOP cucks realize this
"Composition over inheritance" is everywhere.

>encapsulation is bad for code reuse
It's difficult to reuse code when it's tied to data and locked behind a public interface. It also tends to encourage shared mutable state because it's much easier for encapsulated objects to call methods back and forth than to have some mediating code do it when the mediating code has limited access to the objects' internals.

>encapsulation is bad for cache optimization
This is pretty obvious. You can't organize your memory based on access patterns if the data comes packaged in objects.

>these things being true make the statement "OOP is trash" objectively true.
Inheritance and encapsulation are the only unique features OOP has to offer.
>>
File: 1485473684854.png (408KB, 824x792px) Image search: [Google]
1485473684854.png
408KB, 824x792px
>>59580122
>If it doesn't have it by then, then it will never have it.
D lang literally confirmed dead.
>>
>>59580130
You realize he isn't even being serious, right?
>>
>>59580133
Good. It's OOP trash.
>>
>>59577583
Could you not just run the max number of threads? based on the host cpu.
>>
>>59580075
It would kind of make sense for Tesla to be interested in Rust. They do a lot of stuff which requires something similar to C++ but with more safety, and their corporate culture is less risk-averse than traditional automakers.
>>
>>59580136
Even if someone is jokingly asking for evidence that OOP is shit I'll gladly share it.
>>
>>59580163
Sure, but you could share it without replying to him.
>>
>>59580122
Is that a rule of thumb? Neat. I mean obviously mozilla is going to be jumping on it so that's a big push but not sure if enough.
>>
>>59580163
Please tell me about it.

I am learning Elixir (Functional Programming) and it is wayyyy different than what I am used to writing in imperative OOP languages. I am still not confident I would be more productive in a non-OOP language.

Senior in college if that makes any difference.
>>
>>59580209
>>59580130
>>
>>59580133
I'd hardly say that, despite how much /dpt/ wants to meme
>>
>>59580209
>Elixir (Functional Programming)
No. Elixir is not functional programming, nor is Erlang. They are object-oriented languages, in the Smalltalk rather than the Java sense.
>>
>>59580209
>Only OOP and Functional languages exist.
Try procedural programming.
>>
>>59580209
>I am still not confident I would be more productive in a non-OOP language.
>Senior in college
Is that college in India, by any chance?
>>
>>59580225
Go home, Andrei.
Your language is shit, and only the most ironic of memesters actually use it.
>>
>>59580230
Are you really this retarded or is this some sort of triple-layered ironic meme?
>>
>>59580228
http://elixir-lang.org/
>Elixir is a dynamic, functional language

https://en.wikipedia.org/wiki/Erlang_(programming_language)
>Erlang (/ˈɜːrlæŋ/ er-lang) is a general-purpose, concurrent, functional programming language
>>
>>59580133
>D lang literally confirmed dead.
Facebook uses it, among many other sponsors.
I honestly dont get why 'dpt' think d is dead.
>>
>>59580252
>dynamic
So in other words it's garbage?
>>
>>59580252
Elixir can describe itself however it wants. It is not a functional language, though.
>>
>>59580249
That's wrong
>>
>>59580208
Can you name me a modern, post-Internet language that breaks the '5 years since stable rule'?

Ruby and PHP share this trait. So does Golang.

If you can't get your open-sourced language popular within 5 years of stable release, then that means that nobody really wants it. And that it is not going to take off, no matter how long you wait.
>>
is this anti-OOP guy the same anti- C autist. They both have that annoying vibe to them.

t. dont use either
>>
- Sockpuppet / persona management software.

- Agent based modeling of Bitcoin.
>>
>>59580228
see >>59580251
>>
>>59580270
Nope.

D would have been relevant in the 90s and early 00s, had it not lost.

It is not relevant now.
>>
>>59580280
It's "functional" in the same way Java is "functional" because it finally has lambdas.
>>
>>59580274
>post-Internet
How's that?
>>
>>59580245
>Is that college in India, by any chance?

US.

Already have a pretty decent offer from a large company with good pay in a cheap city. ~80k isn't so bad starting from college, right?
>>
>>59580282
Relevance doesn't determine how good a language is
>>
>>59580297
You claimed that POO and FP are somehow incompatible, even though one is a subset of the other.
>>
>>59580308
Go on, this should be funny.
>>
>>59580305
Agreed, I'll rephrase.

D was good compared to late 90s and early 00s languages. It is not good compared to modern day languages.
>>
>>59580314
Are you a literal retard?
Is this really that fucking hard to get?
POO : either """F"""P or imperative.
Procedural : either FP or imperative.
>>
>>59580299
make sure their expectations arent extravagant

lot of employers make the mistake of hiring college grads thinking that they learned shit that they didnt
>>
>>59580328
Functional does not mean declarative.
>>
>>59580298
What I meant was any language that has been created since the internet went mainstream.

Passing around libraries, compilers, etc. before that was such a pain that it fundamentally restricted language proliferation.

With that limitation removed, there is no real impediment to a language's adoption apart from the qualities of the language itself.
>>
>>59580308
OOP is about dynamic dispatch and message passing.

FP is about functions, where everything is a function, and you construct programs by composing and reusing smaller functions to construct larger functions.

Functions do not have side effects.
>>
>>59580267
When a language makes everything immutable and forces you to use tail recursion and higher order functions instead of loops, not calling it functional is an exercise in sophistry.
>>
>>59580343
Why are you so desperate for your favorite shitlang to be called "functional"? Is it because you don't want to have to learn any real functional languages?
>>
What's a good resource for learning Android development if I'm already (somewhat) familiar with Java?
>>
>>59580017
Is this b8?
>>
>>59580337
Declarative isn't a valid word to use. Fuck off to your webdev subreddit if you claim otherwise.
I didn't say that, by the way.
>>59580342
Everything in this post is literally true >>59580328
Please try to understand basic things before you post here.
>>
>>59580024
so have the array be a global variable?
>>
File: 1490233029280.jpg (23KB, 240x207px) Image search: [Google]
1490233029280.jpg
23KB, 240x207px
>>59580343
>and forces you to use tail recursion and higher order functions instead of loops
What if a language supports both?
>>
@59580360 (You)
>>
>>59580336
Why would you assume that you would always be more productive with non-OOP languages?

The job itself is all Java, Golang, and Python. Evidently they can still get shit done in those 'lesser' languages as Paul Graham would say.
>>
>>59580360
t. wasn't actually taught OOP, FP, or anything about programming at all really
>>
>>59580353
I despise Elixir, but it's still a "functional" language. Not functional since it's dynamic garbage.
>>
>>59580323
>It is not good compared to modern day languages.
Like what?
It has much better metas than Rust
A focused STL
Improves all of C++'s shit.
Proper module system.
no preproc bullshit.

Its literal only drawback is a GC thats getting phased out. But many, many parts of the language can be done with MMM
>>
>>59580375
You deny basic facts, how can you possibly claim to be sane and worthy of being treated as a human being?
>>
>>59580017
I'm not qualified to answer, but I'm pretty sure arrays are pointers in c and c++.
>>
>>59580323
I'd disagree to an extent. While it may or may not have failed it's goal of replacing C/++ as a systems programming language (I've stopped holding my breath a while ago for completely nogc), I find it infinitely better to use than its counterparts such as Java or C++ for application programming.
>>
>>59580371
Such a shame, they could easily be twice as productive if they used a better language.

Go in particular is responsible for many millions of man-hours of lost productivity.

Just imagine the hundreds of thousands of programmers using Go, each typing the same shit over and over again, not able to do it once and reuse it because Go has almost no capacity for abstraction.
>>
>>59580382
>It has much better metas than Rust
Isn't D metaprogramming literally string manipulation?
>>
>>59580353
Not same guy. I don't use Elixir, I mainly use Haskell and prefer ML syntax for a variety of reasons. Elixir is definitely functional though, much like Erlang.
>>
>>59580382
It has POO, making it worse that anything which doesn't have POO.
>>
>>59580364
pointers seem like a better choice
>>
>>59580274
Not sure, most <CURRENT YEAR> langs that are jumping into popularity are 20+ years old. Usually with some new hypelib.
>>
>>59580376
>Not functional since it's dynamic garbage

It is Functional, but not really pure like Haskell or LISP.

I am not sure Pure Functional languages are any good, since they have never really been adopted by any major industry. Erlang/Elixir has at least got major traction is telecoms.
>>
>>59580382
>comparing it to Rust and C++
Those aren't the languages I was referring to.

As long as D has a GC it cannot compete with Rust or C++.

Since it has a GC, it's competing against other GC languages, and guess what: Idris, Haskell, Scheme, etc. blow it out of the water.
>>
>>59576840
hard to imagine anyone graduating with a CS degree without getting a bingo
>>
>>59580415
Inb4 "Muh optional GC".
It's far too late for that.
>>
>>59580392
Arrays are areas of allocated memory.
Pointers can point at anything.
Well, you can use array name as a pointer to the zeroth element.
>>
>>59580399
>Isn't D metaprogramming literally string manipulation?
wew, love arguing with people whove never actually used the language
>>
>>59580410
It's not functional, it simply isn't possible if it's dynamic garbage. It's definitely "functional" though.
>I am not sure x is any good, since it has never really been adopted by any major group
That's a pretty retarded way to think if you're over 18.
>>
>>59580425
It's like Rust and HKTs. It's never going to happen.

If you don't design for these things from the start, you will never have them, it seems. Much like Haskell is now stuck when it comes to dependent types.
>>
>>59580405
so have a function pop that takes a pointer to an array, mutates that array, and returns the former first index? can a C function mutate an array from a pointer like that?
>>
>>59580430
He asked a question, retard.
>>
>>59580410
>I am not sure Pure Functional languages are any good, since they have never really been adopted by any major industry.
This isn't an argument in the first place but I will humour it. The industry requires labour. Programmers by and large are not taught to program in a highly principled and disciplined way that is required in pure functional languages. It's a chicken and egg problem since schools mostly only teach what the industry wants.

>>59580430
What is it, then?
>>
>>59580397
>Such a shame, they could easily be twice as productive if they used a better language.

What company is using these 'mythically productive languages' so effectively? And what languages are you referring to in particular?

I know Facebook uses some Haskell as part of their Spam-filtering stack. Walmart uses Clojure. Erlang is used in a lot of telecom companies. And that is about it as far as I can tell. Only Erlang is really irreplaceable here.
>>
>>59580403
>Elixir is definitely functional though, much like Erlang.
I strongly disagree.

I also don't think ML can really be called functional. Functions are referentially transparent. They don't have side effects.
>>
>>59580415
You said modern.
Rust is the gimmick language currently.
>>59580415
>Idris, Haskell, Scheme, etc. blow it out of the water.
Not really in terms of actual production code.
Idris does have a bright future. Haskell is quickly becoming the C++ of FP though.
>>
>>59580446
yes. refer to >>59580017. although you'd have to remove the const
>>
>>59580455
>This isn't an argument in the first place but I will humour it
Why? What purpose does it serve?
>>
>>59580407
And what languages are those?

Python is the big one, but its inception was before internet went mainstream. The developer even talked about how difficult it was to actually distribute it to people.
>>
>>59580467
>actual
as opposed to?
>production code
what's a "production code"?
>>
>>59580462
A lot of fintech companies use Haskell, OCaml, Scala, etc.

>>59580467
If D can't compete with old languages like Haskell and Scheme, then it has no chance against modern languages like Idris.

Of course D beats shitty modern languages, but that's not what I'm interested in.
>>
NEW THREAD!

>>59580498
>>59580498
>>
>>59580445
I dunno, HKTs aren't all that ground shaking to add to a language, compared to getting rid of garbage collection or adding dependent types. AFAIK the blocker is deciding on syntax.
>>
>>59580110
fixed it
double numConcat(double a, double b){
double tempA = a * 10;
int divCount = 0;

while(b >= 10 ){
b = b / 10;
divCount++;

}

double tempRet = tempA + b;
return tempRet * pow(10, divCount);
}
>>
>>59580504
>I dunno, HKTs aren't all that ground shaking to add to a language
I know, and that just makes it worse that they're not there. HKTs are my bread and butter, I use them every day when programming. They're not special. They're not controversial. They are, however, essential.

>AFAIK the blocker is deciding on syntax.
That's an absolutely pathetic excuse for not having them.
>>
>>59580455
>Programmers by and large are not taught to program in a highly principled and disciplined way that is required in pure functional languages

And what would the industry look like if they were?
>>
>>59580577
Less of an absolute shitshow with a new JS framework every week.
>>
>>59580495
Python, ruby, erlang, ocaml, lisps, etc.
>>
>>59577898
>https://www.tutorialspoint.com/assembly_programming/
I'm looking at the tutorial and it says on page 2:

>"According to the rule of parity, the number of bits that are ON (1) in each byte should always be odd."

It's not clear to me if this means odd- or even-parity. Does "odd" include the checkbit itself. It does say "in each byte", but it's not really clear. And I assume this is 32 bit assembly?
>>
>>59580530
HKT's can make the type system turing complete though. There are valid reasons for avoiding them.

Also, a lot of typeclasses such as generic monads can be implemented without them and end up being slightly more general if you do it since it doesn't imply free theorems. It will be a bit more verbose though, with an Parameter/Element type for each instance instead of a type constructor like in monotraversable.
>>
>>59580505
But why doubles?
>>
>>59580723
can 3/10 be expressed as an int?
>>
>>59580392
>>59580472
Buthe why is it written float*?
Isn'the a float memory allocated differently than an arrays? An array has to have its memory allocated sequentially.

Referring to >>59580017
>>
>>59580766
just cast it...?
>>
>>59580865
True. Is there a practical difference?
>>
>>59580766
When would it even get to that? 3 is not >= 10
>>
>>59580865
>3/10 == 1
Nailed it
>>
>>59580906
when you make a double/float/etc it reserves more memory when its initialized than an int would
>>
>>59580935
anon please...you cast the equation, not the result
>>
>>59580935
echo '3/10' | bc 
0

Seems legit
>>
>>59580938
Ah right. Gotcha.
>>
>>59580783
To answer your first question, it's a const float * since you would conceivably have an already generated array of grades that you want to pass in when making a new student. Consider someone actually using your software, and they have a pre-existing gradebook that they want to enter as floats and pass into a new student. In this case in question, when you pass in just an int parameter, it constructs a float array itself with a default grade (0 here), and then uses the Student constructor that initializes all the fields of the student class.

To answer the second one, arrays of any type of 'object' (char, int, floats, even students) are just ways of interpreting/traversing regions in memory. For example, an array of 5 floats says that for the next 5 float 'sized' locations in memory, the data we see there should be interpreted as floating point numbers. Thus a pointer to a float 'array' is really a pointer to the first 'float' location in the array, and knowing it's a float array means we can offset this pointer the correct amount to get the correct data of any float in the array (notice that myArray[n] is syntactic sugar for pointerToFirstItem + (sizeOfItems * n)).
>>
>>59581011
the last sentence you wrote does not make sense to me. Could you write pointerToFirstItem + (sizeOfItems * n)
In actually c++ code?
I just don't understand the last sentence you wrote. Like I was trying to read it like was c++ code but it doesn't make sense to me.
And why are you adding pointers. I also dont get what you mean by offsetting pointers. I don't understand...
>>
>>59581236
>Could you write pointerToFirstItem + (sizeOfItems * n)
>In actually c++ code?
sizeof is implied so it would just be pointer + n
>>
>>59581302
I'm trying to understand it like this...
randomArr [9]=2;
Is like saying
addressOfFirstPositionInrandomArry + 8=2;

Am u correct?
>>
>>59581380
I suggest you read up on arrays. You don't seem to understand are. Saying "randomArr[9] = 2" is setting the 10th element of the array to carry an int of 2. What >>59581011 is saying is the general idea of an array in C is that the syntax "array[9]" really means "a pointer to the first item: array[0] + sizeof(type) * 9. In an array like array[9] there are 9 items, the first of which is the address that a pointer holds so it may access the array.
>>
>>59581577
>In an array like array[9] there are 9 items
there are 10 items. array[0] to array[9].

fix.
>>
>>59581577
So for any array, any at all...
If I cout <<xArray[0] <<endl;
Out should come a hexadecimal value...because it's a memory address.
Am I correct?
>>
>>59581711
Array[&0]
>>
>>59581711
In theory yes, you could do something like:
cout << (*int) myArray[0] << endl;

And it will interpret the bits located at the memory address starting with myArray[0] + next 4ish bytes as an int, even if it's an array of say Student objects like above, although the compiler might throw a fit. There is nothing special about the memory or the data within it.
>>
>>59581786
Woops, would probably be more like:
cout << *((*int)myArray[0]) << endl;
>>
>>59581711
element 0 can also hold a value though. But its address, that one is carried by "type array[n]" upon declaration. Otherwise C would not know how to get to the other elements. Arrays are stored in sequential order in memory. To get the address of any value, you need to use the ampersand. (&x means the address of x.)
>>
>>59581786
is this why in for statements i++ increments i so as to skip the first part of the array which is array[0]?

Also, does this mean that for any array i cannot store anything at array[0] or i would risk having an error when looping from array[0] to array[9]?
>>
>>59581820
>>59581872
Ok i get it. So when an array is passwd into a function only the address at array[0] is passed.
>>
>>59581872
You should really just learn about arrays from a book or website. Array element 0 CAN store data.
>>
>>59581930
Yes, that's right. Only the pointer to the first element is passed. That first element is like any other variable
>>
>>59581943
so am i correct in saying that if i were to pass an array to a function, i would have to use float * array[0].
And then inside the function would it be able to loop to wherever it wants?
>>
>>59582010
heres a pic of related
>>
>>59582010
float * x
is a pointer to a float. If it's an array of floats, then you can read the next 32(?) bits and it will also be a float. You read until you find an address holding a null
>>
File: Screenshot_2017-03-26-00-45-31.jpg (734KB, 1440x2560px) Image search: [Google]
Screenshot_2017-03-26-00-45-31.jpg
734KB, 1440x2560px
>>59582034
>>59582034
>>
>>59582039
Looks like you got that right. g, the name of the array, withing a function argument, will be the pointer to the first element of g, that's g[0]. So yes.
>>
>>59582039
However, it's NOT the same as writing g[0] in the function's argument because 'g' means the entire array whereas g[0] is just one element.
>>
>>59582039
g[0] would be the value at position 0 in the array, while *g is an address pointing to the first element in the array.
>>
>>59582077
but if i wrote g[0] would the rest of the function still be able to access the rest of the arrays elements?
>>
>>59582119
No.
>>
>>59582129
i disagree. im trying it out now on visual studio.

it shud work. float * g is still just referencing g[0]
>>
>>59582119
'g' is the pointer. (subject) and 'g[0]' is what's being pointed to (object).
>>
>>59582151
Update...
It didn't work. I don't know why.
If when passing an array into an argument all that is happening is the addresss at array[0] is being passed then the rest of the function should know just to increment one memory address ahead of array[0].
After all the memory allocation for an array is sequential.
>>
>>59582291
It's because your function, if passed g[0] as an argument, will not know the ADDRESS of g[0] and therefore it will not know WHERE the other elements are in memory. You NEED the pointer to tell the function the ADDRESS of g[0].
>>
>>59582305
so if instead of g, i write the address of g[0] then my function should work just as if writing g??
>>
>>59582424
Technically yes.
>>
>>59582424
g[&0]
>>
>>59582428
Hiw would someone go about doing what i want to do, which is to write the address of g[0] explicitly, instead of writing g?
>>
>>59582565
>>59582546
That's the equivalent of 'g'.
>>
>>59582575
in visual studio if i write that its giving me a red line under 0 saying error function must have an l value or a function designator.
http://imgur.com/a/2sfft
>>
>>59582630
Yeah. An & operator is always a rvalue. rvalues are right-side of the equivalence. What the function wants is an lvalue. Does it compile?
>>
>>59582654
s/equivalence/equal sign/
>>
>>59582654
>>59582630
Hey, but 'g' is an lvalue. And it means the same as g[&0]. Why don't you use that?
>>
>>59582654
Before I added g[&0] it was compiling perfectly.
http://pastebin.com/2WbZXqUS
I created a pastebin incase anyone wants to try it out with the error.

http://imgur.com/a/OlZcp
That imgur is the error, screenshot taken from my 4k 65 inch tv, zoom in on it if u want.

NOTE: this material and code is from a book.

>>59582671
I just want it to work with g[&0].
>>
before this thread exits heres a new thread for my problem incase anyone is interested

>>59582748
Thread posts: 372
Thread images: 35


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