Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 702 703 [704] 705 706 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 890115 times)

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #10545 on: April 21, 2017, 04:53:41 am »

I'd argue that even if it's not necessary, reading a page or two of online documentation with a search bar is much easier than hunting through a potentially massive source to find the information you need.

Agreed, which is what I was trying to convey with the documentation need not be extensive. Things like brief return descriptions and functionality descriptions are increasingly useful as file size increases.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10546 on: April 21, 2017, 10:14:55 am »

But good code is self-documenting! :P

But seriously, if your code is straightforward, well set-out, and commented on occasion, docs don't have to be extensive.
I don't disagree with you, but there does need to be documentation, for certain.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10547 on: April 21, 2017, 12:44:26 pm »

I don't think anyone here is arguing against documentation of code :P

Half of you are saying code should make sense and be legible in-line, that you should be able to understand, at least in part, what it does in-context. I would agree.

The other half are asking for out-of-code documentation that includes function definitions, possible function overloading, input and output, along with any possible quirks that may arise on edge cases. I would also agree.

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #10548 on: April 21, 2017, 01:01:07 pm »

I'm saying both! If your function does very crazy things, it should be documented in-depth, but otherwise an "@Override @param [foo] [bar] @return [jam]" will do.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10549 on: April 21, 2017, 04:27:06 pm »

To touch on the question of whether you need to know C or C++ to be a real programmer, the answer is no.  Adding another anecdote to the pile, I've been a web developer for 8 years and have only had to use C++ twice in that time period.  Once was to write a helper program for a web proxy, because our PHP version was too slow.  The other time was to debug and fix a buffer overflow error in some program we had to use for something else.

All of the rest of the coding has been in PHP or JavaScript.  You can accomplish amazing things with those languages alone.

Oh, that's except for the Roku app I just had to write, which was written in BrightScript.  I can't imagine many languages are worse than BrightScript.  It has goto statements at the next level, where you can't call functions in other modules and instead have to write to fields, which are observed.  Writing to a field can trigger an arbitrary number of observing functions in an arbitrary number of other modules.  Debugging that is loads of fun.

Supposedly they added function calls between modules in a recent firmware version, but I couldn't get it to work following their examples, so I guess the Roku I had doesn't support it.

And speaking of BrightScript and documentation... this is a language that it took me 10 minutes to figure out how to do a for loop, because of how confusing and poor its documentation is.  I never did learn if there was a continue statement for the language, but I don't think there is.
Logged
Through pain, I find wisdom.

prefuzek

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10550 on: April 21, 2017, 08:36:23 pm »

I'll be starting work as a co-op student pretty soon, and I'd like to quickly learn some Java before I start (I'll be mostly working with Selenium WebDriver if that makes a difference). Most of my coding experience is in functional programming, but I've done a little C as well. Are there any particularly good resources out there for learning Java/OOP?
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10551 on: April 22, 2017, 01:32:16 am »

I've kind of wondered what the best approach to learning OOP is, I've read some suggestions that learning about code "design patterns" is a good way to get into the right frame of mind for understanding OOP issues. Another way to think about it that can help you avoid dumb newbie problems is if you understand relational databases. Design your OO system as if it really was going to be implemented as a set of database tables and you can avoid doing a number of idiotic design decisions. e.g. some of the traditional "learning examples" kind of suck. e.g. one of the canonical examples is this:

Code: [Select]
- make a "person" type, with the right data and functions (name, age, address fields etc).

- "student" derives from "person", they gain extra fields such as "major", and "course_start_date"

- "teacher" also derives from "person", they gain extra fields such as "lesson_taught" and "salary"

Sounds great, as long as things stay simple. But what happens in this database (and it is in fact a hardcoded database) when a teacher asks to enrol in a class taught by a different teacher? Or if a student can also tutor other students, thus earns a salary? A teacher is the teacher type, they cannot be a subclass of student and vice versa. In fact, this is the exact same problem you get when dealing with relational databases and the solution is the same. You can understand that classes are conceptually similar to database tables and objects are the rows of the table.

And the solution to the above problem is exactly the same as you do in a database. In a database, you'd make an "enrolments" table, linking the person table to the classes table, and another "teacher_assignment" table, also linking the person table to the classes table, whereas in OOP, you'd make an "enrolments" object, and each enrolment object references one person object and one class object, and you'd make a "teaching_assignment" object that links a person to a class, as the teacher. And this way you didn't need to split your "table" of people into separate tables for teachers and students in the first place. ... so a lot of the common sense from database design can in fact help you do better OOP.

So avoid inheritance-based splits whenever possible. Splitting on derived types is effectively like if you had a "widgets" table in your database, then you had different colored widgets so you made separate tables for every color, the "blue widgets" database table, the "red widgets" database table, and so on. You would'nt do that in a database, you'd have a field for color, maybe referencing a "colors" table. And in OOP, you can do that too, you can make "color" objects, and every widget object gets a reference to one color object. Whenever possible, don't use inheritance to define subtypes, create property objects and put them inside the generic object.
« Last Edit: April 22, 2017, 01:46:20 am by Reelya »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #10552 on: April 22, 2017, 02:32:10 am »

the more i actually use OO pattersn the more i realize that the typical teaching examples are really terrible....

I'm a fan of composition/components.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

breadman

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10553 on: April 24, 2017, 04:01:38 pm »

I can't imagine many languages are worse than BrightScript.  It has goto statements at the next level, where you can't call functions in other modules and instead have to write to fields, which are observed.  Writing to a field can trigger an arbitrary number of observing functions in an arbitrary number of other modules.  Debugging that is loads of fun.
I'm reminded of Intercal's COME FROM instruction.   ;)  Then again, I've tried out a few esoteric languages, many of which are designed to be terrible in some form or another.  That doesn't excuse terrible languages in production, though.

Nevertheless, I've worked with a couple of signal-based systems like that.  Just within the last week, I ran into an obscure test case failure where a function was getting called too early, due to a signal watching the creation of a nearly unrelated component.  Nasty stuff.

I've kind of wondered what the best approach to learning OOP is, I've read some suggestions that learning about code "design patterns" is a good way to get into the right frame of mind for understanding OOP issues. Another way to think about it that can help you avoid dumb newbie problems is if you understand relational databases. Design your OO system as if it really was going to be implemented as a set of database tables and you can avoid doing a number of idiotic design decisions.
Many of my recent projects have actually been designed with databases underlying the main objects, and yes, it's a convenient way to think about the system.

I've also encountered the idea of semantic compression as a programming methodology; the example presented there includes a case of OOP arising naturally out of the state shared by a set of functions.  Meanwhile, I'll frequently refactor a function into a class when I find myself needing interesting variations, or when it becomes convenient to pull parts of it into their own functions that need some of its state.
Logged
Quote from: Kevin Wayne, in r.g.r.n
Is a "diety" the being pictured by one of those extremely skinny aboriginal statues?

WealthyRadish

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10554 on: May 04, 2017, 06:33:12 pm »

I'm going to try to learn Java with no prior experience with it over about two weeks to try a challenge exam for an introductory course in Java (equivalent of CS I in the program when I've taken CS I-II and some other courses in C++ at another school).

Is there anything in broad strokes I should look out for when learning Java from C++, or particularly good reference materials?
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10555 on: May 04, 2017, 09:24:43 pm »

As someone who mostly avoided learning Java, and so has an interpretation which is highly specious at best, it's very similar to heavily object oriented programming in C++ aside from garbage collection. As is the case with C#, depending on what you are using it for, garbage collection will either be a super-easy-it-just-works thing for you (smaller projects) or it will be what you spend half your time learning quirks about in order to tip-toe around it, hoping the big bad garbage collector doesn't wake up and cause a several hundred ms hang (large game projects, software parsing lots of data). So probably read up on that and how it differs from C++'s mix of RAII and explicit allocation/frees.
Logged

Strife26

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10556 on: May 04, 2017, 09:51:01 pm »

Anyone know of a good matlab tutorial? This class is very big on the "fuck learning the language in class, figure it out on the homework on your own time" philosophy.
Logged
Even the avatars expire eventually.

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10557 on: May 10, 2017, 08:56:10 am »

After a great ordeal of wrestling with frameworks, IDEs and installers for, like, two days, I've finally made a thing.

Spoiler: Much cutting edge, wow (click to show/hide)

Now what is the thing, you might ask? Why, it's the most unlikely communication tool ever to be used. Not only is it CLI only and likely to break if you look at it funny, it also currently sends the message contents in the clear and almost certainly stores it permanently on the blockchain for everyone to see (HELLO NSA!)

All for the sake of learning how Solidity smart contracts on Ethereum blockchains work outside of Remix. This tech is so cutting edge even the documentation can cut you.

Also seemingly biased against Windows if the installation instructions are anything to go by.  :-\

Seriously, I think I've left a dent on the desk from repeatedly smashing my head against it after:
  • JavaScript framework console being so godawful when past commands can be backspaced away and keyboard input being seemingly insert-only
  • JavaScript framework hell
  • JavaScript callback hell
  • JavaScript hell in general
  • Package installers failing due to seemingly random errors (and obviously barely anyone else having encountered them)
  • Downloading gigabytes of software just to get the test server software working including Visual Studio Community and Windows 8.1 SDK
  • Downloading Visual C++ compiler for a Python package
  • Having to manually edit the Python source code for a Solidity compiler wrapper package just to be able to programmatically compile Solidity contracts
  • Still not being able to compile Solidity source code snippets from within Python code
  • Python Ethereum framework documentation being so awful and outdated that even for the most simplest smart contract interactions, you'll have more success getting your code to work by using trial and error and source code inspection

Pls. Send halp.

Ceterum, censeo JavaScriptum esse delendum.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

DeKaFu

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10558 on: May 14, 2017, 09:42:00 am »

This is the programming help thread, right? I think I need help. :P

I'm fairly new to programming and very new (under a week) to object-oriented languages and C++, but I'm trying to use it to make a program I've been planning out for a long time.

I've got a specific problem I'm trying to solve and it's busting my brain a bit.

I have a class that contains a rather large private struct (large in terms of # of members). At runtime, you can generate an unlimited number of instances of that class which are all stuck in a vector.

The question: Is it possible for one instance of that class to access the contents of the struct of other specific instances of the same class, without exposing anything outside the class? If so, what does that look like in terms of code?

I think it's probably something to do with pointers but... :P

(I essentially want to be able to initialize a new instance's struct using a function that examines the struct-contents of two other existing instances and comes up with something based on that.)
Logged

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10559 on: May 14, 2017, 11:37:42 am »

Sounds similar to a copy-constructor.

Code: (C++ code) [Select]
class Foo {

struct large_struct;

Foo() { /* Regular constructor stuff */ }
Foo(Foo & instance) { /* (Deep?) Copy over data from instance.large_struct */ }
Foo(Foo & foo_instance, Foo & bar_instance) { /* (Deep?) Copy over data from foo_instance.large_struct and bar_instance.large_struct */ }
}
« Last Edit: May 14, 2017, 11:40:48 am by da_nang »
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.
Pages: 1 ... 702 703 [704] 705 706 ... 796