Jump to content
Science Forums

Programming


Recommended Posts

First of all that is not the direction that the original question was asking, the original question was asked from the genetic programming, not network-based applications. Second of all if you say that Java deals with wider range of networking applications than Python, you obviously dont know Python, do you? Anything you do in java concerinig both of these applications is very much doable in Python...

Ok… First I know that the question didn’t mention network-based applications, but I was making a general statement about JAVA in here, considering that no one took it in consideration even as a good programming language. Second I know Python and I didn’t say it’s not good, I just said that I prefer JAVA and this is fair.

 

just wondering by what you meant when you said "so secure"?

This means that it's optimal for users who really are not into security issues, as JAVA make some constraints on the code preventing it from getting deep in the system, this may be viewed as inflexibility, but still, some programmers don’t need this kind of flexibility.

 

for who? a person wh knows very little about programming, yeah I'm sure that having to create a class to do any simple task is very easy for beginner programmers to grasp... Besides the fact that you have to use OO everywhere you go in Java, the synthax is very, very similar to that of C++, and that is pretty cryptic and discombobulating.

Python on the other hand was created to teach people how to program right, how to propperly tab in your code; it teaches and promotes good programming practices!

sure! It’s not difficult to learn at all, and once its learnt it becomes a lot easier for beginners to learn other programming languages, besides I don’t see it cryptic.

Again… Python is a good choice but it’s not the only choice.

 

I don’t believe in “ best programming language” concept, this is why I said I preferred JAVA, but I didn’t say that it was perfect or any near to be so, Python is not perfect either, every language serves in a particular field better than the other, even c, c++, and it just happens that I like assembly too, it’s just the purpose of the application that implies the choice of the programming language to use.

 

P.S. sorry to snap like that, its just that Java has its applications, but not in teaching people how to program nor genetic programming...

P.P.S. welcome to the forums :friday:

Still JAVA is one of the good programming languages out there :eek:

 

Thanks for welcoming me

Link to comment
Share on other sites

sure! It’s not difficult to learn at all, and once its learnt it becomes a lot easier for beginners to learn other programming languages, besides I don’t see it cryptic.

Again… Python is a good choice but it’s not the only choice.

 

not difficult to learn? first of all the concept of classes in c++ is not taught until all the procedural programming is out of the way and students have played enough with the language to learn object orientation concepts of programming, and even then many people take a long time to adapt and understand what is happening, where and why, i'm sure that for a person never introduced to programming, getting the grasp of the reason you have to create a class in order to print out a line is very easy.

once its learnt it becomes a lot easier for beginners to learn other programming languages
i absolutely agree, and once you learn assembly, java is a piece of cake as well, so perhaps we should recommend learning assebly, but wait, if you know binary, assembly is a piece of cake too, so try to start with binary, and then you can learn any language.
Link to comment
Share on other sites

i absolutely agree, and once you learn assembly, java is a piece of cake as well, so perhaps we should recommend learning assebly, but wait, if you know binary, assembly is a piece of cake too, so try to start with binary, and then you can learn any language.

 

well well well !, I think you misunderstod what I said, the "its" in the paragraph refers to JAVA, not to assembly, assembly was mentioned in the next paragraph, as an example of the importance of every language on its own.

besides, who said that you can learn assembly if you learn binary, this is the most strange thing I've ever heared, assembly is a powerful language maybe but only in some fields, never mind, I really meant JAVA in the first paragraph.

Link to comment
Share on other sites

try teaching an object oriented language to someone who only knows assembly, it's not as easy as you think.

thank you so much for figuring out the point i was trying to make rocky, and if there is only one thing i can think of to add to that, it would be, try teaching object oriented programming to people who dont know how to program period...

refers to JAVA, not to assembly

oh trust me, i understand exactly what you said in that paragraph, i was being sorcastic...

can learn assembly if you learn binary

Because after binary, using words insteda of binary operations with 0'z and 1's is that much easier, and you are employing all the similar concepts, cince assembly was built to mimic binary, but it uses words instead of hex or binary that you might use to write binary (with hex it's obvious that you will need a program to convert it to bin). And here is how the lineage traces to Java... ok so I've established that assembly is easy once you know binary, then you have C, which is the next level up from Assembly, and is once again easier than binary because instead of saying take this memory location and add it to that one and store result in the third one, you can now do c=a+b, and there are predefined functions that allow you to print characters to the screen without having to send signals to the monitor to light up those special pixels, in other words its a higher level language. The foundation of C will allow you to quickly progress through C++, which is a bit different and allows object orientation, but objects are just C structs with functions, easy enough, polymophism allows to solve problems with naming in C and so forth. The foundation of C++ ateches you about 90% of Java already, the synthax is similar, there are just a few different libraries which were unavailable before to do more things a little more automated, and a java virtual machine that takes up over a hundred megs of space once started... do you want me to continue to pascal or basic or something?

 

ok so why do i say that java is not a great language to start with, basically because while java allows for this:

package hirondelle.web4j.webUtil;

import javax.servlet.ServletConfig;
import java.util.Properties;
import java.util.logging.*;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.AddressException;
import javax.mail.internet.MimeMessage;
import hirondelle.web4j.util.Args;
import hirondelle.web4j.util.Util;

public final class Mailer {
public static void init(ServletConfig aConfig){fConfig = aConfig;}

public static boolean isValidEmailAddress(String aEmailAddress){
if (aEmailAddress == null) {return false;}

boolean result = true;
try {
InternetAddress emailAddr = new InternetAddress(aEmailAddress);
if ( ! hasNameAndDomain(aEmailAddress) ) {result = false;}}
catch (AddressException ex){result = false;}
return result;}
 
public void send(String aToAddress, String aSubject, String aBody){
Args.checkForContent(aSubject);
Args.checkForContent(aBody);
if ( isMailDisabled() ){fLogger.fine("Mailing is disabled."); return;}
   
Session session = Session.getDefaultInstance( getMailServerConfig(), null );
MimeMessage message = new MimeMessage( session );
try {
message.setFrom( new InternetAddress(new Webmaster().getEmailAddress()) );
message.addRecipient(Message.RecipientType.TO, new InternetAddress(aToAddress));
message.setSubject( aSubject );
message.setText( aBody );
Transport.send( message );
}
catch (MessagingException ex){fLogger.severe("CANNOT SEND EMAIL." + ex);}
fLogger.fine("Mail is sent.");
}

private static ServletConfig fConfig;
private static final String fMAIL_SERVER = "MailServer";
private static final String fNONE = "NONE";
private static final Logger fLogger = Logger.getLogger(Mailer.class.getPackage().getName());  

private String getMailServer(){return fConfig.getInitParameter(fMAIL_SERVER);}

private boolean isMailDisabled(){
return getMailServer().equalsIgnoreCase(fNONE);
}

private Properties getMailServerConfig(){Properties result = new Properties();
result.put("mail.host", getMailServer() ); return result;}

private static boolean hasNameAndDomain(String aEmailAddress){
String[] tokens = aEmailAddress.split("@");
return 
tokens.length == 2 && 
Util.textHasContent( tokens[0] ) && 
Util.textHasContent( tokens[1] ) ;
}
}

 

python will look like this:

#!/usr/bin/python2

import smtplib, mimetypes, string, email, os
from email.Encoders import encode_base64
from email.MIMEText import MIMEText
from email.MIMEAudio import MIMEAudio
from email.MIMEMultipart import MIMEMultipart
from email.MIMEImage import MIMEImage
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase

class SimpleMessage:             
       
   def __init__(self):
       self._files = []

   def AttachFile(self, fullname):

if not fullname in self._files:
self._files.append(fullname)
           return 1
       else: 
return 0

   def DetachFile(self, fullname):

if fullname in self._files:
           return self._files.pop(self._files.index(fullname))
       else: 
return 0

   def To(self, s):
 
if type(s) == type([]):
           self._to = s
       else:
           self._to = s.split(',')

   def Sender(self, s):
       self._sender = s

   def Subject(self, s):
       self._subject = s

   def Body(self, s):
       self._body = s

   def _prepletter(self):
       outer = MIMEMultipart()
       outer['Subject'] = self._subject
       outer['To'] = string.join(self._to, ',')
       outer['From'] = self._sender
       outer.preamble = 'MIME Message'
       outer.epilogue = ''

       body = MIMEText(self._body)
       outer.attach(body)

       for eachfile in self._files:

ctype, encoding = mimetypes.guess_type(eachfile)

if ctype is None or encoding is not None:
               ctype = 'application/octet-stream'
           maintype, subtype = ctype.split('/', 1)
           f = file(eachfile, 'rb')

if maintype == 'text':
inner = MIMEText(f.read(), _subtype=subtype)
            elif maintype == 'message':
               inner = email.message_from_file(f)
           elif maintype == 'image':
               inner = MIMEImage(f.read(), _subtype=subtype)
           elif maintype == 'audio':
               inner = MIMEAudio(f.read(), _subtype=subtype)
           else:
               inner = MIMEBase(maintype, subtype)
               inner.set_payload(f.read())
               encode_base64(inner)
           f.close()

inner.add_header('Content-Disposition', 'attachment', filename=os.path.basename(eachfile))
outer.attach(inner)

       return outer.as_string()

   def Send(self, host='localhost', u='', p=''):
       if not self._to:
           print "No recipients specified."
           return 0

       sendtext = self._prepletter()        
       server = smtplib.SMTP(host)
       
if u:
           server.login(u, p)            

       try:
           server.sendmail(self._sender, self._to, sendtext)
           server.quit()
       except:
           return 0
           
       return 1

yes, yes i know that they are not exactly the same, but i have no time to actually make sure that they are, there is no input checking in this python program, again, did not have the time nor want to write both of these...

 

My point after all of this is that Java is just not a good beginners language, teaching java to beginner programmers is like throwing someone in the middle of the Ontario to teach them to swim (without any kind of a life preserver, because java could use more documentation), and although it might work for a few people, most will drown and will turn away from programming forever...

 

Oh, P.S. I could not propperly space that python code, so it will not propperly execute, but you can at least get the idea..., if you want a real (working) version of the code pm me or post or something...

Link to comment
Share on other sites

That's not really a fair comparison of the *languages* themselves: I find both snippets equally obtuse. But I'll point out a key issue which is that exception handling was an afterthought in all of the C-descended languages, and I *hate* try-catch. In my own code I tend to try to bury calls to the outside that do try-catch at the lowest levels of implementation which makes the code cleaner. It makes you wonder why library writers can't do that coding for you: I'd be happy to pass a few more parameters for timeout and such just to keep the garbage out of my code. Looks like the python folks have started to address this problem, but I don't think it has to do with the language.

 

Cheers,

Buffy

Link to comment
Share on other sites

its just an example buffy, you can see though how Java allows for bad programming practices, no definitive style, spacing... etc

I never said that you can not write clean code with Java that makes sense and does not use bad programming practices, its just almost a necessity with Python, otherwise the code wont execute propperly, and that is what you need to teach people who dont know any better and are just starting to do any kind of programming...

Also you can spealk with something like over 20 years of programming experience, I'm sure you've defined your style and come to liking certain ways of doing things more than others...

Link to comment
Share on other sites

With everyone using syntax directed editors, I'd actually argue that that is a moot point, EXCEPT if you're generating code on the fly, then if your language is sensitive to spacing, you're going to have more errors to deal with!!!! That, I think is the one hole in Python, and if I were writing a compiler for it, i'd loosen that restriction! It does force people to "code properly" but I don't think its a good feature. Java, C++, VB, all mine are properly spaced and indented thanks to the editors I use that force these formatting conventions...Just because you only use the bare-bones free open source compilers doesn't mean the rest of us write hard to read code, cuz we use the fancy ($$) development environments that take care of it just like the Python tools do....

 

Cheers,

Buffy

Link to comment
Share on other sites

EXCEPT if you're generating code on the fly, then if your language is sensitive to spacing, you're going to have more errors to deal with!!!!

I dont know about you, but i find myself making more errors in C++ then i do in Python, mainly because of brackets, parentheses and semicolons...

Link to comment
Share on other sites

I dont know about you, but i find myself making more errors in C++ then i do in Python, mainly because of brackets, parentheses and semicolons...
Ha ha! You betcha! Use a syntax directed editor! Or use vi with "set showmatch" set! Can you imagine what it was like in the old days when Lisp did not yet have the "]" as "close all open ('s? Good ol' showmatch saves the day!

 

I don't have enough experience with Python yet to make a judgement call, and I speciallize in languages so I'm not a good test subject anyway...

 

Cheers,

Buffy

Link to comment
Share on other sites

vi is really depricated...
PPppppbbbbbtttt! Not for us old-timers... I still *think* in vi. Yes, its baroque, and emacs is better, but you'll pry it from my cold dead fingers....

 

ypypyp:1,$s/shme/frobnitz/g,

Buffy

Link to comment
Share on other sites

vi is really depricated, i use emacs with my .emacs script, and vim if i'm logged into someone elses box...

that is what i was hinting on...

Yeah, let me see you put emacs on your emergency boot floppy. I've even fixed many an NT box with a linux boot floppy and vi, especially lost admin passwords ;)

Link to comment
Share on other sites

Yeah, let me see you put emacs on your emergency boot floppy. I've even fixed many an NT box with a linux boot floppy and vi, especially lost admin passwords

 

umm, C1ay, I dont use dinasour-aged computer storage media, such as floppies... i have an emergency live cd (and a knoppix, 3.7, but i'll eventually get around to burning a 3.8) that has all the software you can possibly need to recover anything, and with gentoo live 2005.0 you can install software if you need to, while running off of a cd, which is pretty amazing. But both Knoppix and Gentoo live come with nano, vim and emacs, so whatever you prefer to use, is there anyways, no .emacs script though, but i might customize one of those to fit my need...

 

actually this has been a dream for a while:

ok, you install the OS on a PC thats on 24/7, all your folders and everything is on there, files, and it even boots... then you create a live cd, with automagic hardware detection, but all the filesystems, except for swap would be mounted via nfs on the server that you have, that way, you need a tiny cd to fit the kernel, and your files are with you no matter where you go, its just a matter of opening the CD drive, popping in the cd and rebooting the machine, and voila, you have yourself your machine anywhere you go, as long as there is a x86 computer available, you are all set...

Link to comment
Share on other sites

umm, C1ay, I dont use dinasour-aged computer storage media, such as floppies...

If you ever start doing any on call service you might need to change that philosophy. There's still a lot of boxes out there where a boot floppy is convenient. I'd simply use a bootable USB drive as a preference except that many BIOSes don't support booting from it. You never know what someone will ask you to work on. Heck, there's still a Win95 box here with legacy data and software that I have to maintain just for old workorder lookups from an era gone by :eek:

Link to comment
Share on other sites

well, i think that windows 95 boxes still have cdrom drives, so its not a problem to carry a cd with me, if i was ever to be in the service (but i would never join GeekSquad, you go around and reinstall windows, and bill people for it, it immoral and sad...(well, you might, every once in a while setup a network or even a wireless network, but its still windows, so, uuuugh, i wont do it, i cant look into someone's eye and say, yup your network is all set and secure, if i know that a 14 year old script kiddie can get into any of the boxes or steal their net with no problems))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...