• 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

tokkun

Member
Thanks. I thought that so, but I swear I remember something being inconclusive. Must be remembering things ~.~.

You may have stated parts 2 & 3 incorrectly.

If you find a polynomial-time solution to B, then P = NP.

If you find a polynomial-time solution to A, it's inconclusive.
 

Tater Tot

"My God... it's full of Starch!"
Programming newb here:

A user types a word and a number. Read them into the provided variables. Then print: word_number. End with newline. Example output if user entered: Amy 5
Amy_5
Code:
import java.util.Scanner;

public class SpaceReplace {
   public static void main (String [] args) {
      Scanner scnr = new Scanner(System.in);
      String userWord = "";
      int userNum = 0;
      String sentenceWord = "";
      String sentenceNum = "";
      
      System.out.print("Enter a Word");
      userWord = scnr.next();
      System.out.print("Enter a Number");
      userNum = scnr.nextInt();
      
      sentenceWord = userWord;
      sentenceNum = IntuserNum; //Ithink this is the problem
      System.out.print(sentenceWord);
      System.out.print("_");
      System.out.println(sentenceNum);

      return;
   }
}

How do I assign a value into a string when the variable is an Int?
 

msv

Member
Anyone familiar with Netmodules in VS 2013 here? I think that's what I need, but there's no built in functionality for it apparently :/
 

poweld

Member
Programming newb here:

A user types a word and a number. Read them into the provided variables. Then print: word_number. End with newline. Example output if user entered: Amy 5
Amy_5
Code:
import java.util.Scanner;

public class SpaceReplace {
   public static void main (String [] args) {
      Scanner scnr = new Scanner(System.in);
      String userWord = "";
      int userNum = 0;
      String sentenceWord = "";
      String sentenceNum = "";
      
      System.out.print("Enter a Word");
      userWord = scnr.next();
      System.out.print("Enter a Number");
      userNum = scnr.nextInt();
      
      sentenceWord = userWord;
      sentenceNum = IntuserNum; //Ithink this is the problem
      System.out.print(sentenceWord);
      System.out.print("_");
      System.out.println(sentenceNum);

      return;
   }
}

How do I assign a value into a string when the variable is an Int?

Check out
Code:
String twoString = Integer.toString(2);

edit: oh god i'm tired
 
Guys, I need some help. I can't for the life of me remember some stuff about P, NP and NP- complete and I can't find it on my notes, nor the teachers material nor the internet.

Basically, if I have a problem A which is in NP and a problem B which is in NP-Complete, what can we say about P and NP when:

1. We find a polynomial solution to both A and B
2. We find there's no polynomial solution to A
3. We find there's no polynomial solution to B
4. We find there's no polynomial solution to both A and B

IIRC, from 1 we can deduce P = NP, from 4, P != NP and we can't deduce anything form the other two, but I'm not understanding why.

Thanks.
Here:

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

msv

Member
So for anyone wanting to have their dependencies/references merged into the assembly in .NET, I've found and easy solution. There's alternatives, but the Costura.Fody NuGet package works without hassle. Just installed it on all my projects, and everything gets nicely combined into one file. Doesn't fix the sub-dependency access, and I think the assemblies get embedded instead of actually merged, but hey, at least it works without hassle.
 

Husker86

Member
Lately I've been having an issue with app crashes in Android Studio. I don't know if this is Android specific or Java in general.

Instead of getting my normal crash with some sort of error in Logcat, I'm just getting "Shutting Down VM". Now, with extensive Log statements I can usually find the issue, but it has made the process much longer. I cannot remember what I did when this started happening, but I used to get normal error statements in this same project at one point in time.

Anyone have any idea what could be going on?
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
What are the differences between linters and syntax checkers in say an IDE like IntelliJ?

I'm keep seeing people talk about how awesome this linter or that linter are, especially in the context of Sublime Text, but whenever I think about them and what they do I keep picturing an IDE. Like they are doing what an IDE would already do for you, just in a less efficient way.

Please set me straight and explain these things if you could!
 

Somnid

Member
What are the differences between linters and syntax checkers in say an IDE like IntelliJ?

I'm keep seeing people talk about how awesome this linter or that linter are, especially in the context of Sublime Text, but whenever I think about them and what they do I keep picturing an IDE. Like they are doing what an IDE would already do for you, just in a less efficient way.

Please set me straight and explain these things if you could!

It's usually setup as part of the build process. It would be silly for an IDE to prevent you from saving code that's not properly linted but you don't want to check it in to version control and not everybody is using the same IDE with the same style rules.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
It's usually setup as part of the build process. It would be silly for an IDE to prevent you from saving code that's not properly linted but you don't want to check it in to version control and not everybody is using the same IDE with the same style rules.

Hmm, so are they more popular with larger teams using source control? I'm still ignorant on the big team workings of software development.
 

Water

Member
What are the differences between linters and syntax checkers in say an IDE like IntelliJ?

I'm keep seeing people talk about how awesome this linter or that linter are, especially in the context of Sublime Text, but whenever I think about them and what they do I keep picturing an IDE. Like they are doing what an IDE would already do for you, just in a less efficient way.
1) Syntax checking is just a part of what compilers do. Compilers have to be very fast to be useful in day-to-day development. Separate linters / static analysis tools can take a lot more time to perform deeper analysis that compilers cannot do.
2) Purpose. Linters may look heuristically for things that might not even be errors, style issues that are only relevant in the context of a particular project's / team's agreed coding style, etc. Integrating all of these features into a giant monolithic compiler as optional features that take no performance when disabled would be a miracle and at least make the compiler unmaintainable.
 

msv

Member
1) Syntax checking is just a part of what compilers do. Compilers have to be very fast to be useful in day-to-day development. Separate linters / static analysis tools can take a lot more time to perform deeper analysis that compilers cannot do.
2) Purpose. Linters may look heuristically for things that might not even be errors, style issues that are only relevant in the context of a particular project's / team's agreed coding style, etc. Integrating all of these features into a giant monolithic compiler as optional features that take no performance when disabled would be a miracle and at least make the compiler unmaintainable.
Poster's talking about IDE's though, not compilers. From the sounds of it I'd never use something like atom + linter when a full fledged IDE is available. Unless the functionality is comparable, but it's not though is it?
 

Somnid

Member
Poster's talking about IDE's though, not compilers. From the sounds of it I'd never use something like atom + linter when a full fledged IDE is available. Unless the functionality is comparable, but it's not though is it?

The IDE points out potential problems inline for your benefit but it does nothing to prevent you from checking in bad or inconsistent code to a central repository.
 

msv

Member
The IDE points out potential problems inline for your benefit but it does nothing to prevent you from checking in bad or inconsistent code to a central repository.
And all linters do that? A linter has integrated GIT? What about project package and build management? Debugging?
 

Somnid

Member
And all linters do that? A linter has integrated GIT? What about project package and build management? Debugging?

A linter is just a code analysis tool that takes in the source code files and spits back a bunch of warnings kinda like a compiler would but it's checking more for style than syntax. So in a normal team scenario you have a build process that gets latest from the repository, compiles the build, pushes it up to a clean environment for testing, and runs automated test, typically on a check in. This is to test if the checked in code broke something and if it did it usually flags the build as bad (noting the last check in) and the team should stop what they are doing and fix it. This way you don't check in broken code and take off, leaving everyone else with a broken build they can't work with. As part of this many teams opt to include code linters that check for style and form issues.

It's still recommended you run the linter locally but it's a line of defense to keep code quality high.
 

moka

Member
A linter is just a code analysis tool that takes in the source code files and spits back a bunch of warnings. So in a normal team scenario you have a build process that gets latest from the repository, compiles the build, pushes it up to a clean environment for testing, and runs automated test, typically on a check in. This is to test if the checked in code broke something and if it did it usually flags the build as bad and the team should stop what they are doing and fix it. This way you don't check in broken code and take off, leaving everyone else with a broken build they can't work with. As part of this many teams opt to include code linters that check for style and form issues.

Pre-commit builds!
 
Linters are probably most useful for a JIT-style language, e.g. your pythons/javascript/ruby where you don't have a compiler to tell you you made stupid syntax errors. The linter can catch those...

It also serves as the dual-purpose of keeping code style in sync + enforcing some best practices across a team of devs.
 

Tater Tot

"My God... it's full of Starch!"
Im on chapter 4 and I am looking at looping. The section of the book covers break and continue.

"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Ex: The following patterns yield a userScore of 4:

simonPattern: R, R, G, B, R, Y, Y, B, G, Y
userPattern: R, R, G, B, B, R, Y, B, G, Y

Code:
import java.util.Scanner;

public class SimonSays {
   public static void main (String [] args) {
      String simonPattern = "";
      String userPattern = "";
      int userScore = 0;
      int i = 0;

      userScore = 0;
      simonPattern = "RRGBRYYBGY";
      userPattern  = "RRGBBRYBGY";

      char s;
      char u;
      
      for(i=0; i < 10; i++) {
          s = simonPattern.charAt(i);
          u = userPattern.charAt(i);
          
          if(s == u)
          userScore = userScore + 1;
          continue;
          else if(s != u){
         break;
      
         
      }

      System.out.println("userScore: " + userScore);

      return;
   }
}

I keep getting this error:
Code:
SimonSays.java:24: 'else' without 'if' else if(s != u){ ^ SimonSays.java:34: reached end of file while parsing } ^ 2 errors

I am just not sure what I am doing wrong for the else if statement.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Thanks for the discussion on linters. That helped to clear up my questions.
 

mercviper

Member
I keep getting this error:
Code:
SimonSays.java:24: 'else' without 'if' else if(s != u){ ^ SimonSays.java:34: reached end of file while parsing } ^ 2 errors

I am just not sure what I am doing wrong for the else if statement.
Brackets are your friend. Else statements need to immediately follow the if. For multi line ifs you are going to want brackets
 

Tater Tot

"My God... it's full of Starch!"
It works now!

I used this

Code:
      for(i=0; i < 10; i++) {
          s = simonPattern.charAt(i);
          u = userPattern.charAt(i);
          
          if(s == u)
          userScore = userScore + 1;
          else{break;}

Thanks!
 

Tristam

Member
I've been learning perl this week and have to say that I'm really, really not a fan. Anyone here have a strong opinion on it?

Also not a fan. It's a scripting language often used for hacking quick tasks, and gives you the flexible data containers you would expect from such a language but makes accessing elements of those containers (dereferencing) primitive. Maybe I'm a dummy, but I still find dereferencing to access elements in deeply-nested lists (or hashes, or lists of hashes, or lists of hashes of hashes...) to be quite onerous.
 

msv

Member
So question here regarding class generation in C# / VS. I want to be able to write an interface, and have that interface implemented at compile time, or before, automatically.

The implementations of the methods are all according to the same procedure, all information I need per method is the method's name and parameters and then I can write the body. I also need to be able to generate two different implementations per interface (client and server).

What would you suggest, T4 Templates, Reflection.Emit? Are there any other options (built in to VS preferably)?
 
So question here regarding class generation in C# / VS. I want to be able to write an interface, and have that interface implemented at compile time, or before, automatically.

The implementations of the methods are all according to the same procedure, all information I need per method is the method's name and parameters and then I can write the body. I also need to be able to generate two different implementations per interface (client and server).

What would you suggest, T4 Templates, Reflection.Emit? Are there any other options (built in to VS preferably)?

I know this doesn't answer your question, but have you considered using something like Cap'n Proto. Because it sounds like you're re-inventing the wheel.
 

msv

Member
I know this doesn't answer your question, but have you considered using something like Cap'n Proto. Because it sounds like you're re-inventing the wheel.
Looks really cool, simply storing the data beforehand in a way that you can just write/transfer it. But the RPC part isn't available in C#. Doesn't seem like it does what I need it to do either, waiting for the reply part for example seems to be blocking. As for the serialization part, I don't want to use schema's for this project. Streamlining the development process has a higher priority. 2 to 5x the speed of protobuf is insane though, definitely one to watch.

The serialization and messaging is already implemented by the way and I'm working on streamlining client-server RPC interfaces. That's why I need to generate classes from an interface, so the developer would only have to edit the interface and then regenerate the classes. Perhaps even at runtime, but then the syntax can't be checked.
 
Looks really cool, simply storing the data beforehand in a way that you can just write/transfer it. But the RPC part isn't available in C#. Doesn't seem like it does what I need it to do either, waiting for the reply part for example seems to be blocking. As for the serialization part, I don't want to use schema's for this project. Streamlining the development process has a higher priority. 2 to 5x the speed of protobuf is insane though, definitely one to watch.

The serialization and messaging is already implemented by the way and I'm working on streamlining client-server RPC interfaces. That's why I need to generate classes from an interface, so the developer would only have to edit the interface and then regenerate the classes. Perhaps even at runtime, but then the syntax can't be checked.

Ahh, well in that case if it were me I would create a very simple DSL and then write a tool to generate the classes. You could even make it JSON, like this:

Code:
'client' : {
    'methods' : [
        {
            'return_type' : 'void'
            'name' : 'foo'
            'args' : [
                {
                    type : 'int',
                    name : 'foo_param'
                }
            ]
        },
        {
            'return_type' : 'double'
            'name' : 'bar'
            'args' : [
                {
                    type : 'float',
                    name : 'bar_param'
                }
            ]
        }
    ]
}

Then write a little command line tool that uses JSON.NET to parse this file and output a C# class.

To integrate this into VS, first split your project so that the interface is in a separate assembly. Then add all these JSON files to this same project. For each of the JSON files, set the build action to Custom Build Tool and set the command line to run the tool you wrote. Then have the main project add a reference to this project.

Now everything will just be automatic.
 

survivor

Banned
I've been learning perl this week and have to say that I'm really, really not a fan. Anyone here have a strong opinion on it?

Had to use it for my programming paradigms class mostly for regular expressions. I was also not a fan of it at all, never used it ever since.
 

msv

Member
To integrate this into VS, first split your project so that the interface is in a separate assembly. Then add all these JSON files to this same project. For each of the JSON files, set the build action to Custom Build Tool and set the command line to run the tool you wrote. Then have the main project add a reference to this project.

Now everything will just be automatic.
Hm yeah, sort of like an extension as well. Though I don't want to write outside of the IDE/language. But if I write is as VS extension I could use a normal C# interface as well. I guess I'm trying to decide between that (most flexibility, but also most effort), T4 Templates (I think the options here are limited right?) and runtime with Reflection.Emit/Expression trees (less syntax checking, but also least amount of steps for developer to take).

Kind of leaning towards Emit/Expression trees now. Seems like it would be neat to just provide an interface to the RPC object and out pops an instance you can use. Everything happening in the background. Eh can't seem to make up my mind :(
 

Sandfox

Member
Any good resource recs for learning Java? I have very basic knowledge of the language but I want to spend the summer to begin working towards learning to make apps.
 
Does anyone here have experience with d3.js? I've been messing around with it today and it's really cool and seems extremely powerful, but I've got issues trying to get an ordinal scale for a histogram working. I've posted my code on JSBin. The issue seems to be that the ordinal scale always returns undefined, even though I've defined an input mapping (domain(weekdays)) and an output range. Not sure what the problem is exactly, I'm still very new to the library.
 

Tater Tot

"My God... it's full of Starch!"
Anybody help me with this?

Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex:
Initial scores: 10, 20, 30, 40
Scores after the loop: 30, 50, 70, 40
The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last element remains the same.

Code:
public class StudentScores {
   public static void main (String [] args) {
      final int SCORES_SIZE = 4;
      int[] bonusScores = new int[SCORES_SIZE];
      int i = 0;

      bonusScores[0] = 10;
      bonusScores[1] = 20;
      bonusScores[2] = 30;
      bonusScores[3] = 40;

      /* Your solution goes here  */
      for(i=0; i < 3; ++i){
         bonusScores[i] = bonusScores[i] + bonusScores[i+1];
      }

      for (i = 0; i < SCORES_SIZE; ++i) {
         System.out.print(bonusScores[i] + " ");
      }
      System.out.println();

      return;
   }
}

I got the answer correct but I keep getting this error and I am not sure what is wrong exactly

Code:
  Testing for bonusScores = {10, 20, 30, 40}
Your output:30 50 70 40 
&#10006;   Runtime error (commonly due to an invalid array/vector access, divide by 0, etc.).
Tests aborted.
 

Ambitious

Member
Anybody help me with this?

Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex:
Initial scores: 10, 20, 30, 40
Scores after the loop: 30, 50, 70, 40
The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last element remains the same.

Code:
public class StudentScores {
   public static void main (String [] args) {
      final int SCORES_SIZE = 4;
      int[] bonusScores = new int[SCORES_SIZE];
      int i = 0;

      bonusScores[0] = 10;
      bonusScores[1] = 20;
      bonusScores[2] = 30;
      bonusScores[3] = 40;

      /* Your solution goes here  */
      for(i=0; i < 3; ++i){
         bonusScores[i] = bonusScores[i] + bonusScores[i+1];
      }

      for (i = 0; i < SCORES_SIZE; ++i) {
         System.out.print(bonusScores[i] + " ");
      }
      System.out.println();

      return;
   }
}

I got the answer correct but I keep getting this error and I am not sure what is wrong exactly

Code:
  Testing for bonusScores = {10, 20, 30, 40}
Your output:30 50 70 40 
&#10006;   Runtime error (commonly due to an invalid array/vector access, divide by 0, etc.).
Tests aborted.

Nothing wrong with your code. How is it tested? Where does the runtime error message come from?

Some advice on code style, though: You're using a constant number in the termination condition of the first loop. If the size of the array ever changes, you'd have to modify two lines (the SCORES_SIZE constant and the 3 in the loop head). So you should replace the 3 with SCORES_SIZE-1. Second: The return statement is unnecessary. It's the last line of the method, so it's going to return anyway.
 
Hm yeah, sort of like an extension as well. Though I don't want to write outside of the IDE/language. But if I write is as VS extension I could use a normal C# interface as well. I guess I'm trying to decide between that (most flexibility, but also most effort), T4 Templates (I think the options here are limited right?) and runtime with Reflection.Emit/Expression trees (less syntax checking, but also least amount of steps for developer to take).

Kind of leaning towards Emit/Expression trees now. Seems like it would be neat to just provide an interface to the RPC object and out pops an instance you can use. Everything happening in the background. Eh can't seem to make up my mind :(

Hmm, idk, it seems like the JSON approach I suggested involves very few steps for a developer to take, and is also really easy to implement. All the developer has to do is add add a few lines of self-explanatory JSON to an existing file, then hit build, then it just works. Plus it has the advantage of being fast (actual C# code is generated at build time), and easy to debug / step through because no reflection funny business. Why make it a VS extension though? Just make a simple command line tool, add that to the solution, make a dependency on it so that it builds first and put a post build step to output it to some shared location where other projects can invoke it from.

Everything just works, no magic steps for the developer to do. Edit json, hit Build, F5 to run.
 

Kickz

Member
Hello peoples, I had a quick question. I did a programming focused bachelor degree but have been in Networking side of IT last 2 years. I wanted to transition back to soft dev side I studied during college, so I am planning on taking a 3 month course from Epicodus in Portland to brush up on concepts/network as well. My question is they have 2 course offerings and wanted to know which you fellows would think would be more valuable:

Course 1: PHP/Javascript/Drupal

Course 2: Ruby/Javascript/Railsl

^Let me know what you guys think
 

NotBacon

Member
Hello peoples, I had a quick question. I did a programming focused bachelor degree but have been in Networking side of IT last 2 years. I wanted to transition back to soft dev side I studied during college, so I am planning on taking a 3 month course from Epicodus in Portland to brush up on concepts/network as well. My question is they have 2 course offerings and wanted to know which you fellows would think would be more valuable:

Course 1: PHP/Javascript/Drupal

Course 2: Ruby/Javascript/Railsl

^Let me know what you guys think

Definitely course 2.
 
Hello peoples, I had a quick question. I did a programming focused bachelor degree but have been in Networking side of IT last 2 years. I wanted to transition back to soft dev side I studied during college, so I am planning on taking a 3 month course from Epicodus in Portland to brush up on concepts/network as well. My question is they have 2 course offerings and wanted to know which you fellows would think would be more valuable:

Course 1: PHP/Javascript/Drupal

Course 2: Ruby/Javascript/Railsl

^Let me know what you guys think

Out of those 2, take course 2. More demand and better paid. Only take 1 if you also have a time machine to 2001.

If possible take a course on iOS/Android development, those are scarce and company are even hiring junior dev for those.

The "hotness" right now is node/iOS/new client side js frameworks (react, angular or ember).
 

poweld

Member
Out of those 2, take course 2. More demand and better paid. Only take 1 if you also have a time machine to 2001.

If possible take a course on iOS/Android development, those are scarce and company are even hiring junior dev for those.

The "hotness" right now is node/iOS/new client side js frameworks (react, angular or ember).

I sorta agree, but sorta disagree. PHP (and Perl) can lead to LAMP stack experience, which is, and will be for quite some time, in demand. Maybe is more of a matter of whether he wants to go more towards back end vs front end dev.
 

Kickz

Member
Definitely course 2.

Out of those 2, take course 2. More demand and better paid. Only take 1 if you also have a time machine to 2001.

If possible take a course on iOS/Android development, those are scarce and company are even hiring junior dev for those.

The "hotness" right now is node/iOS/new client side js frameworks (react, angular or ember).

Thank you gentlemen for the advice, I'll go ahead and register for number 2.
 
I sorta agree, but sorta disagree. PHP (and Perl) can lead to LAMP stack experience, which is, and will be for quite some time, in demand. Maybe is more of a matter of whether he wants to go more towards back end vs front end dev.

Learning Rails, an MVC web framework, is probably better than learning how to use and extend a CMS.

Rails also lets you get some experience working with object oriented design, as everything is OO, from all the language libraries up to the application code that you need to code.

Rails is also a very nice framework to work with, as it handles database migration, dependencies and assets in a sensible way.

Once you get more experience on Ruby, you start writing code that writes code for you, which is probably as good as sex.
 

msv

Member
Everything just works, no magic steps for the developer to do. Edit json, hit Build, F5 to run.
With an extension you can generate classes from a context menu, so you don't have to build the project or go outside of VS to gain access to/update the classes.

I'm leaving it for now though. Working on the async RPC now. I decided to have the queries run fully asynchronously, so guess I'll just have to keep the reply delegate around in order to send a reply eventually.
 

danthefan

Member
If I wanted to work on learning Python, which is the best version to go for? 2.7 still seems to be very common, or would it be better to go for the more recent versions?

I don't really have a huge goal in mind other than learning for the sake of learning.
 
If I wanted to work on learning Python, which is the best version to go for? 2.7 still seems to be very common, or would it be better to go for the more recent versions?

I don't really have a huge goal in mind other than learning for the sake of learning.

I'd personally always go with 3.x because that's where the cool new stuff happens. 2.7 has been stagnant for a while. Recently,Python 3.5 introduced a couple of cool new features (@-operator for matrix multiplication, async and await and so on) and the most important libraries are compatible. If there is some library that doesn't work, you can go back to 2.7, but if possible I'd choose 3.
 
Top Bottom