• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Javascript can be a rough transition especially if you come from traditional languages like Java or C++ as you'll have to throw out some of what you had previously thought was best practice and use some different patterns. Though I imagine it'll grow on you over time, certainly I felt the same way when I started but I really like it now.

What don't you like about JS? I wouldn't count on it going away anytime soon. It's only getting more popular.

The language is just full of pitfalls.
Warning big rant incoming:

Arrays can be used as Lists, as well as Associative Arrays, but what actually happens when you call:
Code:
 var arr = [];
arr["key"] = value;
Is that arr is now actually of type object.
So it's the same as
Code:
arr.key = value;

This causes problems when sorting arrays.

Code:
[1,3,20,10].sort();  // returns [1, 10, 20, 3]


The generally scope is a mess.
There are virtually zero name spaces and I've seen at least 3 different ugly work around hacks to simulate the feature (such as wrapping everything in a huge anonymous function for the closure).

You can declare global variables inside a function or something similar if you forget the "var" keyword.
You can declare Instance and class members of a "class" just about anywhere in your code and the "this" reference is utterly confusing as to what it actually points to.

For private instance variables and inheritance, you have to jump through huge hoops to actually get what you want. There is no standardized way to do such a simple thing.
Without interfaces, the only way to know what methods you can call from other classes is to use external documentation, or to actually look at the src code.

I've worked in other dynamically typed languages like Python and even they have interfaces with which you can easily work.

In JavaScript there is no such thing as constants or readonly values, again you have to jump through a lot of hoops and hacks to get this to work.

If you've worked with Regular expressions in js you probably know how ugly the code can get by using them.

Other pitfalls I've written down:
Code:
typeof foo === "object" //returns true if foo is null
typeof NaN === "number" //returns true
NaN === NaN //returns false

 return
  {
      bar: "hello"
  };
//this actually returns "undefined" because in JS, Semicolons are optional, yay!

var a = b = 3;
//this creates var a like you would expect, but also creates the global variable b


I've written these things down, so they never happen to me again, but it's just awful that these things CAN happen.
And I haven't even really gotten started yet about Dynamic vs Static Typing.
 

Snow

Member
True story: the application I currently work on had a ~3000 line method when I first joined several years ago, and several others with well over 1000 lines. I won't tell you whether or not a method that had a 1500+ line loop body still exists. I won't tell you that.

It does.



Forget that. Maintenance on long methods is a nightmare. Break those things apart and name the smaller functions well. You shouldn't need to "remember" it all. The methods should be small and the names should tell you most everything you need to know.

The problem with the application I support is 98% due to its horrid design and 2% due to the natural complexity of the business. And despite working on the application for years, much of the original problems remain (case in point, the 1500+ line loop) because new functionality seems to always get prioritized above dealing with the technical debt of bad, hard to read, harder to maintain code.
I think Jon's thinking matches up with that of Carmack, as expressed in this email. Hosted on Jon's site, not entirely coincidentally.

You have to remember that both of them operate in a fairly specialized environment, where e.g. overhead of function calls can actually matter (and the compiler's inliner doesn't always catch everything) and where a fairly big chunk of the code's main loop needs to be held in the programmer's head to properly reason about performance and correctness. I've done the thing Carmack describes where you're tracing the operations in the main loop and it does get frustrating and hard to follow if the call graph is super deep.

Now, for a lot of programs doing the 'trace out the whole call graph of the main loop' thing in a debugger is nonsense, but for core engine development where you have high performance code with soft real-time requirements, you really do need to reason about the code at times in that way. And so the argument is you might as well have the code reflect that and make it easy to do that. Or that's what I get out of that mail at least.
 

Calvero

Banned
Hey guys
Some advice needed!
What is a good language to learn and through which free services (besides CodeAcademy)? I had been learning Python around this time, last year, but I've forgotten most of it.
Where should I start?
 

Snow

Member
Hey guys
Some advice needed!
What is a good language to learn and through which free services (besides CodeAcademy)? I had been learning Python around this time, last year, but I've forgotten most of it.
Where should I start?
I was going to say Python, using Learn Python the Hard Way or Codecademy. I think in general languages used in web stacks (e.g. Python, Ruby, Javascript) are fairly easy to pick up and have decent free tutorials. Is there a specific thing you want to do? I think it's important to have some fun, easy project that motivate you to learn the language beyond the tutorial. That's where things will really stick.
 

Calvero

Banned
I was going to say Python, using Learn Python the Hard Way or Codecademy. I think in general languages used in web stacks (e.g. Python, Ruby, Javascript) are fairly easy to pick up and have decent free tutorials. Is there a specific thing you want to do? I think it's important to have some fun, easy project that motivate you to learn the language beyond the tutorial. That's where things will really stick.

Thanks for the reply.
There isn't anything in particular that I want to do and to be quite honest I don't really know the full extent of what you can do with a skill like programming. That's a big reason of why I want to learn! I wanna dabble in it and see what's possible! What are simple projects to take on early, so I can apply what I learn?
 

Snow

Member
Thanks for the reply.
There isn't anything in particular that I want to do and to be quite honest I don't really know the full extent of what you can do with a skill like programming. That's a big reason of why I want to learn! I wanna dabble in it and see what's possible! What are simple projects to take on early, so I can apply what I learn?
I guess I could give two suggestions. One is to try to dabble around with web application development. If you're already familiar with things like HTML and CSS this may be a good path. If you have the hang of Python moving on to Django to try and build your own twitter clone, todo app or whatever might be fun. Django has a really nice official tutorial, though I've heard good things about the Django Girls tutorial as a more gentle introduction.

On the other hand, we're on a videogame forum here, so I'm guessing games may hold some interest to you. It might be fun to try and build some simple games, using e.g. Pygame. This book might be worth a look, though it may be a bit child oriented.
 

Aureon

Please do not let me serve on a jury. I am actually a crazy person.
I think I actually saw the stream where he explained it. IIRC he said that, for methods in which you don't expect any part of it to be reused, it doesn't make sense to split long methods into subprocedures because it just adds more things to remember.

I guess it's good enough if you expect nobody to ever read your code.

If you're going to have to write...
// This code does X
And you have to, if you have 50-line methods... just right click and tell your goddamn IDE to extract method.
 
The language is just full of pitfalls.
Warning big rant incoming:

**words**


This post read like a blast from the past: most of the points that are not outdated as hell are mostly just "I don't like a thing".

Like the points about scoping: You can always scope everything global if you want to, but someone who is at least somewhat familiar with JavaScript scoping will never ever do that. Just because you can doesn't mean that you must or have to. All the modern module patters are built around the idea, there are high-quality code quality tools that makes screwing up near impossible and things such as ES6 introducing the let-keyword that restricts the variable to block scope no matter what.

In modern JavaScript there are consts and read only values and the "hoops" you have to jump through are minimal at best.

You mention that there is no namespacing and the hacks are "ugly" when in reality everything can be namespaced.

I agree that "this"-reference can be confusing for a beginner, but it really isn't that hard to wrap your head around as soon as you understand the "everything is an object"-concept. That said, ES6 adds arrows share the same lexical this as it's surrounding code (similar to Java, C#...).

There's tons of ways to create classical inheritance and they are all pretty much standard, if not standardized. It's up to you to select the one that fits your coding style.

I don't know whats up with the regular expressions complaint, RegExp gets ugly in all of the languages.

And so on and so on.
 

Makai

Member
The core of Blow's argument is that programmers waste too much time on optimizing for execution time or memory when they should be optimizing for implementation time.
 

Aureon

Please do not let me serve on a jury. I am actually a crazy person.
The core of Blow's argument is that programmers waste too much time on optimizing for execution time or memory when they should be optimizing for implementation time.

That's kind of true, but smaller methods certainly aren't a ram\cpu optimization.
Programmers, if their code will be read by others, should always optimize for readability.
 

Makai

Member
That's kind of true, but smaller methods certainly aren't a ram\cpu optimization.
Programmers, if their code will be read by others, should always optimize for readability.
His talk is also within the confines of indie game development, so readability by others is not as important as in enterprise.
 

JeTmAn81

Member
This post read like a blast from the past: most of the points that are not outdated as hell are mostly just "I don't like a thing".

Like the points about scoping: You can always scope everything global if you want to, but someone who is at least somewhat familiar with JavaScript scoping will never ever do that. Just because you can doesn't mean that you must or have to. All the modern module patters are built around the idea, there are high-quality code quality tools that makes screwing up near impossible and things such as ES6 introducing the let-keyword that restricts the variable to block scope no matter what.

In modern JavaScript there are consts and read only values and the "hoops" you have to jump through are minimal at best.

You mention that there is no namespacing and the hacks are "ugly" when in reality everything can be namespaced.

I agree that "this"-reference can be confusing for a beginner, but it really isn't that hard to wrap your head around as soon as you understand the "everything is an object"-concept. That said, ES6 adds arrows share the same lexical this as it's surrounding code (similar to Java, C#...).

There's tons of ways to create classical inheritance and they are all pretty much standard, if not standardized. It's up to you to select the one that fits your coding style.

I don't know whats up with the regular expressions complaint, RegExp gets ugly in all of the languages.

And so on and so on.

Some of his complaints seem legit, some just seem like he's not used to the language and how it works. Just because it's not the same as other languages doesn't mean it's bad.

Anyway, if you're developing large applications in Javascript you ought to take advantage of the tools that are available. For instance, Babel lets you use modern JS features such as classes and modules before they're widely supported by all browsers:

https://babeljs.io/

There's also stuff like TypeScript which lets you use strong typing:

In addition, there are linters you can use which automatically check your code for problems:

http://eslint.org

There are a bunch of things which can make JS development more palatable to people who are used to a different style of coding.
 

Somnid

Member
The language is just full of pitfalls.
Warning big rant incoming:

Arrays can be used as Lists, as well as Associative Arrays, but what actually happens when you call:
Code:
 var arr = [];
arr["key"] = value;
Is that arr is now actually of type object.
So it's the same as
Code:
arr.key = value;

This causes problems when sorting arrays.

Code:
[1,3,20,10].sort();  // returns [1, 10, 20, 3]


The generally scope is a mess.
There are virtually zero name spaces and I've seen at least 3 different ugly work around hacks to simulate the feature (such as wrapping everything in a huge anonymous function for the closure).

You can declare global variables inside a function or something similar if you forget the "var" keyword.
You can declare Instance and class members of a "class" just about anywhere in your code and the "this" reference is utterly confusing as to what it actually points to.

For private instance variables and inheritance, you have to jump through huge hoops to actually get what you want. There is no standardized way to do such a simple thing.
Without interfaces, the only way to know what methods you can call from other classes is to use external documentation, or to actually look at the src code.

I've worked in other dynamically typed languages like Python and even they have interfaces with which you can easily work.

In JavaScript there is no such thing as constants or readonly values, again you have to jump through a lot of hoops and hacks to get this to work.

If you've worked with Regular expressions in js you probably know how ugly the code can get by using them.

Other pitfalls I've written down:
Code:
typeof foo === "object" //returns true if foo is null
typeof NaN === "number" //returns true
NaN === NaN //returns false

 return
  {
      bar: "hello"
  };
//this actually returns "undefined" because in JS, Semicolons are optional, yay!

var a = b = 3;
//this creates var a like you would expect, but also creates the global variable b


I've written these things down, so they never happen to me again, but it's just awful that these things CAN happen.
And I haven't even really gotten started yet about Dynamic vs Static Typing.

So if you can't for some reason stop yourself from doing these things, don't use a linter, and you don't have an IDE that points them out to you, then try adding "use strict"; to the top of you file. I actually prevents many of those mistakes.

Constants exist in ECMAscript2015, you can also use getters to create them, or do it by name convention.

In other languages it's super common to create huge amounts of boiler plate for interfaces and classes, in js we don't do that. This does shift some of the responsibility to the consumer but also the emphasis is less on objects, it's on functions. Rather than finagle your data into my global interface you typically pass simple values or object key value hashes into my public functions. There's also more emphasis on convention over configuration, so naming can be more important to call out what's expected. Due to this, it actually won't come up as often as you think. Js devs are happy to sacrifice some of this because it's a huge savings in boilerplate especially in mapping.

Like I said, it will take a little bit to unlearn some of the things you know and really use JS to full effect.
 

Calvero

Banned
I guess I could give two suggestions. One is to try to dabble around with web application development. If you're already familiar with things like HTML and CSS this may be a good path. If you have the hang of Python moving on to Django to try and build your own twitter clone, todo app or whatever might be fun. Django has a really nice official tutorial, though I've heard good things about the Django Girls tutorial as a more gentle introduction.

On the other hand, we're on a videogame forum here, so I'm guessing games may hold some interest to you. It might be fun to try and build some simple games, using e.g. Pygame. This book might be worth a look, though it may be a bit child oriented.

Thank you very much!
 

SOLDIER

Member
I'm currently attending a Python class that hands out assignments that must work on Python 3. As someone who is entirely new to Python and programming in general, this has caused a few hurdles with me in trying to look up the correct format for certain assignments in Google; often I'll find something that works on Python 2 but not 3. More often than not I get hit with an error message without figuring out what to do.

My current assignment requires the following:

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program:

calcAverage: This function should accept five test scores as arguments and return the average of the scores.

determineGrade: This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale:

90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

I found a previous thread here where someone was asking for help with this very assignment. I tried taking the sample code listed there, which is as follows:

import bisect

def main():
num_tests = 5
total = 0.0
for i in range(num_tests):
total += determine_grade()
print ("The average score is "), total / num_tests

def determine_grade():
score = input ("Enter your test score: ")
print ["F", "D", "C", "B", "A"][bisect.bisect_right([60, 70, 80, 90], score)]
return score

main()


As it stands, I get the following message trying to run the code:

Traceback (most recent call last):
File "C:/Users/Jorge/Documents/School/Intro to Programming Logic/Python Files/Assignment 5 Test.py", line 15, in <module>
main()
File "C:/Users/Jorge/Documents/School/Intro to Programming Logic/Python Files/Assignment 5 Test.py", line 7, in main
total += determine_grade()
File "C:/Users/Jorge/Documents/School/Intro to Programming Logic/Python Files/Assignment 5 Test.py", line 12, in determine_grade
print ["F", "D", "C", "B", "A"][bisect.bisect_right([60, 70, 80, 90], score)]
TypeError: 'builtin_function_or_method' object is not subscriptable

I could use help getting this to work correctly. In addition, I could also use the best online resources for Python 3 to help me learn this and future assignments.
 
Is this common? I feel like this is probably the case with the company I work at too, or at least the team I am on.

As an aside, do companies usually attempt to invest in teaching developers software design, or do most developers pick it up while working on software if at all? I've been working for almost a year and I feel like I've only improved because the software I'm maintaining is painful to maintain and I like reading programming books and listening to talks, so I can contextualize my painful maintenance experiences with what I'm learning outside of work. Does learning design even matter that much? Lol, am I just confusing what's important because of my lack of experience?

On your first question, it's common enough in my experience. Lines of business do not like paying to fix code that works. The code might be badly written and hard to maintain, but it works and, besides that, it's hard to convince somebody who doesn't know code that the current state of the code makes it more expensive to maintain than otherwise -- they think code is essentially "paint by numbers" and anyone can do it and produce the same output. The flip side of the coin, of course, is that often enough, rewriting the code actually is a bad idea -- it works! Programmers always want to throw it out and do better (I'm convinced that's why video game sequels take so long to produce in many places -- too many developers throwing out too much working code, fixing what was perhaps not optimal but was never broken, just to rewrite it to produce 3 extra sparks) without considering how much that will cost and what important functionality will be left to wait while a "grand rewrite in the sky" is taking place. So I say to you this: get it right the first time. But if you get it wrong, learn to live with it (to an extent -- "fix it" incrementally as you can while you're working on new functionality, not at the expense of that functionality),

Regarding your second question, that's going to vary. You're already learning the lesson that we all learn, and that's we'll get better with practice. Each project, particularly as you're early in your career, will push you and stretch your boundaries hopefully in productive, educational ways. But some companies are just going to be better than others at nurturing you. I work for a bank, not a software house. We don't really have people guiding the way, we hire people with the expectation that they know their stuff and they'll hit the ground running. Other companies might act differently, hire you and pair you with mentors. Regardless of your environment, taking an active role in your own development is key.
 

Dereck

Member
I'm looking for a little Java help please.

I'm trying to understand this code, and I think I do, there is just a few things that I'm unclear on.

Code:
public class Noodles {

    public static void main(String[] args) {
    
         double[] values = {4.1, 3.4, 6.7, 4.3, 2.3, 1.1, 3.4, 5.1};
   
         for(int i = 1; i < values.length; i = i + 3) {
            System.out.print(values[i] + "  ");
         }
        }
       }
If this code prints out 3.4, 2.3, and 5.1

This means that: i is 1, so we're starting out at 3.4, and i equals i plus 3, so that means we count 3 integers from 3.4, which leaves us at 2.3, and then we count another three from there, which leaves us at 5.1.

Is this correct?
 

Makai

Member
I'm looking for a little Java help please.

I'm trying to understand this code, and I think I do, there is just a few things that I'm unclear on.

Code:
public class Noodles {

    public static void main(String[] args) {
    
         double[] values = {4.1, 3.4, 6.7, 4.3, 2.3, 1.1, 3.4, 5.1};
   
         for(int i = 1; i < values.length; i = i + 3) {
            System.out.print(values[i] + "  ");
         }
        }
       }
If this code prints out 3.4, 2.3, and 5.1

This means that: i is 1, so we're starting out at 3.4, and i equals i plus 3, so that means we count 3 integers from 3.4, which leaves us at 2.3, and then we count another three from there, which leaves us at 5.1.

Is this correct?
Yep
 

Dereck

Member
Code:
public class Noodles {

    public static void main(String[] args) {
    
         double[] values = {4.1, 3.4, 6.7, 4.3, 2.3, 1.1, 3.4, 5.1};
   
         for(int i = 0; i < values.length - 3; i++) {
            System.out.print(values[i+3] + "  ");
         }
        }
       }

For this one, if this prints out 4.3, 2.3, 1.1, 3.4, and 5.1

In Java IDE I found out that values.length is 8

So, in the beginning, int = 0, which means we're at 4.1

i < values.length - 3 (which is also i < 5) means that i equals every double in this array from 4 and up, and if not, what does that mean?

EDIT: if values in an array equal N-1, then it would make sense for i < 5 to mean "starting from value 4", right?

i++ equals i plus 1

So if we print out values[i+3]

We're printing out 4.3, 2.3, 1.1, 3.4, and 5.1, and I'm not entirely sure why.
 

Makai

Member
Code:
public class Noodles {

    public static void main(String[] args) {
    
         double[] values = {4.1, 3.4, 6.7, 4.3, 2.3, 1.1, 3.4, 5.1};
   
         for(int i = 0; i < values.length - 3; i++) {
            System.out.print(values[i+3] + "  ");
         }
        }
       }

For this one, if this prints out 4.3, 2.3, 1.1, 3.4, and 5.1

In Java IDE I found out that values.length is 8

So, in the beginning, int = 0, which means we're at 4.1

i < values.length - 3 (which is also i < 5) means that i equals every double in this array from 4 and up, and if not, what does that mean?

EDIT: if values in an array equal N-1, then it would make sense for i < 5 to mean "starting from value 4", right?

i++ equals i plus 1

So if we print out values[i+3]

We're printing out 4.3, 2.3, 1.1, 3.4, and 5.1, and I'm not entirely sure why.
Here's each iteration:

0 -> 0 + 3 = 3 -> 4.3
1 -> 1 + 3 = 4 -> 2.3
2 -> 2 + 3 = 5 -> 1.1
3 -> 3 + 3 = 6 -> 3.4
4 -> 4 + 4 = 7 -> 5.1
 

Dereck

Member
Sorry, I have to type out exactly what I'm thinking in order to understand this

So when it says i is less than values.length minus three

It's saying that we're only looking at everything below 5, which is 4.

So we're not using 4 as "4 in the array" we're looking at 4 which means, every number that leads to 4, that is below 5, which is 0 to 4.

i equals 0

i < 5, and then we add one to every value less than 5.

0+1 = 1
1+1 = 2
2+1 = 3
3+1 = 4

Then, we add three on everyone one of those?

0+3
1+3
2+3
3+3
4+3

Why did you do 4 plus 4?
 

Makai

Member
Sorry, I have to type out exactly what I'm thinking in order to understand this

So when it says i is less than values.length minus three

It's saying that we're only looking at everything below 5, which is 4.

So we're not using 4 as "4 in the array" we're looking at 4 which means, every number that leads to 4, that is below 5, which is 0 to 4.

i equals 0

i < 5, and then we add one to every value less than 5.

0+1 = 1
1+1 = 2
2+1 = 3
3+1 = 4

Then, we add three on everyone one of those?

0+3
1+3
2+3
3+3
4+3
Yes. The confusing part might be that "i < array.length" only restricts the assignment of i in the loop, but it does not restrict the output of "i + 3" in the print.

Why did you do 4 plus 4?
Typo. You add 3 to all.
 

Makai

Member
OK. Thanks
image.php


No prob. I remember being confused by for-loops. Pretty soon this kind of problem will seem trivial to you.
 
Code:
typeof foo === "object" //returns true if foo is null
typeof NaN === "number" //returns true
NaN === NaN //returns false

 return
  {
      bar: "hello"
  };
//this actually returns "undefined" because in JS, Semicolons are optional, yay!

var a = b = 3;
//this creates var a like you would expect, but also creates the global variable b
.

The typeof's make sense to me.

NaN is a special double defined in the IEEE 754 standard. Therefore, it's type should be number. As well, it is also defined in that same specification that NaN != NaN.

An object that is null should have type object. Just because it's null does not mean it should not have a type. The base type of all objects is object so it makes sense that null would have an object type. The only things that should have an undefined type are undefined values.

I think I actually saw the stream where he explained it. IIRC he said that, for methods in which you don't expect any part of it to be reused, it doesn't make sense to split long methods into subprocedures because it just adds more things to remember.

Breaking things down into the smallest reasonable component helps with testing as well since you can increase your test coverage. It's not always about code reuse.
 

Dereck

Member
image.php


No prob. I remember being confused by for-loops. Pretty soon this kind of problem will seem trivial to you.
Out of curiosity, if you wanted to print out that same set of integers, what code would you use that isn't i < 5 or i < values.length?
 

Makai

Member
Out of curiosity, if you wanted to print out that same set of integers, what code would you use that isn't i < 5 or i < values.length?
Well, academic problems end up being a bit different from the types you'd encounter in the real world. If all I had to do is output those 5 numbers, I'd just use the list I wanted to iterate over:

Code:
var numbers = { 4.3, 2.3, 1.1, 3.4, 5.1 };

numbers.ForEach(element => Console.WriteLine);

This is C#. I haven't used Java since college, but it probably has similar features to simplify code.
 

Nelo Ice

Banned
So what did you make?

Well I barely coded since I'm still a noob but at least I helped make the team. Anyway it was an api based hackathon. We built a travel app that makes you an itinerary based on a personality quiz api. Basically the point is planning a vacation is a PITA, so we wanted to make it easier. Using the quiz results, you get a list of cities and local businesses that fit your personality. Then you can say have a full schedule of stuff to do and things to in say 3 days and all scheduled out with times and all. We used 4 apis and came out with 3/4 of those sponsor prizes.
 

Moosichu

Member
True story: the application I currently work on had a ~3000 line method when I first joined several years ago, and several others with well over 1000 lines. I won't tell you whether or not a method that had a 1500+ line loop body still exists. I won't tell you that.

It does.



Forget that. Maintenance on long methods is a nightmare. Break those things apart and name the smaller functions well. You shouldn't need to "remember" it all. The methods should be small and the names should tell you most everything you need to know.

The problem with the application I support is 98% due to its horrid design and 2% due to the natural complexity of the business. And despite working on the application for years, much of the original problems remain (case in point, the 1500+ line loop) because new functionality seems to always get prioritized above dealing with the technical debt of bad, hard to read, harder to maintain code.

After reading about John Carmack's justification for it I think long methods can actually improved readability if done well and for the right reasons. One idea that was really interesting when Jonathan Blow was discussing his new langue was the idea of 'capturing' variables in blocks of code. Eg.

Code:
//Do some stuff here
int a = 5;
int b = 4;
int c = 10;
int d = 7;
int f = 0;

[a, b, d] { //Can comment what this block does here!
    f = a + b - d;
    //f += c; This wouldn't compile!
}

It's a good idea to help keep good code hygiene, but avoid having to follow methods down rabbit holes especially if they are only used in one place.
 

Somnid

Member
After reading about John Carmack's justification for it I think long methods can actually improved readability if done well and for the right reasons. One idea that was really interesting when Jonathan Blow was discussing his new langue was the idea of 'capturing' variables in blocks of code. Eg.

Code:
//Do some stuff here
int a = 5;
int b = 4;
int c = 10;
int d = 7;
int f = 0;

[a, b, d] { //Can comment what this block does here!
    f = a + b - d;
    //f += c; This wouldn't compile!
}

It's a good idea to help keep good code hygiene, but avoid having to follow methods down rabbit holes especially if they are only used in one place.

The only way I see long methods is for task scripting where each line can be roughly one unit of work and the logic truly isn't shareable. Maybe that's what Blow was getting at?

Also that concept just looks like a closure to me. I could see benefit of restricting access to globals in public methods (which people should do anyway) as a way to give guarantees to the user but in private code I'm not sure I see a benefit.
 

ferr

Member
Not sure if this is the right thread for this- but I have some questions about.. programming on the west coast.

Those in San Francisco and nearby radius, is it mostly Java, Android/iOS, PHP, MEAN/Full stack? The chatter on .NET/MSFT tech seems quiet, but not silent. Can a developer survive/flourish without Java, Mobile Dev (Android/iOS), Python, PHP, etc -- the non-MSFT families?

Similar question for the Seattle area, but I take it MSFT tech has a better grasp on that area considering how close it is to Redmond/MSFT.

Or is it simply all the same nationwide? As someone who has ~15 years with MSFT tech (using .NET since beta), is it worth throwing that away to pick up Java/Python/PHP/etc to "fit in"?
 
Not sure if this is the right thread for this- but I have some questions about.. programming on the west coast.

Those in San Francisco and nearby radius, is it mostly Java, Android/iOS, PHP, MEAN/Full stack? The chatter on .NET/MSFT tech seems quiet, but not silent. Can a developer survive/flourish without Java, Mobile Dev (Android/iOS), Python, PHP, etc -- the non-MSFT families?

Similar question for the Seattle area, but I take it MSFT tech has a better grasp on that area considering how close it is to Redmond/MSFT.

Or is it simply all the same nationwide? As someone who has ~15 years with MSFT tech (using .NET since beta), is it worth throwing that away to pick up Java/Python/PHP/etc to "fit in"?

It's best not to settle on any technology suite. Don't rest on your laurels. All that good stuff. I'd say it's an even mixture here in Dallas. Lots of stuff is cloud and web these days. With Xamarin mostly focusing on improving the mobile versions of Mono, C# mostly locks you to a Windows server platform. For this reason, Python, PHP, Java, and Ruby are much preferred over .Net. Java also has the added advantage of web frameworks that beat C# and Asp.Net's performance by quite a bit. On the other hand, C# still wins out on things where a rich client is involved.
 
Not sure if this is the right thread for this- but I have some questions about.. programming on the west coast.

Those in San Francisco and nearby radius, is it mostly Java, Android/iOS, PHP, MEAN/Full stack? The chatter on .NET/MSFT tech seems quiet, but not silent. Can a developer survive/flourish without Java, Mobile Dev (Android/iOS), Python, PHP, etc -- the non-MSFT families?

Similar question for the Seattle area, but I take it MSFT tech has a better grasp on that area considering how close it is to Redmond/MSFT.

Or is it simply all the same nationwide? As someone who has ~15 years with MSFT tech (using .NET since beta), is it worth throwing that away to pick up Java/Python/PHP/etc to "fit in"?

- MSFT has its niche, but not very popular in SF area
- Yes, it's worth to "throw" that away. You should always be trying to add new tools to your arsenal. It's not about fitting in.
- Java/Python/PHP are also not very hot either. Look into mobile development, js, ruby and scala.
 

ferr

Member
Thanks for the replies.

- MSFT has its niche, but not very popular in SF area
- Yes, it's worth to "throw" that away. You should always be trying to add new tools to your arsenal. It's not about fitting in.
- Java/Python/PHP are also not very hot either. Look into mobile development, js, ruby and scala.

Looking into companies in SF, I see Java so often. But my guess is that has something to do with Android development? I have a ton of HTML/CSS/JS in my background, so that helps, but I do wonder if I should dive into some other languages, especially back-end stuff.

I'm always picking up new languages/tech every day, but tech like Java/Ruby etc are a bit too far out of my domain professionally for me to fit that in. Just at a point now where I'm considering which avenues to take.. I have a couple of years to do this. I am considering setting a goal of developing/publishing an Android app to get my hands dirty.
 
Can someone help me out with this problem, the wording is confusing the hell out of me.

Write a complete C++ program that will calculate the interest earned on a fixed savings account in one year. The the total amount of interest plus principal is calculated by the following formula assuming that the owner does not deposit any additional money in the account other than the compounded interest during the year.

total at year end = principal * (1.0 + (rate/t))^t

here the '^' indicates raising the quantity (1.0 + (rate/t)) to a power. The variables are the beginning amount in the account (principal), the annual interest rate, rate, and t is the number of times the interest is computed during the year (t = 12 if it is calculated monthly).
The program should ask the user for the principal, the interest rate and the number of times the interest is calculated. It then writes to standard output the principal, the interest rate and the number of times the interest is calculated plus the total amount in the account at the end of the year. The interest can be calculated by subtracting principal from the total. Write the yearly interest to standard output as well.

So I need to find the interest rate and rate.
1) I'm assuming those two variables made up and inputted by the user.
2) What is the difference between interest rate and rate?

I feel like this is simple as hell but the wording is making it unnecessarily complicated.
 

LegatoB

Member
Can someone help me out with this problem, the wording is confusing the hell out of me.



So I need to find the interest rate and rate.
1) I'm assuming those two variables made up and inputted by the user.
2) What is the difference between interest rate and rate?

I feel like this is simple as hell but the wording is making it unnecessarily complicated.
The variable named "rate" in the formula holds the interest rate. It's not a very well-written sentence, to your credit.
 
I have a c# Web Application (a VS MVC project) I'm now maintaining and making alterations to. It's simply displays a schedule for digital signage based on the URL being sent. We needed to get a more specific schedule so I made the necessary alterations to account for new URLs but I'm not sure how to test them. When I run the program in Visual Studio it connects to the localhost with an Internet Explorer browser and shows the full schedule. The full schedule is shown by default. The schedule is filtered based on the URL sent depending on where the display is but I don't know how to run through the other URLs in Visual Studio, even in the version that is currently live. I also don't know how to deploy my changes to IIS on the server but that's a different question for a different day.

It's something I found lacking in my classes, that is, what to do after you're done programming and testing. We never really talked about deploying/publishing projects, getting them to run as a standalone program, or what have you. We just ran then for the prof in the IDE/dev environment then went on our way.

Edit: Well now I feel like an ass because I just figured out the damn thing. Maybe I'll repent by checking in here more and helping out.
 

SOLDIER

Member
Now that I figured out how to paste code, let me try this again:

Code:
import bisect

def main():
    num_tests = 5
total = 0.0
for i in range(num_tests):
    total += determine_grade()
print ("The average score is "), total / num_tests

def determine_grade():
    score = input ("Enter your test score: ")
print (["F", "D", "C", "B", "A"][bisect.bisect_right([60, 70, 80, 90], score)])
print (score)

main()

I'm trying to get this working with Python 3. My current error statement is:

Assignment 5 Test.py", line 7, in <module>
for i in range(num_tests):
NameError: name 'num_tests' is not defined
 
Now that I figured out how to paste code, let me try this again:

Code:
import bisect

def main():
    num_tests = 5
total = 0.0
for i in range(num_tests):
    total += determine_grade()
print ("The average score is "), total / num_tests

def determine_grade():
    score = input ("Enter your test score: ")
print (["F", "D", "C", "B", "A"][bisect.bisect_right([60, 70, 80, 90], score)])
print (score)

main()

I'm trying to get this working with Python 3. My current error statement is:

Assignment 5 Test.py", line 7, in <module>
for i in range(num_tests):
NameError: name 'num_tests' is not defined

You have an indentation error. Everything before the determine_grade function and under the main identifier should be indented, so that python will consider it part of the definition. Otherwise, it actually is defining main to he a function that sets num_tests to be 5. Then it executes all the other lines, but by the time it gets to num_tests it hasn't actually defined that variable because main has not yet run.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Python has no curly braces for blocks, right? It's all indent based?
 

SOLDIER

Member
You have an indentation error. Everything before the determine_grade function and under the main identifier should be indented, so that python will consider it part of the definition. Otherwise, it actually is defining main to he a function that sets num_tests to be 5. Then it executes all the other lines, but by the time it gets to num_tests it hasn't actually defined that variable because main has not yet run.

Indented how far? Could you perhaps show me how it should look?
 

Water

Member
Python has no curly braces for blocks, right? It's all indent based?

Yeah. That's one of the reasons I think it's a very good language for people new to programming. It ensures the visual shape of the code text reflects the semantics, and doesn't allow laying out the code deceptively.
 
Indented how far? Could you perhaps show me how it should look?

Blocks of code in Python are determined by the indentation. If you want a line of code to be part of a given block, it needs to be indented at the right level. Other languages have curly braces {} or keywords like "begin/end" to determine blocks.

Code:
def function():
    x = 5
    print(x)
    if x > 2:
        print(x+2)
    return x

The line "def function():" starts a block in this case, so does the if-statement. In this case, the indentation level of the line "return x" determines whether it belongs to the function block or the if-block.
Scope (where variables are valid) is also determined by blocks, which is why you're getting the error. In line 5, you have some code that is in a different block than the preceding line because it's not properly indented. This site explains this in more detail.
 

SOLDIER

Member
I think I have the indentation right...

Code:
import bisect

def main():
    num_tests = 5
    total = 0.0
    for i in range(num_tests):
        total += determine_grade()
        print ("The average score is "), total / num_tests

def determine_grade():
    score = input ("Enter your test score: ")
    print (["F", "D", "C", "B", "A"][bisect.bisect_right([60, 70, 80, 90], score)])
    return (score)

main()

It asks me to input the first test score, but after that it says:

NameError: name 'num_tests' is not defined
 
Top Bottom