Vui code để code đỡ bị dính bug khi code hơn

Hôm nay đang ngồi code nghịch để xa stress hết tuần này nên mình đăng cái code dạng này cho vui vui tí:

2 Likes

How cute!

//father of legendary programmer
if (((n - 2) <= 0 == false) && ((n - 2) > 0 == true)) {
 //code
}
4 Likes

How about:

//father of father of super duper ultimate programmer
if(Boolean.toString(Math.sqrt(4) > 2 && Math.log(100) > 2).equals("true") && Boolean.toString(Math.sqrt(4) < 2 && Math.log(100) < 2).equals("false"))
{
      //code
}

Chưa test

public class Main {
  public static void main(String[] args) {
    Rule minRule = new MinRule(2);
    List<Rule> rules = new ArrayList<>();
    rules.addRule(minRule);
    Validation validation = new Validation(rules);

    if (Validation.validate(2)) {
      // your business logic
    }
  }
}

class Validation {
  private List<Rule> rules;

  public Validation(List<Rule> rules) {
    this.rules = rules;
  }

  public void addRule(Rule rule) {
    if (!this.rules == null) {
      this.rules = new ArrayList<>();
    }
    this.rules.add(rule);
  }

  public boolean validate(int value) {
    for (Rule rule : this.rules) {
      if (rule.validate(value)) {
        return true;
      }
    }
    return false;
  }
}

interface Rule {
  public boolean validate(int value);
}

class MinRule implements Rule {
  private int min = 0;

  public void setMin(int min) {
    this.min = min;
  }

  public int getMin() {
    return this.min;
  }

  public boolean validate(int value) {
    return value > this.min;
  }
}
3 Likes

Chưa hết đâu nha(hơi ngắn):

//Intern
while(true)
{

}

//Junior
while(!false)
{

}

//Senior
while(true && !false)
{

}

//Pro
do
{

} while(true || !false || true && !false)

//Innovation
boolean running;
while(running == true && !running == false)
{
}

Cách quản lý file css:

Đơn giản vòng lặp game

public class Main {
  public static void main(String[] args) {
    GameLoop game = new GameLoopImpl();
    game.init();
    int result = game.execute();
    game.exit(result);
  }
}

abstract class GameLoop {
  public init() {
    this.onStart();
  }

  public void execute() {
    while (true) { // or event = this.nextEvent()
      this.onUpdate();
    }
  }

  public void exit(int result) {
    this.onDestroy();
    // ...
  }

  public abstract void onStart();
  public abstract void onUpdate();
  public abstract void onDestroy();
}

class GameLoopImpl extends GameLoop {
  public void onStart() {
    // ...
  }

  public void onUpdate() {
    // ...
  }

  public void onDestroy() {
    // ...
  }
}
1 Like

#define true false
if (true) { ... }

MUAHAHAHAHAHAHAHAHAHAHAHAH

3 Likes

if(Boolean.toString(null).equals("!true") !! Boolean.toString(null).equals(“false”))
{

}

MUAHAHAHAHAHAHAHA x100

Toàn mấy pác dùng dao mổ trâu giết gà =))))))

1 Like

Mình số 4. Công lực mạnh v…c…l…z :))

//Noob
while(true) {
    //code here
} 

//======================================

//Classical
while(!false) {
    //code here
}

//======================================

//God of the gods 
for (;;) { 
    //code here
}

//======================================

sao không:

//god of the Kratos :))
#define ever (;;);

for ever 
{
    //code here
}
1 Like

Code kiểu này là dễ bị dính bug hơn! Làm game thì code càng tường minh càng tốt, ko thì tới lúc debug & profiling khóc ròng!

1 Like

Vui là chính mà anh! :smile: Cái này là để làm cho mục đích gây cười chứ không thực tiễn gì mấy. Dù sao sorry vì em biết anh hơi nghiêm túc

2 Likes

Anh nghiêm túc nhưng anh làm dc, và sự thật là anh chưa thấy ai trong diễn đàn này làm game ra ngô ra khoai cả nên mới khuyên thế! Tụi em suy nghĩ thêm nhé!

2 Likes
// Source : https://gist.github.com/lolzballs/2152bc0f31ee0286b722
// Nể ông làm ra cái này :wink:
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

public class HelloWorld{
	private static HelloWorld instance;
    public static void main(String[] args){
        instantiateHelloWorldMainClassAndRun();
    }
    
    public static void instantiateHelloWorldMainClassAndRun(){
    	instance = new HelloWorld();
    	
    }
    
    public HelloWorld(){
    	HelloWorldFactory factory = HelloWorldFactory.getInstance();
    	IHelloWorld helloWorld = factory.createHelloWorld();
    	IHelloWorldString helloWorldString = helloWorld.getHelloWorld();
    	IPrintStrategy printStrategy = helloWorld.getPrintStrategy();
    	IStatusCode code = helloWorld.print(printStrategy, helloWorldString);
    	if(code.getStatusCode() != 0){
    		throw new RuntimeException("Failed to print: " + code.getStatusCode());
    	}
    }
}

class StringFactory{
	private static StringFactory instance = new StringFactory();
	public static StringFactory getInstance(){
		return instance;
	}
	public HelloWorldString createHelloWorldString(String str){
		HelloWorldString s = new HelloWorldString();
		s.s = str;
		return s;
	}
}

class PrintStrategyFactory{
	private static PrintStrategyFactory instance = new PrintStrategyFactory();
	public static PrintStrategyFactory getInstance(){
		return instance;
	}
	public IPrintStrategy createIPrintStrategy(){
		IPrintStrategy printStrategy = new PrintStrategyImplementation();
		IStatusCode code = printStrategy.setupPrinting();
		if(code.getStatusCode() != 0){
			throw new RuntimeException("Failed to create IPrintStrategy: " + code.getStatusCode());
		}
		return printStrategy;
	}
}

class PrintStrategyImplementation implements IPrintStrategy{
	private OutputStream print;
	public IStatusCode setupPrinting() {
		try{
			FileDescriptor descriptor = FileDescriptor.out;
			print = new FileOutputStream(descriptor);
			return new StatusCodeImplementation(0);
		}
		catch(Exception e){
			return new StatusCodeImplementation(-1);
		}
	}
	public IStatusCode print(IHelloWorldString string) {
		try{
			print.write(string.getHelloWorldString().getHelloWorldString().concat("\n").getBytes("UTF-8"));
			return new StatusCodeImplementation(0);
		}
		catch(Exception e){
			return new StatusCodeImplementation(-1);
		}
	}
	
}

class StatusCodeImplementation implements IStatusCode{
	private int code;
	public StatusCodeImplementation(int code){
		this.code = code;
	}
	public int getStatusCode() {
		return code;
	}
}

class HelloWorldString{
	String s;
	public String getHelloWorldString(){
		return s;
	}
}

class HelloWorldStringImplementation implements IHelloWorldString{
	public HelloWorldString getHelloWorldString(){
		StringFactory factory = StringFactory.getInstance();
		HelloWorldString s = factory.createHelloWorldString("Hello, World!");
		return s;
	}
}

class HelloWorldFactory{
	private static HelloWorldFactory instance = new HelloWorldFactory();
	public static HelloWorldFactory getInstance(){
		return instance;
	}
	public IHelloWorld createHelloWorld(){
		IHelloWorld helloWorld = new HelloWorldImplementation();
		return helloWorld;
	}
}

class HelloWorldImplementation implements IHelloWorld{
	public IHelloWorldString getHelloWorld() {
		IHelloWorldString string = new HelloWorldStringImplementation();
		return string;
	}
	public IPrintStrategy getPrintStrategy() {
		PrintStrategyFactory factory = PrintStrategyFactory.getInstance();
		return factory.createIPrintStrategy();
	}
	public IStatusCode print(IPrintStrategy strategy, IHelloWorldString toPrint) {
		IStatusCode code = strategy.print(toPrint);
		return code;
	}
}

interface IHelloWorldString{
	public HelloWorldString getHelloWorldString();
}
interface IHelloWorld{
    public IHelloWorldString getHelloWorld();
    public IPrintStrategy getPrintStrategy();
    public IStatusCode print(IPrintStrategy strategy, IHelloWorldString toPrint);
}
interface IStatusCode{
	public int getStatusCode();
}
interface IPrintStrategy{
	public IStatusCode setupPrinting();
	public IStatusCode print(IHelloWorldString string);
}

Hello world enterprise edition :laughing:
Mới đầu có thể không hiểu, nhưng sau khi đi làm thì tẩu hoả nhập ma ngay :laughing:

2 Likes

Topic có category fun anh ơi!
Vui vẻ cho đời nó tươi, nghiêm túc quá không tốt đâu anh :laughing:

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?