Jump to content

madknight3

Member
  • Posts

    1,786
  • Joined

  • Last visited

Reputation Activity

  1. Like
    madknight3 got a reaction from Sergio45 in C# Program issue   
    You don't need to check both a == b and b == a so your if statements can be simplified a little.
    if (a == b || a == c || b == c) { // at least two match // ... if (a == b && a == c && b == c) { // all three match } } else { // No matches } Just in case it's not clear, replace a, b and c with fruits[0], fruits[1], and fruits[2] respectively.
  2. Like
    madknight3 reacted to HPWebcamAble in C# Program issue   
    Same as 
    if (a == b && a == c) Transitive property 
  3. Like
    madknight3 got a reaction from Sergio45 in C# Program issue   
    Damn it, that's what I meant to write. I guess I need to pay better attention. Oh well, good catch.
  4. Informative
    madknight3 got a reaction from Fyfey96 in Java Help Please   
    Your method isn't returning a value. Add the return statement.
    public String simpleMessage(String name){ //this is taking the varible sent from the call method name = name +(" Is a god"); return name; } Note that you can shorten it to
    public String simpleMessage(String name) { return name + " Is a god"; // brackets also aren't doing anything so I removed them too }  
  5. Informative
    madknight3 got a reaction from Cruorzy in Insecure about coding   
    Many popular frameworks provide authentication functionality (among other things). Some PHP information on the topic here. You might want to consider going with one of them as it'll likely be more secure than doing everything from scratch yourself. For PHP, Laravel is a popular option these days (source) and I've seen it recommended before so I would probably give that a try first. It certainly doesn't hurt to give the other popular options a try either and see which you like best but that's up to you.
  6. Informative
    madknight3 got a reaction from naza98m in [VB.NET] Remote inventory server?   
    It sounds like you're going to want to use a database like Sql Server or another popular option (MySQL, PostgreSQL, etc). It can go up on a server and your application can connect to it remotely or get data access through another service (like a web service). Also in case it becomes necessary, SQLite is a nice option for when you need a local database for your app.
     
    If you're new to this stuff you'll want to learn a bit about SQL and database design. You can use the basic ADO.NET library for working with databases in .NET or you can go with a micro/full ORM like Dapper, Entity Framework, etc.
     
     
  7. Like
    madknight3 got a reaction from jslowik in Java might be getting local-variable type inference   
    Many languages already have local-variable type inference and it looks like Java may finally be getting there too. JEP 286 has the proposal details. There's also a survey you can take to go with it to give them some feedback about the proposal. One thing the survey asks about is the preferred syntax for the feature. Options are
    //A: var only (like C#) var lib = getMusicLibrary(); var artists = lib.getArtists(); var personCount = artists.size(); var works = lib.getTracks(); var workCount = works.size(); //B: var/val (like Scala, Kotlin) val lib = getMusicLibrary(); val artists = lib.getArtists(); var personCount = artists.size(); val works = lib.getTracks(); var workCount = works.size(); //C: var/let (like Swift) let lib = getMusicLibrary(); let artists = lib.getArtists(); var personCount = artists.size(); let works = lib.getTracks(); var workCount = works.size(); //D: let only let lib = getMusicLibrary(); let artists = lib.getArtists(); let personCount = artists.size(); let works = lib.getTracks(); let workCount = works.size(); //E: auto only (like C++) auto lib = getMusicLibrary(); auto artists = lib.getArtists(); auto personCount = artists.size(); auto works = lib.getTracks(); auto workCount = works.size();  
    It's small, and there's still a lot more that can be done to reduce boilerplate, but I expect many people who use Java will support this proposal (and as always, many people will probably hate it for some reason too).
  8. Like
    madknight3 got a reaction from DKL in Java might be getting local-variable type inference   
    Many languages already have local-variable type inference and it looks like Java may finally be getting there too. JEP 286 has the proposal details. There's also a survey you can take to go with it to give them some feedback about the proposal. One thing the survey asks about is the preferred syntax for the feature. Options are
    //A: var only (like C#) var lib = getMusicLibrary(); var artists = lib.getArtists(); var personCount = artists.size(); var works = lib.getTracks(); var workCount = works.size(); //B: var/val (like Scala, Kotlin) val lib = getMusicLibrary(); val artists = lib.getArtists(); var personCount = artists.size(); val works = lib.getTracks(); var workCount = works.size(); //C: var/let (like Swift) let lib = getMusicLibrary(); let artists = lib.getArtists(); var personCount = artists.size(); let works = lib.getTracks(); var workCount = works.size(); //D: let only let lib = getMusicLibrary(); let artists = lib.getArtists(); let personCount = artists.size(); let works = lib.getTracks(); let workCount = works.size(); //E: auto only (like C++) auto lib = getMusicLibrary(); auto artists = lib.getArtists(); auto personCount = artists.size(); auto works = lib.getTracks(); auto workCount = works.size();  
    It's small, and there's still a lot more that can be done to reduce boilerplate, but I expect many people who use Java will support this proposal (and as always, many people will probably hate it for some reason too).
  9. Informative
    madknight3 got a reaction from Shoob in Java might be getting local-variable type inference   
    Many languages already have local-variable type inference and it looks like Java may finally be getting there too. JEP 286 has the proposal details. There's also a survey you can take to go with it to give them some feedback about the proposal. One thing the survey asks about is the preferred syntax for the feature. Options are
    //A: var only (like C#) var lib = getMusicLibrary(); var artists = lib.getArtists(); var personCount = artists.size(); var works = lib.getTracks(); var workCount = works.size(); //B: var/val (like Scala, Kotlin) val lib = getMusicLibrary(); val artists = lib.getArtists(); var personCount = artists.size(); val works = lib.getTracks(); var workCount = works.size(); //C: var/let (like Swift) let lib = getMusicLibrary(); let artists = lib.getArtists(); var personCount = artists.size(); let works = lib.getTracks(); var workCount = works.size(); //D: let only let lib = getMusicLibrary(); let artists = lib.getArtists(); let personCount = artists.size(); let works = lib.getTracks(); let workCount = works.size(); //E: auto only (like C++) auto lib = getMusicLibrary(); auto artists = lib.getArtists(); auto personCount = artists.size(); auto works = lib.getTracks(); auto workCount = works.size();  
    It's small, and there's still a lot more that can be done to reduce boilerplate, but I expect many people who use Java will support this proposal (and as always, many people will probably hate it for some reason too).
  10. Like
    madknight3 reacted to fizzlesticks in Here we go again...   
    Ah yes that's a mighty fine lookin problem you've got there.  And I have no idea how to solve it.
     
    But my brute force method got 30% so that's something.
  11. Agree
    madknight3 got a reaction from jslowik in Programming Brevity and Style   
    The goal isn't the least number of lines. Readability and consistency are bigger factors. Style guides can be useful for keeping everyone in sync so you don't have to worry about these little details. Sometimes reducing the number of lines can help readability, sometimes it can hurt it (complex one liners, etc).
     
    Your example is pretty trivial so I don't think it really matters much although I don't think you gain anything with option 1. I personally prefer option 2. Given how verbose Java can be, I can understand why it might look pretty ugly to one line it. In C#, which is still more verbose than many languages, you get to use var keyword to help shorten things but Java has no such luck.
    // Java HashMap<String, String> map = new HashMap<String, String>(); // C# var map = new Dictionary<string, string>(); It's still not too bad when you're looking at it in an editor with syntax highlighting though so I still probably wouldn't break it up across two lines.
     
    If you have a large/complex method where things are declared all over the place, it might be useful to have the declarations grouped together somewhere but chances are you have bigger issues if that's the case.
     
    Stick to a style you like and be consistent. When working with a team it's useful to use a style guide as mentioned above.
  12. Agree
    madknight3 got a reaction from devilirium in Need help with a program   
    Python should be pretty simple. You have plenty of options to choose from to help you out.
    BeautifulSoup Scrapy lxml
  13. Agree
    madknight3 got a reaction from alex_read in Programming Brevity and Style   
    The goal isn't the least number of lines. Readability and consistency are bigger factors. Style guides can be useful for keeping everyone in sync so you don't have to worry about these little details. Sometimes reducing the number of lines can help readability, sometimes it can hurt it (complex one liners, etc).
     
    Your example is pretty trivial so I don't think it really matters much although I don't think you gain anything with option 1. I personally prefer option 2. Given how verbose Java can be, I can understand why it might look pretty ugly to one line it. In C#, which is still more verbose than many languages, you get to use var keyword to help shorten things but Java has no such luck.
    // Java HashMap<String, String> map = new HashMap<String, String>(); // C# var map = new Dictionary<string, string>(); It's still not too bad when you're looking at it in an editor with syntax highlighting though so I still probably wouldn't break it up across two lines.
     
    If you have a large/complex method where things are declared all over the place, it might be useful to have the declarations grouped together somewhere but chances are you have bigger issues if that's the case.
     
    Stick to a style you like and be consistent. When working with a team it's useful to use a style guide as mentioned above.
  14. Funny
    madknight3 reacted to fizzlesticks in Programming Brevity and Style   
    new is so 1998. 
    auto m = make_unique<map<string,string>>(); C++ really forces the second style for most stuff since
    map<string, string> map; isn't just declaring something. 
     
    Though I'm a fan of Python's way of declaring variables
       
  15. Informative
    madknight3 got a reaction from alex_read in Need help with a program   
    Python should be pretty simple. You have plenty of options to choose from to help you out.
    BeautifulSoup Scrapy lxml
  16. Agree
    madknight3 got a reaction from jslowik in Best Book to Learn Android Development   
    If this is your first language and you've never done any programming before then you'll probably want to just focus a little on Java first. You don't need to become an expert in Java before you move on, but it'll help to know the basics. You'll be diving into Android before you know it.
     
    Here are some Java resources to get you started.
    Head First Java (book) Java Tutorial for Complete Beginners (video course) More stuff (also includes an Android section)
  17. Agree
    madknight3 got a reaction from MatazaNZ in More C# Help ( YAY! )   
    Create some fields for your class to store the results.
    public partial class form_MulchCalc : Form { private double totalCubitFeet; private double totalCubicYards; private double totalPrice; // ... } Then add the results to these fields each time before displaying them.
  18. Agree
    madknight3 got a reaction from Nineshadow in Need help with making something O(logn)   
    I think he means that because the result can only be a 1 or a 2 then you can just choose one to output every time. Basically, return 1;
     
    edit: After reading the comment over again, I'm assuming you already understood what he meant so now I feel stupid for posting. Oh well, maybe it'll help someone else who doesn't get it... 
  19. Funny
    madknight3 got a reaction from prolemur in Need help with making something O(logn)   
    I think he means that because the result can only be a 1 or a 2 then you can just choose one to output every time. Basically, return 1;
     
    edit: After reading the comment over again, I'm assuming you already understood what he meant so now I feel stupid for posting. Oh well, maybe it'll help someone else who doesn't get it... 
  20. Like
    madknight3 got a reaction from alex_read in Need help with VB project   
    When it comes to string conversions, there's more than just the Convert.To methods as well which you alluded to but I'll explain below.
     
    The Convert.To methods (on strings) are simply adding a null check to the Parse methods.
    // Implementation of Convert.ToInt16 given a string (using dotPeek) // Sorry about the C#. dotPeek doesn't generate any VB code at this time public static short ToInt16(String value) { if (value == null) return 0; return Int16.Parse(value, CultureInfo.CurrentCulture); } public static short ToInt16(String value, IFormatProvider provider) { if (value == null) return 0; return Int16.Parse(value, NumberStyles.Integer, provider); } If this is the functionality you want, then go ahead and use it. If not, you'll want to choose another method. If you know the value can never be null, then just go ahead and use Parse. If you need to know the difference between input that is a valid, like "0", vs a null input, then Convert.To isn't what you want either.
     
    Since both Convert.To and Parse can throw exceptions on invalid input you'll need to handle those exceptions as well. One option is to wrap them in a Try/Catch. This can be useful if you need to handle specific exceptions in different ways, but many times you do the same thing no matter which exception is raised and the TryParse methods are specifically optimized to handle this task.
     
    tl;dr: In many cases you'll probably want to use TryParse over any other string conversion method.
  21. Agree
    madknight3 got a reaction from alex_read in Give me some ideas!   
    For algorithms, there are so many websites that will provide you with more than enough practice. Here's a list of them. There are of course more sites out there that aren't mentioned on the list (like CodeAbbey, Advent Of Code, etc) so feel free to look around for more (not that you'll need more).
     
    As for projects, there was a list of ideas done up on the forum here. Here is another big list of ideas.
     
    Since you're working with C#, and given your experience, you can probably learn the language, the .NET framework, and a UI framework at the same time.
    If you have any interest in web development you can learn the new ASP.NET version (was called ASP.NET 5 and now is being renamed to ASP.NET Core 1.0) or stick to ASP.NET 4.6 and MVC for the more traditional experience. If you want to work on Windows desktop apps you can go with the Windows Presentation Foundation (WPF). If you want to build cross platform apps you can look into the Universal Windows Platform and Xamarin. Or you can stick to the console app if you'd rather just focus on the language and .NET framework alone first.
  22. Informative
    madknight3 got a reaction from fizzlesticks in First N factorial numbers using recursion C   
    Look at your loop. Look at the variable you're passing to fact(). "n" never changes, it's "i" that changes.
  23. Like
    madknight3 reacted to Nineshadow in First N factorial numbers using recursion C   
    Better now?
    int n , factorial = 1; void fact(int i) { factorial*=i; printf("%i ",factorial); if(i<n)fact(i+1); } int main() { scanf("%i",&n); fact(2); }
  24. Agree
    madknight3 got a reaction from Nineshadow in First N factorial numbers using recursion C   
    That's fair. He gave you an example in C++, not C, so if you're not familiar with the C++ syntax I can understand the confusion.
     
    We are telling you how to do it.
     
    I hope that is clear enough for you. You literally only have to change 1 letter.
  25. Informative
    madknight3 got a reaction from MisterWhite in Do i need pathfinding for this?   
    Start with recursion.
×