• Register
  • TOS
  • Privacy
  • @NeoGAF
  • Like

firehawk12
Subete no aware
(10-08-2017, 09:37 PM)
firehawk12's Avatar
I'm late, but thanks for the explanations!

Thinking about it as a string object being formatted makes sense. It's just trying to figure out what format can do then.
Somnid
Member
(10-08-2017, 09:48 PM)
Somnid's Avatar

Originally Posted by cpp_is_king

Hints:

sizeof(foo) == 1. It doesnít contains any function pointers.

The using statements are both correct and name actual types, but the declaration of wtf is illegal because you canít have an instance of this type, even though itís a legal type.

Thereís also another thing Iím not saying it because itís too stupid to believe, so Iíll see if anyone figures it out

Edit: actually I might be wrong, the declaration of wtf is legal,
But you canít make a pointer of it, even though you can with int_func

So if it has size of 1 what's actually there in memory? Like my understanding of a "struct" is a block of bytes with some type information, so if you declare something a type of function, what does that mean if it's not a reference?
cpp_is_king
(10-08-2017, 09:52 PM)
cpp_is_king's Avatar

Originally Posted by Somnid

So if it has size of 1 what's actually there in memory? Like my understanding of a "struct" is a block of bytes with some type information, so if you declare something a type of function, what does that mean if it's not a reference?

Itís basically the same as an empty struct, because itís not declaring a variable, itís declaring a function. Size of an empty struct is defined to be 1, because you have to be able to take its address, and you wouldnít want two different objects to have the same address
Somnid
Member
(10-08-2017, 10:06 PM)
Somnid's Avatar

Originally Posted by cpp_is_king

Itís basically the same as an empty struct, because itís not declaring a variable, itís declaring a function. Size of an empty struct is defined to be 1, because you have to be able to take its address, and you wouldnít want two different objects to have the same address

So then would the compiler force me to implement int_func like it was part of a class?
cpp_is_king
(10-08-2017, 10:21 PM)
cpp_is_king's Avatar

Originally Posted by Somnid

So then would the compiler force me to implement int_func like it was part of a class?

Yep. I said it was weird didnít i? :)

This is not something you should ever do btw, itís just one of the dark corners of c++
The Last Wizard
Member
(10-08-2017, 11:11 PM)
The Last Wizard's Avatar
Hey guys, I'm having some troubles with passing arguments from my main method to another so it can do calculations.

Code:

  public static void main(String[] args){
    double len, wid, priceGallon,paintReq;
    welcomeMsg();
    priceGallon = readPricePerGallon();
    System.out.println("The price per gallon is " + priceGallon);
    len = readLength();
    System.out.println("The length is " +len);
    wid = readWidth();
    System.out.println("The width is " + wid);
    double squareFeet = wid * len;
    System.out.println("The square feet is " + squareFeet);
    paintRequired(squareFeet);
I'm trying to take squareFeet and pass it into this method called paintRequired. But I keep getting errors.

Code:

 public static double paintRequired(){
    double paintGallons = 1;
    paintRequired = paintGallons * squareFeet;
    return paintRequired;
How can I get squareFeet passed into the new method I've created?

Also if anyone knows a resource I can learn about methods that'd be really helpful, I'm learning Java from the beginning and I've done well so far but I've just started methods and hit a wall:/
SigmasonicX
Member
(10-09-2017, 12:14 AM)
SigmasonicX's Avatar

Originally Posted by The Last Wizard

Hey guys, I'm having some troubles with passing arguments from my main method to another so it can do calculations.

Code:

  public static void main(String[] args){
    double len, wid, priceGallon,paintReq;
    welcomeMsg();
    priceGallon = readPricePerGallon();
    System.out.println("The price per gallon is " + priceGallon);
    len = readLength();
    System.out.println("The length is " +len);
    wid = readWidth();
    System.out.println("The width is " + wid);
    double squareFeet = wid * len;
    System.out.println("The square feet is " + squareFeet);
    paintRequired(squareFeet);
I'm trying to take squareFeet and pass it into this method called paintRequired. But I keep getting errors.

Code:

 public static double paintRequired(){
    double paintGallons = 1;
    paintRequired = paintGallons * squareFeet;
    return paintRequired;
How can I get squareFeet passed into the new method I've created?

Also if anyone knows a resource I can learn about methods that'd be really helpful, I'm learning Java from the beginning and I've done well so far but I've just started methods and hit a wall:/

public static double paintRequired(double squareFeet) { ... }

You need to include parameters in the parentheses.
Gunslinger
Member
(10-09-2017, 03:02 AM)
Gunslinger's Avatar

Originally Posted by The Last Wizard

Hey guys, I'm having some troubles with passing arguments from my main method to another so it can do calculations.

Code:

  public static void main(String[] args){
    double len, wid, priceGallon,paintReq;
    welcomeMsg();
    priceGallon = readPricePerGallon();
    System.out.println("The price per gallon is " + priceGallon);
    len = readLength();
    System.out.println("The length is " +len);
    wid = readWidth();
    System.out.println("The width is " + wid);
    double squareFeet = wid * len;
    System.out.println("The square feet is " + squareFeet);
    paintRequired(squareFeet);
I'm trying to take squareFeet and pass it into this method called paintRequired. But I keep getting errors.

Code:

 public static double paintRequired(){
    double paintGallons = 1;
    paintRequired = paintGallons * squareFeet;
    return paintRequired;
How can I get squareFeet passed into the new method I've created?

Also if anyone knows a resource I can learn about methods that'd be really helpful, I'm learning Java from the beginning and I've done well so far but I've just started methods and hit a wall:/

Your method signature is different. Currently your paintRequired Function is not talking in any parameters but you are passing it one anyway. Correct Way:


Code:

 public static double paintRequired(double val){
    double paintGallons = 1;
    paintRequired = paintGallons * squareFeet;
    return paintRequired;
esmith08734
Member
(10-09-2017, 03:20 AM)
esmith08734's Avatar
You'll want to assign something to your passed parameter in the method body or your argument doesn't have much meaning.
Koren
Member
(10-09-2017, 10:20 AM)
Koren's Avatar

Originally Posted by cpp_is_king

itís just one of the dark corners of c++

C++ has more dark corners than an icositruncateddodecadodecahedron in a pitch black room...
Slavik81
Member
(10-09-2017, 12:27 PM)
Slavik81's Avatar

Originally Posted by cpp_is_king

Yep. I said it was weird didnít i? :)

This is not something you should ever do btw, itís just one of the dark corners of c++

I think that oddity stems from C. It's a little known fact that you can forward-declare functions by typedefing their signature and then declaring them like variables. using is just acting like a fancy typedef.

Another fun one: you can swap your array index and your array variable. 5[arr] is every bit as valid as arr[5].
The Last Wizard
Member
(10-09-2017, 03:44 PM)
The Last Wizard's Avatar

Originally Posted by Gunslinger

Your method signature is different.

Originally Posted by esmith08734

You'll want to assign something to your passed parameter in the method body or your argument doesn't have much meaning.

Originally Posted by SigmasonicX

public static double paintRequired(double squareFeet) { ... }

You need to include parameters in the parentheses.

Thanks guys. I'm starting to understand it a bit more but damn if these methods, arguments and parameters aren't confusing:/

I really wanna stick with it this time too, I gave up the last two times cause the roadblocks are annoying.
oxrock
Gravity is a myth, the Earth SUCKS!
(10-11-2017, 09:25 AM)
oxrock's Avatar
I've been a tad bit worn out from working on my game lately so I decided to write a fractal tree script in python after seeing some cool pictures online. I also hardly ever use recursion so I thought it would help getting more practice in there as well. Anyhow, here's a picture made from an earlier version of the code:

Since then I've added a lot more randomness in the hopes of making the result look more natural.
updated example:

Here's a video using the updated code of a fractal tree taking shape: Fractal Tree Video. There's a link to the repository in the description if anyone's interested at taking a peek at the code.
Last edited by oxrock; 10-11-2017 at 09:49 AM.
Koren
Member
(10-11-2017, 12:49 PM)
Koren's Avatar
Great job...


Btw,in Python, it's really easy to develop a generic L-system engine, that makes this kind of procedural generation a breeze, and basically recursionless.

An by using generator functions, you can avoid memory costs.

If someone is interested, I'll post an example...
Slavik81
Member
(10-11-2017, 01:00 PM)
Slavik81's Avatar
The Algorithmic Beauty of Plants is a nice read. http://algorithmicbotany.org/papers/#abop

My supervisor wrote it 27 years ago. There has been a lot of progress improving plant modelling since then, but it's still a good introduction even today.

Would you believe there are researchers who spend a significant amount of time doing more or less the same sort of model-building you did? Sometimes we start with a biological processes and build matching rules to see if that process is the cause of the plant shape. Other times, we take guesses at the rules and hope it helps biologists narrow down candidates for the processes that inform the shape.

Of course, sometimes we just make things look pretty.
Last edited by Slavik81; 10-11-2017 at 01:16 PM.
Koren
Member
(10-11-2017, 03:35 PM)
Koren's Avatar

Originally Posted by Slavik81

The Algorithmic Beauty of Plants is a nice read. http://algorithmicbotany.org/papers/#abop

I concur... I even quote this one to my students. You can thank your supervisor for me ;)
oxrock
Gravity is a myth, the Earth SUCKS!
(10-12-2017, 12:03 AM)
oxrock's Avatar

Originally Posted by Slavik81

The Algorithmic Beauty of Plants is a nice read. http://algorithmicbotany.org/papers/#abop

My supervisor wrote it 27 years ago. There has been a lot of progress improving plant modelling since then, but it's still a good introduction even today.

Would you believe there are researchers who spend a significant amount of time doing more or less the same sort of model-building you did? Sometimes we start with a biological processes and build matching rules to see if that process is the cause of the plant shape. Other times, we take guesses at the rules and hope it helps biologists narrow down candidates for the processes that inform the shape.

Of course, sometimes we just make things look pretty.

I've never studied this stuff and I kind of did it on a whim because the pictures looked cool. Thanks for the link to that book, it'd be nice to read more about this. Maybe I'll give it another go after I do.
BuddyTheBestPuppy
Junior Member
(10-12-2017, 02:20 AM)
Hey does anyone here have any experience working with VBA/Excel? I have to automate a lab outage schedule, I have completed the entire program except for one critical component :P

There's are two columns with the date and time format of yyyy-mm-dd h:mm I want to extract this value into vba and split the time and the day as a string.

How to go about this?
phisheep
NeoGAF's Chief Barrister
(10-12-2017, 06:50 AM)
phisheep's Avatar

Originally Posted by Koren

Btw,in Python, it's really easy to develop a generic L-system engine, that makes this kind of procedural generation a breeze, and basically recursionless.

An by using generator functions, you can avoid memory costs.

If someone is interested, I'll post an example...

Ooh, yes please Koren. I've got a fairly intricate thing on the go that could do with something exactly like this.
Koren
Member
(10-12-2017, 08:03 AM)
Koren's Avatar
Will do, just give me a bit of time to get a computer...

Originally Posted by BuddyTheBestPuppy

Hey does anyone here have any experience working with VBA/Excel? I have to automate a lab outage schedule, I have completed the entire program except for one critical component :P

There's are two columns with the date and time format of yyyy-mm-dd h:mm I want to extract this value into vba and split the time and the day as a string.

How to go about this?

IIRC, dates are basically stored as doubles, so you can just read the cell and use format to convert it to a string to you liking...

Like format(date, "YYYY-MM-DD") to get a string with the date only in this format.

I'll check if that doesn't work, that'd from memory.
Pokemaniac
Member
(10-12-2017, 08:10 AM)
Pokemaniac's Avatar

Originally Posted by BuddyTheBestPuppy

Hey does anyone here have any experience working with VBA/Excel? I have to automate a lab outage schedule, I have completed the entire program except for one critical component :P

There's are two columns with the date and time format of yyyy-mm-dd h:mm I want to extract this value into vba and split the time and the day as a string.

How to go about this?


Using VBA for pretty much anything is a mistake. If you must use Visual Basic, you really should at least use the full .NET version to write a standalone program.

VBA will inevitably become a maintainability nightmare if allowed to exist for long enough.
Koren
Member
(10-12-2017, 09:35 AM)
Koren's Avatar

Originally Posted by Pokemaniac

Using VBA for pretty much anything is a mistake. If you must use Visual Basic, you really should at least use the full .NET version to write a standalone program.

VBA will inevitably become a maintainability nightmare if allowed to exist for long enough.

Well, to automatize a spreadsheet, I don't think it's that bad. I used to have very awful experiences (like when each language has his own, incompatible, version of Excel VB), but it's now pretty stable and usable.
Koren
Member
(10-12-2017, 09:39 AM)
Koren's Avatar

Originally Posted by phisheep

Ooh, yes please Koren. I've got a fairly intricate thing on the go that could do with something exactly like this.

So... about Python and L-systems (I hope it's short enough that people don't mind I post the pieces of code)

In case anyone is not familiar with thoses, L-systems are easy way to represent and construct fractals.

I'll take the Koch fractal (the snowflake) as an example...

You begin with a token or a sequence of tokens (e.g. "frrfrrf")

And you apply rules:
"f" is replaced by the sequence"flfrrflf"
"r" is replaced by "r"
"l" is replaced by "l"

Assuming you use a dict, it's easy to store rules:

Code:

Koch_rules = { "f" : "flfrrflf" }
(I won't store rules where the result is the same as the input)

You can write a generator function that take a set of rules and an iterable and behave as an iterable of tokens:

Code:

def Apply(rules, it) :
    for elem in it :
        if elem not in rules :
            yield elem
        else :
            for elem in rules[elem] :
                yield elem
To test:

Code:

"".join( Apply(Koch_rules, "rlrlf") )
will gives you the "rlrlflfrrflf" string

Now, to get a fractal, you have to apply the rules several times. You can use a loop, but it's better to chain iterables, since you won't have to store any string ever, the tokens will be processed automatically. You can do this insanely easily in Python:

Code:

def Fractal(it_rules, x) :
    for rules in it_rules :
        x = Apply(rules, x)
    return x
Functional programming gurus may prefer folding, using reduce from functools module (though not as Pythonic, probably):

Code:

def Fractal(it_rules, x) :
    return reduce(lambda seq, rules : Apply(rules, seq), it_rules, x)

With this function,

Code:

Apply( [Koch_rules]*6, "frrfrrf" )
will gives you the sequence of tokens that produce the 6th order Koch fractal. See that the it_rules are an iterable of rules, so you can easily define different rules for different recursion orders (for example, in plants, use different recursion rules for trunk/branches and leaves). I just applied 6 times the same Koch rules here.


Basically, you can see it as processing streams: a sequence of tokens enter a "box", and a different sequence exit the box. You just chained the boxes, put "frrfrrf" at one side, and get the stream of tokens at the other side. There's basically no cost in memory, because tokens are processed one at a time (each box will accept the next token only when it has finished with producing the resulting tokens of the previous accepted ones).

I find it really nice, and generator functions makes everything a breeze in Python, though it's hardly language-specific.


Then, to get a graphical output, you only need to process the tokens. A simple way in Python to process this kind of actions is to use the turtle module.

In the Koch fractal, "f" means "move forward", "r" means "turn right 60", "l" means "turn left 60".

So I define a set of drawing rules

Code:

Koch_draw = { "f" : (turtle.forward, [5]),
              "r" : (turtle.right, [60]),
              "l" : (turtle.left, [60]) }
And a function to apply them, given a sequence of tokens (Unknown tokens are ignored, but are useful to construct fractals... Also, there's two special tokens, here "a" and "p", that push and pop the position/heading of the turtle on a stack, that's especially useful with plants)

Code:

def Act(actions, it) :
    import turtle
    turtle.reset()
    turtle.speed(0)
    
    stack = []
    for elem in it :
        if elem == "a" : # push
            stack.append( (turtle.position(), turtle.heading()) )
        elif elem == "p" : # pop
            pos, hd = stack.pop()
            turtle.penup()
            turtle.setposition(pos)
            turtle.setheading(hd)
            turtle.pendown()
        elif elem in actions :
            f, vargs = actions[elem]
            f(*vargs)
Now, just use

Code:

Act(Koch_draw, Fractal( [Koch_rules]*4, "frrfrrf" ))
and you'll have a nice Koch fractal.


Some other examples:

A tree (I'll let you adapt it to have different sizes/color for lines):

Code:

Tree_rules = { "g" : "gf",
               "x" : "gfaaxupdrxupdlx" }
Tree_draw = { "f" : (turtle.forward, [5]),
              "r" : (turtle.right, [35]),
              "l" : (turtle.left, [35]) }

Act(Tree_draw, Fractal( [Tree_rules]*6, "x" ))
Harter-Heighway dragon:

Code:

Dragon_rules = { "x" : "xlyf",
                 "y" : "fxry" }
Dragon_draw = { "f" : (turtle.forward, [5]),
                "r" : (turtle.right, [90]),
                "l" : (turtle.left, [90]) }

Act(Dragon_draw, Fractal( [Dragon_rules]*10, "fx" ))
Gosper curve:

Code:

Gosper_rules = { "x" : "xlyfllyfrfxrrfxfxryfl",
                 "y" : "rfxlyfyfllyflfxrrfxry" }
Gosper_draw = { "f" : (turtle.forward, [5]),
                "r" : (turtle.right, [60]),
                "l" : (turtle.left, [60]) }
Act(Gosper_draw, Fractal( [Gosper_rules]*6, "xf" ))
Sierpinski curve:

Code:

Sierp_rules = { "x" : "yfrxfry",
                 "y" : "xflyflx" }
Sierp_draw = { "f" : (turtle.forward, [5]),
                "r" : (turtle.right, [60]),
                "l" : (turtle.left, [60]) }
Act(Sierp_draw, Fractal( [Sierp_rules]*6, "xf" ))
You'll find hundreds of rulesets on the Internet, and it's easy to design your owns (though the most interesting ones are not that easy to create)

Hope it'll help. Happy coding ;)
Last edited by Koren; 10-12-2017 at 09:53 AM.
phisheep
NeoGAF's Chief Barrister
(10-12-2017, 11:20 AM)
phisheep's Avatar

Originally Posted by Koren

So... about Python and L-systems (I hope it's short enough that people don't mind I post the pieces of code)

...

Hope it'll help. Happy coding ;)

It certainly does Koren. That will significantly demystify the monstrosity that I have been working on. Thank you.
Pokemaniac
Member
(10-12-2017, 06:52 PM)
Pokemaniac's Avatar

Originally Posted by Koren

Well, to automatize a spreadsheet, I don't think it's that bad. I used to have very awful experiences (like when each language has his own, incompatible, version of Excel VB), but it's now pretty stable and usable.

Well, it's not as bad as using VBA in Access, I guess (side note, if you are even considering using VBA in Access you are using the wrong tool for the job). It is not without risk though.

Generally speaking, though, using Microsoft Office macros in place of actual software tends to be an indicator of more general issues. Especially if it's happening in, for example a business. Even if it's not bad by itself, it's something to be wary of when it comes up.
Koren
Member
(10-12-2017, 07:21 PM)
Koren's Avatar
They're designed to improve functionality of a spreadsheet... It's quite good at this, and while using spreadsheets from untrustable sources is dangerous, I don't see the issue of creating you own.

If you use Excel because you think it's a replacement for an IDE to developp applications, you're doing it wrong, indeed.
cpp_is_king
(10-12-2017, 07:39 PM)
cpp_is_king's Avatar

Originally Posted by BuddyTheBestPuppy

Hey does anyone here have any experience working with VBA/Excel? I have to automate a lab outage schedule, I have completed the entire program except for one critical component :P

There's are two columns with the date and time format of yyyy-mm-dd h:mm I want to extract this value into vba and split the time and the day as a string.

How to go about this?

Check out the Excel Help Thread http://www.neogaf.com/forum/showthread.php?t=1420804
Pokemaniac
Member
(10-12-2017, 09:16 PM)
Pokemaniac's Avatar

Originally Posted by Koren

They're designed to improve functionality of a spreadsheet... It's quite good at this, and while using spreadsheets from untrustable sources is dangerous, I don't see the issue of creating you own.

If you use Excel because you think it's a replacement for an IDE to developp applications, you're doing it wrong, indeed.

The problem is that a lot of people actually do the bolded (more often with Access than Excel, but it still happens sometimes with Excel).

I once had a summer job at a small business where they had developed an internal suite of "apps" that were just Access files on a shared drive. General impressions I've seen online suggest that this is not an isolated occurrence.
esmith08734
Member
(10-12-2017, 11:49 PM)
esmith08734's Avatar
To the people in here who mentioned to me to look into Kotlin, thank you. This language is something else.
JesseZao
Member
(10-13-2017, 12:56 AM)
JesseZao's Avatar
Anybody been messing around with clojure.spec?

I've been wanting to start working on a functional language side project and it seems awesome.
BuddyTheBestPuppy
Junior Member
(10-13-2017, 01:04 AM)

Originally Posted by cpp_is_king

Check out the Excel Help Thread http://www.neogaf.com/forum/showthread.php?t=1420804

Thanks I fixed the issue this morning.

I just declared string variables, and used the DateValue and TimeValue to get the values from the columns. Worked like a charm.
Antagon
Member
(10-13-2017, 09:19 AM)
Antagon's Avatar

Originally Posted by JesseZao

Anybody been messing around with clojure.spec?

I've been wanting to start working on a functional language side project and it seems awesome.

Not personally, but I'm starting a new job next month where they use clojure for some plugins for Atlassian tools. Heard some pretty positive stuff from a guy on that project. Seems like as good a place to start as any. Not sure about the .spec part though.

A downside of using a functional language in the VM is that using a lot of immutable objects puts quite a bit of strain on the GC, but that's not something you'd have to worry about when doing a hobby project.
Last edited by Antagon; 10-13-2017 at 09:23 AM.
JesseZao
Member
(10-13-2017, 02:38 PM)
JesseZao's Avatar

Originally Posted by Antagon

A downside of using a functional language in the VM is that using a lot of immutable objects puts quite a bit of strain on the GC, but that's not something you'd have to worry about when doing a hobby project.

Clojure has persistent immutable data structures so it's better than pure immutable objects for that concern.
Ryujin
Member
(10-13-2017, 10:12 PM)
Ryujin's Avatar
Not a question really but I'm learning C in college at the moment and I find myself really enjoying it.

Learning about pointers, memory addresses, how arrays work, stacks, queues, execution stack etc...

I just find it really fun, no idea why. I guess I feel like I'm getting a better grounding in understanding the fundamentals of computer science/programming.

I mean I'm a complete novice at C so I don't consider myself skilled or anything like that but I guess I really like understanding what is going on one step closer to the machine code so to speak.

I was always afraid of C/C++ because I heard horror stories about the difficulty of understanding pointers and memory management in general. To be honest it seems reasonably straight forward to me, at least for the basics of Pointers etc..

I have the Deitel & Deitel book on C which I find really good, although I've only really skimmed a few chapters so far.

I guess I'm just surprised that I enjoy C so much. :)
dabig2
Member
(10-14-2017, 07:04 PM)
dabig2's Avatar

Originally Posted by Ryujin

Not a question really but I'm learning C in college at the moment and I find myself really enjoying it.

Learning about pointers, memory addresses, how arrays work, stacks, queues, execution stack etc...

I just find it really fun, no idea why. I guess I feel like I'm getting a better grounding in understanding the fundamentals of computer science/programming.

I mean I'm a complete novice at C so I don't consider myself skilled or anything like that but I guess I really like understanding what is going on one step closer to the machine code so to speak.

I was always afraid of C/C++ because I heard horror stories about the difficulty of understanding pointers and memory management in general. To be honest it seems reasonably straight forward to me, at least for the basics of Pointers etc..

I have the Deitel & Deitel book on C which I find really good, although I've only really skimmed a few chapters so far.

I guess I'm just surprised that I enjoy C so much. :)

Yeah, I loved learning C myself. At the University of Illinois in freshman year when I went a billion years ago, my first programming class actually had us start learning assembly code (specifically LC-3) . Then in the latter half of the course after that foundation we moved onto C. I thought it was great, because it really makes you appreciate what's going on under the hood a lot more than if you were to start out with Python, Java, VB, etc.

I think a large reason why things like pointers and memory management are such an obstacle to new people learning C is because classes aren't taking the time to really delve into the hardware and explain things like registers, memory addresses, frame pointers, stack pointers, etc.

All that said, I haven't touched a C program since college :D But I still appreciate the knowledge.
Koren
Member
(10-14-2017, 07:24 PM)
Koren's Avatar
Hell, I feels stupid tonight...

For a LOT of time, I've written

Code:

def foo(args) :
   ...

foo = np.vectorize(foo)
And I haven't thought a single time to write instead

Code:

@np.vectorize
def foo(args) :
   ...
I fully know how decorators work, I use them a lot, and it took me years to think that vectorize can be used as a decorator. It's so stupidly obvious that it bothers me a lot.

It's only because I'm trying to think of a way I'll be able to explain vectorize to people that may want to use Python to draw data (such as 3D surfaces, implicit plots...) but do not have time/interest to fully learn the language.

Granted, there's plently of issues with using np.vectorize as a decorator, but in a lot of simple cases, it may be an easier solution...

Originally Posted by dabig2

think a large reason why things like pointers and memory management are such an obstacle to new people learning C is because classes aren't taking the time to really delve into the hardware and explain things like registers, memory addresses, frame pointers, stack pointers, etc.

I don't think you need stack pointers (and even less frame pointers) but I have trouble to understand difficulties people have with pointers (to me, the most difficult thing with C is the typing of functions, when you want to pass a function as parameter of another ^_^) but I agree, it's most probably a lack of basic explanation on how a computer memory work.

And while learning how a computer works may not be a necessity for beginners (you may begin with C, but you may as well begin with Python), I believe you need to learn about memory management and the way CPU work soon or late.

Somehow, I'd say the main difference between C and C++ is that C++ coders don't always know what's under the hood. Try to explain the need of copy constructor or move constructor to someone that only used C++ as a high level language (which is fine, but if you try to be efficient, well...)
cpp_is_king
(10-15-2017, 02:34 AM)
cpp_is_king's Avatar
The talk finally got uploaded to CppCon youtube.

https://www.youtube.com/watch?v=QTLn3goa3A8

Hard to really do it justice, I think even a YouTube video doesn't do it justice, but most people who were there agreed this was probably the best talk of the conference, and perhaps of all CppCon talks ever.
esmith08734
Member
(10-15-2017, 04:43 PM)
esmith08734's Avatar
The fact that this code in Java

Code:

public class Student {
private final String name;

public Student(final String name) {
 this.name = name;
is the same as

Code:

class Student(val name: String)
in Kotlin is amazing.
Somnid
Member
(10-15-2017, 07:20 PM)
Somnid's Avatar

Originally Posted by esmith08734

The fact that this code in Java

Code:

public class Student {
private final String name;

public Student(final String name) {
 this.name = name;
is the same as

Code:

class Student(val name: String)
in Kotlin is amazing.

I don't really care for this type of declaration in typescript because you need to look at the constructor to see what properties an object has and for data objects those can be large.

How does this work with dynamic dispatch?
Kansoku
(10-15-2017, 08:13 PM)
Kansoku's Avatar

Originally Posted by Somnid

I don't really care for this type of declaration in typescript because you need to look at the constructor to see what properties an object has and for data objects those can be large.

How does this work with dynamic dispatch?

That's just the primary constructor. You have a bunch of options in Kotlin with regards to properties and constructors:

Normal class declaration with properties:

Code:

class Clazz {
    val a: Int = ...
    var b: String = ...
}
You then can define a primary constructor:

Code:

class Clazz (a: Int, b: String) {
   val a = a
   var b = b
   val c = b.toUpperCase()
}
But there's also a syntactic sugar for properties that you don't modify on construction:

Code:

class Clazz (val a: Int, var b: String){
   val c = b.toUpperCase()
}
If you need to do some other work aside from just assignment you put it in a init block:

Code:

class Clazz (val a: Int, var b: String){
   val c = b.toUpperCase()
   var d: String
   init {
      d = generateString(a)
   }
}
You can have multiple constructors:

Code:

class Clazz (val a: Int, var b: String){
   val c = b.toUpperCase()
   var d: String
   constructor (e: Int) {
      a = e
      d = generateString(a)
      ...
   }
}
But generally it's better to use default parameters on the primary for overloading:

Code:

class Clazz (val a: Int = 0, var b: String = "Hello World"){
   val c = b.toUpperCase()
}
There's also a bunch of other stuff like lazy init or delagating initiation. You can see more at:
https://kotlinlang.org/docs/reference/classes.html
https://kotlinlang.org/docs/reference/properties.html
Last edited by Kansoku; 10-15-2017 at 08:18 PM.
Antagon
Member
(Yesterday, 08:32 AM)
Antagon's Avatar

Originally Posted by esmith08734

The fact that this code in Java

Code:

public class Student {
private final String name;

public Student(final String name) {
 this.name = name;
is the same as

Code:

class Student(val name: String)
in Kotlin is amazing.

There's definitely a lot of cool things about Kotlin. I also like that almost everything is an expression.

My main problem with Kotlin as someone who has worked a lot on Java software is that while it offers full interoperability, the Java ecosystem often abuses some of the weak points in the language.

For example, not only can everything in Java be null, a lot of libraries even expect an empty constructor and then use reflection to set all the properties in the class (I'm looking at you, JPA). This means you have to use hacks in Kotlin to use this effectively. There's a compiler extension that helps with this (it generates an empty constructor for classes with specific annotations that can only be accessed using reflection), but it just doesn't feel all that great.
unknownstranger
Member
(Today, 12:35 AM)
unknownstranger's Avatar
I have a dumb question. How do I set up ranges in C++? I know I use [] but not much else.

Thread Tools