Jump to content

Yamoto42

Member
  • Posts

    235
  • Joined

  • Last visited

Reputation Activity

  1. Informative
    Yamoto42 got a reaction from BuckGup in Generics in Java   
    Yeah, the big problem with generics in Java is type erasure.

    Simply put, type parameters are effectively lost at runtime...and it can really messes with overloading and reflection.
    What you actually get from the compiler is something like:
    // This is your code public class GenericExample<T> { private T myVar; public T getVar() { return myVar; } public void setVar(T var) { myVar = var; } static main(String ... args) { GenericExample<MyOtherClass> tmp = new GenericExample<>(); MyOtherClass var = 1; tmp.setVar(var); var = tmp.getBar(); } } // This is what the compiler actually compiles public class GenericExample { private Object myVar; public Object getVar() { return myVar; } public void setVar(Object var) { myVar = var; } static main(String ... args) { GenericExample tmp = new GenericExample(); MyOtherClass var = 1; tmp.setVar(var); // Because of compile time checking, there may not be a hard type check here. var = (MyOtherClass)tmp.getBar(); } } You will notice that the compiled class looses its reference to T.  Type restrictions are also solved by inserting casts.
    // Example classes public interface Customer { boolean likesSpam(); } public class GrahamChapman implements Customer { public boolean likesSpam() { return false; } } // What you wrote public class Server<T extends Customer> { private T myCustomer; public Server(T customer) { myCustomer = customer; } public String getBreakfast() { if (!myCustomer.likesSpam()) return "Spam"; else return "Eggs"; } public static main() { Server<GrahamChapman> eric = new Server<>(new GrahamChapman()); String meal = eric.getBreakfast(); } } // What gets compiled public class Server { private Object myCustomer; public Server(Object customer) { myCustomer = customer; } public String getBreakfast() { Customer tmp = (Customer)myCustomer; if (!tmp.likesSpam()) return "Spam"; else return "Eggs"; } public static main() { Server eric = new Server(new GrahamChapman()); String meal = eric.getBreakfast(); } } You'll see again, the type itself looses the actual type information, and the compiler just inserts cases where needed.

    Without getting into too much detail about dynamic dispatch, a good example of a side effect are the types Collection<Double> and Collection<Integer>:  Or more specifically the singular type Collection.
    public class TypeErasureExample { public double sum(Collection<Double> values) { ... } public int sum(Collection<Integer> values { ... } } Because generics are implement as type Object, then cast to T, the original type T is not stored as part of the type.  Ergo, if the above were allowed to compile the runtime would see:
    public class CompiledTypeErasure { public double sum(Collection values) { ... } public int sum(Collection values) { ... } } And (as return types are not part of a method signature in Java) not know what method to actually call.
  2. Agree
    Yamoto42 reacted to Enderman in Making your own super simple OS??   
    That's like asking how to build a super simple nuclear fusion reactor.
     
    First learn programming, then get a university degree, then get a masters or Ph.D and you should be able to build a simple operating system.
  3. Agree
    Yamoto42 reacted to bowrilla in Any Good Websites with C++ or System Language?   
    Sure, node.js has some issues and bugs. So has every single piece of code out there that reached a certain scale. There are Buddha knows how many bugs in all OS out there that'll make them crash or are open for attacks. The bug got fixed. And I'm with the dev team on this one: you shouldn't rely on your service running without a backup and a load balancer for weeks or even months. I know of too many services that get funny after a while and they need a reboot to free up resources. 
     
    Considering your claims: Well … no. C# is being brought to other systems but it's mainly Windows only. You can use Xamarin to get your code to other platforms but it's not MS/Visual C# anymore because that is developed with .Net in mind and Xamarin ports it … which takes time. If you want to make apps for iOS and Android that match the look and feel of those platforms you still need platform specific code. Third party libraries have compatibility issues and graphic heavy stuff is basically out of the question.
     
    Delphi – well in most parts of the worlds it's pretty dead.
     
    Java is not a straight compiled language, it runs in a runtime enviroment so it's not native. And you make it sound as if you just use C or C++ and your app runs on all systems. That might be true for a program of hello world complexity but as soon as you have a gui it gets tricky – unless you want to use some libraries or frameworks like qt but those you already did dismiss before. And then there's the look and feel again. If you're ok with qt's look and are willing to make an exception from your "no third party libraries" rule then sure, it's an option. It has its very own issues again though. 
     
    And are you really telling me that you'd trust a dev that claims to be an expert for iOS, Android, Windows, macOS and Linux development? An expert meaning really knowing a system, its architecture, system calls and so on? I wouldn't because that's hardly possible. You might find a dev who focused on cross platform solutions but he or she will surely struggle to get the best performance out of it. I'm not saying it's impossible but if performance is so utterly damn important than you surely don't want to compromise by making a choice solely based on cross platform compatibility. 
     
    The thing is: you just don't like web technologies and are making an emotional decision you can't really back with hard facts. Nobody is denying that native apps have advantages but its more work to deploy your app on different systems and keeping them running. If performance is a number one priority then there's hardly a way around, I agree. If it itsn't since your logic is just not that resource hungry then you're wasting time and therefore money by not going the web technology route. If your clients are willing to pay the extra, good for you. I surely wouldn't if I didn't need to.
  4. Agree
    Yamoto42 reacted to Praesi in Pre order cancelation   
    The Day i preorder Hardware is the Day Hell will freeze.
  5. Informative
    Yamoto42 reacted to Master Disaster in Supreme Court Nominee: ISPs have 1st Amendment right to block websites   
    Do you even know who he is?
     
    He invented HTTP and is the current leader of the W3C, his job is to oversee and approve the development and standardisation of WWW protocols.
     
    I feel you need a bit of a lesson in computing history tbh.
     
    The Internet was invented by the US military and federal government in the 60s though it was originally called ARPANET and was intended to allow computers from different military academies and universities to talk to each other.
     
    By the early 80s ARPANET was in use by lots of business and private entities so during the 80s a push was made to unify all the separated networks into a single conjoined network called NSFNET.
     
    By the early 90s NSFNET had evolved into what we call the modern internet, while it was still mostly only used by business and academia it was using TCP/IP and had spread worldwide.
     
    By the mid 90s things had changed, public PC ownership was growing hugely and the public were all logging onto BBs to share data and talk to each other.
     
    While this growth was happening Lee was working at MIT, he'd had the idea for
    HTTP back in 89, had presented the paper in 90 and by 91 was employed at MIT developing his idea.
     
    By 95 when BBs were hugely popular across the world Lee founded W3C at MIT and presented HTTP as a way of standardising internet communications, within a year HTTP had taken and by 1997 HTTP/1.1 was accepted as the industry standard.
     
    To this day he is responsible for accepting protocol changes to the standard he invented and I guarantee you nobody on the face of the planet knows more about how the world wide web works than he does.
  6. Agree
    Yamoto42 reacted to Master Disaster in Supreme Court Nominee: ISPs have 1st Amendment right to block websites   
    Tim Berners Lee is 63, you going to argue he doesn't understand the internet too?
  7. Like
    Yamoto42 got a reaction from Beskamir in most used non-OOP lanuage?   
    I've heard convincing arguments for Excel considering how much of the world is run by spreadsheets...
  8. Agree
    Yamoto42 reacted to Mira Yurizaki in Does programming languages prefer higher clocked CPUS with less cores or more cores just a lower clock speed?   
    Taking the question at face value, the programming language itself doesn't care about what hardware you have in the system.
     
    Otherwise the applications you build from said languages depending on faster IPC or more cores is highly dependent on how you program it. You can program a single core application or a multicore one. Often times there's no free lunch either, you must explicitly program for multicore applications.
     
    If you're getting into programming and you're fresh at this, it matters zero if you get something with higher IPC or core counts because anything you usually make in those starting days could run on an Atom and you wouldn't notice a difference.
  9. Agree
    Yamoto42 reacted to Beskamir in Which code language to learn?   
    I would suggest C# or Python. C# is basically Java done well but is tied to Microsoft. Python is easier to setup and potentially easier to learn however it's somewhat different from the C like appearance (functionality is more or less the same, just slightly different syntax for things) of most useful languages so it'll be a bit more annoying to switch to something more C like later.
  10. Agree
    Yamoto42 got a reaction from ScratchCat in Is this encryption method secure?   
    It's not just that per se, as that is itself ultimately rooted in the bootstrap problem of cryptography.

    Much like how people call TCP reliable, yet it is absolutely 100% impossible to create a reliable transport protocol on top of an unreliable medium.  It is literally impossible to establish a secure channel within an insecure medium.
     
    Therefore we "solve" the problem of impossibility by bypassing the medium entirely at the start of the process (ie. sysadmins externally deciding to mutually trust a CA).  As you note, it is not a true solution, but it is the best approximation we have been able to come up with so far to a truly impossible problem.
  11. Agree
    Yamoto42 got a reaction from leodaniel in Is this encryption method secure?   
    Yeah...rule 1 of cryptography:  Don't do it yourself.
  12. Agree
    Yamoto42 reacted to leodaniel in Is this encryption method secure?   
    Not really, you need just a trusted 3. Party, like a certificate authority... or a pre shared key... it's basically what you solve with SSL/TLS... you have a trusted 3. Party. Then you can check if the given message really comes from your server and was not intercepted. This of course requires, that you can trust the certificate authority... if thats the case, you re save  
     
    By the way, two factor authentication has nothing to do with transmission security  
  13. Agree
    Yamoto42 reacted to JacobFW in Is this encryption method secure?   
    Not really.  That's a fairly realistic scenario, at pretty much both ends of the spectrum.  On one end at the higher security levels, you have the private keys being generated inside a Faraday cage inside a vault by a computer not hooked up to any network.  Both the people who work for the Certificate authority and the people who are buying the certificate are present.  The keys are generated, stored on a hard drive which is then given to the buyers, who then take it to their own server.  On the other hand (this is not as common anymore) you have people who meet and share their PGP keys in person so they can safely transmit files between each other.  
     
    It's all about channels of communication.  If we restrict ourselves to only trying to establish a secure channel via digital means, then security is just a myth.  There is too little information to provide proper authentication.  When you buy a computer or a windows install disk/drive which again, comes preloaded with certificates, that is a physical channel of communication.  
  14. Like
    Yamoto42 got a reaction from Mira Yurizaki in C Programming   
    This.   The fundamental concept of Turing completeness.
  15. Like
    Yamoto42 got a reaction from mackncheesiest in C Programming   
    This.   The fundamental concept of Turing completeness.
  16. Agree
    Yamoto42 reacted to Mira Yurizaki in C Programming   
    Wow this got heated.
     
    Though I did see the whole "C teaches you how computers work." But I fail to see how this is important from a general software development standpoint. Other than a super high-level explanation of "a computer is going to do exactly what you tell it" (which actually isn't even the case anymore), there's not much else you really need to know about how a computer works. If your problem solving requires extreme high performance, then sure, you can start poking into how your computer architecture of choice works. But if all you want to do is write bash scripts, then does it matter if the computer is RISC or CISC? Is Von Nuemann or Harvard? If you're speaking to Intel or ARM?
     
    All in all, software development is solving a problem. Design your software soundly first before worrying about the implementation.
  17. Agree
    Yamoto42 reacted to Unimportant in C Programming   
    Defining a string literal that way is considered bad practice, it should be:
    const char *s = "Hello world!"; //(1) char s[] = "Hello world!"; //(2) Note that the explicit 0 terminator is not necessary. It is implicitly included by the compiler.
    "Hello World!" is a string literal, part of read only storage. By assigning it to a non-const pointer, as in your example, you can (accidentally) modify the string which leads to undefined behavior due to writing to RO memory. You'll probably get a segfault. Some compilers also warn about deprecated assigning of string literals to non-const pointers because of this.
     
    Either make it a const pointer (1) which will catch any (accidental) attempts to modify the string at compile time or make it a array (2) which allows for modifying the string because arrays are normal variables in RW memory.
  18. Like
    Yamoto42 reacted to Sebivor in C Programming   
    Don't what?

    Don't discourage someone from taking the same path I took, and realising how much of a mistake it was five years later?

    Python and Javascript have no undefined behaviour. That is the significant issue here. Anyone who argues against that point doesn't know C or is trying to engage in psychological warfare.

    Have you ever had a problem which seemed to go away for some strange reason, like, you comment out an unused variable and the code starts crashing? Undefined behaviour... Tell me, how long did it take you to learn about the cause? Two hours, if you're lucky? Two weeks, if not? Perhaps you never even see your undefined behaviours!

    It could go unseen for years, like the Heartbleed bug, which constitutes a security vulnerability (hello, undefined behaviour!)... Or it could instill misinformation into the student; for example, students commonly analyse `printf("%d", x++, x, ++x);` to try to determine the order of operation, and expect that analysis to be true well into the future...

     


    It could be justified, "well, C isn't a portable language, after all". No. C is portable. Undefined behaviour is not. C does not define the undefined behaviour. You get no guarantees from the C standard, when you invoke undefined behaviour. It might "work", whatever that means, as expected for mny years, and then break for any reason or no reason at all.
  19. Like
    Yamoto42 got a reaction from Sebivor in C Programming   
    This.   The fundamental concept of Turing completeness.
  20. Agree
    Yamoto42 reacted to Sebivor in C Programming   
    By binding speed to the language, you're saying all existing C implementations are equally fast (they're not, and this is provable).

    You're also stating that because most implementations don't perform bounds checking, all implementations must not perform bounds checking...

    That or you're stating that the bounds checking has no overhead, because all implementations of C are equally fast, apparently...

    Don't you see the flaw in your logic? The perceived speed is bound to your system, to your implementation, but isn't required by others.

    Similarly, some implementations have bounds checking, and are permitted to do so because... undefined behaviour... the behaviour is undefined... they're free to do that...

    ... and so undefined behaviour doesn't necessarily make a language fast!

    Imagine if someone asked you which is faster: French or English... It depends on who is speaking/writing/hearing/reading it, right?

    Speed is bound to the implementation, NOT the language!
  21. Informative
    Yamoto42 got a reaction from Sebivor in C Programming   
    @Sebivor  You can't convince a true believer.  If they can't see the inherent contradiction in saying Turing complete languages operate at different speeds when the fundamental core of Turing completeness is recursive equivalency...
  22. Like
    Yamoto42 got a reaction from Unimportant in C Programming   
    @Unimportant And I do agree as a rule of thumb.

    J = C+x && J = C <-> x = 0

    But the C STANDARD does not guarantee x=0, or that x > 0, or x < 0.  Undefined literally means we know nothing about x.  It could be negative, making C slower for all the language should assume.

    And you'd have to be a certain kind of stupid to use an implementation of C where x<=0...which is while it's not TECHNICALLY correct, I do agree in general.
  23. Agree
    Yamoto42 reacted to Unimportant in C Programming   
    Just a nitpick but undefined behavior is only applicable when your program does certain things it should not be doing in the first place. A correctly written program never invokes undefined behavior so everything is defined.
  24. Like
    Yamoto42 got a reaction from Slickrr13 in How many built-in classes does C# have?   
    I reckon 'bout a few.
  25. Like
    Yamoto42 got a reaction from Dat Guy in The great language debate !!!   
×